function stripper(word) 
{
	while(word.length && word.substring(0,1) == " ") word = word.substring(1, word.length);
	while(word.length && word.substring(word.length-1, word.length) == " ") word = word.substring(0, word.length-1);

       return word;
}

function window_popup(url,w,h) 
{
	var winl = parseInt((screen.width - w) / 2);
    	var wint = parseInt((screen.height - h) / 2);
        var win = window.open(url,"docwin","height="+h+",width="+w+",top="+wint+",left="+winl+",toolbar=no,menubar=no,directories=no,status=no,linemenubar=no,scrollbars=yes,resizable=no,modal=yes,return=false,center=1");

}

function verifyCreditCard(form)
 {
        var message = "";
        var flag = 0;
        with(form)
        {
                CCNUMBER.value = stripper(CCNUMBER.value);
                CCADDRESS.value = stripper(CCADDRESS.value);
                CCZIPCODE.value = stripper(CCZIPCODE.value);

                CCNUMBER.value = CCNUMBER.value.replace(/-/g, '');
                CCNUMBER.value = CCNUMBER.value.replace(/ /g, '');
                CCNUMBER.value = CCNUMBER.value.replace(/\./g, '');


                if (typeof(CCTYPE) != 'undefined')
                {
			if(CCTYPE.selectedIndex == 0){
                        	message +="Select a Credit Card\n";
                        	CCTYPE.style.background="#ffffcc";
                        	CCTYPE.focus();
                        	if(flag == 0){
                        	        flag++;
                        	}
			}

                }

                if(CCNUMBER.value.length == 0)
                {
                        message += "Enter a Credit Card Number\n";
                        CCNUMBER.style.background="#ffffcc";
                        if(flag == 0){
                                flag++; 
                                CCNUMBER.focus();
                        }
                }
                else
                {
                        if(isNaN(CCNUMBER.value))
                        {
                                message += "The Credit Card Number must be numeric\n";
                                CCNUMBER.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        CCNUMBER.focus();
                                }
                        }
                        if(CCNUMBER.value.length>16) {
                                message += "The Credit Card Number must not be more than 16 characters\n";
                                CCNUMBER.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        CCNUMBER.focus();
                                }
                        }
                }
                if(typeof(CCNAME) != 'undefined' && CCNAME.value.length == 0)
                {
                        CCNAME.value = stripper(CCNAME.value);
                        message += "Enter the Name of the Cardholder\n";
                        CCNAME.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                CCNAME.focus();
                        }
                }

                if (CCMONTH.selectedIndex == 0 || CCYEAR.selectedIndex == 0)
                {
                        if(CCMONTH.selectedIndex == 0){
                                message +="Enter Expiration Date\n";
                                CCMONTH.style.background="#ffffcc";
                                if(CCYEAR.selectedIndex == 0){
                                        CCYEAR.style.background="#ffffcc";
                                }
                                if(flag == 0){
                                        flag++;
                                        CCMONTH.focus();
                                }
                        }
                        else if(CCYEAR.selectedIndex == 0){
                                message +="Enter Expiration Date\n";
                                CCYEAR.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        CCYEAR.focus();
                                }
                        }
                }
                if (CCADDRESS.value.length == 0) {
                        message += "Enter Credit Card Address\n";
                        CCADDRESS.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                CCADDRESS.focus();
                        }
                }
                if(typeof(CCCITY) != 'undefined' ){
                        CCCITY.value = stripper(CCCITY.value);
                        if (CCCITY.value.length == 0) {
                                message += "Enter Credit Card City\n";
                                CCCITY.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        CCCITY.focus();
                                }
                        }
                }
                if(typeof(CCSTATE) != 'undefined' ){
                        CCSTATE.value = stripper(CCSTATE.value);
                        if (CCSTATE.value.length == 0) {
                                message += "Enter Credit Card State\n";
                                CCSTATE.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        CCSTATE.focus();
                                }
                        }
                }
                if (CCZIPCODE.value.length == 0) {
                        message += "Enter Credit Card Zip Code\n";
                        CCZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                CCZIPCODE.focus();
                        }
                }else if(CCZIPCODE.value.length!=5 || isNaN(CCZIPCODE.value)) {
                        message += "Enter a valid Credit Card Zip Code\n";
                        CCZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                CCZIPCODE.focus();
                        }
                }
                if(typeof(PHONE1) != 'undefined' ){
                        PHONE1.value = stripper(PHONE1.value);
                        PHONE2.value = stripper(PHONE2.value);
                        PHONE3.value = stripper(PHONE3.value);
                        if(PHONE1.value=='' || PHONE2.value=='' || PHONE3.value==''){
                                message += "Enter your Phone Number\n";
                                if(PHONE1.value==''){
                                        PHONE1.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE1.focus();
                                                flag++;
                                        }
                                }
                                if(PHONE2.value==''){
                                        PHONE2.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE2.focus();
                                                flag++;
                                        }
                                }
                                if(PHONE3.value==''){
                                        PHONE3.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE3.focus();
                                                flag++;
                                        }
                                }
                        }
                        else if(isNaN(PHONE1.value) || isNaN(PHONE2.value) || isNaN(PHONE3.value) || PHONE1.value.length<3 || PHONE2.value.length<3 || PHONE3.value.length<4 ){
                                message += "Enter correct Phone Number\n";
                        }
                }
        }

        return message;
}



