
// function to check alpha numaric values with space

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123)||(hh==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}


//function to check special character


function special_char(input_value){
    var iChars = "!#%^&*()+=-[]\\\';,/{}|\":<>?$";
    var ster12=input_value.length;
    for (var i = 0; i <ster12;  i++) {
      	if (iChars.indexOf(input_value.charAt(i)) != -1) {
//      	alert ("Special characters are not allowed.\n Please remove them and try again.");
     return false;
  	}
  }
  
}

function price(input_value){
    var iChars = "1234567890.";
    var ster12=input_value.length;
    for (var i = 0; i <ster12;  i++) {
      	if (iChars.indexOf(input_value.charAt(i)) != -1) {
//      	alert ("Special characters are not allowed.\n Please remove them and try again.");
     
  	}else{
  	    return false;
  	}
  }
  
}

// function to trim the values

function trim(input_val)
{
	while(''+input_val.charAt(input_val.length-1)==' ')
	{
		input_val = input_val.substring(0,input_val.length-1);
	}
	return input_val;
 }
 
 
 // email validation check
 
 function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address.")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address.")
		    return false
		 }

 		 return true
	}
//admin login form validation check

function login_validation(){
    
    var fa= document.Login_frm;
    
    if(fa.user.value==""){
        alert("Please enter user name.");
        fa.user.focus();
        return false;
    }
    
    if(fa.password.value==""){
        alert("Please enter passwod.");
        fa.password.focus();
        return false;
        
    }
    fa.submit();
    return true;
    
    
}

//admin change password validation

function validate_change_pass(){
     var fa= document.change_pw;
    if(fa.old_pass.value==""){
        alert("Please enter old password.");
        fa.old_pass.focus();
        return false;
    }
    if(fa.new_pass.value==""){
        alert("Please enter new password.");
        fa.new_pass.focus();
        return false;
    }
    if(fa.con_pass.value==""){
        alert("Please enter confirm password.");
        fa.con_pass.focus();
        return false;
    }
    if(fa.con_pass.value!=fa.new_pass.value){
        alert("New password and confirm password does not match.");
        fa.con_pass.focus();
        return false;
    }
    return true;
    
}

//function for validate category
function validate_category(){
       
    var fa=document.frmAddCategory;
     if(trim(fa.txtcategoryname.value)==""){
        alert("Please enter category name.");
        fa.txtcategoryname.focus();
        return false;
    }
    var flag1 = 0;		
	for(var l = 0;l < document.getElementById('ching_2').length;l++)
	{
		if(document.getElementById('ching_2').options[l].selected)
		{
				flag1 = 1;
		}
	}
	if(!flag1)
	{
		alert("Please select atleast one feature.");
		return(false);
	}
    if(trim(fa.txtcategorydesc.value)==""){
        alert("Please enter category description.");
        fa.txtcategorydesc.focus();
        return false;
    }
    if(trim(fa.txtcategoryImage.value)==""){
        alert("Please upload small Image.");
        fa.txtcategoryImage.focus();
        return false;
    }
	/*if(trim(fa.txtcategoryImage1.value)==""){
        alert("Please upload large Image.");
        fa.txtcategoryImage.focus();
        return false;
    }*/

   //code for multiple selection
    

    return true
    
    
}

function validate_category_edit(){
       
    var fa=document.frmAddCategory;
     if(trim(fa.txtcategoryname.value)==""){
        alert("Please enter category name.");
        fa.txtcategoryname.focus();
        return false;
    }
    var flag1 = 0;		
	for(var l = 0;l < document.getElementById('ching_2').length;l++)
	{
		if(document.getElementById('ching_2').options[l].selected)
		{
				flag1 = 1;
		}
	}
	if(!flag1)
	{
		alert("Please select atleast one feature.");
		return(false);
	}
    if(trim(fa.txtcategorydesc.value)==""){
        alert("Please enter category description.");
        fa.txtcategorydesc.focus();
        return false;
    }



   //code for multiple selection
    

    return true
    
    
}


//function for subcategory dropdown
function select_sub(str){
    
    document.catform.catid.value=str;
    document.catform.submit();
    return;
    
}

