﻿
/****************************************************
    The following function is for phone validation
*****************************************************/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
/****************************************************
    The above functions are for phone validation
*****************************************************/

/****************************************************
    The following function are for email validation
*****************************************************/
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid Email")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid Email")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid Email")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid Email")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid Email")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid Email")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid Email")
	    return false
	 }

	 return true					
}

function ValidateForm(){
	var emailID=document.frmSample.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


/****************************************************
    The above functions are for email validation
*****************************************************/
function validateSearch() {
	if (document.search.txtKeyword.value == "SEARCH")
	{
		alert("Please enter keyword(s) to search for.");
		return false;
	}
	else
	{	
		document.search.submit();
	}
}

function validateSprcialOff()
{ 
  var strMsg = "";
  var valid = "0123456789-";
  var hyphencount = 0;
  
  var country = document.specialoffer_form.country;
  //var name = document.specialoffer_form.name;
  var fname = document.specialoffer_form.fname;
  var lname = document.specialoffer_form.lname;
  var title = document.specialoffer_form.SPtitle;
  var email = document.specialoffer_form.email;
  //var school = document.specialoffer_form.school;
  var zip = document.specialoffer_form.zip;


  if ((ltrim(fname.value)).length ==0)
  {
	strMsg = "Please enter your first name!";
	fname.focus();
	alert(strMsg);
	return false ;
  }
  if ((ltrim(lname.value)).length ==0)
  {
	strMsg = "Please enter your last name!";
	lname.focus();
	alert(strMsg);
	return false ;
  }
  if ((ltrim(title.value)).length ==0)
  {
	strMsg = "Please enter your title!";
	title.focus();
	alert(strMsg);
	return false ;

  }
  if ((ltrim(email.value)).length ==0)
  {
	strMsg = "Please enter your email!";
	email.focus();
	alert(strMsg);
	return false ;

  }
  else 
  {
    if (echeck(email.value)==false){
	    email.focus();
	    return false ;

    }
  }
  if ((ltrim(zip.value)).length !=0)
  { //if (document.getElementById('MDR_PID').value != "")
    //var school = document.specialoffer_form.MDR_PID_Special.selectedindex;
      if (document.getElementById("orgList").style.display == 'block')
    {//alert(document.getElementById("MDR_PID_Special").value.text + " " + (ltrim(document.getElementById("MDR_PID_Special").value)).length)
       if ((ltrim(document.getElementById("MDR_PID_Special").value)).length == 0 ) 
       
        {
        //alert((ltrim(document.getElementById("MDR_PID_Special").value)).length   )
        //if (!(document.getElementById("MDR_PID_Special").text== "None of the Above"))
	       // {
	        strMsg = "Please enter your school!";
	        document.specialoffer_form.MDR_PID_Special.focus();
	        alert(strMsg);
	        return false ;
	       // }
	       // else
	       // {
	       // alert(document.getElementById("MDR_PID_Special").text)
	       // }
        }
       
    }
 
}

   //check if state is filled right & zip format is right with respect to which country
 if (country.value =="USA" || country.value =="US")	//for USA, certain states and zip in xxxxx/xxxxx-xxxx format
  {
	if ((ltrim(zip.value)).length == 0)
	{
		strMsg = "Please enter your zip code.";
		zip.focus();
		alert(strMsg);
    	return false ;

	}
	else if ((ltrim(zip.value)).length!=5 && (ltrim(zip.value)).length!=10)
	{  
		strMsg = "Please enter your 5 digit or 5 digit+4 zip code.";
		zip.focus();
		alert(strMsg);
    	return false ;

	}
	/*for (var i=0; i < ltrim(zip.value).length; i++) 
	{
		var temp = ltrim(zip.value).substring(i, i+1)
		if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") 
		{
			fOK = false
			strMsg = "Invalid characters in your zip code.  Please try again."
			zip.focus()
		}
		else if ((hyphencount > 1) || ((ltrim(zip.value).length==10) && ltrim(zip.value).charAt(5)!="-"))  
		{
			fOK = false
			strMsg = "The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again."
		}
	  }*/
   }
  
 if (country.value == "CAN" || country.value == "CA")	//for Canada, certain states and zip in xxxxxx format
  {
	if ((ltrim(zip.value)).length == 0)
	{
		strMsg = "Please enter your zip code.";
		zip.focus();
		alert(strMsg);
	    return false ;

	}		
	else if ((ltrim(zip.value)).length !=7)
	{
		strMsg = "The \"Zip Code\" must be \"XXX XXX\" format.";
		zip.focus();
		alert(strMsg);
	    return false ;

	}
  }
    document.specialoffer_form.Isspecialoffer_form.value=1;
    return true;
}

function validateEmail(email)
{
    if (email != null)
    {
      if ((ltrim(email.value)).length !=0)
      {
        if (echeck(email.value)==false)
        {
	        email.focus();
	        return false ;
	    }
      }
   }
}

function pageInit(){
	var spPagetext = document.getElementById("briefcomments");
    var strIsspecialoffer_form = document.getElementById("Isspecialoffer_form").value;
	if (strIsspecialoffer_form == "1")
		spPagetext.innerHTML = "Thank you for submitting your information.";
		
}

function openwindow(strURL)
{
 var newWindow;

 newWindow = window.open(strURL,'','toolbar=no,resizable=no,scrollbars=no,width=350,height=200');
 if(newWindow!=null) newWindow.focus();
}

function validateRepbyZip(currentAction,IsQuestionMark)
{
   if (IsQuestionMark == 0)
      window.location = currentAction + "&repBYzip=" + document.getElementById("repBYzip").value;
   else
      window.location = currentAction + "?repBYzip=" + document.getElementById("repBYzip").value;

}

function SprcialOff(currentAction,IsQuestionMark)
{   //alert(currentAction  + " " + IsQuestionMark)
    var IsSubmit = validateSprcialOff();
    var queryItem;
    
    if (IsSubmit)
    {
        //queryItem = "name=" + document.getElementById("name").value;
        queryItem = "fname=" + document.getElementById("fname").value;
        queryItem = queryItem + "&lname=" + document.getElementById("lname").value;
        queryItem = queryItem + "&SPtitle=" + document.getElementById("SPtitle").value;
        queryItem = queryItem + "&email=" + document.getElementById("email").value;
        if (document.getElementById("orgList").style.display == 'block')
        {
            queryItem = queryItem + "&school=" + document.getElementById("MDR_PID_Special").value;
        }
        else
        {
            queryItem = queryItem + "&school=" ;
        }
        queryItem = queryItem + "&zip=" + document.getElementById("zip").value;
        queryItem = queryItem + "&country=" + document.getElementById("country").value;
        queryItem = queryItem + "&Isspecialoffer_form=" + document.getElementById("Isspecialoffer_form").value;
      if (IsQuestionMark == 0)
            window.location = currentAction + "&" + queryItem;
        else
            window.location = currentAction + "?" + queryItem;

    }
    
}

function validateRepbyState(currentAction)
{
    if (document.RepbyStateForm.RepbyState.value=="NYC")
      window.location = currentAction + "statecode=NY&AnswerforNYC=YES&CustType=NYC&repBYzip=";
    else
    {
      if (document.RepbyStateForm.RepbyState.value != "")
      {
          window.location = currentAction + "statecode=" + document.RepbyStateForm.RepbyState.value;
       }
    }
}

function LeftNavActive()
{
 
    var temp = document.getElementById("TopicForNav").value;
    if (temp != "")
    {
        if (document.getElementById(temp) !=null)
            document.getElementById(temp).style.color = "#EF6000";
    }
}

function checkacctTypeform()
{
    if (document.acctTypeform.acctType.value=="")
    {
        alert("Please select account type.");
    }
    else
    {
        document.acctTypeform.action = "logon.asp";
        document.acctTypeform.submit();
    }

}



function jumpTo()
{
    var str;
     if (isNaN(document.getElementById("RecID").value))
    {
        alert("Please input a valid number.");
        document.getElementById("RecID").focus();
        return false;
    }
    else
    {
        if (parseInt(document.getElementById("RecID").value) <=parseInt(document.getElementById("total").value)) 
        {
	        window.location.href = "default.asp?page=" + document.getElementById("RecID").value + "&bk=tabs";
        }
        else 
            if (parseInt(document.getElementById("RecID").value) > parseInt(document.getElementById("total").value)) 
            {
                alert("Page is out of the range");
                document.getElementById("RecID").focus();
                 return false;
             }
     }

}		
function jumpToQ()
{
    var str;

    if (isNaN(document.getElementById("QRecID").value))
    {
        alert("Please input a valid number.");
        document.getElementById("QRecID").focus();
        return false;
    }
    else
    {
        if (parseInt(document.getElementById("QRecID").value) <=parseInt(document.getElementById("Qtotal").value)) 
        {
	        window.location.href = "default.asp?Qpage=" + document.getElementById("QRecID").value + "&bk=tabs&currtab=Quotes";
        }
        else 
            if (parseInt(document.getElementById("QRecID").value) > parseInt(document.getElementById("Qtotal").value)) 
            {
                alert("Page is out of the range");
                document.getElementById("QRecID").focus();
                 return false;
             }
    }

}
function checkcomment()
{
  var comments = document.account.comments.value;
  var destination = document.account.destination;
  var destOption = -1;

	for (i=0; i<destination.length; i++)
	{
		if (destination[i].checked)
		{
			destOption = destination[i].value;
		}
	}

	if (destOption == -1)
	{
		alert("Please check which area you have a question about!");
		destination[0].focus();
		return false;
	}
  if (document.account.name.value.length == 0)
  {
	alert("Please write your name!");
	account.name.focus();
	return false;
  }
  if (document.account.email.value.length == 0)
  {
	alert("Please write your email!");
	account.email.focus();
	return false;
  }
  else
  {
    if (echeck(document.account.email.value)==false){
	    document.account.email.focus();
	    return false ;

    }
  }
  if (comments.length == 0)
  {
	alert("Please write your comments!");
	account.comments.focus();
	return false;
  }

 }
 

function windowopenhelp(URL,child) {
window.open(URL,child,'height=530,width=750,resizable=1,status=1');
}

		 
function validateHelpSearch() {
	if (document.search.txtKeyword.value == "SEARCH")
	{
		alert("Please enter keyword(s) to search for.");
		return false;
	}
	else
	{	
		document.search.submit();
	}
}

/********************************
********************************
The below is for registion/log in/request a catalog

********************************
********************************/	

function LoginValidation()
{
    if (document.getElementById("Signin_uname").value=="")
    {
        alert("Please enter your user name for log in.");
        document.getElementById("Signin_uname").focus();
        return false;
    }
    else
        if (document.getElementById("Signin_pword").value=="")
        {
            alert("Please enter your Password for log in.");
            document.getElementById("Signin_pword").focus();
            return false;
        }
    else
        return true;
}
		
function validategen(form)
{
    var fOK = true;
    var strMsg = "";
    var valid = "0123456789-";
    var hyphencount = 0;

    var username = form.username;
    var Pword = form.Pword;
    var Pword2 = form.Pword2;
    var passhint = form.passhint;
    //var contact = form.contact;
    var fname = form.fname;
    var lname = form.lname;
    var address1 = form.address1;
    var city = form.addrcity;
    var state = form.state.value;
    var zip = form.mainzip;
    var country = form.country.value;
    var phone = form.phone;
    var email = form.email;
    var CRM_AcctType = form.CRM_AcctType;
    var schFlag = false;
    if (CRM_AcctType.value == "School" || CRM_AcctType.value == "Day Care Center" || CRM_AcctType.value == "Head Start" || CRM_AcctType.value == "Public School District")
        schFlag = true;
    if (document.getElementById("From").value!="SCHINQ")
    {
        if ((ltrim(username.value)).length == 0)
        {
            alert("Please enter your CA User-ID!");
            username.focus();
            return false;
        }

        if ((ltrim(Pword.value)).length == 0)
        {
            alert("Please enter your password!");
            Pword.focus();
            return false;
        }
        if ((ltrim(Pword2.value)).length == 0)
        {
            alert("Please enter your password again!");
            Pword2.focus();
            return false;
        }
        if (ltrim(Pword2.value) != ltrim(Pword.value))
        {
            alert("Please type the same password!");
            Pword2.focus();
            return false;
        }

        if ((ltrim(passhint.value)).length == 0)
        {
            alert("Please enter your password hint!");
            passhint.focus();
            return false;
        }
    }
   
    if ((ltrim(fname.value)).length ==0)
    {
        alert("Please enter your first name!");
        fname.focus();
        return false;
    }

    if ((ltrim(lname.value)).length ==0)
    {
        alert("Please enter your last name!");
        lname.focus();
        return false;
    }

    if ((ltrim(phone.value)).length == 0) 
    {
          alert("Please enter your phone number!");
          phone.focus();
          return false;
    }

    if ((ltrim(email.value)).length == 0) 
    {
          alert("Please enter your email address!");
          email.focus();
          return false;
    }
    else 
    {
        if (echeck(email.value) == false)
        {
            email.focus();
            return false ;
        }
    }
  
    if ((ltrim(CRM_AcctType.value)).length == 0) 
    {
        alert("Please enter your school/organization type!");
        CRM_AcctType.focus();
        return false;
    }

    //check if state is filled right & zip format is right with respect to which country
    if ((country =="USA" || country =="US") && schFlag == true)//&& document.getElementById("ziptable").style.display == 'block')	//for USA, certain states and zip in xxxxx/xxxxx-xxxx format
    {
        if (state.length == 0 && (ltrim(zip.value)).length == 0)
        {
	        alert("Please enter your zip code or select your STATE!");
	        form.state.focus();
	        return false;
        }
        if ((state=="N/A")||(state=="AB")||(state=="BC")||(state=="MB")||(state=="NB")||
            (state=="NL")||(state=="NS")||(state=="NT")||(state=="NU")||(state=="ON")||(state=="PE")||
            (state=="QC")||(state=="SK")||(state=="YT"))
        {
            alert("Please select a correct state for USA");
            form.state.focus();
            return false;
        }		
        if ((ltrim(zip.value)).length != 0)
        {
             if ((ltrim(zip.value)).length!=5 && (ltrim(zip.value)).length!=10)
            {  
                alert("Please enter your 5 digit or 5 digit+4 zip code.");
                zip.focus();
                return false;
            }
            for (var i=0; i < ltrim(zip.value).length; i++) 
            {
                var temp = ltrim(zip.value).substring(i, i+1);
                if (temp == "-") 
                    hyphencount++;
                if (valid.indexOf(temp) == "-1") 
                {
                    alert("Invalid characters in your zip code.  Please try again.");
                    zip.focus();
                    return false;
                }
             }
         }
	}
	
    if ((country =="CAN" || country =="CA") && schFlag == true)//&& document.getElementById("ziptable").style.display == 'block')	//for USA, certain states and zip in xxxxx/xxxxx-xxxx format
    {
        if (state.length == 0 && (ltrim(zip.value)).length == 0)
        {
	        alert("Please enter your postal code or select your province!");
	        form.state.focus();
	        return false;
        }
       if ((state!="N/A")&&(state!="AB")&&(state!="BC")&&(state!="MB")&&(state!="NB")&&
	        (state!="NL")&&(state!="NS")&&(state!="NT")&&(state!="NU")&&(state!="ON")&&(state!="PE")&&
	        (state!="QC")&&(state!="SK")&&(state!="YT"))
        {
	        alert("Please select a correct state for Canada");
	        form.state.focus();
	        return false;
        }
       if ((ltrim(zip.value)).length != 0)
        {
             if ((ltrim(zip.value)).length !=7)
            {
	            alert("The \"Zip Code\" must be \"XXX XXX\" format.");
	            zip.focus();
	            return false;
            }
        }
    }
    
    if (document.getElementById("cityList").style.display == 'block')
    {
       if ((ltrim(document.getElementById("city").value)).length == 0) 
       {
          alert("Please select your city!");
          document.getElementById("city").focus();
          return false;
       }
   }
    
    if (document.getElementById("orgnizationList").style.display == 'block')
    {
       if ((ltrim(document.getElementById("MDR_PID").value)).length == 0) 
       {
          alert("Please select Organization!");
          document.getElementById("MDR_PID").focus();
          return false;

       }
    }      
    
     if (document.getElementById("Schoolname").style.display == 'block' && document.getElementById("AddrForm").style.display == 'block')
    {
        //other than school, district and other/personal options
       if ((ltrim(document.getElementById("name1").value)).length == 0) 
       {
          alert("Please enter your school/organization name!");
          document.getElementById("name1").focus();
          return false;
       }
   }  
    
    if (document.getElementById("SchoolTypeList").style.display == 'block')
    {
       if ((ltrim(document.getElementById("SchoolType").value)).length == 0) 
       {
          alert("Please enter your school type!");
          document.getElementById("SchoolType").focus();
          return false;

       }
       else
            CRM_AcctType.value = document.getElementById("SchoolType").value;
    }
        
    if (document.getElementById("AddrForm").style.display == 'block')
    {    
        if ((ltrim(document.getElementById("address1").value)).length ==0)
        {
            alert("Please enter your address!");
            address1.focus();
            return false;
        }

        if ((ltrim(document.getElementById("addrcity").value)).length ==0)
        {
            alert("Please enter your CITY!");
            document.getElementById("addrcity").focus();
            return false;
        }
        
        if (country =="USA" || country =="US")	//for USA, certain states and zip in xxxxx/xxxxx-xxxx format
        {
           if (ltrim(form.addrstate.value).length == 0)
            {
                alert("Please select your state.");
                form.addrstate.focus();
                return false;
            }

            if ((form.addrstate.value=="N/A")||(form.addrstate.value=="AB")||(form.addrstate.value=="BC")||(form.addrstate.value=="MB")||(form.addrstate.value=="NB")||
                (form.addrstate.value=="NL")||(form.addrstate.value=="NS")||(form.addrstate.value=="NT")||(form.addrstate.value=="NU")||(form.addrstate.value=="ON")||(form.addrstate.value=="PE")||
                (form.addrstate.value=="QC")||(form.addrstate.value=="SK")||(form.addrstate.value=="YT"))
            {
                alert("Please select a correct state for USA");
                form.addrstate.focus();
                return false;
            }		
            if (ltrim(document.getElementById("addrzip").value).length == 0)
            {
                alert("Please enter your zip code.");
                form.addrzip.focus();
                return false;
            }
             if ((ltrim(form.addrzip.value)).length != 0)
            {
                 if ((ltrim(form.addrzip.value)).length!=5 && (ltrim(form.addrzip.value)).length!=10)
                {  
                    alert("Please enter your 5 digit or 5 digit+4 zip code.");
                    form.addrzip.focus();
                    return false;
                }
                for (var i=0; i < ltrim(form.addrzip.value).length; i++) 
                {
                    var temp = ltrim(form.addrzip.value).substring(i, i+1);
                    if (temp == "-") 
                        hyphencount++;
                    if (valid.indexOf(temp) == "-1") 
                    {
                        alert("Invalid characters in your zip code.  Please try again.");
                        form.addrzip.focus();
                        return false;
                    }

                  }
               }
         }
 
       if (country == "CAN" || country == "CA")	//for Canada, certain states and zip in xxxxxx format
       {
            if (form.addrstate.value=="")
            {
                alert("Please select your province.");
                form.addrstate.focus();
                return false;
            }

            if ((form.addrstate.value!="N/A")&&(form.addrstate.value!="YT")&&(form.addrstate.value!="AB")&&(form.addrstate.value!="BC")&&(form.addrstate.value!="MB")&&(form.addrstate.value!="NB")&&
                (form.addrstate.value!="NL")&&(form.addrstate.value!="NS")&&(form.addrstate.value!="NT")&&(form.addrstate.value!="NU")&&(form.addrstate.value!="ON")&&(form.addrstate.value!="PE")&&
                (form.addrstate.value!="QC")&&(form.addrstate.value!="SK"))
            {
                alert("Please select a correct province for Canada");
                form.addrstate.focus();
                return false;
            }
            if (ltrim(document.getElementById("addrzip").value).length == 0)
            {
                alert("Please enter your postal code.");
                form.addrzip.focus();
                return false;
            }
            if ((ltrim(form.addrzip.value)).length != 0)
            {
                 if ((ltrim(form.addrzip.value)).length !=7)
                {
                    alert("The \"Postal Code\" must be \"XXX XXX\" format.");
                    form.addrzip.focus();
                    return false;
                }
            }
        }
        
        if (country != "CAN" && country != "USA" && country != "CA" && country != "US" )
        {
            if (form.addrstate.value != "N/A" && form.addrstate.value != "")
            {
                alert("Please select \"INTERNATIONAL\" as your STATE");
                form.addrstate.focus();
                return false;
            }
            form.addrzip.value = "";    
        }
 
    }
    return true;                    
}	

function LogonAjax(strChoice)
{
   ClearHidden(); 
   if (strChoice=='state' && document.regform.state.value!="")
    {
       if ((ltrim(document.regform.CRM_AcctType.value)).length == 0) 
       {
          alert("Please enter your school/organization type!");
          document.regform.CRM_AcctType.focus();
          if (document.regform.state.value != "")
            document.regform.state.value = "";
          if (document.regform.mainzip.value != "")
            document.regform.mainzip.value = "";
          if (document.getElementById('ziptable').style.display == 'block')
           document.getElementById('ziptable').style.display = 'none';   
          return false;
       }
       document.getElementById("submit_button").style.display = 'none'; 
       document.getElementById("submit_button_alt").style.display = 'block';
       if (document.regform.mainzip.value != "")
           document.regform.mainzip.value = ""; 
       if (document.getElementById('cityList').style.display == 'block')
        {
            document.getElementById('cityList').style.display = 'none';
           // if (document.getElementById('city').value != "")
           //     document.getElementById('city').value="";
        } 
        
        if (document.getElementById("orgnizationList").style.display == 'block')
        { 
            document.getElementById("orgnizationList").style.display = 'none'; 
            if (document.getElementById('MDR_PID').value != "")
                document.getElementById('MDR_PID').value="";
        }   
        
       
       //openwindow("StateAjax.asp?state="+document.regform.state.value);
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        var url="/shop/StateAjax.asp";
        url=url+"?state="+document.regform.state.value;
        xmlhttp.onreadystatechange=stateChanged_state;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    
    else
        if (strChoice=='city') 
        {
            if (document.getElementById("city").value!="")
            {
               document.getElementById("submit_button").style.display = 'none'; 
               
              // openwindow("MDRAjax.asp?city="+document.getElementById("city").value+"&state="+document.regform.state.value + "&CRM_AcctType="+document.getElementById("CRM_AcctType").value);
               xmlhttp=GetXmlHttpObject();
                if (xmlhttp==null)
                  {
                  alert ("Your browser does not support XMLHTTP!");
                  return;
                  }
                var url="/shop/MDRAjax.asp";
                url=url+"?city="+document.getElementById("city").value;
                url=url+"&state="+document.regform.state.value;
                url=url+"&CRM_AcctType=" + document.getElementById("CRM_AcctType").value;
                xmlhttp.onreadystatechange=stateChanged_cityZip;
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);

                //
            }
            else
            {
                if (document.getElementById("AddrForm").style.display == 'none')
                    document.getElementById("AddrForm").style.display = 'block'; 
                document.regform.addrstate.selectedIndex = document.regform.state.selectedIndex;
            }
       }
     
       else 
         if (strChoice=='zip' && document.getElementById("mainzip").value!="")
            {
           /*
                if (isNaN(document.getElementById("mainzip").value))
                    {
                        alert("Please input a valid zip/postal code.");
                        document.getElementById("mainzip").focus();
                        return false;
                    }*/
               document.getElementById("submit_button").style.display = 'none'; 

               //openwindow("MDRAjax.asp?zip="+document.getElementById("mainzip").value);
                xmlhttp=GetXmlHttpObject();
                if (xmlhttp==null)
                  {
                  alert ("Your browser does not support XMLHTTP!");
                  return;
                  }
                var url="/shop/MDRAjax.asp";
                url=url+"?zip="+document.getElementById("mainzip").value;
                url=url+"&CRM_AcctType="+document.getElementById("CRM_AcctType").value;
                xmlhttp.onreadystatechange=stateChanged_cityZip;
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);
            
            }     
    //document.regform.action = "logon.asp";
    //document.regform.submit();
}
/*	
function LogonAjax1(strChoice)
{

            if (strChoice=='zipspecial' && document.getElementById("zip").value !="")
            {//alert("hello");
                
                xmlhttp=GetXmlHttpObject();
                if (xmlhttp==null)
                  {
                  alert ("Your browser does not support XMLHTTP!");
                  return;
                  }
                var url="/shop/MDRAjax1.asp";
                url=url+"?zip="+document.getElementById("zip").value;
                xmlhttp.onreadystatechange=ZipChanged;
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);
            }
}*/