function verifyCC(form) 
{
        var message = "";
        with(form) 
        {
                CCNUMBER.value = stripper(CCNUMBER.value);
                CCNUMBER.value = CCNUMBER.value.replace(/-/g, '');
                CCNUMBER.value = CCNUMBER.value.replace(/ /g, '');
                CCNUMBER.value = CCNUMBER.value.replace(/\./g, '');

                
		if(CCNUMBER.value.length == 0) 
		{
			message += "Card Number\n";
			CCNUMBER.style.backgroundColor='#ffffcc';
		} 
		else 
		{
			if(isNaN(CCNUMBER.value)) 
			{
				message += "Card Number must be numeric\n";
			}
		}
		if(typeof(CCNAME) != 'undefined' && CCNAME.value.length == 0)
		{
			message += "Cardholder Name\n";
			CCNAME.style.backgroundColor='#ffffcc';
		} 
                
                if (CCMONTH.selectedIndex == 0 || CCYEAR.selectedIndex == 0)
                {
                        message +="Expiration Date\n";
			if(CCMONTH.selectedIndex == 0) {
				CCMONTH.style.backgroundColor='#ffffcc';
			}
			if(CCYEAR.selectedIndex == 0) {
				CCYEAR.style.backgroundColor='#ffffcc';
			}
                }
		if(CCADDRESS.value.length == 0)
                {
                        message += "Street Address\n";
			CCADDRESS.style.backgroundColor='#ffffcc';
                }
		if(CCZIPCODE.value.length == 0 || CCZIPCODE.value.length != 5)
                {
                        message += "Zip Code\n";
			CCZIPCODE.style.backgroundColor='#ffffcc';
                }
        }
        return message;
}

function verifyTandC(form)
{
        var message = "";
        with(form)
        {
	        if (! ACCEPT.checked)
                {
                        message = "You must accept the terms & conditions.\n";
			ACCEPT.style.backgroundColor='#ffffcc';
                }
        }
        
        return message;
}

function verifyCheck(form) 
{
	var message = "";
	with(form) 
	{
		if(ECNAME.value.length == 0)
                {
                        message += "Name on Check\n";
			ECNAME.style.backgroundColor='#ffffcc';
                }
		if(CHKNUM.value.length == 0)
                {
                         message += "Check Number\n";
			 CHKNUM.style.backgroundColor='#ffffcc';
                }
                if(MICR.value.length == 0)
                { 
                        message += "MICR\n";
			MICR.style.backgroundColor='#ffffcc';
                }
		if(ECADDRESS.value.length == 0)
                {
                        message += "Street Address\n";
			ECADDRESS.style.backgroundColor='#ffffcc';
                }
		if(ECCITY.value.length == 0)
                {
                        message += "City\n";
			ECCITY.style.backgroundColor='#ffffcc';
                }
		
                if(ECSTATE.selectedIndex == 0) 
                {
                        message += "State\n";
			ECSTATE.style.backgroundColor='#ffffcc';
                }
		
                if(ECZIPCODE.value.length == 0)
                {
                        message += "Zip Code\n";
			ECZIPCODE.style.backgroundColor='#ffffcc';
                }
		
                if(typeof(SSN) != 'undefined')
                {
                        if (SSN.value.length == 0) {
				message += "Enter your Social Security Number\n";
				SSN.style.backgroundColor='#ffffcc';
			}
                }

	        return message;
        }
}


 function verifyShipping(form)
 {
        var message = "";
        var flag=0;
        with(form)
        {
                if (ADDRESS.value.length == 0) {
                        message += "Enter the Street  Address\n";
                        ADDRESS.style.background="#ffffcc";
                        ADDRESS.focus();
                        if(flag == 0){
                                flag++;
                        }
                }
                if (CITY.value.length == 0) {
                        message += "Enter the  City\n";
                        CITY.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                CITY.focus();
                        }
                }
                if (STATE.value.length == 0) {
                        message += "Please Select the State\n";
                        STATE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                STATE.focus();
                        }
                }
                if (ZIPCODE.value.length == 0) {
                        message += "Enter the  Zip Code\n";
                        ZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ZIPCODE.focus();
                        }
                }else if(ZIPCODE.value.length!=5 || isNaN(ZIPCODE.value)) {
                        message += "Please enter a valid Zip Code\n";
                        ZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ZIPCODE.focus();
                        }
                }
        }

        return message;
}

