// JavaScript Document

function validateFormOnSubmit(theForm) {
var reason = "";

  
  reason += validatePassword(theForm.Password);
  reason += validateEmail(theForm.email);
  
      
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }

  return true;
}



function testingalert()
{
	
//alert('testtest');	
theForm=document.checkoutprocess;
var reason = "";

  reason += validateEmpty(theForm.First_Name,' First Name');
	   reason += validateEmpty(theForm.Last_Name,' Last Name');
      reason += validateEmpty(theForm.Phone,'Phone');
	 reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.Country,'Country');
	  reason += validateEmpty(theForm.Address1,' Address');
	  
	 //delivery 
	  
	   reason += validateEmpty(theForm.TownCity,'Town City');
      reason += validateEmpty(theForm.Postcode,'Postcode');
	 // reason += validateEmail(theForm.Email);

  
      
 
  return reason;
	
	
}

/*function checkcontactusmail()
{
	
	


var reason = "";

var name=document.getElementById('name');
var email=document.getElementById('email');
var enquiry=document.getElementById('enquiry');
var address=document.getElementById('address');



reason += validateEmpty(name,' First Name');
reason += validateEmail(email);

reason += validateEmpty(address,'Address');
reason += validateEmpty(enquiry,'Message');



return reason;


}
*/


function checkcontactusmail()
{
	
	


var reason = "";

var name=document.getElementById('name');
var email=document.getElementById('email');
var enquiry=document.getElementById('enquiry');



reason += validateEmpty(name,' First Name');
reason += validateEmail(email);
reason += validateEmpty(enquiry,'Message');



return reason;


}








function validatepaypament() {
	
	//alert('dfdf22');
	theForm=document.DoDirectPaymentForm;
var reason = "";



  
      /*reason += validateEmpty(theForm.firstName,'Billing information firstname');
      reason += validateEmpty(theForm.lastName,'Billing information lastname');
	  reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.creditCardNumber,'Card Number');
	  reason += validateEmpty(theForm.cvv2Number,'Card verification');*/
	  
	  reason += validateEmpty(theForm.Billingfirstname,'Contact Address First Name');
	   reason += validateEmpty(theForm.Billinglastname,'Contact Address Last  Name');
      reason += validateEmpty(theForm.address1,'Contact Address');
	 // reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.city,'Contact Address City');
	  reason += validateEmpty(theForm.zip,'Contact Address Postal code');
	  
	 //delivery 
	  
	   reason += validateEmpty(theForm.delivery_fname,'Delivery address first Name');
      reason += validateEmpty(theForm.delivery_lname,'Delivery address last Name');
	 // reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.delivery_city,'Delivery address City');
	  reason += validateEmpty(theForm.delivery_postcode,'Delivery address Postal code');
  
      
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }
  else
   {
	   
	   document.DoDirectPaymentForm.submit();
   }
  

  return true;
}


function validatepaypamentinformation(theForm) {
var reason = "";

  
      reason += validateEmpty(theForm.firstName,'Billing information firstname');
      reason += validateEmpty(theForm.lastName,'Billing information lastname');
	  reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.creditCardNumber,'Card Number');
	  reason += validateEmpty(theForm.cvv2Number,'Card verification');
	  
	  
	  
	  
  
      
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }
  

  return true;
}





function validatepaypamentbilling(theForm) {
var reason = "";

  
      reason += validateEmpty(theForm.Billingname,'Billing Name');
      reason += validateEmpty(theForm.address1,'Billing Address');
	 // reason += validateEmail(theForm.Email);
	  reason += validateEmpty(theForm.city,'Billing City');
	  reason += validateEmpty(theForm.zip,'Postal code');
	  
	  
	  
  
      
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }
  

  return true;
}



function validate_forgetpassword(theForm)
{
	var reason = "";

 var theForm= document.login;
  reason += validateEmail(theForm.email);
  if (reason != "") {
	  
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }

  return true;
}


function signup_validation()
{
	
	var theForm= document.sign_up;
	
	var reason = "";
  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.firstname,'firstname');
  reason += validateEmpty(theForm.lastname,'lastname');
  reason += validatePassword(theForm.password);
  reason +=validateconfirmpassword(theForm.confirmpassword,theForm.password)
  
  if (reason != "") {
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
     }
	else
	 {
		 
		 alert('test');
		 document.sign_up.submit();
		 
	 }

 // return true;


}


function validformcontact(theForm)
{
	var reason = "";
	
	 reason += validateEmpty(theForm.contactname,'Name');
	 reason += validateEmail(theForm.contactemail);
	 reason += validateEmpty(theForm.message,'Message');
 // reason += validateEmpty(theForm.lastname,'lastname');
	
	
	  if (reason != "") {
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
  }

  return true;
	
	
	
}


function validateEmpty(fld,fieldname) {
    var error = "";
 
    if (fld.value.length == 0) {
       // fld.style.background = 'White'; 
        error = "<li>"+fieldname +"   has not been filled in.</li>"
    } else {
        //fld.style.background = 'White';
    }
    return error;  
}


function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
      //  fld.style.background = 'White'; 
        error = "<li>You didn't enter a username.</li>";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
       // fld.style.background = 'Yellow'; 
        error = "<li>The username is the wrong length.</li>";
    } else if (illegalChars.test(fld.value)) {
       // fld.style.background = 'White'; 
        error = "<li>The username contains illegal characters.</li>";
    } else {
       // fld.style.background = 'White';
    }
    return error;
}


function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
       // fld.style.background = 'White';
        error = "<li>You didn't enter a password </li>";
    } else if ((fld.value.length < 4) || (fld.value.length > 15)) {
        error = "<li>The password is the wrong length</li>";
       // fld.style.background = 'White';
    } else if (illegalChars.test(fld.value)) {
        error = "<li>The password contains illegal characters</li>";
      //  fld.style.background = 'White';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "<li>The password must contain at least one numeral</li>";
       // fld.style.background = 'White';
    } else {
      //  fld.style.background = 'White';
    }
   return error;
} 



function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}




function validateconfirmpassword(fld,passwordfield) {
    var error = "";
    
	    if (fld.value == "") {
      //  fld.style.background = 'White';
        error = "<li>You didn't enter a confirm password </li>";
		}
        else if (fld.value!= passwordfield.value) {
         error = "<li>The confirm password and password should be same</li>";
        } 
    return error;
}







function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
       // fld.style.background = 'White';
        error = "<li>You didn't enter an email address.</li>";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
       // fld.style.background = 'White';
        error = "<li>Please enter a valid email address.</li>";
    } else if (fld.value.match(illegalChars)) {
      //  fld.style.background = 'White';
        error = "<li>The email address contains illegal characters.</li>";
    } else {
       // fld.style.background = 'White';
    }
    return error;
}




function submitpage(formname)
{
	
	var reason='';
  reason += validatePassword(document.login.Password);
  reason += validateEmail(document.login.email);
   if (reason != "") {
    //alert("Some fields need correction:" + reason);
	var errormessage='<ul>'+reason+'</ul>';
	document.getElementById('loginerror').innerHTML=errormessage;
    return false;
    }
   else
   {
	  document.login.submit(); 
   }
	
}

