function Validate_Gift_Certificate(form) {
	
	 	  if (form.start_amount.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter an amount");
	           form.start_amount.focus();
	           return false;
	   }
	
	
	
	  if (form.to_fname.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter the recipient\'s first name");
	           form.to_fname.focus();
	           return false;
	   }
	
    
    	  if (form.from_fname.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter the sender\'s first name");
	           form.to_fname.focus();
	           return false;
	   }
	
	
	 if (form.to_email.value == "") {
     alert("Please enter the recipient's email address.");
     form.to_email.focus();
     return false;	
			 
  }
    
    if (validateEmail(form.to_email.value) == 0) {
   
          form.to_email.focus();
          return false;
   }

   
   if (form.confirm_email.value == "") {   
   
           alert("Please confirm the recipient's Email address");
           form.confirm_email.focus();
           return false;
   }
    
    
       if (form.to_email.value != form.confirm_email.value) {
          alert("Your email addresses do not match \n Please check your entries");
          form.email.focus();
          return false;
    }
    
    
}
    
 
function save_for_later () {
   
	           alert("To use \"Save for Later\" or to view your saved items\nplease sign into your account\n\nTo sign in to your account or to create a new account\nclick on the link at the top of the cart OR select \n \"Your Account\" on the Menu Bar");
	            return false;
 }
	   
	
function advanced_classical (form) {
		
	if (form.sub_category.value == "solos"   && form.composer.value == "" && form.editor.value == ""   && form.search_string.value == ""  && form.level.value == "ANY" && form.period.value == "ANY"   ) {
	    alert ("Because of the large number of items in the Solo Heading\n you must also select something to search for.") ;
		return false; 
	}		

}


