function chkDate(ppDate) { // (nM),nD,nY){
//	window.onerror=null // for all other strange errors
	var err=0
	var psj=0;
	
	var nM ;
	var nD ;
	var nY ;
	var indexPos1 ;
	var indexPos2 ;
	indexPos1 = ppDate.indexOf("/") ;
	nM = ppDate.substring(0,indexPos1) ;
	indexPos2 = ppDate.lastIndexOf("/") 
	nD = ppDate.substring(indexPos1 + 1,indexPos2) ;
	nY = ppDate.substring(indexPos2 + 1,ppDate.length) ;
	
	if (nY.length != 4) err=1
	d = nD // day
	b = nM // month
	f = nY // year

	//basic error checking
	if (b<1 || b>12) err = 1
	if (d<1 || d>31) err = 1
	if (f<0 ) err = 1
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1
	}

	// february, leap year
	if (b==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (d>29) err=1
		//if (d==29 && ((f/4)!=parseInt(f/4))) err=1
		if (d == 29) {
			err = 1;
   			if ((f/4) == parseInt(f/4)) err = 0;
			if ((f/100) == parseInt(f/100)) err = 1;
   			if ((f/400) == parseInt(f/400)) err =0;
		}
	}

	if (err==1){
		return false;
	}
	else{
		return true;
	}
}
function formatDDate(elm, e) {
    var keychar;
    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }
        keychar = String.fromCharCode(keynum)
    } 
    if (/[\b]/.exec(keychar)) {
        return true;
    } else {
		if ((window.event.keyCode) == 13) {
			return true;
		}  
        var p = elm.value + keychar;
        //p = p.replace(/^[00]/,"");
        p = p.replace(/\D+/g, "");
        if (p.length >= 0 && p.length < 2) {
            p = p;
        } else if (p.length >= 2 && p.length < 5) {
            p = p.substring(0,2)+"/"+p.substring(2);
        } else if (p.length >= 5 && p.length < 8) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4);
        } else if (p.length) {
            p = p.substring(0,2)+"/"+p.substring(2,4)+"/"+p.substring(4,8);
        }
        elm.value = p ;
        return false ;
    }
}

function formatDate(txtObj){

	var txtVal ;
	txtVal = txtObj.value ;
	if (txtVal.length == 2){ txtObj.value = txtVal + '/' } ;
	if (txtVal.length == 5){ txtObj.value = txtVal + '/' } ;
	
}


function chkNum(inString)
{
	var iTemp; 
	var tmpArray = new Array();
	
	for (iTemp=0 ; iTemp < inString.length ; iTemp++){
		tmpArray[iTemp] = inString.substring(iTemp, iTemp+1);
	}
	for (iTemp=0 ; iTemp < inString.length ; iTemp++){
		if(!((parseInt(tmpArray[iTemp])>=0) && (parseInt(tmpArray[iTemp])<=9))){
			return false;
		}
    }
	return true;
}
function isEmailOK(usrInput) {
    var rXP = new RegExp("^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$")
    if (rXP.test(usrInput))
    { return true }
    else
        return false;
}

function isPhoneOK(usrInput){
	var rXP = new RegExp("\\(?\\d{3,5}\\)?\\s?[-\\/]\\s?(\\d{4,7})$")
	if(rXP.test(usrInput))
		{return true}
	else
		{return false}
}




function formatPhoneNumber(txtObj, objValue){
	var txtVal ;
	var indVal ;
	var curVal ;
	curVal = txtObj.value ;
	txtVal = curVal ;
	if (window.event.keyCode == 45){
		if (txtVal.length < 3) {
			return false ;
		} else if ((txtVal.length > 3) && (txtVal.length < 7)){
			txtVal = curVal ;
			return false ;
		} else if (txtVal.length > 7){
			txtVal = curVal ;
			return false ;
		} 
	} else {
		if (txtVal.length == 3){ txtVal = txtVal + '-' } ;
		if (txtVal.length == 7){ txtVal = txtVal + '-' } ;
	}
	txtObj.value = txtVal ;
}

