// JavaScript Document
function checkEmail()
 {
 var strEmail, strError, countAtRate, countDot, i; 
 var checkAtRate, checkDot;
 var ValidChars,CountValidChars;
 ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
 strEmail = checkEmail.arguments[0];
 countAtRate=0;
 countDot=0;
 CountValidChars=0;
 if (strEmail.length >= 7)
  {  
  for(i=0;i<strEmail.length;i++)
   {
   if(strEmail.charAt(i)=="@")
    countAtRate++;
   if(strEmail.charAt(i)==".")
    countDot++;
   CountValidChars=0;
   for(j=0;j<ValidChars.length;j++)
    {
    if(strEmail.charAt(i)==ValidChars.charAt(j))
     {
     CountValidChars++;
     }
    }
   if(CountValidChars==0)
    {
    strError=0;
    break;
    }       
   }
  }
 checkAtRate=strEmail.indexOf("@",1);
 checkDot=strEmail.indexOf(".",1);
 for(i=1;i<countDot;i++)
  checkDot=strEmail.indexOf(".",checkDot+1);
 if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
  strError=1;
 else
  strError=0;
 if(checkDot>=strEmail.length-2)
  strError=0;
 if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
  strError=0;
 if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
  strError=0;
 if(checkDot < checkAtRate)
  strError=0; 
 
 return strError;
}


function validatenewsletter()
{
	var strError="";
	dm = document.frmleftpanel;
	if(dm.fname.value=="")
	 strError+="\nFirst Name";
	if(dm.lname.value=="")
	 strError+="\nLast Name";
	if(checkEmail(dm.email.value)==0)
	 strError+="\nEmail";
	if(strError!="")
	 alert("Please check the missing field(s)\n================"+strError);
	else
	{
		dm.action=validatenewsletter.arguments[0];
		dm.method="post";
		dm.submit();
	}
}

function validatesearch()
{
	var dm=document.frmleftpanel;
	
	var strError="";
	if(validatesearch.arguments[0]==1)
	{
		if(dm.cmbgender[dm.cmbgender.selectedIndex].value=="")
		strError+="Sorry, please choose a Gender to retrieve search results. ";
	}
	if(validatesearch.arguments[0]==2)
	{
		if(dm.cmbgender1[dm.cmbgender1.selectedIndex].value=="")
		strError+="Sorry, please choose a Gender to retrieve search results.";
	}
	if(validatesearch.arguments[0]==3)
	{
		if(dm.cmbgender2[dm.cmbgender2.selectedIndex].value=="")
		strError+="Sorry, please choose a Gender to retrieve search results. ";
	}
	if(validatesearch.arguments[0]==4)
	{
		if(dm.cmbgender3[dm.cmbgender3.selectedIndex].value=="")
		strError+="Sorry, please choose a Gender to retrieve search results. ";
	}

	if(strError!="")
	 alert(strError);
	else
	{
		dm.action=validatesearch.arguments[1];
		dm.method="post";
		dm.submit();
	}

}

function postme()
{
	document.frm.action=postme.arguments[0];
	document.frm.method="post";
	document.frm.submit();
}

function postPage(frmName,strAction)
{
	eval("document."+frmName).action=strAction;
	eval("document."+frmName).method="post";
	eval("document."+frmName).submit();
}

//***** validate Login Form
function validlogin()
{
  var dm = document.frmlogin;
  var strError = "";
  if(dm.uname.value=="")
    strError+="\nUser Name";
  if(dm.upassword.value=="")
    strError+="\nPassword";
  if(strError!="")
  {
    alert("Please check the missing field(s)\n================="+strError);
    return false;
  }
  
}