function validate_search (form) {
     if (form.search_text.value == "") {   
           alert("Please enter something to search for\nbefore submitting this form.");
           form.search_text.focus();
           return false;
    }

}

 function Validate_Address(form) {

   var this_country = form.country.value.split("|");
   
	
	  if (form.fname.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter your first name");
	           form.fname.focus();
	           return false;
	   }
	
	  if (form.lname.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter your last name");
	           form.lname.focus();
	           return false;
	   }
	
	    if (form.address_line1.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter your street address in Address Line 1");
	           form.address_line1.focus();
	           return false;
	   }
	
	
	  if (form.city.value == "") {   
	   
	           alert("Required Field Missing!\nPlease enter your city");
	           form.city.focus();
	           return false;
	   }
	
	if (this_country[0] == "United States") { 
	  if (form.state.value == "") {   
	           alert("Required Field Missing!\nPlease select your State");
	           form.state.focus();
	           return fales;
      }
	}
	
	if (this_country[0] == "United States") { 
   	  if (form.zip.value == "") {   
	           alert("Required Field Missing!\nPlease enter your Zip Code");
	           form.zip.focus();
	           return false;
	   }
   } 

	  if (form.homephone.value == "") {   
	            alert("Required Field Missing!\nPlease enter your phone number");
	           form.homephone.focus();
	           return false;
	   }



if (this_country[0] == "United States") { 

     if (form.address_line2.value != "") {
         var address_label = form.fname.value + " " +  form.lname.value + "\n" + form.address_line1.value + "\n" +  form.address_line2.value + "\n" +   form.city.value + ", " + form.state.value + " " +  form.zip.value ;  
      } else {
          var address_label = form.fname.value + " " +  form.lname.value + "\n" + form.address_line1.value + "\n" +    form.city.value + ", " + form.state.value + " " +  form.zip.value ;  
      }
   
  } else if ( this_country[0] != "United States")  { 
      if (form.address_line2.value != "") {
         var address_label = form.fname.value + " " +  form.lname.value + "\n" + form.address_line1.value + "\n" +  form.address_line2.value + "\n" +   form.city.value + ", " + form.province.value + " " +  form.zip.value  + "\n" + this_country[0];
      } else {
          var address_label = form.fname.value + " " +  form.lname.value + "\n" + form.address_line1.value + "\n" +    form.city.value + ", " + form.province.value + " " +  form.zip.value + "\n" + this_country[0] ;  
      }
   
  	
  }	
    
 if (form.bill_ship.value == "both" || form.bill_ship.value == "shipping") {

     if (confirm("This is what your shipping label will look like\n\n______________________________\n\n" +  address_label + "\n\n______________________________\n\nClick CANCEL  to return to the form and make changes to your address.\n\nClick OK To submit the form and continue. "  )  == 0  ) {
    	return false ;
     }  else {
    	return true ;
     } 	
    
   } else {
   	   return true;
  } 	    

}  <!-- end of function -->

  function is_empty_email (form) {
    
    		  if (form.email.value == "") {   
	   	           alert("Please enter an email address before submitting this form.");
	           form.email.focus();
	           return false;
	           }
	  return true;
    	
   }	

   function is_empty (form) {
    
    		  if (form.search_text.value == "") {   
	   	           alert("Please enter an email address or last name to search for.");
	           form.search_text.focus();
	           return false;
	           }
	  return true;
    	
   }	

  function confirm_delete_customer (form) {
         
       if (form.email.value == "") {   
	           alert("Please enter an email address before submitting this form.");
	           form.email.focus();
	           return false;
	   }       
	   
	   	           
       if (confirm ("This will delete the all of the  addresses associated with \nthe customer "   +   form.email.value.toUpperCase() +   " from your customer list. \n\nOnce this is done it is not reversable. \n\n Click OK to continue  OR click CANCEL  to return to the customer management page.") == 0  ) {
    	       return false ;
       } 
         
       return true;  
 
}

 function Check_Card(form) {
         
  
                if (form.bill_type.value == "none")  {
                	alert("Please select your payment method before submitting this form") ;
                	return false; 
             	
                }	
         
         
 if ( form.bill_type.value == "credit") {
          
         var cc_exp_month = form.exp_month.value.split(",");  
    
         var thedate = new Date( );
         var theyear = thedate.getFullYear( );
         var themonth = thedate.getMonth( ) + 1; 
         var card_number = RemoveNonNumeric(form.cardnumb.value);
         var card_number = trim(card_number) ;
         var security_code = trim(form.security.value) ;

         form.cardnumb.value = card_number ;
         form.security.value = security_code ;
    
            
           if (card_number == "" ) {
          	          alert("If you select Pay By Credit  or Debit Card\nyou must enter a valid card number\nin order to submit this form");
          	          form.cardnumb.focus() ;
          	          return false ;
          }
         
 	if ( card_number.charAt(0) != '3' && card_number.charAt(0) != '4' && card_number.charAt(0) != '5' &&  card_number.charAt(0) != '6' ) {
 			alert ("The card number you entered is not valid. Please check your card and re-enter your number") ;
          	          form.cardnumb.focus() ;
          	          return false ;
          }



      if ( card_number.length > 4 && (card_number.charAt(0) > 6  ||  card_number.charAt(0) < 3) ) {
          alert("The Card Number You Submitted Is Not A Valid Number\nPlease Check Your Card and Re-Enter the Card Number");
          return false;
      }    


     
      if ( card_number.charAt(0) == '3' && (card_number.length  < 15   &&  card_number.length > 4  ||  card_number.length > 15)  ) {
      
         alert("The American Express Card number you entered needs to contain  15 numbers. \n Please check your card and enter the card number again.");
         form.cardnumb.focus();
         return false;
      }   
      
      if (  (card_number.charAt(0) == '4' || card_number.charAt(0) == '5')  &&  (card_number.length  < 16  && card_number.length > 4  || card_number.length > 16 )   ) {
      
         alert("The MasterCard or Visa number you entered needs to contain  16 numbers. \n Please check your card and enter the card number again.");
         form.cardnumb.focus();
         return false;
      }   
  
     
      if ( card_number.charAt(0) == '6'   &&  (card_number.length  < 16 && card_number.length > 4  ||  card_number.length > 16) ) {
      
         alert("The Discover Card number you entered needs to contain  16 numbers.\n Please check your card and enter the card number again.");
         form.cardnumb.focus();
         return false;
      }
      
                
              
       if ( cc_exp_month[1] < themonth && form.exp_year.value <= theyear) {
             alert("Your Card Has Expired!\nPlease Update Your Expiration Date.");
            return false;
            form.exp_month.focus();
       }
       
       if (security_code  == "") {
       		alert("Please enter  your security code") ;
       		form.security.focus() ;
		   return false ;
		}
		
		
      if ( card_number.charAt(0) == '3'  &&  security_code.length != 4 ) {
		    		alert("The security code for American Express Cards should be a 4 digit number. \n Please check your card and re-enter your security code.") ;
					form.security.focus() ;
					return false ;
		
		 }	else if ( (card_number.charAt(0) == '4' ||  card_number.charAt(0) == '5'  ||  card_number.charAt(0) == '6' ) &&  security_code.length != 3 ) {
		    		alert("The security code for Visas and Mastercard and Discover Cards should be a 3 digit number. \n Please check your card and re-enter your security code.") ;
					form.security.focus() ;
					return false ;
		}	
					
	
	  
	      
 		
					
					
 }   /* end if billtype = credit */
     
}  /*  end check card */

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}


  
function RemoveNonNumeric( strString )
{
     // Variables
     var strValidCharacters = "1234567890";
     var strReturn = "";
     var strBuffer = "";
     var intIndex = 0;


     // Loop through the string
     for( intIndex = 0; intIndex < strString.length; intIndex++ )
     {
          // Get this character
          strBuffer = strString.substr( intIndex, 1 );

          // Is this a number
          if( strValidCharacters.indexOf( strBuffer ) > -1 )
          {
               // Yes
               strReturn += strBuffer;
          }
     }

     // Return the value
     return strReturn;
}


