function validate_login(loginfrm)
{
	var val_emailid=loginfrm.txt_email.value;
	var val_pass=loginfrm.txt_pass.value;
    var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	if(val_emailid=="")
	{
	inlineMsg('txt_email','<strong>Enter your emailid</strong>',2);
    return false;
	}
	if(val_emailid!="")
	{
	  if(!val_emailid.match(emailRegex))
	  {
		  inlineMsg('txt_email','<strong>Enter correct emailid</strong>',2);
          return false;
	  }
	 	
	}
	if(val_pass=="")
	{
	inlineMsg('txt_pass','<strong>Enter password</strong>',2);
    return false;
	}
	
}

function valideate_newsletter(form)
{
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var person = form.name.value;
  var emailid = form.email.value;
  
  if(person == "") 
  {
    inlineMsg('awf_field-6899376',"Please enter your name.",2);
    return false;
  }
  if(emailid == "")
  {
   inlineMsg('awf_field-6899377','Please enter your email.',2); 
   return false;
  }
  
  if(!emailid.match(emailRegex)) 
  {
   inlineMsg('awf_field-6899377','Please enter correct email.',2);
   return false;
  }
	
}


function validate_contactus(form)
{
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var emailid = form.user_emailid.value;
  var person = form.user_name.value;
  var subject = form.user_subject.value;
  var desc = form.user_message.value;
 
  if(person == "") 
  {
    inlineMsg('user_name',"Please enter your name.",2);
    return false;
  }
  if(emailid == "")
  {
   inlineMsg('user_emailid','Please enter your email.',2); 
   return false;
  }
  
  if(!emailid.match(emailRegex)) 
  {
   inlineMsg('user_emailid','Please enter correct email.',2);
   return false;
  }

 
  
  if(subject == "") 
  {
    inlineMsg('user_subject',"Please enter feedback subject.",2);
    return false;
  } 
  
  if(desc == "") 
  {
    inlineMsg('user_message',"Please enter your feedback.",2);
    return false;
  } 
  return true;
}



function validate_user(form)
{
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var emailid = form.user_emailid.value;
  var pass=form.user_password.value;
  var confirm_password = form.user_con_password.value;
  var firstname = form.user_firstname.value;
  var lastname = form.user_lastname.value;
  var user_street = form.user_street.value;
  var user_address = form.user_address.value;
  var city = form.user_city.value;
  var state = form.user_region.value;
  var country = form.user_country.value;
  var zip_code = form.user_zipcode.value;
  var faxno = form.user_faxno.value;
  var contact_no = form.user_contactno.value;
  var gender = form.user_gender1.checked;
  var age = form.user_age.value;
  var height = form.user_height.value;
  var weight = form.user_weight.value;
  var agree_terms = form.agree_terms.checked;

    if(emailid == "")
  {
   inlineMsg('user_emailid','Please enter your email.',2); 
   return false;
  }
  
  if(!emailid.match(emailRegex)) 
  {
   inlineMsg('user_emailid','You have entered an invalid email.',2);
   return false;
  }
    
  if(pass =="") 
  {
    inlineMsg('user_password',"Please enter password.",2);
    return false;
  } 
  
  if(pass!= "") 
  {
	if(pass.length < 6)
	{
      inlineMsg('user_password','<strong>Please enter atleast 6 character password.</strong>',2);
       return false;
	}
  }
       
  if(confirm_password == "") 
  {
    inlineMsg('user_con_password',"Please confirm your password.",2);
    return false;
  }
  
  if(pass != confirm_password) 
  {
    inlineMsg('user_con_password','Please confirm your  password.',2);
    return false;
  }




  if(firstname == "") 
  {
    inlineMsg('user_firstname',"Please enter first name.",2);
    return false;
  }
  
  if(lastname == "") 
  {
    inlineMsg('user_lastname',"Please enter  last name.",2);
    return false;
  } 

  if(user_address == "") 
  {
    inlineMsg('user_address',"Please enter address Line2.",2);
    return false;
  } 
  /*   if(user_street == "") 
  {
    inlineMsg('user_street',"Please enter street address .",2);
    return false;
  }*/
  if(city == "") 
  {
    inlineMsg('user_city',"Please enter city name.",2);
    return false;
  } 
  
  if(state == "") 
  {
    inlineMsg('user_region',"Please enter  state name.",2);
    return false;
  } 
   
  if(country == "") 
  {
    inlineMsg('user_country',"Please select country .",2);
    return false;
  }
  
  if(zip_code == "") 
  {
    inlineMsg('user_zipcode',"Please enter  zipcode.",2);
    return false;
  } 
  
/*  if(isNaN(zip_code))
  {
   inlineMsg('user_zipcode','Invalid zipcode',2);
   return false;
  }
  */

 
   
   if(contact_no!= "" && isNaN(contact_no))
  {
    inlineMsg('contact_no','Invalid contact no',2);
    return false;
  }
   if(faxno!= "" && isNaN(faxno))
  {
    inlineMsg('user_faxno','Invalid fax no',2);
    return false;
  }  
/*   if(gender ==false) 
  {
    inlineMsg('user_gender1',"Please select gender.",2);
    return false;
  }
  
  if(age =="") 
  {
    inlineMsg('user_age',"Please select age.",2);
    return false;
  }
  
  if(height =="") 
  {
    inlineMsg('user_height',"Please select height.",2);
    return false;
  }
  
  if(weight =="") 
  {
    inlineMsg('user_weight',"Please select your weight.",2);
    return false;
  }*/
  
  if(agree_terms == false) 
  {
    inlineMsg('agree_terms',"Please check the box for terms and conditions.",2);
    return false;
  } 
  
  
  
  return true;

}