//****** copy billing customer info to shipping
function copydate()
{
 var dm = document.frmregister;

 if(!dm.chkcopydate.checked)
 {
	 document.getElementById("tdship").style.display="none";
	 dm.sfname.value=dm.bfname.value;
	 dm.slname.value=dm.blname.value;
	 dm.saddr1.value=dm.baddr1.value;
	 dm.saddr2.value=dm.baddr2.value;
	 dm.scity.value=dm.bcity.value;
	 dm.scounty.value=dm.bcounty.value;
	 dm.scountry[dm.bcountry.selectedIndex].selected=true;
	 dm.spostalcode.value=dm.bpostalcode.value;
	 dm.sphone.value=dm.bphone.value;
 }else{
	 document.getElementById("tdship").style.display="block";
 	 dm.sfname.value="";
	 dm.slname.value="";
	 dm.saddr1.value="";
	 dm.saddr2.value="";
	 dm.scity.value="";
	 dm.scounty.value="";
	 dm.scountry[0].selected=true;
	 dm.spostalcode.value="";
	 dm.sphone.value="";
 
 }
}

//**** validate register form
function validateregisterform()
{
 var dm = document.frmregister;
 var strError="";
 var strError1="";
 var strError2="";
 if(validateregisterform.arguments[0]==1)
 {
	 if(dm.bfname.value=="")
	  strError+="\nFirst Name";
	 if(dm.blname.value=="")
	  strError+="\nLast Name";
	 if(dm.baddr1.value=="")
	  strError+="\nAddress 1";
	 if(dm.bcity.value=="")
	  strError+="\nCity";
	 if(dm.bcounty.value=="")
	  strError+="\nCounty";
	 if(dm.bpostalcode.value=="")
	  strError+="\nPostal Code";
	 if(dm.bphone.value=="")
	  strError+="\nPhone";

	 if(dm.sfname.value=="")
	  strError1+="\nFirst Name";
	 if(dm.slname.value=="")
	  strError1+="\nLast Name";
	 if(dm.saddr1.value=="")
	  strError1+="\nAddress 1";
	 if(dm.scity.value=="")
	  strError1+="\nCity";
	 if(dm.scounty.value=="")
	  strError1+="\nCounty";
	 if(dm.spostalcode.value=="")
	  strError1+="\nPostal Code";
	 if(dm.sphone.value=="")
	  strError1+="\nPhone";

	 if(checkEmail(dm.email.value)==0)
	  strError+="\nEmail";
	 if(checkEmail(dm.cemail.value)==0)
	  strError+="\nConfirm Email";

	 if((dm.email.value!="")&&(dm.cemail.value!=""))
	 {
	   if(dm.email.value!=dm.cemail.value)
	    strError+="\nEmail not matched";
	 }
	 if(dm.upassword.value=="")
	  strError+="\nPassword";
	 else{
	  if((dm.upassword.value.length<6) || (dm.upassword.value.length>12))
	   strError+="\nCharacter length";
	 }
	 if(dm.cupassword.value=="")
	  strError+="\nConfirm Password";
	if((dm.upassword.value!="")&&(dm.cupassword.value!=""))
	 {
	   if(dm.upassword.value!=dm.cupassword.value)
	    strError+="\nPassword not matched";
	 }  
	 if(strError!="")
	 	strError2+="\nBilling Info\n=================="+strError;
	 if(strError1!="")
	 	strError2+="\n==============\nShipping Info\n=============="+strError1;
	 
	 if((strError!="")||(strError1!=""))
	 {
	  alert("Please check the missing field(s)\n=================="+strError+strError1);
	  return false;
	 }

   }else{
   
	 if(dm.sfname.value=="")
	  strError+="\nFirst Name";
	 if(dm.slname.value=="")
	  strError+="\nLast Name";
	 if(dm.saddr1.value=="")
	  strError+="\nAddress 1";
	 if(dm.scity.value=="")
	  strError+="\nCity";   
	 if(strError!="")
	 {
	  alert("Please check the missing field(s)\n=================="+strError);
	  return false;
	 }

   }
	
}