function delete_card (form) {
              	
        	  var  ans=confirm("This will remove your card number from our system. \n\nIf you are about to submit an order and wish to pay by credit card click CANCEL\nto return to the form and then click SUBMIT FORM.\n\nOtherwise click OK to continue and remove your card from the system.\n\nIf you wish to pay by credit card but do not want your card information saved click\nthe Do Not Save Information box on the form and we will remove your card\nafter the order has been submitted.") ;
         	           	   
         	    if (ans) {
         	       	form.card_number.value = "" ;
      			    form.security.value = "" ;
      			    return true;
         	  } else {
          	    	 return false;
         	   }	  
      
       
       return (true) ;
}  
 
           
function card_expired(form) {
	
	alert("Your Credit Card Has Expired!\nPlease Click On Your Card Number To Update Your Information.")
	return false;
	
}	
 
 
 function Validate_Change_Email_Form(form) {

     if (form.email.value == "") {   
   
           alert("Please enter your Email address");
           form.email.focus();
           return false;
    }

   
   if (validateEmail(form.email.value) == 0) {
   
          form.email.focus();
          return false;
   }

   
   if (form.confirm_email.value == "") {   
   
           alert("Please confirm your New Email address");
           form.confirm_email.focus();
           return false;
   }
   
      

    if (form.email.value != form.confirm_email.value) {
          alert("Your email addresses do not match \n Please check your entries");
          form.email.focus();
          return false;
    }
 
	return true;
 
} 


function validateEmail(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 E-mail ID")
		   return false
		}

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

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

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

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

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}



function Validate_Change_Password_Form(form) {

     if (form.old_password.value == "") {   
   
           alert("Please enter your current password");
           form.old_password.focus();
           return false;
    }

     if (form.password.value == "") {   
   
           alert("Please enter your new password");
           form.password.focus();
           return false;
    }

   
   if (form.confirm_password.value == "") {   
   
           alert("Please confirm your new password");
           form.confirm_password.focus();
           return false;
   }
       

    if (form.password.value != form.confirm_password.value) {
          alert("Your passwords do not match \n Please check your entries");
          form.password.focus();
          return false;
    }

	return true;
 
} 

function Validate_Login_Form (form) {
			

 if (form.email.value == "" || form.password.value == "") {
     alert("You must enter both your email address and your password\n to login to your account");
     form.email.focus();
     return false;	
			 
  }
		       
 if (validateEmail(form.email.value) == 0) {
     form.email.focus();
     return false;
  }  
              
   return true;
            				
  }
         
  
function Validate_sendEmail (form) {
	
 if (form.email.value == "") {
     alert("Please enter your email address.");
     form.email.focus();
     return false;	
			 
  }
		       
 if (validateEmail(form.email.value) == 0) {
     form.email.focus();
     return false;
  }  
              
  return true;
            				
  }
         
 
