// JavaScript Document
function popsize(id)
{
var url="messagepopup.php?id="+id;
 newwindow=window.open(url,'name','height=200,width=400,left=350,top=225,resizable=yes,scrollbars=yes');
 if (window.focus) {newwindow.focus()}
}
function popupclose(id,type)
{
	if(id=='1')
	window.opener.location.href="member_login.php?type="+type;
	else if(id=='2')
	window.opener.location.href="become_a_member.php?type="+type;
	self.close();
}
function invoicepopup(id)
{
	var url="invoice.php?id="+id;
 newwindow=window.open(url,'name','height=500,width=600,left=350,top=225,resizable=yes,scrollbars=yes');
 if (window.focus) {newwindow.focus()}
}

  function trimspaces(str)
  {
   while((str.indexOf(' ',0) == 0) && (str.length > 1))
   {
    str = str.substring(1, str.length);
   }
   while((str.lastIndexOf(' ') == (str.length - 1) && (str.length > 1)))
   {
    str = str.substring(0,(str.length - 1));
   }
   if((str.indexOf(' ',0) == 0) && (str.length == 1)) str = '';
   return str;
  }

 function validate_form(Obj)
  {
    
    var color_count=0;
    
    for ( i = 0; i < Obj.elements.length; i++) {
      formElem = Obj.elements[i];
       //alert(formElem.name);
       if(formElem.name=='password' && formElem.value!='' )
       {
        var password1=formElem.value;
       }
       
       if(formElem.name=='confirm_password' && formElem.value!='' )
       {
        var password2=formElem.value; 
        if(password1!=password2)
        {
         alert("Please Enter same Password in Confirm Password Field as in Password Field.");
         formElem.focus();
         return false;
        }
       }
       
       if(formElem.name=='new_password' && formElem.value!='' )
       {
        var password1=formElem.value;
       }
       
       if(formElem.name=='confirm_password' && formElem.value!='' )
       {
        var password2=formElem.value; 
        if(password1!=password2)
        {
         alert("Please Enter same Password in Confirm Password Field as in Password Field.");
         formElem.focus();
         return false;
        }
       }
       
       if(formElem.name=='pdf_file' && formElem.value!='' )
       {
        var pdf_file2=formElem.value;
       if(pdf_file2.lastIndexOf(".pdf")==-1) {
           alert("Please upload only .pdf extention file");
           return false;
       }
       }
       
      
       
      switch (formElem.type) {
        case 'text':
        case 'password':
        case 'select-one':
        case 'textarea':
        case 'select-multiple':
        case 'checkbox':
        case 'radio':
        case 'file':
          
          split_title=formElem.title.split("::");
          
          if(split_title[0]=='mandatory112' ){
           if(formElem.checked==true)
           {
             color_count=color_count+1;
           }
          }
          if(split_title[0]=='mandatory111' && trimspaces(formElem.value)=='' ){
           if(color_count==0)
           {
             alert(split_title[1]);
             formElem.focus();
             return false;
           }
          }
          else if(split_title[0]=='mandatory111' && trimspaces(formElem.value)!='' ){
           if(color_count>0)
           {
             alert(split_title[1]);
             formElem.focus();
             return false;
           }
          }
          
          
          if(split_title[0]=='Fill' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill2' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill2'  && isNaN(formElem.value)){
          alert('Please enter numeric value');
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill2'  && parseInt(formElem.value)<=0){
          alert('Please enter positive value grater than zero');
          formElem.focus();
          return false;
          }
          
          
          
          if(split_title[0]=='Fill250'  && trimspaces(formElem.value)==''){
           alert(split_title[1]);
           formElem.focus();
           return false;
           }
          if(split_title[0]=='Fill250'  && formElem.value.length>250){
           alert('Your biodata length is max 250 charecter allowed.');
           formElem.focus();
           return false;
           }
           
           
          if(split_title[0]=='Quantity' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Quantity'  && isNaN(formElem.value)){
          alert('Please enter numeric value');
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Quantity'  && parseInt(formElem.value)<0){
          alert('Please enter positive value grater than zero');
          formElem.focus();
          return false;
          } 
           
          if(split_title[0]=='Fill3' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill3' ){
           if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formElem.value)){
            }else{
             alert('Invalid E-mail Address! Please re-enter.');
             formElem.focus();
             return false;
           }
          }
          if(split_title[0]=='Fill4' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill4' ){
           if(formElem.value !='')
            {
             var strLength = formElem.value.length;
             var spaceindex = formElem.value.lastIndexOf(' ');
             if(strLength < 6)
             {
              alert("Please enter "+formElem.name+" atleast 6 characters.");
              formElem.focus();
              return false;
             }
             if(spaceindex!='-1')
             {
              alert("Please remove space from "+formElem.name+".");
              formElem.focus();
              return false;
             }
            }
          }
          if(split_title[0]=='Fill14' ){
           var type=document.getElementById('product_type').value;
           if(type!='accessories')
           {
            if(split_title[0]=='Fill14' && trimspaces(formElem.value)==''){
            alert(split_title[1]);
            formElem.focus();
            return false; 
            }
           }
          }
          
          if(split_title[0]=='Fill5' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill5' && !isNaN(formElem.value)){
          alert("Please enter only letter");
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill6' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill6'  && isNaN(formElem.value)){
          alert('Please enter numeric value');
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill6'  && parseInt(formElem.value)<0){
          alert('Please enter positive value');
          formElem.focus();
          return false;
          }
          if(split_title[0]=='FillC' && trimspaces(formElem.value)=='')
          {
 
           alert(split_title[1]);
           formElem.focus();
           return false;
          }
         /* if(split_title[0]=='FillEm' && trimspaces(formElem.value)!='')
          {
 
           alert(split_title[1]);
           formElem.focus();
           return false;
          }*/
          
          if(split_title[0]=='Fill20')
          {
           if(formElem.checked == false)
           {
           alert(split_title[1]);
           formElem.focus();
           return false;
           }
          }
       
		 
          if(split_title[0]=='Fill222' && trimspaces(formElem.value)==''){
          alert(split_title[1]);
          formElem.focus();
          return false;
          }
          if(split_title[0]=='Fill222' ){
          if(formElem.value !='')
            {
             var strLength = formElem.value.length;
             //var spaceindex = formElem.value.lastIndexOf(' ');
             if(strLength < 7)
             {
              alert("Please enter identity code of 7 characters.");
              formElem.focus();
              return false;
             }
             var myRegxp1 = /^[a-zA-Z]+$/;
             var myRegxp2 = /^[0-9]+$/;
             if(myRegxp1.test(formElem.value)==false && myRegxp2.test(formElem.value)==false)
             {
             }
             else
             { 
              alert("Please enter alphabets and numeric both.");
              formElem.focus();
              return false;
             }
 
            }
          }
          
        break;
        }
      }//end of for loop
      
      return true;
  }

var r={
   'notnumbers':/[^\d\-]/g
}
function valid(o,w){
  o.value = o.value.replace(r[w],'');
}

 

 

 