//**** validate register form
function validateprofileform()
{
 var dm = document.frmregister;
 var strError="";
	 if(dm.bfname.value=="")
	  strError+="\nFirst Name";
	 if(dm.blname.value=="")
	  strError+="\nLast Name";
	 if(dm.baddr1.value=="")
	  strError+="\nAddress 1";
	 if(dm.bcity.value=="")
	  strError+="\nCity";
 
    if(dm.email.value!="")
    {
	 if(checkEmail(dm.email.value)==0)
	  strError+="\nEmail";
	
     }
	 if(dm.upassword.value!="")
	 {
	  if((dm.upassword.value.length<6) || (dm.upassword.value.length>12))
	   strError+="\nCharacter length";
	 
		 if(dm.cupassword.value=="")
		  strError+="\nConfirm Password";
		if((dm.upassword.value!="")&&(dm.cupassword.value!=""))
		 {
		   if(dm.upassword.value!=dm.cupassword.value)
		    strError+="\nPassword not matched";
		 }  
	}
	 if(strError!="")
	 {
	  alert("Please check the missing field(s)\n=================="+strError);
	  return false;
	 }


	
}

function prescriptionSunDetail(val)
{
	var dm=document.frm;
	var rdo="";
	if(dm.rdoFrameColor.length>1)
	{
		for(var j = 0; j < dm.rdoFrameColor.length; j++)
		{
			if(dm.rdoFrameColor[j].checked==true)
			{
				rdo = dm.rdoFrameColor[j].value;
				break;
			}
		}
	}
	else if(dm.rdoFrameColor.checked==true)
		rdo=dm.rdoFrameColor.value;

	if(rdo == "")
	{
		alert("Submit error - Please select a frame color!");
		return false;
	}

	if((val!="Non Presc. Sun Glasses") && (val!="Reading Glasses"))
	{
		if(dm.cmboption.value=="")
		{
		alert("Submit error - I would like my glasses Option is not selected!");
		dm.cmboption.focus();
		return false;
		}
	}
	
	if((val=="Reading Glasses"))
	{
		if(dm.cmbReadingStrength.value=="")
		{
			alert("Submit error -  Please select Reading Strength");
			dm.cmbReadingStrength.focus();
			return false;
		}
	}
	if(dm.cmbsize.value=="" && val!="Reading Glasses")
	{
		alert("Submit error - Size is not selected!");
		dm.cmbsize.focus();
		return false;
	}

	if(val!="Non Presc. Sun Glasses" && val!="Reading Glasses")
	{
		if(dm.cmbLensMaterial.value=="")
		{
			alert("Submit error - Lens Material is not selected!");
			dm.cmbLensMaterial.focus();
			return false;
		}
		
		if(dm.cmbSunProtection.value=="")
			{
				alert("Submit error - Sun Protection is not selected!");
				dm.cmbSunProtection.focus();
				return false;
			}
		

		if(dm.cmbLensCoating.value=="")
		{
			alert("Submit error - Lens Coating is not selected!");
			dm.cmbLensCoating.focus();
			return false;
		}
		if((dm.cmbday[dm.cmbday.selectedIndex].value=="")||(dm.cmbmonth[dm.cmbmonth.selectedIndex].value=="")||(dm.cmbyear[dm.cmbyear.selectedIndex].value==""))
		{
			alert("Submit error - Please select Date of Birth!");
			return false;
		}
		/*if((dm.cmbPday[dm.cmbPday.selectedIndex].value=="")||(dm.cmbPmonth[dm.cmbPmonth.selectedIndex].value=="")||(dm.cmbPyear[dm.cmbPyear.selectedIndex].value==""))
		{
			alert("Submit error - Please select Prescription Date!");
			return false;
		}*/
	}
	else
		return true;
}



//***** Validate Final Credit Card Processing

function validateCCProcessing()
{
  var dm = document.frmfinalorder;
  var strError="";
  if(dm.cmbtype[dm.cmbtype.selectedIndex].value=="")
   strError+="\nCredit Card Type";
  if(dm.ccnum.value=="")
   strError+="\nCredit Card Number";
  if((dm.cmbmonth[dm.cmbmonth.selectedIndex].value=="")||(dm.cmbyear[dm.cmbyear.selectedIndex].value==""))
   strError+="\nExpiry Date";

  
  if(dm.cvv.value=="")
   strError+="\nCVV Number";
  if(strError!="")
  {
    alert("Please check the missing field(s)\n================="+strError);
   // return false;
  }
  else{
   dm.method="post";
   dm.action=validateCCProcessing.arguments[0];
   dm.submit();
  }
}
function validateCCProcessing1()
{
  var dm = document.frmfinalorder;
   dm.method="post";
   dm.action=validateCCProcessing1.arguments[0];
   dm.submit();

}