function Validate_Create_PW_Form(form) {

     if (form.email.value == "") {   
   
           alert("Please enter your Email address");
           form.email.focus();
           return false;
    }

   
   if (validateEmail(form.email.value) == 0) {
   
          form.email.focus();
          return false;
   }

   
   if (form.confirm_email.value == "") {   
   
           alert("Please confirm your Email address");
           form.confirm_email.focus();
           return false;
   }
   
    if (form.password.value == "") {   
   
           alert("Please enter your password");
           form.password.focus();
           return false;
   }
   
    if (form.confirm_password.value == "") {   
   
           alert("Please confirm your password");
           form.confirm_password.focus();
           return false;
    }
   
  
    

    if (form.email.value != form.confirm_email.value) {
          alert("Your email addresses do not match \n Please check your entries");
          form.email.focus();
          return false;
    }

    if (form.password.value != form.confirm_password.value) {
    
          alert("Your passwords do not match \n Please enter them again");
          form.password.value = "";
          form.confirm_password.value = "";
          form.password.focus();
          return false;
    }
 
	return true;
 
} 


function Validate_wishlistform (form) {
			
 if (form.wish_id.value == "") {
     alert("Please enter an email address.");
     form.wish_id.focus();
     return false;	
			 
  }
		       
 if (validateEmail(form.wish_id.value) == 0) {
     form.wish_id.focus();
     return false;
  }  
              
   return true;
            				
  }
         





function check_quantity(field) {
    var strValidChars = "0123456789";
    var strString =  field.value ;
    var strChar  ;
       
   if (strString.length == 0) return false;
     for (i = 0; i < strString.length ;   i++)
       {
        strChar = strString.charAt(i);
         if (strValidChars.indexOf(strChar) == -1)
           {
             alert("You may only enter numbers in this field");
             field.focus(); 
           	 return false;
           }
     }
      return true;;
 }


function openInfoWin (window_file, width, height) {
     var window_width = width + 50 ;
     var window_height = height + 50;
      win =  window.open (window_file , 'popwin',  'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,top=10,left=100,width=' + window_width +', height='  + window_height );
      return false;   
  }
  
function openItemWin(parmStr) {
  win =  window.open("http://www.robertaharris.com/tests/show_item.php?"+parmStr, "coverwin",  "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=40,left=50,width=750,height=400");
}  



function Validate_Review_Form (form) {
		
		

 if (form.name.value == "") {
     alert("Please enter your name (First Name only is OK) before submitting this form.");
     form.name.focus();
     return false;	
			 
  }
			

 if (form.comments.value == "") {
     alert("Please enter your comments about this item before submitting this form.");
     form.comments.focus();
     return false;	
			 
  }

              
   return true;
            				
  }

 function openItemWin(parmStr) {
   win =  window.open("http://www.guitargallerymusic.com/show_item.php?"+parmStr, "coverwin",  "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes, resizable=yes, top=40, left=50, width=750, height=400");
 }
   
            
 function openContentsWin(parmStr) {
   win =  window.open("http://www.guitargallerymusic.com/show_contents.php?"+parmStr, "contentswin",  "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes, resizable=yes, top=40, left=50, width=630, height=600");
 }
    


 function openScoreWin(parmStr) {

 win =  window.open('http://www.guitargallerymusic.com/show_score.php?'+parmStr  , 'scorewin',  'toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=yes, resizable=yes, top=40, left=50, width=630, height=600');  

 }  

    
function openTestWin(parmStr) {

 win =  window.open(parmStr  , 'scorewin')  ;  

 }  