function formatPhone(elm, e) {
    var keychar;
    if (e) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        }
        else if (e.which) {
            keynum = e.which
        }
        keychar = String.fromCharCode(keynum)
    } 
    if (/[\b]/.exec(keychar)) {
        return true;
    } else {
		if ((window.event.keyCode) == 13) {
			return true;
		}  
        var p = elm.value + keychar;
        //p = p.replace(/^[01]/,"");
        p = p.replace(/\D+/g, "");
        if (p.length >= 0 && p.length < 3) {
            p = p;
        }
        else if (p.length >= 3 && p.length < 7) {
            p = p.substring(0,3)+"-"+p.substring(3);
        }
        else if (p.length >= 7 && p.length < 10) {
            p = p.substring(0,3)+"-"+p.substring(3,6)+"-"+p.substring(6);
        }
        else if (p.length) {
            p = p.substring(0,3)+"-"+p.substring(3,6)+"-"+p.substring(6,10);
        }
        elm.value = p;
        return false;
    }
}

function xxxformatPhoneNumber(txtObj){
	var txtVal ;
	txtVal = txtObj.value ;
	if (txtVal.length == 3){ txtObj.value = txtVal + '-' } ;
	if (txtVal.length == 7){ txtObj.value = txtVal + '-' } ;
}




 


// validtions for the rep sign up page is done below 
// Checking for radio button index For the Customer Enrollment Form -->	

//Validating the Customer Enrollment Form
function wSubmit(){

		var byemail="no";
		var byphone="no";
		var moreinfo="no";
		var value=0;
		if (document.Contact.fname.value == ''){
		alert("Please Enter the First Name.");
		value=1;
		document.Contact.fname.focus();
		return false ;
	}
		if (document.Contact.lname.value == ''){
		alert("Please Enter the Last Name.");
		value=1;
		document.Contact.lname.focus();
		return false ;
	}
	if (document.Contact.email.value == ''){
		alert("Please Enter the Email Address.");
		value=1;
		document.Contact.email.focus();
		return false ;
	}

	if ( !isEmailOK(document.Contact.email.value)){
		alert("Please Enter the Correct Email Address");
		value=1;
		document.Contact.email.focus();
		return false ;
	}

	if (document.Contact.address.value == ''){
		alert("Please Enter the Address.");
		value=1;
		document.Contact.address.focus();
		return false ;
	}
	if (document.Contact.csz.value == ''){
		alert("Please Enter the City/State/Zip.");
		value=1;
		document.Contact.csz.focus();
		return false ;
	}
	if (document.Contact.country.value == ''){
		alert("Please Enter the Country.");
		value=1;
		document.Contact.country.focus();
		return false ;
	}
	if (document.Contact.phone.value == '' ){
		alert("Please Enter  Phone Number.");
		value=1;
		document.Contact.phone.focus();
		return false ;
	}
	if (! chkNum(document.Contact.phone.value )){
		alert("Please Enter the Correct Phone number");
		value=1;
		document.Contact.phone.focus();
		return false ;
	}


	if (document.Contact.eventdate.value == ''){
		alert("Please Enter the Date of Event.(mm/dd/yyyy)");
		value=1;
		document.Contact.eventdate.focus();
		return false ;
	}
	if (! chkDate(document.Contact.eventdate.value )){
		alert("Please Enter the Correct Date .(mm/dd/yyyy)");
		value=1;
		document.Contact.eventdate.focus();
		return false ;
	}

	if(value==0)
	{
		var fname=document.Contact.fname.value;
		var lname=document.Contact.lname.value;
		var address=document.Contact.address.value;
		var csz=document.Contact.csz.value;
		var phone=document.Contact.phone.value;
		var email=document.Contact.email.value;
		var date=document.Contact.eventdate.value;
		var country=document.Contact.country.value;
		var comments=document.Contact.comments.value;
		if (document.Contact.moreinfo.checked == true ){
        moreinfo="yes";
    	}
		if (document.Contact.byemail.checked == true ){
        byemail="yes";
    	}		
		else
		{
		byphone="yes";
		}
	
	window.location="order.php?fname="+fname+"&lname="+lname+"&address="+address+"&csz="+csz+"&phone="+phone+
"&email="+email+"&date="+date+"&country="+country+"&moreinfo="+moreinfo+"&byemail="+byemail+"&byphone="+byphone+"&comments="+comments;
	return false;
	}
}


// ====== 	END OF FUNCTION DistSubmitStep123 =======