function validate_shipping(form)
{
	  var firstname = form.user_firstname.value;
	  var lastname = form.user_lastname.value;
	  var user_address = form.user_address.value;
	  var user_street = form.user_street.value;
	  var city = form.user_city.value;
	  var state = form.user_region.value;
	  var country = form.user_country.value;
	  var zip_code = form.user_zipcode.value;
	  
	  if(firstname == "") 
	  {
		inlineMsg('user_firstname',"Please enter first name.",2);
		return false;
	  }
	  
	  if(lastname == "") 
	  {
		inlineMsg('user_lastname',"Please enter  last name.",2);
		return false;
	  } 
	
	  if(user_address == "") 
	  {
		inlineMsg('user_address',"Please enter address Line2.",2);
		return false;
	  } 
	  
	 /* if(user_street == "") 
	  {
		inlineMsg('user_street',"Please enter street address .",2);
		return false;
	  }*/
	  
	  if(city == "") 
	  {
		inlineMsg('user_city',"Please enter city name.",2);
		return false;
	  } 
	  
	  if(state == "") 
	  {
		inlineMsg('user_region',"Please enter  state name.",2);
		return false;
	  } 
	   
	  if(country == "") 
	  {
		inlineMsg('user_country',"Please select country .",2);
		return false;
	  }
	  
	  if(zip_code == "") 
	  {
		inlineMsg('user_zipcode',"Please enter  zipcode.",2);
		return false;
	  } 
	  
	/*  if(isNaN(zip_code))
	  {
	   inlineMsg('user_zipcode','Invalid zipcode',2);
	   return false;
	  }*/
	  return true;

}




function validate_generalinfo(form)
{
  var firstname = form.firstname.value;
  var lastname = form.lastname.value;
  var street_address = form.street_address.value;
  var addressline2 = form.address_line2.value;
  var city = form.city.value;
  var state = form.state.value;
  var zip_code = form.zip_code.value;
  var country = form.country.value;
  
   if(firstname == "") 
  {
    inlineMsg('firstname',"Please enter first name.",2);
    return false;
  }
  
  if(lastname == "") 
  {
    inlineMsg('lastname',"Please enter  last name.",2);
    return false;
  } 
   if(street_address == "") 
  {
    inlineMsg('street_address',"Please enter street address .",2);
    return false;
  }
  if(addressline2 =="") 
  {
    inlineMsg('address_line2',"Please enter address Line2.",2);
    return false;
  } 
  
  if(city == "") 
  {
    inlineMsg('city',"Please enter city name.",2);
    return false;
  } 
  
  if(state == "") 
  {
    inlineMsg('state',"Please enter  state name.",2);
    return false;
  } 
   
  if(zip_code == "") 
  {
    inlineMsg('zip_code',"Please enter  zipcode.",2);
    return false;
  } 
  
  if(isNaN(zip_code))
  {
   inlineMsg('zip_code','Invalid zipcode',2);
   return false;
  }
  
  if(country == "") 
  {
    inlineMsg('country',"Please select country .",2);
    return false;
  }
  
}

function validate_contact(form)
{
	  var contact_no = form.contact_no.value;
   if(contact_no == "") 
  {
    inlineMsg('contact_no',"Please enter  zipcode.",2);
    return false;
  } 
  
  if(isNaN(contact_no))
  {
    inlineMsg('contact_no','Invalid contact no',2);
    return false;
  }

}


function change_password(frm)
{ 
	var old_pass=frm.txt_oldpass.value;
	var new_pass=frm.txt_newpass.value;
	var confirm_pass=frm.txt_conpass.value;
	
		
	if(old_pass == "") 
   {
    inlineMsg('txt_oldpass','<strong>Please enter your old password.</strong>',2);
    return false;
   }
   
    
   if(new_pass == "") 
   {
    inlineMsg('txt_newpass','<strong>Please enter your new password.</strong>',2);
    return false;
   }
   
   if(new_pass != "") 
   {
	   if(new_pass.length < 6)
	   {
       inlineMsg('txt_newpass','<strong>Please enter atleast 6  character password.</strong>',2);
       return false;
	   }
   }
  
   if(confirm_pass == "") 
   {
    inlineMsg('txt_conpass','<strong>Please enter your confirmation password.</strong>',2);
    return false;
   }
  
  
   if(new_pass != confirm_pass) 
   {
    inlineMsg('txt_conpass','<strong>Please confirm your new password.</strong>',2);
    return false;
  }
  
 }
 