function verifyElectronicCheck(form)
{
        var message = "";
        var flag=0;
        with(form)
        {
                if(ECNAME.value.length == 0)
                {
                        message += "Enter the Name on Check\n";
                        ECNAME.style.background="#ffffcc";
                        ECNAME.focus();
                        if(flag == 0){
                                flag++;
                        }
                }
                if(MICR.value.length == 0)
                {
                        message += "Enter the Routing Number\n";
                        MICR.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                MICR.focus();
                        }
                }
                if(typeof(ECACCT) != 'undefined'){
                        if(ECACCT.value.length == 0)
                        {
                                message += "Enter the Account Number\n";
                                ECACCT.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        ECACCT.focus();
                                }
                        }
                }
                if(CHKNUM.value.length == 0)
                {
                         message += "Enter the Check Number\n";
                         CHKNUM.style.background="#ffffcc";
                         if(flag == 0){
                                flag++;
                                CHKNUM.focus();
                         }
                }
                if(typeof(DRIVERSLICENSE) != 'undefined' ){
                        DRIVERSLICENSE.value=stripper(DRIVERSLICENSE.value);
                        if(DRIVERSLICENSE.value.length == 0)
                        {
                                message += "Enter the Driver's License\n";
                                 DRIVERSLICENSE.style.background="#ffffcc";
                                 if(flag == 0){
                                        flag++;
                                        DRIVERSLICENSE.focus();
                                }
                        }
                }
                if(typeof(DLSTATE) != 'undefined' ){
                        if(DLSTATE.selectedIndex == 0)
                        {
                                message += "Enter the Driver License State\n";
                                DLSTATE.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;
                                        DLSTATE.focus();
                                }
                        }
                }
                if(ECADDRESS.value.length == 0)
                {
                        message += "Enter the Address on Check\n";
                        ECADDRESS.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ECADDRESS.focus();
                        }
                }
                if(ECCITY.value.length == 0)
                {
                        message += "Enter the City\n";
                        ECCITY.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ECCITY.focus();
                        }
                }

                if(ECSTATE.selectedIndex == 0)
                {
                        message += "Select the State\n";
                        ECSTATE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ECSTATE.focus();
                        }
                }

                if(ECZIPCODE.value.length == 0)
                {
                        message += "Enter Zip Code\n";
                        ECZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ECZIPCODE.focus();
                        }
                }
                else if(ECZIPCODE.value.length!=5 || isNaN(ECZIPCODE.value)) {
                        message += "Please enter a valid Zip Code\n";
                        ECZIPCODE.style.background="#ffffcc";
                        if(flag == 0){
                                flag++;
                                ECZIPCODE.focus();
                        }
                }
                if(typeof(SSN) != 'undefined')
                {
                        if (SSN.value.length == 0){
                                message += "Enter your Social Security Number\n";
                                SSN.style.background="#ffffcc";
                                if(flag == 0){
                                        flag++;

                                        SSN.focus();
                                }
                        }
                }
                if(typeof(PHONE1) != 'undefined'){
                        if(PHONE1.value=='' || PHONE2.value=='' || PHONE3.value==''){
                                message += "Enter your Phone Number\n";
                                if(PHONE1.value==''){
                                        PHONE1.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE1.focus();
                                                flag++;
                                        }
                                }
                                if(PHONE2.value==''){
                                        PHONE2.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE2.focus();
                                                flag++;
                                        }
                                }
                                if(PHONE3.value==''){
                                        PHONE3.style.background="#ffffcc";
                                        if(flag==0){
                                                PHONE3.focus();
                                                flag++;
                                        }
                                }
                        }
                        else if(isNaN(PHONE1.value) || isNaN(PHONE2.value) || isNaN(PHONE3.value) || PHONE1.value.length<3 || PHONE2.value.length<3 || PHONE3.value.length<4 ){
                                message += "Enter correct Phone Number\n";
                 }
                }


                return message;
        }
}


