
var udwin = null;
function win_popup(url,w,h) {
    if(udwin && udwin.open && !udwin.closed){ udwin.window.close(); }
    var winl = parseInt((screen.width - w) / 2);
    var wint = parseInt((screen.height - h) / 2);
    udwin = window.open(url,"unique","width="+w+",height="+h+",top="+wint+",left="+winl+",resize=no,scrollbars=yes");
    udwin.focus();
}
function win_popup1(url,w,h) {
    if(udwin && udwin.open && !udwin.closed){ udwin.window.close(); }
    udwin = window.open(url,"unique","width="+w+",height="+h+",resize=no,scrollbars=yes");
    udwin.focus();
}

function changeState(form) 
{
	var state = document.getElementById('STATE').options[document.getElementById('STATE').selectedIndex].text; 
	 state = (state.replace(' ','-'));
	 state = state.toLowerCase();
	 var stateVal = document.getElementById('STATE').options[document.getElementById('STATE').selectedIndex].value; 
	if(stateVal==0 || state == "" || state=='Select State ...') {
		alert("Select State ...");
	} else {
		var actionValue;
		actionValue="/"+state+"/";
		with(form) {
			action=actionValue;
			submit();
		}
	}
}

function changePage(form)
{
        var state = document.getElementById('STATENAME').options[document.getElementById('STATENAME').selectedIndex].value;	
        if(state == " " || state=='Select State ...') {
                alert("Select State ...");
                return;
        } else {
                var actionValue;
                actionValue=state;
                with(form) {
                        action=actionValue;
                        submit();
                }
        }
}

function changeState1(form){		
        var state = document.getElementById('STATELIST').options[document.getElementById('STATELIST').selectedIndex].value;
        if(state == "") {
                alert("Select State ...");
                return;
        }
        var actionValue;
        actionValue=state;
        with(form) {
                   action=actionValue;
                    submit();
        }
       
}

function changeState2(form)
{
        var state = document.getElementById('STATENAMES').options[document.getElementById('STATENAMES').selectedIndex].value;
        if(state == "") {
                alert("Select State ...");
        } else {
                var actionValue;
                actionValue=state;
                with(form) {
                        action=actionValue;

                        submit();
                }
        }
}

function changeStateSendMeDVD(form){		
    var state = document.getElementById('STATELIST').options[document.getElementById('STATELIST').selectedIndex].text;
    if(state == "") {
            alert("Select State ...");
            return;
    }
    var actionValue;
    state = (state.replace(' ','-'));
	state = state.toLowerCase();
    actionValue=state;
    with(form) {
             action='/'+actionValue+'/signup/displaycourseselection.html';
             submit();
    }
   
}




function loginSubmit(form)
{
        var msg = "";
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{1,4})+$/;
        with (document.F_LOGIN)
        {
                if (! DRIVERSLICENSE.value.length)       msg += 'Email or Drivers License\n';
                //else if(!filter.test(DRIVERSLICENSE.value)) {    msg += 'Valid Email\n'; }
                if (! PASSWORD.value.length)             msg += 'Password';
                if (msg)        {alert('Please enter your: \n' + msg);}
                else            submit();
        }
}

function loginSubmitOld(form) {
	var msg = "";
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{1,4})+$/;
        with (document.F_LOGINOLD) {
		if (! DRIVERSLICENSE_OLD.value.length)       msg += 'Email or Drivers License\n';
		if(DRIVERLICENSESTATE.value == 0){ msg += 'Select Driver License State\n'};
		if (!LASTNAME.value) { msg += 'Enter Last Name' };
		if (msg)        {alert('Please enter your: \n' + msg);}
                else            submit();	
	}
}

function zipCodeSearch(){
	var ZipCode;
	var obj=document.getElementById('ZipSearch');
	zipCodeValidation(obj);
	if(obj)ZipCode=obj.value;	
	if(!ZipCode || ZipCode.length<5 ){
		 alert('Please Enter Zip Code');
		 return;
	}
	document.ZipSearchForm.submit();
}

function zipCodeValidation(obj){
	var ZipCode;
	ZipCode=obj.value;	
	var ZipCodeLen=ZipCode.length;
	var NewZipStr='';
	for(var i=0;i<ZipCodeLen;i++){
	  if((ZipCode.charCodeAt(i)<48 || ZipCode.charCodeAt(i) > 57) && (ZipCode.charCodeAt(i) < 65 || ZipCode.charCodeAt(i) > 90 ) && (ZipCode.charCodeAt(i) < 97 || ZipCode.charCodeAt(i) > 122 )){
		  obj.value=NewZipStr;
		  return;
	  }
	  NewZipStr+=ZipCode[i];
	}
	obj.value=NewZipStr;
}
	
