// JScript source code
var paymenterrormsg="";

function  validate(checkcontact, checkshipping)
{

      contactsign = true;
      shippingsign = true;

     if(document.forms.saveaddress.shipaddressId[0].checked)
	 {
	  	check = "false";
	 }
	 else
	 {
	  	 check = "true";
	 }


      if(check=="true")
      {
         shippingsign = checkshippinginfo();
      }

      if(checkcontact ==1)
      {
         contactsign = checkcontactinfo();
      }

      if((contactsign)&&(shippingsign))
      {
      	return true
      }
      else
      {
        /*if((checkcontact==1) && (checkshipping==1))
        {
       	 	x = document.getElementById("msg");
	        x.innerHTML = "Wrong Information, please check your contact information"
	        x.className = "FormFieldLabelError";
        } */
        return false
      }
}




function checkcontactinfo()
{
       flag = "TRUE";

       var x = document.getElementById("cfirstnameId");
	    str = x.value ;
	     if(str.length<=0)
	     {
	     	flag = "FALSE";
            y= document.getElementById("tbcfirstnameId");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcfirstnameId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("clastnameId");
         str = x.value ;
	     if(str.length<=0)
	     {
	         flag = "FALSE";
              y= document.getElementById("tbclastnameId");
	        y.className = "RequiredHighlightError";

	     }
         else
         {
           y= document.getElementById("tbclastnameId");
	        y.className = "RequiredHighlight";
         }


         var x = document.getElementById("caddress1Id");
          str = x.value;
	     if(str.length<=0)
	     {
	       flag = "FALSE";
             y= document.getElementById("tbcaddress1Id");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcaddress1Id");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("ccityId");
          str = x.value ;
	     if(str.length<=0)
	     {
	         flag = "FALSE";
             y= document.getElementById("tbccityId");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbccityId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("czipId");
         str = x.value;
         var reg1= /^\d{5}$/
		 var reg2= /^\d{5}-\d{4}$/

		 if(!( ( reg1.test(str) ) || ( reg2.test(str) ) ) )
	     {
	         flag = "FALSE";
             y= document.getElementById("tbczipId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbczipId");
	         y.className = "RequiredHighlight";
         }

         var x = document.getElementById("cstateId");
         sid = x.selectedIndex ;
	     if(sid==0)
	     {   flag = "FALSE";
             y= document.getElementById("tbcstateId");
	         y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcstateId");
	        y.className = "RequiredHighlight";
         }


         if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Wrong Information, please check your contact information"
        x.className = "FormFieldLabelError";
        return false
     }
     else
     {
     	return true
     }
}

function checkshippinginfo()
{
     flag = "TRUE";
    var x = document.getElementById("firstnameId");
	     str = x.value ;
	     if(str.length<=0)
	     {

	         flag = "FALSE";
             y= document.getElementById("tbfirstnameId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbfirstnameId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("lastnameId");
          str = x.value ;
	     if(str.length<=0)
	     {
	       flag = "FALSE";
            y= document.getElementById("tblastnameId");
	        y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tblastnameId");
	        y.className = "RequiredHighlight";
         }

	     var x = document.getElementById("address1Id");
          str = x.value ;
	     if(str.length<=0)
	     {
	         flag = "FALSE";
             y= document.getElementById("tbaddress1Id");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbaddress1Id");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("cityId");
        str = x.value ;
	     if(str.length<=0)
	     {
	        flag = "FALSE";
             y= document.getElementById("tbcityId");
	        y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbcityId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("zipId");
         str = x.value ;
         var reg1= /^\d{5}$/
		 var reg2= /^\d{5}-\d{4}$/

		 if(!( ( reg1.test(str) ) || ( reg2.test(str) ) ) )
	     {
	         flag = "FALSE";
             y= document.getElementById("tbzipId");
	        y.className = "RequiredHighlightError ";
	     }
         else
         {
             y= document.getElementById("tbzipId");
	        y.className = "RequiredHighlight";
         }

         var x = document.getElementById("stateId");
         sid = x.selectedIndex ;
	     if(sid==0)
	     {
             flag = "FALSE";
             y= document.getElementById("tbstateId");
	        y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbstateId");
	        y.className = "RequiredHighlight";
         }

    if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Wrong Information, please check your shipping information"
        x.className = "FormFieldLabelError";
        return false
     }
     else
     {
     	return true
     }
}

function set(shipvalue)
{
     //alert(shipvalue)
     var x = document.getElementById("shipaddressId");
     x.value = shipvalue
    // alert (x.value)
}

////////////////////For Payment Page////////////////


function validatepayment()
{
  paymenterrormsg ="";
  var flag =true;
  var bill = checkbillinginfo();
  var payment = checkpaymentinfo();
  var phoneemail = checkphoneemail();
  var termbox = checktermbox();
  if((bill==false)||(payment==false) || (phoneemail==false)|| (termbox == false) )
  {
    flag = false;

    x = document.getElementById("msg");
    x.innerHTML = paymenterrormsg ;
    x.className = "FormFieldLabelError";
  }
  return  flag
}

function checkbillinginfo()
{
         flag = "TRUE";

         var x = document.getElementById("bfirstnameId");
    	str = x.value ;
	    if(str.length<=0)
	    {

	        flag = "FALSE";
	         y= document.getElementById("tbbfirstnameId");
	         y.className = "RequiredHighlightError ";
	    }
        else
        {
            y= document.getElementById("tbbfirstnameId");
	         y.className = "RequiredHighlight";
        }
	    var x = document.getElementById("blastnameId");
	    str = x.value ;
	    if(str.length<=0)
	    {

	        flag = "FALSE";
	         y= document.getElementById("tbblastnameId");
	         y.className = "RequiredHighlightError ";
	    }
        else
        {
           y= document.getElementById("tbblastnameId");
	       y.className = "RequiredHighlight";
        }


         var x = document.getElementById("baddress1Id");
         str = x.value;
	     if(str.length<=0)
	     {

		   flag = "FALSE";
           y= document.getElementById("tbbaddress1Id");
	       y.className = "RequiredHighlightError ";
	     }
         else
         {
           y= document.getElementById("tbbaddress1Id");
	       y.className = "RequiredHighlight";
         }

	     var x = document.getElementById("bcityId");
          str = x.value ;
	     if(str.length<=0)
	     {

			 flag = "FALSE";
             y= document.getElementById("tbbcityId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
             y= document.getElementById("tbbcityId");
	         y.className = "RequiredHighlight";
         }

	     var x = document.getElementById("bzipId");
          str = x.value;

         var reg1= /^\d{5}$/
		 var reg2= /^\d{5}-\d{4}$/

		 if(!( ( reg1.test(str) ) || ( reg2.test(str) ) ) )
	     {

			flag = "FALSE";
            y= document.getElementById("tbbzipId");
	        y.className = "RequiredHighlightError ";
	     }
         else
         {
             y= document.getElementById("tbbzipId");
	         y.className = "RequiredHighlight";
         }


         var x = document.getElementById("bstateId");
         sid = x.selectedIndex ;
	     if(sid==0)
	     {   flag = "FALSE";
             y= document.getElementById("tbbstateId");
	         y.className = "RequiredHighlightError";
	     }
         else
         {
           y= document.getElementById("tbbstateId");
	        y.className = "RequiredHighlight";
         }







     if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Wrong Information, please check your billing address information "
        x.className = "FormFieldLabelError";

        paymenterrormsg = "Wrong Information, please check your billing address information <br>";
        return false
     }
     else
     {
     	return true
     }
}

function checkpaymentinfo()
{
	flag = "TRUE";

    var x = document.getElementById("cardholderId");
   str = x.value ;
	if(str.length<=0)
	{
		 	 flag = "FALSE";
             y= document.getElementById("tbcardholderId");
	        y.className = "RequiredHighlightError ";
	}
    else
    {
         y= document.getElementById("tbcardholderId");
	     y.className = "RequiredHighlight";
    }

   var x = document.getElementById("cardtypeId");
   sid = x.selectedIndex ;
	if(sid==0)
	{
		flag = "FALSE";
        y= document.getElementById("tbcardtypeId");
	    y.className = "RequiredHighlightError ";
	}
    else
    {
         y= document.getElementById("tbcardtypeId");
	     y.className = "RequiredHighlight";
    }

       var x = document.getElementById("cardnumberId");
	    str = x.value ;

        var reg= /^\d{13,16}$/


		 if(!( reg.test(str)) )

         //if(str.length<=0)
	     {
			flag = "FALSE";
            y= document.getElementById("tbcardnumberId");
	        y.className = "RequiredHighlightError ";

	     }
         else
         {
            y= document.getElementById("tbcardnumberId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("securitycodeId");
         str = x.value ;
	     if(str.length<=0)
	     {
			 flag = "FALSE";
             y= document.getElementById("tbsecuritycodeId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
           y= document.getElementById("tbsecuritycodeId");
	       y.className = "RequiredHighlight";
         }

         var x = document.getElementById("startmonthId");
         sid_month = x.selectedIndex ;
		 var expmm= x.options[x.selectedIndex].text+'';
	     if(sid_month==0)
	     {
			 flag = "FALSE";
             y= document.getElementById("tbstartmonthId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
             y= document.getElementById("tbstartmonthId");
	         y.className = "RequiredHighlight";
         }


         var x = document.getElementById("startyearId");
         sid_year = x.selectedIndex ;
         var expyy = x.options[x.selectedIndex].text+'';
	     if(sid_year==0)
	     {
			 flag = "FALSE";
             y= document.getElementById("tbstartyearId");
	         y.className = "RequiredHighlightError ";
		}
        else
        {
            y= document.getElementById("tbstartyearId");
	        y.className = "RequiredHighlight";
        }


         var todate = new Date()
 		 var todmm = todate.getMonth() + 1+''
         if(todmm.length==1)
        {
         	todmm = "0"+todmm
         }
         var todyy = todate.getFullYear()+''
         var tostr = todyy+todmm

         var expdate = expyy + expmm;

          //alert("expdate="+expdate+"tostr="+tostr)
         if ( (expdate<tostr) || (sid_year==0) || (sid_month==0)  )
         {
			flag = "FALSE";
            y= document.getElementById("tbstartmonthId");
	        y.className = "RequiredHighlightError ";
            y= document.getElementById("tbstartyearId");
	        y.className = "RequiredHighlightError ";
         }
         else
         {
            y= document.getElementById("tbstartmonthId");
	        y.className = "RequiredHighlight";
            y= document.getElementById("tbstartyearId");
	        y.className = "RequiredHighlight";
         }




	if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Incorrect or missing payment information. Please try again."
        x.className = "FormFieldLabelError";
        paymenterrormsg = paymenterrormsg + "Incorrect or missing payment information. Please try again. <br>";
        return false
     }
     else
     {
     	return true
     }
}

function checkphoneemail()
{
    flag = "TRUE";

    var x = document.getElementById("emailId");
    str = x.value ;

    var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;

     if(!( emailRegxp.test(str)) )
	 {
           	flag = "FALSE";
	    	y= document.getElementById("tbemailId");
	    	y.className = "RequiredHighlightError ";
	 }
     else
     {
            y= document.getElementById("tbemailId");
	        y.className = "RequiredHighlight";
     }


    var x = document.getElementById("dayphoneId");
    str = x.value ;

    var phoneRegxp1 = /^\(\d{3}\)\d{3}-\d{4}$/;
    var phoneRegxp2 =/^\d{3}-\d{3}-\d{4}$/;


	if( ! ( (phoneRegxp1.test(str)) ||  (phoneRegxp2.test(str)) ) )
	{
		flag = "FALSE";
	    y= document.getElementById("tbdayphoneId");
	    y.className = "RequiredHighlightError ";
	}
    else
    {
            y= document.getElementById("tbdayphoneId");
	         y.className = "RequiredHighlight";
    }

     if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Please check your phone and email information" ;
        x.className = "FormFieldLabelError";
        paymenterrormsg = paymenterrormsg + "Please check your phone and email information<br>";
        return false
     }
     else
     {
     	return true
     }

}

function checktermbox()
{
    flag = "TRUE";

    var x = document.getElementById("termboxId");

	if(!(x.checked))
	{

		flag = "FALSE";
	}

    if( flag=="FALSE")
    {
        x = document.getElementById("msg");
        x.innerHTML = "You must agree to our Terms and Conditions in order to place this order." ;
        x.className = "FormFieldLabelError";
         paymenterrormsg = paymenterrormsg + "You must agree to our Terms and Conditions in order to place this order.<br>";
        return false
     }
     else
     {
     	return true
     }
}




function updateitems(count)
{
    valid = true;

    for (i=0; i<count; i++)
	{
    	var x = document.getElementById("jq["+i+"]");
        var y = document.getElementById("jsq["+i+"]");
	    updatequantity = x.value ;
        stockquantity = y.value ;

	   if(updatequantity >stockquantity)
	    {
	        alert("If your ordering product exceed our stock quantity, please use our online quote feature. Thanks.");
	        valid = false
	    }
	}

    return valid

}

////////////////////For edit_contactinfo.php/////////////////

function validatecontactinfo()
{

    flag = "TRUE";

       var x = document.getElementById("cfirstnameId");
	    str = x.value ;
	     if(str.length<=0)
	     {
	     	flag = "FALSE";
            y= document.getElementById("tbcfirstnameId");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcfirstnameId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("clastnameId");
         str = x.value ;
	     if(str.length<=0)
	     {
	         flag = "FALSE";
              y= document.getElementById("tbclastnameId");
	        y.className = "RequiredHighlightError";

	     }
         else
         {
           y= document.getElementById("tbclastnameId");
	        y.className = "RequiredHighlight";
         }


         var x = document.getElementById("caddress1Id");
          str = x.value;
	     if(str.length<=0)
	     {
	       flag = "FALSE";
             y= document.getElementById("tbcaddress1Id");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcaddress1Id");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("ccityId");
          str = x.value ;
	     if(str.length<=0)
	     {
	         flag = "FALSE";
             y= document.getElementById("tbccityId");
	        y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbccityId");
	        y.className = "RequiredHighlight";
         }
	     var x = document.getElementById("czipId");
         str = x.value;
         var reg1= /^\d{5}$/
		 var reg2= /^\d{5}-\d{4}$/

		 if(!( ( reg1.test(str) ) || ( reg2.test(str) ) ) )
	     {
	         flag = "FALSE";
             y= document.getElementById("tbczipId");
	         y.className = "RequiredHighlightError ";
	     }
         else
         {
            y= document.getElementById("tbczipId");
	         y.className = "RequiredHighlight";
         }

         var x = document.getElementById("cstateId");
         sid = x.selectedIndex ;
	     if(sid==0)
	     {   flag = "FALSE";
             y= document.getElementById("tbcstateId");
	         y.className = "RequiredHighlightError";
	     }
         else
         {
            y= document.getElementById("tbcstateId");
	        y.className = "RequiredHighlight";
         }


    if( flag=="FALSE")
     {
        x = document.getElementById("msg");
        x.innerHTML = "Wrong Information, please check your contact information"
        x.className = "FormFieldLabelError";
        return false
     }
     else
     {
        x = window.opener.document.getElementById("myaccount");
        document.forms.savecontact.submit();
        //delay(50);
        //close_win('1')
     }
}

function fillparentfields()
{
    var x = document.getElementById("cfirstnameId");
    px = window.opener.document.getElementById("firstnameId");
    px.value =  x.value;

    var x = document.getElementById("clastnameId");
    px = window.opener.document.getElementById("lastnameId");
    px.value =  x.value;

     var x = document.getElementById("caddress1Id");
    px = window.opener.document.getElementById("address1Id");
    px.value =  x.value;

    var x = document.getElementById("caddress2Id");
    px = window.opener.document.getElementById("address2Id");
    px.value =  x.value;

    var x = document.getElementById("ccompanyId");
    px = window.opener.document.getElementById("companyId");
    px.value =  x.value;

    var x = document.getElementById("ccityId");
    px = window.opener.document.getElementById("cityId");
    px.value =  x.value;

     var x = document.getElementById("czipId");
    px = window.opener.document.getElementById("zipId");
    px.value =  x.value;

    var x = document.getElementById("cstateId");
    px = window.opener.document.getElementById("stateId");
    px.selectedIndex =  x.selectedIndex;
}



function open_win()
{
window.open("edit_contactinfo.php","EditContactInfo","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=450, height=400, left=500, top=200")
}


function close_win(myaccount)
{

    if(myaccount==1)
    {
        //delay(50);
        var openerForm = opener.document.forms.editaddress;
		openerForm.action = window.opener.location; // servlet, jsp, html, etc...
		openerForm.method = "post";
		openerForm.submit();

     	//window.opener.location.reload()
        //fillparentfields();
    }
    window.close()
}

/* gap is in millisecs */
function delay(gap)
{
var then,now;
then=new Date().getTime();
now=then;
while((now-then)<gap)
{now=new Date().getTime();}
}