function  validate_forgotpassword(frm)
{
  var val_emailid=frm.email_forgot.value;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  if(val_emailid=="")
  {
	inlineMsg('email_forgot','Enter your emailid',2);
    return false;
  }
  
  if(val_emailid!="")
	{
	  if(!val_emailid.match(emailRegex))
	  {
		  inlineMsg('email_forgot','Enter correct emailid',2);
          return false;
      }
i  }
}

function Validate_BillingAddress(form)
{
  var firstname = form.firstname.value;
  var lastname = form.lastname.value;
  var street_address = form.street_address.value;
  var addressline2 = form.address_line2.value;
  var city = form.city.value;
  var state = form.state.value;
  var country = form.country.value;
  var pincode = form.pincode.value;
  

  if(firstname == "") 
  {
    inlineMsg('firstname',"Please enter first name.",2);
    return false;
  }
  
  if(lastname == "") 
  {
    inlineMsg('lastname',"Please enter  last name.",2);
    return false;
  }
  
  if(city == "") 
  {
    inlineMsg('city',"Please enter city name.",2);
    return false;
  } 
  
  if(state == "") 
  {
    inlineMsg('state',"Please enter  state name.",2);
    return false;
  } 

  if(country == "") 
  {
    inlineMsg('country',"Please select country .",2);
    return false;
  }
  
  if(street_address == "") 
  {
    inlineMsg('street_address',"Please enter street address .",2);
    return false;
  }

  if(addressline2 == "") 
  {
    inlineMsg('address_line2',"Please enter address Line2.",2);
    return false;
  } 
  

  if(pincode == "") 
  {
    inlineMsg('pincode',"Please enter  zipcode.",2);
    return false;
  } 
  
  if(isNaN(pincode))
  {
   inlineMsg('pincode','Invalid zipcode',2);
   return false;
  }
}

function Validate_Card(frm)
{
var card_type=frm.CardType.value;
var card_no=frm.CardNumber.value;
var month=frm.Expired_month.value;
var year=frm.Expired_year.value;
var cvv=frm.txtCVVCode.value;

if(card_type == "") 
  {
    inlineMsg('CardType',"Please select the card type .",2);
    return false;
  } 
  
if(month == "") 
  {
    inlineMsg('Expired_month',"Please select the card expiration month.",2);
    return false;
  } 
  
  if(year == "") 
  {
    inlineMsg('Expired_year',"Please select the card expiration year.",2);
    return false;
  } 
   if(cvv == "") 
  {
    inlineMsg('txtCVVCode',"Please enter the your card verification number",2);
    return false;
  } 



}

function testCreditCard(frm) 
{
 var CardType=frm.CardType.value;
 var CardNumber=frm.CardNumber.value;	
 var month=frm.Expired_month.value;
 var year=frm.Expired_year.value;
 var cvvCode = document.getElementById('txtCVVCode').value;
 var myCardNo = document.getElementById('CardNumber').value;
 var myCardType = document.getElementById('CardType').value;
  
 if(CardType == "") 
  {
    inlineMsg('CardType',"Please select the card type .",2);
    return false;
  } 
 if(CardNumber == "") 
  {
    inlineMsg('CardNumber',"Please enter  the card number .",2);
    return false;
  } 
 if(month == "") 
  {
    inlineMsg('Expired_month',"Please select the card expiration month.",2);
    return false;
  } 
 if(cvvCode == "") 
  {
    inlineMsg('txtCVVCode',"Please select the card verification version number .",2);
    return false;
  } 
 if (!checkCreditCard(myCardNo,myCardType))
  {
    inlineMsg('CardNumber',"Please enter  a valid card number.",2);
    return false;
  } 
 if(cvvCode!="")
 {
   var result = validateCvvCode();
   if (!result)
   {
     inlineMsg('txtCVVCode',"Please enter  a valid card verification version numberr",2);
     return false;
   }
 }
}

function validateCvvCode()
{
  var cardType=document.getElementById('CardType').value;
  var cvvCode = document.getElementById('txtCVVCode').value;
  var digits = 0;
			switch (cardType.toUpperCase()) {
				case 'MASTERCARD':
				case 'EUROCARD':
				case 'EUROCARD/MASTERCARD':
				case 'VISA':
				case 'DISCOVER':
					digits = 3;
					break;
				case 'AMEX':
				case 'AMERICANEXPRESS':
				case 'AMERICAN EXPRESS':
					digits = 4;
					break;
				default:
					return false;
			}
  var regExp = new RegExp('[0-9]{' + digits + '}');
  return (cvvCode.length == digits && regExp.test(cvvCode))
		}




/////////////Start login form validation///
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 1);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}