function NumericTextBox(obj){
	var val=obj.value;
	var len=val.length;
	var NewStr='';
	for(var i=0;i<len;i++){
	  if(val.charCodeAt(i)<48 || val.charCodeAt(i) > 57){
		  obj.value=NewStr;
		  return;
	  }
	  NewStr+=val[i];
	}
	obj.value=NewStr;
}


function AlphaNumericTextBox(obj){
	var val=obj.value;
	var len=val.length;
	var NewStr='';
	for(var i=0;i<len;i++){
	  if( (val.charCodeAt(i)<48 || val.charCodeAt(i) > 57) && (val.charCodeAt(i) < 65 || val.charCodeAt(i) > 90 ) && (val.charCodeAt(i) < 97 || val.charCodeAt(i) > 122 )){
		  obj.value=NewStr;
		  return;
	  }
	  NewStr+=val[i];
	}
	obj.value=NewStr;
}



function verifyForm(form) 
{
        var message = "", notFocused = true;
        with(form) 
        {

                if (typeof(ADDRESS_1) != 'undefined')
                {
                        if (ADDRESS_1.value.length == 0) 
                        {
                                message += "Enter your address\n"; 
                                if (notFocused) 
                                { 
                                        ADDRESS_1.focus(); notFocused = false; 
                                }
                       }
                }
                if (typeof(CITY) != 'undefined')
                {
                        if (CITY.value.length == 0) 
                        {
                                message += "Enter your city\n"; 
                                if (notFocused) 
                                { 
                                        CITY.focus(); notFocused = false; 
                                }
                       }
                }

                if (typeof(STATE) != 'undefined')
                {
                        if (STATE.selectedIndex == 0) 
                        {
                                message += "Enter your state\n"; 
                                if (notFocused) 
                                { 
                                        STATE.focus(); notFocused = false; 
                                }
                        }
                }       
                
                if (typeof(ZIP) != 'undefined')
                {
                        re = /^\d{5}$|^\d{9}$|^\d{5}-\d{4}$/;
                        if (!re.test(ZIP.value)) 
                        {
                                message += "Enter a valid zip code\n"; 
                                if (notFocused) 
                                { 
                                        ZIP.focus(); notFocused = false;
                                }
                        }
                }
                if (typeof(PHONE1) != 'undefined')
                {
                        if (PHONE1.value.length != 3 || PHONE2.value.length != 3 || PHONE3.value.length != 4 ) 
                        {
                                message += "Enter your phone\n";
                                if (notFocused) 
                                {
                                        PHONE1.focus();notFocused = false;
                                }
                        } 
			else if (isNaN(PHONE1.value) || isNaN(PHONE2.value) || isNaN(PHONE3.value)) 
			{
                                message += "Enter Valid Phone Number\n";
                        }
                }
                if (typeof(FNAME) != 'undefined')
		{
                        if (FNAME.value == '')
			{
                                message += "Enter your  firstname\n";
                                if (notFocused)
                                {
                                        FNAME.focus();notFocused = false;
                                }

                        }
                }
                if (typeof(LNAME) != 'undefined')
		{
                        if (LNAME.value == '')
			{
                                message += "Enter your  lastname\n";
                                if (notFocused)
                                {
                                        LNAME.focus();notFocused = false;
                                }
                        }
                }
		if (typeof(DL) != 'undefined')
                {
                        if (DL.value == '')
                        {
                                message += "Enter your  Driver's Lic\n";
                                if (notFocused)
                                {
                                        DL.focus();notFocused = false;
                                }
                        }
                }
                if (typeof(EMAIL) != 'undefined')
                {
                	EMAIL.value = stripper(EMAIL.value);
                        if (EMAIL.value < 2)
                        {
                                message += "Enter a valid email address\n";
                                if (notFocused) 
                                {
                                        EMAIL.focus();notFocused = false;
                                }
                        }
                }

                if (typeof(DOB_D) != 'undefined' || typeof(DOB_M) != 'undefined')
                {
                	DOB_M.value = parseInt(DOB_M.value)?parseInt(DOB_M.value):stripper(DOB_M.value);
                	DOB_D.value = parseInt(DOB_D.value)?parseInt(DOB_D.value):stripper(DOB_D.value);
                	DOB_Y.value = parseInt(DOB_Y.value)?parseInt(DOB_Y.value):stripper(DOB_Y.value);
                        var dob = Date.UTC(DOB_Y.value, DOB_M.value , DOB_D.value,0,0,0);
                        var l_dt = new Date();
                        var today = Date.UTC( l_dt.getFullYear(), l_dt.getMonth()+1, l_dt.getDate(),0,0,0);

                        if (DOB_M.value=='' || DOB_D.value=='' || DOB_Y.value=='' || DOB_M.value=='MM' || DOB_D.value=='DD' || DOB_Y.value=='YYYY')
			{
                                message += "Enter your Date of Birth\n";
                        }
			else if (!isDate(DOB_D.value,DOB_M.value,DOB_Y.value) || (dob > today) || DOB_Y.value.length<4 || isNaN(DOB_D.value) || isNaN(DOB_M.value) || isNaN(DOB_Y.value)) 
			{
                                message += "Enter valid Date of Birth\n";
                        }
                }
                var count = 0;  
                if (typeof(SEX) != 'undefined')
		{
                        for (var i=0;i<SEX.length;i++)
			{
                                if (SEX[i].checked==true)
				{
                                	count =1;
				  	if (typeof(SEXVAL) != 'undefined')
					{
						SEXVAL.value = SEX[i].value;
					}
                                }
                        }
                }
                if (count==0)
		{
                        message += "Check the Sex\n";
                }       
                return message;
        }
}