function ZipChanged()
{
    if (xmlhttp.readyState==4)
      {
        if (trim(xmlhttp.responseText) != "block")
        {  
            //alert(xmlhttp.responseText);
            document.getElementById("orgList").style.display = 'block'; 
            document.getElementById("orgList").innerHTML=xmlhttp.responseText;
         }
      }
}

function stateChanged_state()
{
    if (xmlhttp.readyState==4)
    {
        if (trim(xmlhttp.responseText)=="block")
        {
             document.getElementById("AddrForm").style.display = 'block';
	         if (document.getElementById("SchoolTypeList").style.display == 'block')
                document.getElementById("SchoolTypeList").style.display = 'none';
             if (document.getElementById("Schoolname").style.display == 'none')
                 document.getElementById("Schoolname").style.display = 'block';

        }
        else  
        {    
            document.getElementById("cityList").style.display = 'block'; 
            document.getElementById("cityList").innerHTML=xmlhttp.responseText;
        }
        document.getElementById("submit_button").style.display = 'block'; 
        document.getElementById("submit_button_alt").style.display = 'none'; 
    }
}

function stateChanged_cityZip()
{
    if (xmlhttp.readyState==4)
    {

        if (trim(xmlhttp.responseText)=="block")
        {//alert(xmlhttp.responseText);
             document.getElementById("AddrForm").style.display = 'block';
             if ((document.regform.CRM_AcctType.value=="School" || document.regform.CRM_AcctType.value=="Public School District")&& document.getElementById("SchoolTypeList").style.display == 'none')
                document.getElementById("SchoolTypeList").style.display = 'block';
             if (document.getElementById("Schoolname").style.display == 'none')
                 document.getElementById("Schoolname").style.display = 'block';


        }
        else
        {//alert(xmlhttp.responseText);
            document.getElementById("orgnizationList").style.display = 'block'; 
            document.getElementById("orgnizationList").innerHTML=xmlhttp.responseText;
         }
        document.getElementById("submit_button").style.display = 'block'; 
        document.getElementById("submit_button_alt").style.display = 'none'; 
    }
}

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
      }
    if (window.ActiveXObject)
      {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
}

