function check_fields_subscription(formObj) {		
   if (emptyField(formObj.subscription_name)) {
	   alert("אנא מלא/י שם");
	   formObj.subscription_name.focus()
	return false;}	
	if (formObj.subscription_email.value == "" ){
	   alert("אנא מלא/י כתובת דואר אלקטרוני");
	   formObj.subscription_email.focus()
	return false;}
    if (!checkEmail(formObj.subscription_email.value)){
	   alert("כתובת דואר אלקטרוני לא חוקית")
	   formObj.subscription_email.focus()
	return false;}
	toSubscription();
	return false;					
}

function check_fields_unSubscription() {		
	if (document.getElementById('subscription_email').value == "" ){
	   alert("אנא מלא/י כתובת דואר אלקטרוני");
	   document.getElementById('subscription_email').focus()
	return false;}
    if (!checkEmail(document.getElementById('subscription_email').value)){
	   alert("כתובת דואר אלקטרוני לא חוקית")
	   document.getElementById('subscription_email').focus()
	return false;}
	if (confirm("?האם ברצונך להסיר את האימייל ")){
	    unSubscription();
	}
	return false;					
}


var window_subscription
function toSubscription(){
     window_subscription = window.open('','window_subscription','width=500,height=400, left=100,top=0,screenX=0,screenY=0,outerwidth=500,outerheight=230,resizable=1,status=0,toolbar=0,scrollbars=0');
   	 window_subscription.focus();			
   	 window.document.subscriptionForm.action="subscription_thanks.asp"
   	 window.document.subscriptionForm.target="window_subscription"
   	 window.document.subscriptionForm.submit();
     return false;
}

var window_unSubscription
function unSubscription(){
     window_unSubscription = window.open('','window_unSubscription','width=500,height=400, left=100,top=0,screenX=0,screenY=0,outerwidth=500,outerheight=230,resizable=1,status=0,toolbar=0,scrollbars=0');
   	 window_unSubscription.focus();			
   	 window.document.subscriptionForm.action="unSubscription.asp"
   	 window.document.subscriptionForm.target="window_unSubscription"
   	 window.document.subscriptionForm.submit();
     return false;
}

function getNumbers(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || ch ==46);
}

function changeQuant(changVal,itemNumber){
  //alert(itemNumber)
   currVal=window.document.Form_basket.elements['quantity'+itemNumber].value;
   //alert(currVal)
   if (changVal=='+' && !isNaN(currVal))
      currVal=eval(currVal)+1;
   else if (changVal=='-' && !isNaN(currVal))
      currVal=eval(currVal)-1;
   else if (changVal=='' && !isNaN(currVal)){
       check_alert=checkValue.checker(eval(currVal),5)
       if (check_alert!=''){
           alert(check_alert)
           currVal=0;
       }
       else{
         currVal=eval(currVal);
       }   
   }
   if (!isNaN(currVal)&& eval(currVal)>0 )
      window.document.Form_basket.elements['quantity'+itemNumber].value=currVal;
 return false;
}

function check_to_basket(productID){
   if (window.document.Form_basket.elements['toOrder']){
       window.document.Form_basket.elements['toOrder'].value="";
   }
   
   var checkValue;
   checkValue=window.document.Form_basket.elements['quantity'+productID].value;
   check_alert=checkValue.checker(checkValue,5)
   if (check_alert!=''){
      alert(check_alert)
   }   
   else{
	  window.document.Form_basket.elements['productID'].value=productID
	  window.document.Form_basket.submit()
	  return false
   }
return false;
}

function emptyField(textObj){
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; i++) {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;	
	}
	return true;	
}

function checkEmail(checkThisEmail){
//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID
if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}
// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID
if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}
// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID
if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}
// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid
if (mySpaceAt != -1) 
 {myEMailIsValid = false}
return myEMailIsValid

}