function verifyStudent(form)
{
        var message = "";
        with (form)
        {
		FIRST_NAME.value = stripper(FIRST_NAME.value);
		LAST_NAME.value = stripper(LAST_NAME.value);
		DRIVERSLICENSE.value = stripper(DRIVERSLICENSE.value);
		ADICOURSECHECK = FLADICOURSE.value;
		if(FIRST_NAME.value.length == 0 || FIRST_NAME.value == "First" || FIRST_NAME.value == "Primero")
                {
                        message += "First Name\n";
			FIRST_NAME.style.backgroundColor='#ffffcc';
                }
		if(LAST_NAME.value.length == 0 || LAST_NAME.value == "Last" ||  LAST_NAME.value == "último")
                {
                        message += "Last Name\n";
			LAST_NAME.style.backgroundColor='#ffffcc';
                }
		if(DRIVERSLICENSE.value.length == 0)
                {
                        message += DLMESSAGE.value+"\n";
			DRIVERSLICENSE.style.backgroundColor='#ffffcc';
                }
		if(PASSWORD1.value.length == 0)
                {
                        message += "Create Password\n";
			PASSWORD1.style.backgroundColor='#ffffcc';
                }
		if(PASSWORD2.value.length == 0)
                {
                        message += "Confirm Password\n";
			PASSWORD2.style.backgroundColor='#ffffcc';
                } else if(PASSWORD1.value.length < 6 && FLADICOURSE.value == 0) {
			message += "Passwords must be at least six characters long\n";
		} else if( FLADICOURSE.value == 1 && (PASSWORD1.value.length < 6 || PASSWORD1.value.length > 8)) {
			message += "Passwords must be between 6 and 8 characters long\n";
		}
                else if (PASSWORD1.value != PASSWORD2.value)
                {
                        message += "Make sure your passwords match\n";
			PASSWORD1.style.backgroundColor='#ffffcc';
			PASSWORD2.style.backgroundColor='#ffffcc';
                }
                if (EMAIL.value.length == 0)
                {
                        message += "E-mail Address\n";
			EMAIL.style.backgroundColor='#ffffcc';
                }
                else 
                {
                        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                        if (! filter.test(EMAIL.value))
                                message += "Enter a valid E-mail Address\n";
                }
                if (typeof(DOB_MONTH) != 'undefined')
                {
                        if (DOB_MONTH.selectedIndex == 0 || DOB_YEAR.selectedIndex == 0 || DOB_DATE.selectedIndex == 0)
                        {
                                message += "Date of Birth\n";
				if(DOB_MONTH.selectedIndex == 0) {
					DOB_MONTH.style.backgroundColor='#ffffcc';
				}
				if(DOB_YEAR.selectedIndex == 0) {
					DOB_YEAR.style.backgroundColor='#ffffcc';
				}
				if(DOB_DATE.selectedIndex == 0) {
					DOB_DATE.style.backgroundColor='#ffffcc';
				}
                        }
                }
                if(typeof(DLSTATE) != 'undefined')
                {
                        if (DLSTATE.selectedIndex == 0) {
			 	message += DLMESSAGE.value+" State\n";
				DLSTATE.style.backgroundColor='#ffffcc';
			}
                }
        }

        return message;
}

function verifyTandCDR(form)
{
        var message = "";
        with(form)
        {
		if(typeof(ACCEPT) != 'undefined'){
	        	if (! ACCEPT.checked)
                	{
                        	message += "You must accept the terms of use.\n";
				ACCEPT.style.backgroundColor='#ffffcc';
                	}
		}
		if(typeof(ACCEPTREFUND) != 'undefined'){
	        	if (! ACCEPTREFUND.checked)
                	{
                        	message += "You must accept the refund policy.\n";
				ACCEPTREFUND.style.backgroundColor='#ffffcc';
                	}
                }
        }
        
        return message;
}

function verifyTandCNJ(form) {
        var message = "";
        with(form) {
		if(typeof(ACCEPT) != 'undefined'){
                	ACCEPT.value = stripper(ACCEPT.value);
                	if (ACCEPT.value.length==0) {
                        	message = "You must type 'I Agree' for accepting the Terms & Conditions.\n";
                	        ACCEPT.style.backgroundColor='#ffffcc';
                	} else if(ACCEPT.value != 'I Agree' && ACCEPT.value != 'i agree' && ACCEPT.value != 'I AGREE') {
                        	message = "You must type 'I Agree' for accepting the Terms & Conditions.\n";
                        	ACCEPT.style.backgroundColor='#ffffcc';
                	}
		}	
        }
        return message;
}


