function checkTerms()
{
    if(!document.ispa.confirm_read_tc[0].checked)
    {
        DoChanges(5);
        alert("You must read the Terms and Conditions and confirm your acceptance");
        return false;
    }
    else
        return true;
}

function checkServiceDetails()
{
    var errorFlag = false;
    var errorMessage = "";
    if (document.ispa.dedicatedhosting_award.checked)
    {
        if (document.ispa.dedicatedHostingMarketName.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Dedicated Hosting Product Name must be entered\n";
        }
    }
    if (document.ispa.sharedhosting_award.checked)
    {
        if (document.ispa.sharedHostingMarketName.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Shared Hosting Product Name must be entered\n";
        }
    }    
    if (document.ispa.consumerFixedbbBox.checked)
    {
        if (document.ispa.consumerFixedbbText.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Consumer Fixed Product Name must be entered\n";
        }
    }
    if (document.ispa.businessFixedbbBox.checked)
    {
        if (document.ispa.businessFixedbbText.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Business Fixed Product Name must be entered\n";
        }
    }  
    if (document.ispa.mobilebbBox.checked)
    {
        if (document.ispa.mobilebbText.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Mobile Product Name must be entered\n";
        }
    }
    if (document.ispa.internettelephony_award.checked)
    {
        if (document.ispa.internettelephonyMarketName.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Internet Telephony Product name must be entered\n";
        }
    }
    if (document.ispa.accessinnovation_award.checked)
    {
        if (document.ispa.accessInnovationMarketName.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Access Innovation Product name must be entered\n";
        }
    }
    if (document.ispa.digitalinclusion_award.checked)
    {
        if (document.ispa.digitalInclusionMarketName.value.length==0)
        {
            errorFlag=true;
            errorMessage += "Digital Inclusion Product name must be entered\n";
        }
    }

    if (errorFlag)
    {
        alert(errorMessage);
        DoChanges(4);
        return false;
    }
    else
        return true;
}

function checkAwards()
{
    var noAwardsSelected = false;

    if(
        !document.ispa.dedicatedhosting_award.checked
        &&!document.ispa.sharedhosting_award.checked
        &&!document.ispa.consumerFixedbbBox.checked
         &&!document.ispa.businessFixedbbBox.checked
         &&!document.ispa.mobilebbBox.checked
         &&!document.ispa.consumerCustomerServiceBox.checked
         &&!document.ispa.businessCustomerServiceBox.checked
         &&!document.ispa.internettelephony_award.checked
         &&!document.ispa.digitalinclusion_award.checked
         &&!document.ispa.accessinnovation_award.checked
         &&!document.ispa.safety_award.checked
         &&!document.ispa.corporatesocial_award.checked
        )
    {
        DoChanges(3);
        alert("You have not entered any categories");

        return false;
    }
    else
        return true;
}

function validateData()
{
    var errorflag = false;
    var errormessage = '';

    //First round of validation is check for mandatory values
    if(document.ispa.isp_name.value=='')
    {
        errormessage+=' ISP name,'
        errorflag = true;
    }
    if(document.ispa.isp_contact_name.value=='')
    {
        errormessage+=' ISP contact name,'
        errorflag = true;
    }
    if(document.ispa.isp_contact_address.value=='')
    {
        errormessage+=' ISP contact address,'
        errorflag = true;
    }
        if(document.ispa.isp_contact_job_title.value=='')
    {
        errormessage+=' ISP contact job title,'
        errorflag = true;
    }
    if(document.ispa.isp_contact_email.value=='')
    {
        errormessage+=' ISP contact email,'
        errorflag = true;
    }
    if(document.ispa.isp_contact_phone.value=='')
    {
        errormessage+=' ISP contact office number,'
        errorflag = true;
    }
    if(document.ispa.isp_technical_name.value=='')
    {
        errormessage+=' ISP technical contact name,'
        errorflag = true;
    }
    if(document.ispa.isp_technical_email.value=='')
    {
        errormessage+=' ISP technical contact email,'
        errorflag = true;
    }
    if(document.ispa.isp_technical_phone.value=='')
    {
        errormessage+=' ISP technical contact number,'
        errorflag = true;
    }
    if(document.ispa.isp_technical_mobile.value=='')
    {
        errormessage+=' ISP technical contact mobile,'
        errorflag = true;
    }
    if(document.ispa.isp_technical_title.value=='')
    {
        errormessage+=' ISP technical contact title,'
        errorflag= true;
    }


    if(errorflag)
    {
        //Remove the final comma if present
        var messagelength = errormessage.length;

        if(errormessage.charAt(messagelength-1)==',')
            errormessage = errormessage.substring(0, messagelength-1);

    }

    if(!errorflag)
    {
        //Second round of validation is check for valid entries
        if (!checkemail(document.ispa.isp_contact_email))
        {
            errormessage+='The ISP contact email must be valid.  '
            errorflag = true;
        }
        if(document.ispa.isp_contact_reenter_email.value!=document.ispa.isp_contact_email.value)
        {
            errormessage+='The ISP contact email does not match the re-entered value. '
            errorflag=true;
        }
        if (!checkemail(document.ispa.isp_technical_email))
        {
            errormessage+='The ISP technical contact email must be valid.  '
            errorflag = true;
        }
        if(document.ispa.isp_technical_reenter_email.value!=document.ispa.isp_technical_email.value)
        {
            errormessage+='The ISP technical contact email does not match the re-entered value. '
            errorflag=true;
        }

        if(errorflag)
        {
            DoChanges(2);
            alert(errormessage);
        }
    }
    else
    {
        DoChanges(2);
        alert('The' + errormessage+ ' must be entered.');
    }

    if(!errorflag)
        errorflag = !checkAwards();

	if(!errorflag)
        errorflag = !checkServiceDetails();

    if(!errorflag)
        errorflag = !checkTerms();

    return errorflag;
}