function ClearHidden()
{
   /* if (document.regform.state.value != "")
     document.regform.state.value = "";
    if (document.getElementById('cityList').style.display == 'block')
        {
            document.getElementById('cityList').style.display = 'none';
            if (document.getElementById('city').value != "")
                document.getElementById('city').value="";
        } 
    if (document.getElementById("orgnizationList").style.display == 'block')
    { 
        document.getElementById("orgnizationList").style.display = 'none'; 
            if (document.getElementById('Organization').value != "")
                document.getElementById('Organization').value="";
    }*/
    if (document.getElementById("AddrForm").style.display == 'block')
        document.getElementById("AddrForm").style.display = 'none';
    if (document.getElementById("addrcity").value != "")
        document.getElementById("addrcity").value = "";
    if (document.regform.addrstate.value != "")
        document.regform.addrstate.value = "";
    if (document.regform.name.value != "")
        document.regform.name.value = "";  
    if (document.regform.address1.value != "")
        document.regform.address1.value = "";                    
    if (document.regform.addrzip.value != "")
        document.regform.addrzip.value = "";
    if (document.getElementById("SchoolTypeList").style.display == 'block')
       document.getElementById("SchoolTypeList").style.display = 'none';            
    if (document.getElementById("SchoolType").value!="")
        document.getElementById("SchoolType").value=""; 
}
 