function win(filename,winName,height,width,scroll,resize)
{
	window.open(filename,winName,"directories=no,scrollbars="+scroll+",status=no,resizable="+resize+",height="+height+",width="+width+",top=1,left=1")
}

function chkcontact()
{
 var dm = document.frm;
 var strError="";

if(dm.txtName.value=="")
  strError+="\nName";

if(checkEmail(dm.txtEmail.value)==0)
  strError+="\nEmail";

if(dm.txtMessage.value.length==0)
  strError+="\nMessage";

if(strError!="")
	{
	 alert("Please check the missing field(s)\n======================"+strError);
	 return false;
	}
}

//for validating refer friend's page 
function validate_refer_form()
{
	var dm = document.frmRefer;
	var strError="";
	var counter=0;
	var EmailCount=0;
	if(dm.urfname.value=="")
		strError+="\nYour First Name";
	if(dm.urlname.value=="")
		strError+="\nYour Last Name";
	if(checkEmail(dm.uremail.value)==0)
		strError+="\nYour Email";
	for(i=0;i<=9;i++)
	{
		if((dm.firstname[i].value!="")&&(dm.clmail[i].value!=""))
			counter++;
	}
	
	for(i=0;i<=9;i++)
	{
		if(((dm.firstname[i].value!="")&&(dm.clmail[i].value==""))||((dm.firstname[i].value=="")&&(dm.clmail[i].value!="")))
			counter++;
	}
	
	if(counter==0)
		strError+="\nAt Least One Friend's Name & Email Address Required";
	else{
		for(i=0;i<=9;i++)
		{
			if(dm.clmail[i].value!="")
			{
				if(checkEmail(dm.clmail[i].value)==0)
					EmailCount++;
			}
				
		}
	}
	counter=0;
	for(i=0;i<=9;i++)
	{
		if(((dm.firstname[i].value!="")&&(dm.clmail[i].value==""))||((dm.firstname[i].value=="")&&(dm.clmail[i].value!="")))
			counter++;
	}
	if(counter!=0)
		strError+="\nMissing Friend's Name/Email";
		
	if(EmailCount!=0)
		strError+="\nInvslid Email";

	if(dm.urmsg.value=="")
		strError+="\nMessage";

	if(strError!="")
	{
		alert("Please check the missing field(s)\n==================="+strError);
		return false;
	}

}
//*** validation for forget password
function validate_forgetpassword()
{
  var dm = document.frmlogin;
  if(checkEmail(dm.uname.value)==0)
  {
   alert("Invalid Username");
   return false;
  }
}

function QA()
{
	var dm=document.frmQA;
	var err="Yes";
	var noOfChk=0;
	for (i=1;i<11 ;i++ )
	{
		for (j=0;j<eval("dm.rdo"+i).length;j++ )
		{
			if(eval("dm.rdo"+i+"["+j+"]").checked==true)
				noOfChk=noOfChk+1;
		}
	}

	for(j=0; j<dm.cmbPriceBand.length; j++)
	{
		if(eval("dm.cmbPriceBand["+j+"]").checked==true)
			noOfChk=noOfChk+1;
	}
	
	if(noOfChk<11)
	{
		alert("Please answer all questions to continue.");
		return false;
	}
	else
		return true;
}

<!-- Begin
function v1() { 
     xt=true;
      df=document.frmleftpanel;
            if ((df.xF.value=='')&&(df.xL.value=='')&&(df.xE.value=='')) {
                  alert('You must fill in ALL fields before proceeding!')
                   df.xF.focus()
                   xt=false
                   }
                   
     if(df.xE.value!='')
     {
	     if (!(df.xE.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1))  {
		   alert('Your EMAIL information does not appear to be Valid!')
		   df.xE.focus()
		   xt=false
		   }
	}
        if (xt==true) {
         df.method="post";
         df.action="submit_newsletter.asp?mode=Ad"
         df.submit();
       }
       //return xt
}
//  End -->