function checkemail(elem)
{
    var testresults;
    var str=elem.value;

    //var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    //var filter=/^([a-zA-Z\-_0-9])+(\.[a-zA-Z0-9_\-]+)*@([a-zA-Z0-9_\-])+(\.[a-zA-Z0-9_\-]+)$/i
    var filter=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/i
    if (filter.test(str))
    {
        testresults=true;
    }
    else
    {
        testresults=false;
    }
    return (testresults)
}

function printFriendly()
{
    if(window.print)
        window.print();
}


function CountDate () {

var date = new Date("May 23, 2007");
var description = "The <i>2007 ISPAs</i>";
var now = new Date();
var diff = date.getTime() - now.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));

document.write("( ");
if (days > 1) {
document.write(days+1 + " days until " + description);
}
else if (days == 1) {
document.write("Only two days until " + description);
}
else if (days == 0) {
document.write("Tomorrow is " + description);
}
document.write(" )");

}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match(/gecko/)) {navigator.family = "gecko"}
if (window.navigator.userAgent.toLowerCase().indexOf('opera') != -1) {navigator.family = 'opera';}

toplevel="5";

function submitCategories()
{
	DoChanges(4);
}


function DoChanges(num)
{
    toplevel++;
    var box = "box" + num;

    if (navigator.family == "ie4")
    {
        if(document.all[box])
            document.all[box].style.zIndex = toplevel;

        for (i=1; i<6; i++)
        {
            var mytab="tab" + i;

            if(document.all(mytab))
                document.all(mytab).className = "tab";
            if (i == num)
            {
                if(document.all(mytab))
                    document.all(mytab).className = "thistab";
            }
        }

    }

if (navigator.family == "opera" || navigator.family == "gecko")
    {
    document.getElementById(box).style.zIndex = toplevel;

        for (i=1; i<6; i++)
        {
            var mytab="tab" + i;
            document.getElementById(mytab).className = "tab";
            if (i == num)
            {
            document.getElementById(mytab).className = "thistab";
            }
        }
    }


}

function toggleDiv(checkref, whichDiv)
{
	if (document.getElementById)
	{
	    var style2 = document.getElementById(whichDiv).style;
		if (checkref.checked)
	    {
		    style2.display="block";
	    }
	    else
	    {
		    style2.display="none";
	    }
		// this is the way the standards work
		//var style2 = document.getElementById(whichDiv).style
		//style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
	alert(whichDiv + '2');
		// this is the way old msie versions work
		var style2 = document.all[whichDiv].style;
		//style2.display = style2.display? "":"block";
		if (checkref.checked)
	    {
	        style2.display="block";
	    }
	    else
	    {
	        style2.display="";
	    }
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichDiv].style;
		//style2.display = style2.display? "":"block";
		if (checkref.checked)
	    {
	        style2.display="block";
	    }
	    else
	    {
	        style2.display="";
	    }
	}
}

function showDiv(whichDiv)
{
    if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichDiv).style;
		style2.display = "block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichDiv].style;
		style2.display = "block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichDiv].style;
		style2.display = "block";
	}
}

function hideDiv(whichDiv)
{
    if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichDiv).style;
		style2.display = "";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichDiv].style;
		style2.display = "";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichDiv].style;
		style2.display = "";
	}
}

function validateSpeed(control)
{

    var filter=/^\d+[mbk]{0,2}$/i
    if (!filter.test(control.value))
    {
        return true;
    }
    else
        return false;

}

function validateContention(control)
{
    var filter=/^\d{1,2}:\d{1,2}$/
    if (!filter.test(control.value))
    {
        return true;
    }
    else
        return false;
}

function syncDivsWithCheckboxes()
{
    toggleDiv(document.ispa.consumerFixedbbBox,"consumerFixedbb");
    toggleDiv(document.ispa.businessFixedbbBox,"businessFixedbb");
    toggleDiv(document.ispa.mobilebbBox,"mobilebb");
    toggleDiv(document.ispa.dedicatedhostingBox,"dedicatedhosting");
    toggleDiv(document.ispa.sharedhostingBox,"sharedhosting");
    toggleDiv(document.ispa.consumerCustomerServiceBox,"consumerCustomerService");
    toggleDiv(document.ispa.businessCustomerServiceBox,"businessCustomerService");
    toggleDiv(document.ispa.internettelephonyBox,"internettelephony");
    toggleDiv(document.ispa.accessinnovationBox,"accessinnovation");
    toggleDiv(document.ispa.digitalinclusionBox,"digitalinclusion");
    toggleDiv(document.ispa.safetyawardBox,"safetyaward");
    toggleDiv(document.ispa.corporatesocialBox,"corporatesocial");
}

function validateEmailData()
{
    var errorflag = false;
    var errormessage = '';

    //First round of validation is check for mandatory values
	if (!checkemail(document.email.email))
	{
		alert('A valid email address must be entered.');
		return true;
	}
	
    if(document.email.email.value=='')
    {
		errormessage += "email\n";
        errorflag = true;
    }
	if(document.email.subject.value=='')
    {
		errormessage += "subject\n";
        errorflag = true;
    }
	if(document.email.name.value=='')
    {
		errormessage += "name\n";
        errorflag = true;
    }
	if(document.email.message.value=='')
    {
		errormessage += "message\n";
        errorflag = true;
    }
	if (errorflag)
	{
		alert('The following fields.\n'+ errormessage + 'Must not be empty.');
	}
	return errorflag;
}