function ClearForZip()
{
    ClearHidden();
    if (document.regform.state.value != "")
         document.regform.state.value = "";
    if (document.getElementById('cityList').style.display == 'block')
        {
            document.getElementById('cityList').style.display = 'none';
            if (document.getElementById('city').value != "")
                document.getElementById('city').value="";
        } 
    if (document.getElementById("orgnizationList").style.display == 'block')
    { 
        document.getElementById("orgnizationList").style.display = 'none'; 
            if (document.getElementById('MDR_PID').value != "")
                document.getElementById('MDR_PID').value="";
    }
}
  
function ClearForZipSpecial()
{

    if (document.getElementById('DorgList').style.display == 'block')
        {
            document.getElementById('DorgList').style.display = 'none';
            if (document.getElementById('MDR_PID_Special').value != "")
                document.getElementById('MDR_PID_Special').value="";
        } 
   
}
 
function show_hidediv() { 
   ClearHidden(); 
   if (document.regform.country.value!="USA" && document.regform.country.value!="CAN" && document.regform.country.value!="US" && document.regform.country.value!="CA")
    {
        if (document.getElementById('red') != null)
            document.getElementById('red').style.display = 'none';
        if (document.getElementById('ziptable').style.display == 'block')
           document.getElementById('ziptable').style.display = 'none'; 
        if (document.regform.state.value != "")
            document.regform.state.value = "";
        if (document.getElementById('cityList').style.display == 'block')
            {
                document.getElementById('cityList').style.display = 'none';
             //   if (document.getElementById('city').value != "")
             //       document.getElementById('city').value="";
            } 
        if (document.getElementById("orgnizationList").style.display == 'block')
        { 
            document.getElementById("orgnizationList").style.display = 'none'; 
                if (document.getElementById('MDR_PID').value != "")
                    document.getElementById('MDR_PID').value="";
        }              
        if (document.getElementById("AddrForm").style.display == 'none')
            document.getElementById("AddrForm").style.display = 'block';
        for(var i = 0; i <document.regform.addrstate.length; i++) {
            if(document.regform.addrstate.options[i].value=="N/A") 
              document.regform.addrstate.selectedIndex = i;
        }

    }
    else
    {
        if (document.getElementById('red') != null)
            document.getElementById('red').style.display = 'inline';
        if (document.regform.CRM_AcctType.value=="Other/Personal"||(document.regform.CRM_AcctType.value!="School" && document.regform.CRM_AcctType.value!="Day Care Center" && document.regform.CRM_AcctType.value!="Head Start" && document.regform.CRM_AcctType.value!="Public School District"))
        {
            document.getElementById('ziptable').style.display = 'none'
            if (document.regform.state.value != "")
                document.regform.state.value = "";
            if (document.getElementById('cityList').style.display == 'block')
                {
                    document.getElementById('cityList').style.display = 'none';
                 //   if (document.getElementById('city').value != "")
                 //       document.getElementById('city').value="";
                } 
            if (document.getElementById("orgnizationList").style.display == 'block')
            { 
                document.getElementById("orgnizationList").style.display = 'none'; 
                    if (document.getElementById('MDR_PID').value != "")
                        document.getElementById('MDR_PID').value="";
            }	                
            if (document.getElementById("AddrForm").style.display == 'none')
                document.getElementById("AddrForm").style.display = 'block';
      
         }
        else
        {
           if (document.regform.CRM_AcctType.value=="")
            {
                alert("Please enter your school/organization type!");
                document.regform.CRM_AcctType.focus();
            }
            else
            {

                if (document.getElementById('ziptable').style.display == 'none')
                     document.getElementById('ziptable').style.display = 'block';
                if (document.getElementById("orgnizationList").style.display == 'block')
                { 
                    document.getElementById("orgnizationList").style.display = 'none'; 
                    /*if (document.getElementById('MDR_PID').value != "")
                        document.getElementById('MDR_PID').value="";*/
                    if (document.getElementById("AddrForm").style.display == 'block')
                        document.getElementById("AddrForm").style.display = 'none';    
                }  
                if (document.regform.state.value != "")
                    document.regform.state.value = "";
                if (document.getElementById('cityList').style.display == 'block')
                    {
                        document.getElementById('cityList').style.display = 'none';
                       // if (document.getElementById('city').value != "")
                       //     document.getElementById('city').value="";
                    }   
               if (document.regform.mainzip.value != "")
                   document.regform.mainzip.value = ""; 

                //ClearHidden();                            
            }


        }
       }
      
       if (document.regform.CRM_AcctType.value!="Other/Personal" && document.regform.CRM_AcctType.value!="Home School" && (document.regform.country.value=="USA" || document.regform.country.value=="CAN"||document.regform.country.value=="US" || document.regform.country.value=="CA"))
           { 
             document.getElementById("Schoolname").style.display = 'block';
             document.getElementById("HideSchoolName").style.display = 'none';
            }
        else
            if (document.getElementById("Schoolname").style.display == 'block')
            {
                document.getElementById("Schoolname").style.display = 'none';
                document.getElementById("HideSchoolName").style.display = 'block';
            }
     
} 