function isDate(strDay,strMonth,strYear)
{
	var daysInMonth = DaysArray(12)
        strYr=strYear
        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
        for (var i = 1; i <= 3; i++) 
	{
                if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }
        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)

        var i=0;
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || !(daysInMonth[month]) || day > daysInMonth[month])
	{
                  return false
        }
        return true;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
        	this[i] = 31
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
        }
        return this
}

function toggle() {
	var ele = document.getElementById("toggleText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}else {
		ele.style.display = "block";
	}
}
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 verifyContactus(form)
{
	var message = "", notFocused = true;
	with(form)
	{
		/*if (typeof(fname) != 'undefined')
		{
			if (fname.value.length == 0)
                        {
                                message += "Enter your First Name\n";
                                if (notFocused)
                                {
                                        fname.focus(); notFocused = false;
                                }
                       }
		}
		if (typeof(lname) != 'undefined')
                {
                        if (lname.value.length == 0)
                        {
                                message += "Enter your Last Name\n";
                                if (notFocused)
                                {
                                        lname.focus(); notFocused = false;
                                }
                       }
                }*/
		if(typeof(email) != 'undefined')
		{
			if(email.value == "") {
                        	message += "Enter Email Address.\n";
				if (notFocused)
                       		{
                       			lname.focus(); notFocused = false;
                       		}

                	} 
			else 
			{
                        	var filter  = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z0-9]{2,4})$/;
                        	if(!filter.test(email.value))
				{
                                	message += "Please enter a valid Email Address.\n";
                        	}
                	}
		}
		/*if(typeof(phone) != 'undefined')
		{
                	phone.value = stripper(phone.value);
                	var phonere = /[A-Za-z]|(\s+)/;
               		if(phone.value=="") 
			{
                        	message += "Enter Phone Number\n";
				if (notFocused)
                        	{
                                	phone.focus(); notFocused = false;
                        	}

                      	}
			else if (phonere.test(phone.value) || phone.value.length!=10)
			{
                       		message += "Enter valid Phone Number\n";
				if (notFocused)
                        	{
                                	phone.focus(); notFocused = false;
                        	}

                       	}
             	}*/
		if (typeof(comments) != 'undefined')
                {
                        if (comments.value.length == 0)
                        {
                                message += "Enter your Message\n";
                                if (notFocused)
                                {
                                        comments.focus(); notFocused = false;
                                }
                       }
                }		
	}
	if(message.length == '')
	{
		return true;
	}
	else
	{
		message = "Before you can continue, you must:\n\n" + message;
		alert(message);
		return false;
	}
}

function bookmark(title,url){
                if (window.sidebar){ 

                        window.sidebar.addPanel(title,url,'http://aarpdriversafety.org');

                }else{ 

                        window.external.AddFavorite(url,title);

                }

}


function setNumeric(val){
                var str1='';
                for(i=0;i<val.length;i++){
                        num=val.substring(i,i+1);
                        if(num>=0 && num<=9){
                                str1=str1+val.substring(i,i+1);
                        }
                }
                return str1;
        }