function check_cc(form) {
	 if (form.expired.value == "true") {
	     alert("Please note: Your credit card has expired.\nPlease update your billing information before submitting this order");
	       return false;	
	  } 
}	


 function changeHead(email) {
 		
	 	document.order.action = "https://www.guitargallerymusic.com/secure/checkout.php" ;
	  	document.order.doFunction.value = "checkout" ;
	  	document.order.email.value= email ;
	    document.getElementById("newSubmit").innerHTML = '<input type=\"submit\"  value=\"Update the order total to include your gift certificate(s)\"></form><br><br><a href=\"https://www.guitargallerymusic.com/secure/checkout.php?email=' + email +  '&doFunction=checkout\">Cancel changes and reset the order - do not include certificate(s) </a>' ;
	
	return true ; 	  
 
}	
	
 
function returnString(form) {
  
  var email = document.order.email.value ;
   
  // see if pp is stripping out = signs - substitute ^ for = in request[custom] 
//   var paypalReturn = "email=" + email ;   
   var paypalReturn = "email^" + email ;   


	 if (document.order.gift_certificate0.value != "") {
	 	var gift_certificate0 = document.order.gift_certificate0.value ;
	 	//paypalReturn = paypalReturn + "&gift_certificate0=" + gift_certificate0 ;
	 	paypalReturn = paypalReturn + "&gift_certificate0^" + gift_certificate0 ;

	 }	
		
		 
		
	// check for other certs != manual cert  	 
	
	    var num_certs = Number(document.order.num_certs.value) ;
		var a = 0 ;
	    var end =  (num_certs + 1 ) ;
		
		if (num_certs > 0) {
			for (a = 1 ; a < end ;  a++)  {
				var certID = "gift_certificate" + a ;
				var certName = "document.order." + certID + ".checked" ;
					if(eval(certName) == 1) {
					certval = eval("document.order." + certID + ".value") ;
					//paypalReturn = paypalReturn + "&" + certID + "=" + certval ;
					paypalReturn = paypalReturn + "&" + certID + "^" + certval ;

				
				}	  
			}
	   }  	
	
		
	 if (document.order.comments.value != "") {
	 	var comments = escape(document.order.comments.value) ;
	  	//paypalReturn = paypalReturn + "&coments=" + comments ;
	  	paypalReturn = paypalReturn + "&coments^" + comments ;

	 }	
	
 
	
     document.order.custom.value = paypalReturn ;
	

	if (document.order.amount_1.value == 0) { // no balance no need to go to paypal switch head to ggm.
		 	document.order.action = "https://www.guitargallerymusic.com/secure/checkout.php" ;
	} else { 
	   	document.order.action = "https://www.paypal.com/cgi-bin/webscr" ;
	}

    //remove this when going live
    //document.order.email.value = "dgress_1235519461_per@sbcglobal.net" ;
 
	return true; 
	
}		




 function submitChange(form) {
 
 	   var translateText = document.getElementById("itemdescription").innerHTML ;
 	 //   alert(translateText) ;
 	   var destLanguage = document.translate.translateTo.value ;
       var srcLanguage = document.translate.srcLanguage.value ;
       var sourceLength = translateText.length ;
       translateText = translateText.substring(0,1350) ;
      //  alert(translateText) ;
       google.language.translate(translateText, srcLanguage, destLanguage, translateResult);
       document.translate.srcLanguage.value = destLanguage;
 		
 		var translateMessage = "" ;
  
      	if ((destLanguage == "ar" || destLanguage == "zh-CN" || destLanguage == "zh-TW" || destLanguage == "el" || destLanguage == "hi" || destLanguage == "iw" || destLanguage == "ja" || destLanguage == "ko" || destLanguage == "ru" || destLanguage == "sr" ||  destLanguage == "th"  || destLanguage == "vi") && sourceLength < 1350 ) {
		    var translateMessage = translateMessage + "<b>Please Note:</b> Reload the page to translate to another language." ;
     	} else if ((destLanguage == "ar" || destLanguage == "zh-CN" || destLanguage == "zh-TW" || destLanguage == "el" || destLanguage == "hi" || destLanguage == "iw" || destLanguage == "ja" || destLanguage == "ko" || destLanguage == "ru" || destLanguage == "sr" ||  destLanguage == "th" || destLanguage == "vi") && sourceLength > 1350 ) {
			translateMessage = "<br><br><b>Please Note:</b> Only the first 1000 characters have been translated. Reload the page to view the complete original text or to translate to another language." ;
		}
     	
 		if (sourceLength > 1350) {
			translateMessage = "<br><br><b>Please Note:</b> Only the first 1000 characters have been translated. Reload the page to view the complete original text or to translate to another language." ;
		} 			

     	
     	if (translateMessage != "") {
     	    document.getElementById('translateMessage').innerHTML = translateMessage  ;
     	 }   
        				       
}
 

function translateResult(result) {
    	
         if (result.translation) {
	        document.getElementById('itemdescription').innerHTML = result.translation  ;
         }
    }