//function for product validation
function product_validation(){
    
    var fa= document.frmAddfixprod;
    if(trim(fa.txtcategoryid.value)==""){
        alert("Please select a category.");
        fa.txtcategoryid.focus();
        return false;
    }
//    if(trim(fa.txtsubcategoryid.value)==""){
//        alert("Please select a subcategory");
//        fa.txtsubcategoryid.focus();
//        return false;
//    }
if(trim(fa.txtfixproductcode.value)==""){
        alert("Please enter product code.");
        fa.txtfixproductcode.focus();
        return false;
    }
if(trim(fa.txtfixproductname.value)==""){
        alert("Please enter product name.");
        fa.txtfixproductname.focus();
        return false;
    }
     var flag1 = 0;		
    for(var l = 0;l < document.getElementById('ching_2').length;l++)
    {
    	if(document.getElementById('ching_2').options[l].selected)
    	{
    			flag1 = 1;
    	}
    }
    if(!flag1)
    {
    	alert("Please select atleast one feature.");
    	return(false);
    }
//if(trim(fa.txtfixproductdesc.value)==""){
//        alert("Please enter product descrption");
//        fa.txtfixproductdesc.focus();
//        return false;
//    }
if(trim(fa.txtfixproductimg1.value)==""){
        alert("Please select image1 to upload.");
        fa.txtfixproductimg1.focus();
        return false;
    }
if(trim(fa.txtfixproductimg2.value)==""){
        alert("Please select image2 to upload.");
        fa.txtfixproductimg2.focus();
        return false;
    }
if(trim(fa.txtfixproductimg3.value)==""){
        alert("Please select image3 to upload.");
        fa.txtfixproductimg3.focus();
        return false;
    }
if(trim(fa.txtfixproductinventory.value)==""){
        alert("Please enter product inventory.");
        fa.txtfixproductinventory.focus();
        return false;
}
if(isNaN(fa.txtfixproductinventory.value)){
			alert("Please enter product inventory in numeric.");
			fa.txtfixproductinventory.focus();
			return false;
}
if(trim(fa.txtfixproductprice.value)==""){
        alert("Please enter price.");
        fa.txtfixproductprice.focus();
        return false;
    }
    if(price(fa.txtfixproductprice.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductprice.focus();
        return false;
        
        
    }
if(trim(fa.txtfixproductretail.value)==""){
        alert("Please enter retail value.");
        fa.txtfixproductretail.focus();
        return false;
    }
if(price(fa.txtfixproductretail.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductretail.focus();
        return false;
        
        
    }
if(trim(fa.txtfixproductdiscount.value)==""){
        alert("Please enter product discount.");
        fa.txtfixproductdiscount.focus();
        return false;
    }
if(price(fa.txtfixproductdiscount.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductdiscount.focus();
        return false;
        
        
    }
	
	
	if(trim(fa.txtfixproductorder.value)==""){
        alert("Please enter product order.");
        fa.txtfixproductorder.focus();
        return false;
    }
if(isNaN(fa.txtfixproductorder.value)){
        alert("Please enter order in numeric.");
        fa.txtfixproductorder.focus();
        return false;
        
        
    }
	
	
	
return true;
    
    
}
function edit_product_validation(){
    
   var fa= document.frmEditProductditproduct;
   // alert("hi");
    if(trim(fa.txtcategoryid.value)==""){
        alert("Please select a category.");
        fa.txtcategoryid.focus();
        return false;
    }
//    if(trim(fa.txtsubcategoryid.value)==""){
//        alert("Please select a subcategory");
//        fa.txtsubcategoryid.focus();
//        return false;
//    }
    if(trim(fa.txtfixproductcode.value)==""){
        alert("Please enter product code.");
        fa.txtfixproductcode.focus();
        return false;
    }
if(trim(fa.txtfixproductname.value)==""){
        alert("Please enter product name.");
        fa.txtfixproductname.focus();
        return false;
    }
     var flag1 = 0;		
	for(var l = 0;l < document.getElementById('ching_2').length;l++)
	{
		if(document.getElementById('ching_2').options[l].selected)
		{
				flag1 = 1;
		}
	}
	if(!flag1)
	{
		alert("Please select atleast one feature.");
		return(false);
	}
//if(trim(fa.txtfixproductdesc.value)==""){
//        alert("Please enter product descrption");
//        fa.txtfixproductdesc.focus();
//        return false;
//    }
if(trim(fa.txtfixproductinventory.value)==""){
        alert("Please enter product inventory.");
        fa.txtfixproductinventory.focus();
        return false;
}
if(isNaN(fa.txtfixproductinventory.value)){
			alert("Please enter product inventory in numeric.");
			fa.txtfixproductinventory.focus();
			return false;
}
if(trim(fa.txtfixproductprice.value)==""){
        alert("Please enter price.");
        fa.txtfixproductprice.focus();
        return false;
    }
if(price(fa.txtfixproductprice.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductprice.focus();
        return false;
        
        
}
    
    
if(trim(fa.txtfixproductretail.value)==""){
        alert("Please enter retail value.");
        fa.txtfixproductretail.focus();
        return false;
    }

if(price(fa.txtfixproductretail.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductretail.focus();
        return false;
        
        
}
if(trim(fa.txtfixproductdiscount.value)==""){
        alert("Please enter product discount.");
        fa.txtfixproductdiscount.focus();
        return false;
    }
if(price(fa.txtfixproductdiscount.value)==false){
        alert("Please enter correct price.");
        fa.txtfixproductdiscount.focus();
        return false;
    
}    

if(trim(fa.txtfixproductorder.value)==""){
        alert("Please enter product order.");
        fa.txtfixproductorder.focus();
        return false;
    }
if(isNaN(fa.txtfixproductorder.value)){
        alert("Please enter order in numeric.");
        fa.txtfixproductorder.focus();
        return false;
        
        
    }
    
    
return true;
    //  alert("hello");
    //  return false;  
    
}


//validation for auction product
function aproduct_validation(){
   var fa= document.frmAddaprod;
    if(trim(fa.txtcategoryid.value)==""){
        alert("Please select a category.");
        fa.txtcategoryid.focus();
        return false;
    }
//    if(trim(fa.txtsubcategoryid.value)==""){
//        alert("Please select a subcategory");
//        fa.txtsubcategoryid.focus();
//        return false;
//    }

    if(trim(fa.txtfixproductcode.value)==""){
        alert("Please enter product code.");
        fa.txtfixproductcode.focus();
        return false;
    }
if(trim(fa.txtfixproductname.value)==""){
        alert("Please enter product name.");
        fa.txtfixproductname.focus();
        return false;
    }
    
  var flag1 = 0;		
for(var l = 0;l < document.getElementById('ching_2').length;l++)
{
	if(document.getElementById('ching_2').options[l].selected)
	{
			flag1 = 1;
	}
}
if(!flag1)
{
	alert("Please select atleast one feature.");
	return(false);
}
    
if(trim(fa.txtfixproductimg1.value)==""){
        alert("Please select image1 to upload.");
        fa.txtfixproductimg1.focus();
        return false;
    }
if(trim(fa.txtfixproductimg2.value)==""){
        alert("Please select image2 to upload.");
        fa.txtfixproductimg2.focus();
        return false;
    }
if(trim(fa.txtfixproductimg3.value)==""){
        alert("Please select image3 to upload.");
        fa.txtfixproductimg3.focus();
        return false;
    }
    if(trim(fa.txtstaredate.value)==""){
        alert("Please enter start date.");
        fa.txtstaredate.focus();
        return false;
    }
    if(trim(fa.txtenddate.value)==""){
        alert("Please enter end date.");
        fa.txtenddate.focus();
        return false;
    }
    
    //code for date validation start
    
    var start_datetime=fa.txtstaredate.value;
//    alert(start_datetime);
       
    var end_datetime=fa.txtenddate.value;
    var start_date=start_datetime.split(" ");
//    alert(start_date);
      var start=start_date[0];     
    var st_date=start.split("-");
    var s_time=start_date[1];
       st_time=s_time.split(":");
    var st_hh=st_time[0];
    var st_mm=st_time[1];
    var st_ss=st_time[2];

//    alert(st_time);
  
    var end_date=end_datetime.split(" ");
    var end =end_date[0];
    var e_time=end_date[1];
    var ed_time=e_time.split(":");
    
//    alert(ed_time);
    var ed_hh=ed_time[0];
    var ed_mm=ed_time[1];
    var ed_ss=ed_time[2];
//    alert(ed_hh);
    
    var ed_date=end.split("-");
    var s_date= new Date;
    
    s_date.setDate(st_date[2]);
    s_date.setMonth(st_date[1]);
    s_date.setFullYear(st_date[0]);
//    alert(s_date);
     
    var e_date=new Date;
    e_date.setDate(ed_date[2]);
    e_date.setMonth(ed_date[1]);
    e_date.setFullYear(ed_date[0]);
    
    if(s_date>e_date){
         
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
    }if(s_date<e_date){
        
        
    }else{
   

    if( parseInt(st_hh)>parseInt(ed_hh)){
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
    }  
        
      

        if(parseInt(st_hh)==parseInt(ed_hh) && parseInt(st_mm)>parseInt(ed_mm) ){
        
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
   
        
        
    }

    if(parseInt(st_hh)==parseInt(ed_hh) && parseInt(st_mm)==parseInt(ed_mm) && parseInt(st_ss)>parseInt(ed_ss)){
        
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
        
    }

    }
//    alert(start_date)
//    if(trim(fa.txtstaredate.value)>trim(fa.txtenddate.value)){
//     alert("Please enter end date greater then start date");
//        fa.txtenddate.focus();
//        return false;
//    }
    
    //code for date validation 
if(trim(fa.txtminimumbid.value)==""){
        alert("Please enter minimum bid.");
        fa.txtminimumbid.focus();
        return false;
    }
if(price(fa.txtminimumbid.value)==false){
        alert("Please enter correct price.");
        fa.txtminimumbid.focus();
        return false;
    
} 
if(trim(fa.txtbidinc.value)==""){
        alert("Please enter minimum bid increment.");
        fa.txtbidinc.focus();
        return false;
    }
if(price(fa.txtbidinc.value)==false){
        alert("Please enter correct price.");
        fa.txtbidinc.focus();
        return false;
    
}     
if(trim(fa.txtlongtitle.value)==""){
        alert("Please enter long title.");
        fa.txtlongtitle.focus();
        return false;
    }

if(trim(fa.txtsorttitle.value)==""){
        alert("Please enter sort title.");
        fa.txtsorttitle.focus();
        return false;
    }
//    return false;
return true;
    
    
}

//code add

function edit_aproduct_validation(){
   var fa= document.frmEditProductditproduct;
    if(trim(fa.txtcategoryid.value)==""){
        alert("Please select a category.");
        fa.txtcategoryid.focus();
        return false;
    }
//    if(trim(fa.txtsubcategoryid.value)==""){
//        alert("Please select a subcategory");
//        fa.txtsubcategoryid.focus();
//        return false;
//    }
    if(trim(fa.txtfixproductcode.value)==""){
        alert("Please enter product code.");
        fa.txtfixproductcode.focus();
        return false;
    }

if(trim(fa.txtfixproductname.value)==""){
        alert("Please enter product name.");
        fa.txtfixproductname.focus();
        return false;
    }
//if(trim(fa.txtfixproductimg1.value)==""){
//        alert("Please select image1 to upload");
//        fa.txtfixproductimg1.focus();
//        return false;
//    }
//if(trim(fa.txtfixproductimg2.value)==""){
//        alert("Please select image2 to upload");
//        fa.txtfixproductimg2.focus();
//        return false;
//    }
//if(trim(fa.txtfixproductimg3.value)==""){
//        alert("Please select image3 to upload");
//        fa.txtfixproductimg3.focus();
//        return false;
//    }
    if(trim(fa.txtstaredate.value)==""){
        alert("Please enter start date.");
        fa.txtstaredate.focus();
        return false;
    }
    if(trim(fa.txtenddate.value)==""){
        alert("Please enter end date.");
        fa.txtenddate.focus();
        return false;
    }
    //code for date validation start
    
    var start_datetime=fa.txtstaredate.value;
//    alert(start_datetime);
       
    var end_datetime=fa.txtenddate.value;
    var start_date=start_datetime.split(" ");
//    alert(start_date);
      var start=start_date[0];     
    var st_date=start.split("-");
    var s_time=start_date[1];
       st_time=s_time.split(":");
    var st_hh=st_time[0];
    var st_mm=st_time[1];
    var st_ss=st_time[2];

//    alert(st_time);
  
    var end_date=end_datetime.split(" ");
    var end =end_date[0];
    var e_time=end_date[1];
    var ed_time=e_time.split(":");
    
//    alert(ed_time);
    var ed_hh=ed_time[0];
    var ed_mm=ed_time[1];
    var ed_ss=ed_time[2];
//    alert(ed_hh);
    
    var ed_date=end.split("-");
    var s_date= new Date;
    
    s_date.setDate(st_date[2]);
    s_date.setMonth(st_date[1]);
    s_date.setFullYear(st_date[0]);
//    alert(s_date);
     
    var e_date=new Date;
    e_date.setDate(ed_date[2]);
    e_date.setMonth(ed_date[1]);
    e_date.setFullYear(ed_date[0]);
    
    if(s_date>e_date){
         
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
    }if(s_date<e_date){
        
        
    }else{
   

    if( parseInt(st_hh)>parseInt(ed_hh)){
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
    }  
        
      

        if(parseInt(st_hh)==parseInt(ed_hh) && parseInt(st_mm)>parseInt(ed_mm) ){
        
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
   
        
        
    }

    if(parseInt(st_hh)==parseInt(ed_hh) && parseInt(st_mm)==parseInt(ed_mm) && parseInt(st_ss)>parseInt(ed_ss)){
        
        alert("Please enter end date greater then start date.");
        fa.txtenddate.focus();
        return false;    
        
        
    }

    }
    //code end for date validation
if(trim(fa.txtminimumbid.value)==""){
        alert("Please enter minimum bid.");
        fa.txtminimumbid.focus();
        return false;
    }
if(price(fa.txtminimumbid.value)==false){
        alert("Please enter correct price.");
        fa.txtminimumbid.focus();
        return false;
    
}      
if(trim(fa.txtbidinc.value)==""){
        alert("Please enter minimum bid increment.");
        fa.txtbidinc.focus();
        return false;
    }
 if(price(fa.txtbidinc.value)==false){
        alert("Please enter correct price.");
        fa.txtbidinc.focus();
        return false;
    
}   
    
if(trim(fa.txtlongtitle.value)==""){
        alert("Please enter long title.");
        fa.txtlongtitle.focus();
        return false;
    }

if(trim(fa.txtsorttitle.value)==""){
        alert("Please enter sort title.");
        fa.txtsorttitle.focus();
        return false;
    }
//    return false;
return true;
    
    
}

//function validate CMS

function validate_cms()
{
//    alert("123");
 //   return false;
    var fa=document.frmAddpage;
    if(trim(fa.txtpagename.value)==""){
        alert("Please enter page name.");
        fa.txtpagename.focus();
        return false;
    }
	else
	{
		document.frmAddpage.submit();
   		return;
	}
 return true;
}


function edit_cms1(){
  document.edit_cms.submit();
    return;
}
function form_submit(){
    document.frmAddpage.submit();
   return;
    
}

function validate_country(){
    var fa=document.frmAddCountry;

    if(trim(fa.countryname.value)==""){
        alert("Please enter country name.");
        fa.countryname.focus();
        return false;
    }
    if(trim(fa.txtcountrycode.value)==""){
        alert("Please enter country code.");
        fa.txtcountrycode.focus();
        return false;
    }
    if(trim(fa.txtshiping.value)==""){
        alert("Please enter shipping cost.");
        fa.txtshiping.focus();
        return false;
    }
	if(isNaN(trim(fa.txtshiping.value))){
        alert("Please enter valid shipping cost.");
        fa.txtshiping.focus();
        return false;
    }
    return true;
 
    
}
 function validate_register(){
     fa=document.frmRegister;
     var username=trim(fa.txtusername.value);
     if(username==""){
        alert("Please enter user name.");
        fa.txtusername.focus();
        return false;
    }
     if(username.length<5){
        alert("User name must be greater then or equal to 5 characters.");
        fa.txtusername.focus();
        return false;
    }
    if(special_char(username)==false){
        alert("User name should not contain special characters.");
        fa.txtusername.focus();
        return false;
    }
	if(trim(fa.txtpassword.value)==""){
        alert("Please enter password.");
        fa.txtpassword.focus();
        return false;
    }
	if(trim(fa.txtpassword.value).length<6){
        alert("Password should be atleast 6 characters.");
        fa.txtpassword.focus();
        return false;
    }
	if(special_char(trim(fa.txtpassword.value))==false){
        alert("Password should not contain special characters.");
        fa.txtpassword.focus();
        return false;
    }
    if(trim(fa.txtconfpassword.value)==""){
        alert("Please enter confirm password.");
        fa.txtconfpassword.focus();
        return false;
    }
    if(trim(fa.txtconfpassword.value)!=trim(fa.txtpassword.value)){
        alert("Sorry the passwords do not match. Please enter them again.");
        fa.txtconfpassword.select();
        fa.txtconfpassword.focus();
        return false;
        
    }
    if(!isValidEmail(trim(fa.txtemail.value))){
        alert("Please enter valid email address.");
        fa.txtemail.focus();
        return false;
    }
	
	/* if(special_char(trim(fa.txtemail.value)==false){
        alert("Please enter valid email address.");
        fa.txtemail.focus();
        return false;
    }
	*/
	 fa.submit();
     return true;
     
 }
 
 
 function validate_login(){
     fa=document.frmlogin;
    if(trim(fa.txtusername.value)==""){
        alert("Please enter user name.");
        fa.txtusername.focus();
        return false;
    }
    if(trim(fa.txtpassword.value)==""){
        alert("Please enter password.");
        fa.txtpassword.focus();
        return false;
    }
    document.frmlogin.submit();
    return true;
     
 }
 
 function forget_pass(){
     fa=document.frmforget;
     if(trim(fa.txtemail.value)==""){
        alert("Please enter email address.");
        fa.txtemail.focus();
        return false;
     }
 /*    if (echeck(fa.txtemail.value)==false){
			//emailID.value="";
			fa.txtemail.select();
			fa.txtemail.focus();
			return false;
	 }
	 */
	 if(!isValidEmail(trim(fa.txtemail.value))){
        alert("Please enter valid email address.");
        fa.txtemail.focus();
        return false;
     }
	  fa.submit();
     
 }
 function validate_feature(){
     fa=document.frmAddFeature;
     if(trim(fa.txtfeaturename.value)==""){
        alert("Please enter feature name.");
        fa.txtfeaturename.focus();
        return false;
     }
     if(trim(fa.txtfeatureImage.value)==""){
        alert("Please upload feature big image.");
        fa.txtfeatureImage.focus();
        return false;
     }
	 if(trim(fa.txtfeatureImage_small.value)==""){
        alert("Please upload feature small image.");
        fa.txtfeatureImage_small.focus();
        return false;
     }
    if(trim(fa.txtfeaturedesc.value)==""){
        alert("Please enter feature description.");
        fa.txtfeaturedesc.focus();
        return false;
     }
     
    return true; 
 }

  function validate_feature_edit(){
     fa=document.frmAddFeature;
     if(trim(fa.txtfeaturename.value)==""){
        alert("Please enter feature name.");
        fa.txtfeaturename.focus();
        return false;
     }
     
    if(trim(fa.txtfeaturedesc.value)==""){
        alert("Please enter feature description.");
        fa.txtfeaturedesc.focus();
        return false;
     }
     
    return true; 
 }
 
 /*garry code*/
 function validate_link(){
     fa=document.frmAddLink;
     if(trim(fa.link_name.value)==""){
        alert("Please enter link name");
        fa.link_name.focus();
        return false;
     }
     if(trim(fa.link_url.value)==""){
        alert("Please enter link url.");
        fa.link_url.focus();
        return false;
     }
	return true; 
 }

  function validate_link_edit(){
     fa=document.frmAddLink;
     if(trim(fa.link_name.value)==""){
        alert("Please enter link name");
        fa.link_name.focus();
        return false;
     }
     if(trim(fa.link_url.value)==""){
        alert("Please enter link url.");
        fa.link_url.focus();
        return false;
     }
    return true; 
 }
 /*end here*/
 function edit_user_validation(){
         fa=document.frmEditUser;
     if(trim(fa.txtusername.value)==""){
        alert("Please enter user name.");
        fa.txtusername.focus();
        return false;
     }
    if(trim(fa.txtusername.value).length<5){
        alert("User name must be greater then 5 characters.");
        fa.txtusername.focus();
        return false;
    }
    if(special_char(fa.txtusername.value)==false){
        alert("User name should not contain special characters.");
        fa.txtusername.focus();
        return false;
    }
     if(trim(fa.txtfirstname.value)==""){
        alert("Please enter first name.");
        fa.txtfirstname.focus();
        return false;
     }
    if(trim(fa.txtlastname.value)==""){
        alert("Please enter last name.");
        fa.txtlastname.focus();
        return false;
     }
     if(trim(fa.txtemail.value)==""){
        alert("Please enter email address.");
        fa.txtemail.focus();
        return false;
     }
	 if(!isValidEmail(trim(fa.txtemail.value))){
        alert("Please enter valid email address.");
        fa.txtemail.focus();
        return false;
     }
    /* if (echeck(fa.txtemail.value)==false){
			//emailID.value="";
			fa.txtemail.select();
			fa.txtemail.focus();
			return false;
	 }
	 */
      if(trim(fa.txtphone.value)==""){
        alert("Please enter phone.");
        fa.txtphone.focus();
        return false;
     }
    if(trim(fa.txtaddress1.value)==""){
        alert("Please enter address.");
        fa.txtaddress1.focus();
        return false;
     }
//     if(trim(fa.txttown.value)==""){
//        alert("Please enter town");
//        fa.txttown.focus();
//        return false;
//     }
       if(trim(fa.txtstate.value)==""){
        alert("Please select state.");
        fa.txtstate.focus();
        return false;
     }
     if(trim(fa.txtcountry.value)==""){
        alert("Please Select country.");
        fa.txtcountry.focus();
        return false;
     }
     fa.submit();
       return true;      

 }
 
 function form_delete(str){
     if(confirm("Do you really want to delete this?")){
    document.location.href="delete_cms.php?id="+str;
     }
 }
 
 
 //Displaying Image in new Window
 function newWindow(shapes) {
//     alert(shapes)
//     return;
    shapeWindow = window.open(shapes, "Shapes", "width=350,height=395")
    shapeWindow.focus()
}

//closing popup window
function closepopup()
{
 if(false == shapeWindow.closed) 
 {
    shapeWindow.close ();
 }

}


function validate_checkout() {
    
    var fa=document.frm_checkout;
    if(trim(fa.b_first_name.value)==""){
        
        alert("Please enter your billing first name.");
        fa.b_first_name.focus();
        return false;
        
    }
    if(trim(fa.b_last_name.value)==""){
        
        alert("Please enter your billing last name.");
        fa.b_last_name.focus();
        return false;
        
    }
     
   if(trim(fa.b_address1.value)==""){
        
        alert("Please enter your billing address.");
        fa.b_address1.focus();
        return false;
        
    }
   if(trim(fa.b_town.value)==""){
        
        alert("Please enter your billing town.");
        fa.b_town.focus();
        return false;
        
    }
   if(trim(fa.b_state.value)==""){
        
        alert("Please enter your billing state.");
        fa.b_state.focus();
        return false;
        
    }
	
	if(trim(fa.b_zip.value)=="")
	{
        
        alert("Please enter your billing zip code.");
        fa.b_zip.focus();
        return false;
        
    }
	
	if((trim(fa.b_phone.value)=="")){
        
        alert("Please enter your billing phone number.");
        fa.b_phone.focus();
        return false;
        
    } 
	
	
	if(trim(fa.b_email.value)==""){
        
        alert("Please enter your billing email address.");
        fa.b_email.focus();
        return false;
        
    }
   if (echeck(fa.b_email.value)==false){
		//emailID.value="";
		fa.b_email.select();
		fa.b_email.focus();
		return false;
    }
	
	//alert(fa.ship_to_bill[0].checked);
	//return false;
	if(document.frm_checkout.ship_to_bill[1].checked)
	{
	
	
    if(trim(fa.s_first_name.value)=="")
	{
        
        alert("Please enter your shipping first name.");
        fa.s_first_name.focus();
        return false;
        
    }
    if(trim(fa.s_last_name.value)==""){
        
        alert("Please enter your shipping last name.");
        fa.s_last_name.focus();
        return false;
        
    }
     
   if(trim(fa.s_address1.value)==""){
        
        alert("Please enter your shipping address.");
        fa.s_address1.focus();
        return false;
        
    }
   if(trim(fa.s_town.value)==""){
        
        alert("Please enter your shipping town.");
        fa.s_town.focus();
        return false;
        
    }
   if(trim(fa.s_state.value)==""){
        
        alert("Please enter your shipping state.");
        fa.s_state.focus();
        return false;
        
    }
	
	if(trim(fa.s_zip.value)=="")
	{
        
        alert("Please enter your shipping zip code.");
        fa.s_zip.focus();
        return false;
        
    }
	
	if((trim(fa.s_phone.value)=="")){
        
        alert("Please enter your shipping phone number.");
        fa.s_phone.focus();
        return false;
        
    } 
	
	
	
	   
	}
       
       

    fa.submit();
    return true;
    
    
}
//function to copy address

function copy_address_1()
{
    
    var fa=document.frm_checkout;
    if(fa.copy_address.checked==true){
        
        fa.s_address1.value=fa.b_address1.value;
        fa.s_address2.value=fa.b_address2.value;
        fa.s_town.value=fa.b_town.value;
        fa.s_state.value=fa.b_state.value;
        fa.s_country.value=fa.b_country.value;
        fa.s_zip.value=fa.b_zip.value;
        
    }
	/*
	else{
//        alert("hellosad");
         fa.s_address1.value='';
        fa.s_address2.value='';
        fa.s_town.value='';
        fa.s_state.value='';
        fa.s_country.value='';
        fa.s_zip.value='';
    }
    */
}

function validate_change_email(){
    
    var fa=document.change_email;
    
    if(trim(fa.email.value)==""){
        
        alert("Please enter email address.");
        fa.email.focus();
        return false;
    }

    if (echeck(fa.email.value)==false){
			//emailID.value="";
			fa.email.select();
			fa.email.focus();
			return false;
	 }
    
}

function validate_auto(){
    
    var fa=document.frm_auto_bid;
    if(trim(fa.max_bid.value)==""){
        
        alert("Please enter maximum bid.");
        fa.max_bid.focus();
        return false;
        
    }
    return true;
    
    
}
 function changeOrderStatus(orderID){
     
     
     var status= document.getElementById('oder_status').value;
     var url='index.php?oder_id='+orderID+"status="+status;
     document.location.href=url;
     return;
     
     
 }
 
       
// function validate_advertisment(){
//    var fa=document.frmAddadvertisement;
//    if(trim(fa.txtlink.value)==""){
//        
//        alert("Please enter advertisement link");
//        fa.txtlink.focus();
//        return false;
//        
//    }
//    if(fa.txtlink.value!='')
//    {
//      var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
//      if (!tomatch.test(fa.txtlink.value))
//      {
//    		 
//    	  	  alert("Please enter valid url");
//    		  fa.txtlink.focus();
//    	    return false;
//      }
//    }
//
//     if(trim(fa.txtaddImage.value)==""){
//        
//        alert("Please select image to upload");
//        fa.txtaddImage.focus();
//        return false;
//        
//    }
//    return true;
//
//    
// }
// 
//  function validate_advertisment_edit(){
//    var fa=document.frmAddadvertisement;
//    if(trim(fa.txtlink.value)==""){
//        
//        alert("Please enter advertisement link");
//        fa.txtlink.focus();
//        return false;
//        
//    }
//    if(fa.txtlink.value!='')
//    {
//      var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
//      if (!tomatch.test(fa.txtlink.value))
//      {
//    		 
//    	  	  alert("Please enter valid url");
//    		  fa.txtlink.focus();
//    	    return false;
//      }
//    }
//
//     return true;
//
//    
// }
 
 function validate_advertisment(){

    var fa=document.frmAddpage;
    if(trim(fa.txtpagename.value)==""){
        alert("Please enter advertisement name.");
        fa.txtpagename.focus();
        return false;
    }
    if(trim(fa.txtaddImage.value)==""){
        
        alert("Please select image to upload.");
        fa.txtaddImage.focus();
        return false;
        
    }
  
    return true;
    
}
function validate_advertisment_edit(){
    
     var fa=document.frmAddpage;
    if(trim(fa.txtpagename.value)==""){
        alert("Please enter advertisement name.");
        fa.txtpagename.focus();
        return false;
    }
  
    return true;
    
}


function edit_advertisement1(){
  document.edit_add.submit();
    return;
}

function validate_flash(){
    
    var fa=document.frmAddFlash;
    if(trim(fa.pagename.value)==""){
        
        alert("Please enter page name.");
        fa.pagename.focus();
        return false;
        
    }
    
    if(trim(fa.txtflash.value)==""){
        
        alert("Please select flash to upload.");
        fa.txtflash.focus();
        return false;
        
    }
    return true;
    
}

function validate_flash_edit(){
    
    var fa=document.frmEditFlash;
    if(trim(fa.pagename.value)==""){
        
        alert("Please enter page name.");
        fa.pagename.focus();
        return false;
        
    }
    
    return true;
    
}

function validate_register_new(){
     fa=document.newRegistration;
     var username=trim(fa.txtusername.value);
     if(username==""){
        alert("Please enter user name.");
        fa.txtusername.focus();
        return false;
    }
     if(username.length<5){
        alert("User name must be greater then or equal to 5 characters.");
        fa.txtusername.focus();
        return false;
    }
    if(special_char(username)==false){
        alert("User name should not contain special characters.");
        fa.txtusername.focus();
        return false;
    }
  
    if(trim(fa.txtpassword.value)==""){
        alert("Please enter password.");
        fa.txtpassword.focus();
        return false;
    }
	if(trim(fa.txtpassword.value).length<6){
        alert("Password should be atleast 6 characters.");
        fa.txtpassword.focus();
        return false;
    }
    if(trim(fa.txtconfpassword.value)==""){
        alert("Please enter confirm password.");
        fa.txtconfpassword.focus();
        return false;
    }
    if(trim(fa.txtconfpassword.value)!=trim(fa.txtpassword.value)){
        alert("Sorry the passwords do not match. Please enter them again");
        fa.txtconfpassword.select();
        fa.txtconfpassword.focus();
        return false;
        
    }
    if(trim(fa.txtemail.value)==""){
        alert("Please enter email address.");
        fa.txtemail.focus();
        return false;
    }
     if (echeck(fa.txtemail.value)==false)
		{
			//emailID.value="";
			fa.txtemail.select();
			fa.txtemail.focus();
			return false;
		}
	   fa.submit();
     return true;
     
 }
 
  function validate_login_new(){
     fa=document.newLogin;
    if(trim(fa.username.value)==""){
        alert("Please enter user name.");
        fa.username.focus();
        return false;
    }
    if(trim(fa.txtpassword.value)==""){
        alert("Please enter password.");
        fa.txtpassword.focus();
        return false;
    }
    fa.submit();
    return true;
     
 }
 
  function forget_pass_new(){
     fa=document.frmforget;
     if(trim(fa.email.value)==""){
        alert("Please enter email address.");
        fa.email.focus();
        return false;
     }
     if (echeck(fa.email.value)==false){
			//emailID.value="";
			fa.email.select();
			fa.email.focus();
			return false;
	 }
	  fa.submit();
     
 }
 
function newsletter_check(var_check,var_edit)
{
	
	
		if(document.frmnewsletter.fromname.value=="")
		{
			alert("Please enter from name.");
			document.frmnewsletter.fromname.focus();
			return false;
		}
		
		if(document.frmnewsletter.fromemail.value=="")
		{
			alert("Please enter from email.");
			document.frmnewsletter.fromemail.focus();
			return false;
		}
		
		if(document.frmnewsletter.fromemail.value!="")
		{
			var demo
			
			demo=document.frmnewsletter.fromemail.value;
			//alert("email :--"+demo);
	
	
			var AtSym    = demo.indexOf('@')
			var period1  = demo.indexOf('.')
			var Period   = demo.lastIndexOf('.')
			var Space    = demo.indexOf(' ')
			var Length   = demo.length - 1   // Array is from 0 to length-1
	
			//var AtSym    = document.g.email.value.indexOf('@')
			//var period1  = document.g.email.value.indexOf('.')
			//var Period   = document.g.email.value.lastIndexOf('.')
			//var Space    = document.g.email.value.indexOf(' ')
			//var Length   = document.g.email.value.length - 1   // Array is from 0 to length-1
	
			//alert("AtSym :-- " +AtSym);
			//alert("Period :-- " +Period);
			//alert("Length :-- " +Length);
			//alert("Space :-- " +Space);
	
			if ((AtSym < 1) ||                  // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(period1 < 1) ||
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
			{  
				 alert('Please enter a valid e-mail address! for eg. 11abc@yourcompany.com');
				 document.frmnewsletter.fromemail.focus()
				 return(false)
			 }
		}
		
		if(var_check == 2)
		{
			if(document.frmnewsletter.testemail.value=="")
			{
				alert("Please enter test email.");
				document.frmnewsletter.testemail.focus();
				return false;
			}
		
			if(document.frmnewsletter.testemail.value!="")
			{
				var demo
				
				demo=document.frmnewsletter.testemail.value;
				//alert("email :--"+demo);
		
		
				var AtSym    = demo.indexOf('@')
				var period1  = demo.indexOf('.')
				var Period   = demo.lastIndexOf('.')
				var Space    = demo.indexOf(' ')
				var Length   = demo.length - 1   // Array is from 0 to length-1
		
				//var AtSym    = document.g.email.value.indexOf('@')
				//var period1  = document.g.email.value.indexOf('.')
				//var Period   = document.g.email.value.lastIndexOf('.')
				//var Space    = document.g.email.value.indexOf(' ')
				//var Length   = document.g.email.value.length - 1   // Array is from 0 to length-1
		
				//alert("AtSym :-- " +AtSym);
				//alert("Period :-- " +Period);
				//alert("Length :-- " +Length);
				//alert("Space :-- " +Space);
		
				if ((AtSym < 1) ||                  // '@' cannot be in first position
				(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
				(period1 < 1) ||
				(Period == Length ) ||             // Must be atleast one valid char after '.'
				(Space  != -1))                    // No empty spaces permitted
				{  
					 alert('Please enter a valid e-mail address! for eg. 11abc@yourcompany.com');
					 document.frmnewsletter.testemail.focus()
					 return(false)
				 }
			}
		}
		
		if(document.frmnewsletter.subject.value=="")
		{
			alert("Please enter subject.");
			document.frmnewsletter.subject.focus();
			return false;
		}
	if(var_edit == 0)
	{
		if(var_check == 1)
		{		
			document.frmnewsletter.target="_self";
			document.frmnewsletter.action="index.php";
			document.frmnewsletter.submit();
			return false;
		}
		else
		{
			document.frmnewsletter.target="_blank";
			document.frmnewsletter.action="test_promo_newsletter.php";
			document.frmnewsletter.submit();
			return false;
		}
	}
	else
	{
		document.frmnewsletter.target="_self";
		document.frmnewsletter.action="editnewsletter.php";
		document.frmnewsletter.submit();
		return false;
	}
}

function newsletter_check_reg(var_check,var_edit)
{
	if(document.frmnewsletter.fromname.value=="")
	{
		alert("Please enter from name.");
		document.frmnewsletter.fromname.focus();
		return false;
	}
	if(document.frmnewsletter.fromemail.value=="")
	{
		alert("Please enter from email.");
		document.frmnewsletter.fromemail.focus();
		return false;
	}
	if(document.frmnewsletter.fromemail.value!="")
	{
		var demo
		demo=document.frmnewsletter.fromemail.value;
		//alert("email :--"+demo);
		var AtSym    = demo.indexOf('@')
		var period1  = demo.indexOf('.')
		var Period   = demo.lastIndexOf('.')
		var Space    = demo.indexOf(' ')
		var Length   = demo.length - 1   // Array is from 0 to length-1
		
		//var AtSym    = document.g.email.value.indexOf('@')
		//var period1  = document.g.email.value.indexOf('.')
		//var Period   = document.g.email.value.lastIndexOf('.')
		//var Space    = document.g.email.value.indexOf(' ')
		//var Length   = document.g.email.value.length - 1   // Array is from 0 to length-1
		
		//alert("AtSym :-- " +AtSym);
		//alert("Period :-- " +Period);
		//alert("Length :-- " +Length);
		//alert("Space :-- " +Space);
		if ((AtSym < 1) ||                  // '@' cannot be in first position
		(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		(period1 < 1) ||
		(Period == Length ) ||             // Must be atleast one valid char after '.'
		(Space  != -1))                    // No empty spaces permitted
		{  
		alert('Please enter a valid e-mail address! for eg. 11abc@yourcompany.com');
		document.frmnewsletter.fromemail.focus()
		return(false)
		}
	}
	if(var_check == 2)
	{
		if(document.frmnewsletter.testemail.value=="")
		{
			alert("Please enter test email.");
			document.frmnewsletter.testemail.focus();
			return false;
		}
		
		if(document.frmnewsletter.testemail.value!="")
		{
			var demo
			demo=document.frmnewsletter.testemail.value;
			//alert("email :--"+demo);
			var AtSym    = demo.indexOf('@')
			var period1  = demo.indexOf('.')
			var Period   = demo.lastIndexOf('.')
			var Space    = demo.indexOf(' ')
			var Length   = demo.length - 1   // Array is from 0 to length-1
			
			//var AtSym    = document.g.email.value.indexOf('@')
			//var period1  = document.g.email.value.indexOf('.')
			//var Period   = document.g.email.value.lastIndexOf('.')
			//var Space    = document.g.email.value.indexOf(' ')
			//var Length   = document.g.email.value.length - 1   // Array is from 0 to length-1
			
			//alert("AtSym :-- " +AtSym);
			//alert("Period :-- " +Period);
			//alert("Length :-- " +Length);
			//alert("Space :-- " +Space);

			if ((AtSym < 1) ||                  // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(period1 < 1) ||
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
			{  
				alert('Please enter a valid e-mail address! for eg. 11abc@yourcompany.com');
				document.frmnewsletter.testemail.focus();
				return false;
			}
		}
	}
	if(document.frmnewsletter.subject.value=="")
	{
		alert("Please enter subject.");
		document.frmnewsletter.subject.focus();
		return false;
	}
	if(var_edit == 0)
	{
			
		if(var_check == 1)
		{		
			document.frmnewsletter.target="_self";
			document.frmnewsletter.action="reg_index.php";
			document.frmnewsletter.submit();
			return false;
		}
		else
		{
			document.frmnewsletter.target="_blank";
			document.frmnewsletter.action="test_promo_newsletter.php";
			document.frmnewsletter.submit();
			return false;
		}
	}
	else
	{
		document.frmnewsletter.target="_self";
		document.frmnewsletter.action="reg_editnewsletter.php";
		document.frmnewsletter.submit();
	}
}








var valu2 = 2

function add_importers()
{	
	
 	var content ='<table class=sortable border=0  width=40%><tr><td align=left><input type=text name=txtfixproductsize1[] id=txtfixproductsize1[] maxlength=10 size=7></TD></tr></table>'; 
 
 	var newPara = document.createElement('span');
	var bodyRef = document.getElementById('add');
	bodyRef.appendChild(newPara);
	newPara.innerHTML = content;
	valu2 =valu2+1;
}	

var valu2 = 2

function edit_importers()
{	
	
 	var content ='<table class=sortable border=0  width=40%><tr><td align=left><input type=text name=txtfixproductsize1234[] id=txtfixproductsize1234[] maxlength=10 size=7></TD></tr></table>'; 
 
 	var newPara = document.createElement('span');
	var bodyRef = document.getElementById('add');
	bodyRef.appendChild(newPara);
	newPara.innerHTML = content;
	valu2 =valu2+1;
}	

function csvvalidate(){
     fa=document.csvform;
	// alert("hi");
    if(trim(fa.image.value)==""){
        alert("Please enter csv file.");
        fa.image.focus();
        return false;
    }
    fa.submit();
    return true;
     
 }
 
 
 
 function change_password_validation(){
         fa=document.frmChangePassword;
     if(trim(fa.txtoldpassword.value)==""){
        alert("Please enter old password.");
        fa.txtoldpassword.focus();
        return false;
     }
	 if(trim(fa.txtpassword.value)==""){
        alert("Please enter new password.");
        fa.txtpassword.focus();
        return false;
     }
	 
	if(special_char(trim(fa.txtpassword.value))==false){
        alert("Password should not contain special characters.");
        fa.txtpassword.focus();
        return false;
    }
  
	 
    if(trim(fa.txtpassword.value).length < 6){
        alert("New password should be atleast 6 characters.");
        fa.txtpassword.focus();
        return false;
    }
	
	if(trim(fa.txtcpassword.value)==""){
        alert("Please enter confirm password.");
        fa.txtcpassword.focus();
        return false;
     }
    if(trim(fa.txtcpassword.value).length < 6){
        alert("Confirm password should be atleast 6 characters.");
        fa.txtcpassword.focus();
        return false;
    }
	if(trim(fa.txtpassword.value)!=trim(fa.txtcpassword.value)){
        alert("Both passwords do not match.");
        fa.txtpassword.focus();
        return false;
     }
	
	  fa.submit();
       return true;      
 }
 
 
 function isValidEmail(emailField)
   { 
   // var emailregex=/^[\w]+\+?\w*@[\w]+\.[\w.]+\w$/; 
    var emailregex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    var match=emailField.match( emailregex ); 
    if ( !match ) 
    { 
       return false; 
    }
    else
    {
       return true; 
    }
  }	
  
  function confirmcheckoutValidate()
  {
	  	//alert("hi");
		//return false;
		fa=document.confirm_checkout;
		var right_now=new Date();
		var the_year=right_now.getFullYear();
		var the_month=right_now.getMonth() + 1;
		
		
		//alert(the_month+"===="+the_year);

		if(trim(fa.user_name.value)=="")
		{
			alert("Please Enter your name as it appears in the credit card and Try Again.");
			fa.user_name.focus();
			return false;
     	}
	 	if(trim(fa.card_type.value)=="")
		{
			alert("Please select your Credit Card Type and Try again.");
			fa.card_type.focus();
			return false;
     	}
		if(trim(fa.card_number.value)=="")
		{
			alert("Please check the Credit Card Number and Try Again.");
			fa.card_number.focus();
			return false;
     	}
		if(isNaN(fa.card_number.value))
		{
			alert("Please check the Credit Card Number and Try Again.");
			fa.card_number.focus();
			return false;
     	}
		if(fa.card_number.value.length < 16)
		{
			alert("Please check the Credit Card Number and Try Again.");
			fa.card_number.focus();
			return false;
		}
		myCardNo = fa.card_number.value;
  		myCardType = fa.card_type.value;
		if(checkCreditCard(myCardNo,myCardType) == false)
		{
    		alert ("Please check the Credit Card Number and Try Again.")
			fa.card_number.focus();
			return false;
  		} 
  		if(trim(fa.exp_month.value)=="")
		{
			alert("Please check the Credit Card Expiry Date and Try Again.");
			fa.exp_month.focus();
			return false;
     	}
		
		if(trim(fa.exp_year.value)=="")
		{
			alert("Please check the Credit Card Expiry Date and Try Again.");
			fa.exp_year.focus();
			return false;
     	}
		if(trim(fa.exp_year.value) < the_year)
		{
			alert("Please check the Credit Card Expiry Date and Try Again.");
			fa.exp_year.focus();
			return false;
		}
		
		if((trim(fa.exp_year.value) == the_year) && trim(fa.exp_month.value) < the_month)
		{
			alert("Please check the Credit Card Expiry Date and Try Again.");
			fa.exp_year.focus();
			return false;
		}
		if(trim(fa.card_verify_number.value)=="")
		{
			alert("Please check the CVV number and Try Again.");
			fa.card_verify_number.focus();
			return false;
     	}
		if(isNaN(fa.card_verify_number.value))
		{
			alert("Please check the CVV number and Try Again.");
			fa.card_verify_number.focus();
			return false;
     	}
		if(fa.card_verify_number.value.length < 3)
		{
			alert("Please check the CVV number and Try Again.");
			fa.card_verify_number.focus();
			return false;
		}
		
		
	
  }
  
  
  /*============================================================================*/

/*

This routine checks the credit card number. The following checks are made:

1. A number has been provided
2. The number is a right length for the card
3. The number has an appropriate prefix for the card
4. The number has a valid modulus 10 number check digit if required

If the validation fails an error is reported.

The structure of credit card formats was gleaned from a variety of sources on 
the web, although the best is probably on Wikepedia ("Credit card number"):

  http://en.wikipedia.org/wiki/Credit_card_number

Parameters:
            cardnumber           number on the card
            cardname             name of card as defined in the card list below

Author:     John Gardner
Date:       1st November 2003
Updated:    26th Feb. 2005      Additional cards added by request
Updated:    27th Nov. 2006      Additional cards added from Wikipedia
Updated:    18th Jan. 2008      Additional cards added from Wikipedia

*/

/*
   If a credit card number is invalid, an error reason is loaded into the 
   global ccErrorNo variable. This can be be used to index into the global error  
   string array to report the reason to the user if required:
   
   e.g. if (!checkCreditCard (number, name) alert (ccErrors(ccErrorNo);
*/

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {
     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011,650",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "enRoute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
  cards [8] = {name: "Solo", 
               length: "16,18,19", 
               prefixes: "6334, 6767",
               checkdigit: true};
  cards [9] = {name: "Switch", 
               length: "16,18,19", 
               prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
               checkdigit: true};
  cards [10] = {name: "Maestro", 
               length: "16,18", 
               prefixes: "5020,6",
               checkdigit: true};
  cards [11] = {name: "VisaElectron", 
               length: "16", 
               prefixes: "417500,4917,4913",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");
  
  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}

/*============================================================================*/
  