function OrganizationChoice()
{
    ClearHidden();  
    if (document.getElementById('MDR_PID').value == "" || document.getElementById('MDR_PID').value == "N/A")
    {
        document.getElementById("AddrForm").style.display = 'block'; 
        if ((document.regform.CRM_AcctType.value=="School" || document.regform.CRM_AcctType.value=="Public School District" ||document.regform.CRM_AcctType.value=="County School" ||document.regform.CRM_AcctType.value=="Day Care Center"  ||document.regform.CRM_AcctType.value=="Head Start")&& document.getElementById("SchoolTypeList").style.display == 'none')
        {
            document.getElementById("SchoolTypeList").style.display = 'block';
            //document.getElementById("SchoolType1").style.display = 'block';
            //document.getElementById("SchoolType").style.display = 'none';
        }

        if (document.getElementById('ziptable').style.display == "block")
        {
            document.regform.addrstate.selectedIndex = document.regform.state.selectedIndex;
            document.regform.addrzip.value = document.regform.mainzip.value;
            if (document.regform.addrzip.value!="")
            {
                document.regform.addrcity.value = document.regform.maincity.value; 
                 for(var i = 0; i <document.regform.state.length; i++) {
                    if(document.regform.addrstate.options[i].value==document.regform.mainstate.value) 
                      document.regform.addrstate.selectedIndex = i;
                   }
            }
            if (document.getElementById('cityList').style.display == 'block')
            {
               document.regform.addrcity.value = document.regform.city.options[document.regform.city.selectedIndex].value;
            } 
        }
    }
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(varIn)		//Purpose: Trims the leading spaces from a string
{
	var varOut = ""    
	if(!varIn)
	{
	// string is null, so nothing to do
	}
	else // string has at least one character
	{
		for(intI=0; intI < varIn.length; intI++)
		{
			if(varIn.charAt(intI) != " ")
			{
			//first non-space char found so return
			 //string from this character forward
			varOut = varIn.substring(intI)
			break
			}
		}
	}
	return varOut
}
/********************************
********************************
The above is for registion/request a catalog

********************************
********************************/	

function changeAccoutInfo(str, strAction)
{
    document.addraccount.residential.value = str;
    document.addraccount.action = strAction;
    document.addraccount.submit();
}
function cancelOrder()
{
    var elementsInputs = document.getElementsByTagName("input");
    var isCancelOrder = false;
    for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++)
    {
        if (elementsInputs[intCounter].getAttribute('isCancelOrder')=="yes")
        {         
            if (elementsInputs[intCounter].checked)
            {
                isCancelOrder = true;  
                   
            }     
        }

    }
    if (isCancelOrder)
    {
        document.Orderform.action="cancelorder.asp";
        document.Orderform.submit();
    }
    else
    {

        jumpTo();
    }
}

function cancelquote()
{
    var elementsInputs = document.getElementsByTagName("input");
    var isCancelOrder = false;

    for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++)
    {
        if (elementsInputs[intCounter].getAttribute('isdeleteQ')=="yes")
        {         
            if (elementsInputs[intCounter].checked)
            {
                isCancelOrder = true;  
                   
            }     
        }

    }
    if (isCancelOrder)
    {
        document.qform.action="deletequote.asp";
        document.qform.submit();
    }
    else
        jumpToQ();
    
}


function Getzipspecial()
{   
    if (document.getElementById("zip").value != "")
    {
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        var url="/shop/MDRAjax1.asp";
        url=url+"?zip="+document.getElementById("zip").value;
        xmlhttp.onreadystatechange=ZipChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}
 
function GetzipDownload()
{   
    if (document.getElementById("Dzip").value != "")
    {
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        var url="/shop/MDRAjax2.asp";
        url=url+"?zip="+document.getElementById("Dzip").value;
        xmlhttp.onreadystatechange=ZipChanged2;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}
 
function GetzipContact(option)
{   
    if (document.getElementById("Dzip").value != "")
    {
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
          alert ("Your browser does not support XMLHTTP!");
          return;
        }
        var url="/shop/MDRAjax1.asp?contact=1&option="+option;
        url=url+"&zip="+document.getElementById("Dzip").value;
        xmlhttp.onreadystatechange=ZipChanged2;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}
 
function ZipChanged2()
{
    if (xmlhttp.readyState==4)
    {
        if (trim(xmlhttp.responseText) != "block") //schools found; fill up list
        {
            //alert(xmlhttp.responseText);
            document.getElementById("DorgList").style.display = 'block'; 
            document.getElementById("DorgList").innerHTML=xmlhttp.responseText;
        }
        else //no school returned
        {  
            var url="/shop/AddressAjax.asp";
            //url=url+"?PID="+document.getElementById('MDR_PID_Special').value;
            xmlhttp.onreadystatechange=stateChanged_contact;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);    
        
             //document.getElementById("ContactAddrForm").style.display = 'block';
        }
    }
}

function ClearForZipContact()
{
    document.getElementById('Dzip').value = '';
    if (document.getElementById('DorgList').style.display == 'block')
    {
        document.getElementById('DorgList').style.display = 'none';
        document.getElementById("ContactAddrForm").style.display = 'none';
        /*
        if (document.getElementById("address1") != null)
            document.getElementById("address1").value = '';
        if (document.getElementById("addrcity") != null)
            document.getElementById("addrcity").value = '';
        if (document.getElementById("addrzip") != null)
            document.getElementById("addrzip").value = '';
        if (document.getElementById("phone") != null)
            document.getElementById("phone").value = '';
        */
    } 
}

function OrganizationChoice2(option)
{
    ClearHidden(); 
    if (option == "6" || option == "8" || option == "10")
    {
        if (document.getElementById("DorgList").style.display == 'block')
        {
        //get address for selected school
            xmlhttp=GetXmlHttpObject();
            if (xmlhttp==null)
            {
                alert ("Your browser does not support XMLHTTP!");
                return;
            }
            var url="/shop/AddressAjax.asp";
            url=url+"?PID="+document.getElementById('MDR_PID_Special').value;
            xmlhttp.onreadystatechange=stateChanged_contact;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);    
        }
        else
        {
            document.getElementById("ContactAddrForm").style.display = 'block';
        }
    }
    else
    {
        document.getElementById("ContactAddrForm").style.display = 'none'; 
    }  
}

function stateChanged_contact()
{
/*
    if (xmlhttp.readyState==4)
    {
//        document.getElementById("contactList").style.display = 'none';
        if (trim(xmlhttp.responseText)=="block")
        {
             document.getElementById("ContactAddrForm").style.display = 'block';
        }
        else
        {
            document.getElementById("ContactAddrForm_List").style.display = 'block'; 
            document.getElementById("ContactAddrForm_List").innerHTML=xmlhttp.responseText;
         }
        //document.getElementById("submit_button").style.display = 'block'; 
    }*/
    if (xmlhttp.readyState == 4)
    {
        document.getElementById("ContactAddrForm").style.display = 'block'; 
        document.getElementById("ContactAddrForm").innerHTML=xmlhttp.responseText;
    }
}

function validateContact(form)
{ 
	  var strMsg = "";
	  var fname = form.fname;
	  var lname = form.lname;
	  var jtitle = form.jtitle;
	  var email = form.email;
      var comments = form.comments;
      var destination = form.destination;
      
      if (destination.value.length == 0)
      {
        strMsg = "Please make a selection.";
        form.destination.focus();
        alert(strMsg);
        return false;
      }
	  if ((ltrim(fname.value)).length ==0)
	  {
		strMsg = "Please enter your first name!";
		fname.focus();
		alert(strMsg);	
		return false;  
	  }
	  if ((ltrim(lname.value)).length ==0)
	  {
		strMsg = "Please enter your last name!";
		lname.focus();
		alert(strMsg);	
		return false;  
	  }
	  if ((ltrim(jtitle.value)).length ==0)
	  {
		strMsg = "Please enter your job title!";
		jtitle.focus();
		alert(strMsg);	
		return false;  
	  }
	  if ((ltrim(email.value)).length == 0) 
	   {
		  strMsg = "Please enter your email address!";
		  email.focus();
		  alert(strMsg);	
		  return false;  
	  }
	  else 
      {
        if (echeck(email.value)==false)
        {
	        email.focus();
	        return false ;
        }
      }
      if (comments.value == "Write your message here.")
        comments.value = "";
//      if ((ltrim(comments.value)).length == 0 || comments.value == "Contact us about...") 
//      {
//          strMsg = "Please tell us how we can help you.";
//		  alert(strMsg);	
//		  return false;  
//      }
    
    if (destination.value == "6" || destination.value == "8" || destination.value =="10")
    {
        if ((ltrim(form.zip.value)).length == 0)
        {
            strMsg = "Please enter school/organization zip code!";
            form.zip.focus();
            alert(strMsg);
            return false;
        }
        if (form.MDR_PID_Special != null)
        {
            if (form.MDR_PID_Special.value.length == 0)
            {
                strMsg = "Please select your school!";
                form.MDR_PID_Special.focus();
                alert(strMsg);
                return false;
            }
        }
        if (document.getElementById("ContactAddrForm").style.display == 'block')
        {
            //show address
            
            if ((ltrim(form.address1.value)).length == 0) 
            {
                strMsg = "Please enter your address!";
                form.address1.focus();
                alert(strMsg);
                return false;
            }
            if ((ltrim(form.addrcity.value)).length == 0) 
            {
                strMsg = "Please enter city!";
                form.addrcity.focus();
                alert(strMsg);
                return false;
            }
            if (form.addrstate.value.length == 0)
            {
                strMsg = "Please enter state!";
                form.addrstate.focus();
                alert(strMsg);
                return false;
            }
            if ((ltrim(form.addrzip.value)).length == 0) 
            {
                strMsg = "Please enter zip code!";
                form.addrzip.focus();
                alert(strMsg);
                return false;
            }
            if ((ltrim(form.phone.value)).length == 0)
            {
                strMsg = "Please enter phone number!";
                form.phone.focus();
                alert(strMsg);
                return false;        
            }
        }
    }
	return true;   
}

function windowOpen(URL)
{
	var newWin;
	newWin = window.open(URL,"child","width=750,height=550,location=0,resizable=1,status=0,scrollbars=1,menubar=0,toolbar=0");
}