﻿function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("כתובת הדואר האלקטרוני אינה תקינה.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("כתובת הדואר האלקטרוני אינה תקינה.")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("כתובת הדואר האלקטרוני אינה תקינה.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("כתובת הדואר האלקטרוני אינה תקינה")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}




function FormCheck (form) {


 myOption = -1;
 for (i=form.shipping.length-1; i > -1; i--) {
 if (form.shipping[i].checked) {
 myOption = form.shipping[i].value;
 }
 }
 if (myOption == -1) {
 alert("נא לבחור אפשרות משלוח");
  return false;
 }



if (form.f_name.value == "") {
alert( "נא להזין שם פרטי" );
form.f_name.focus();
return false ;
}

if (form.l_name.value == "") {
alert( "נא להזין שם משפחה" );
form.l_name.focus();
return false ;
}



/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var emailStr=form.email.value

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("כתובת הדואר האלקטרוני אינה תקינה")
	form.email.focus()
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("כתובת הדואר האלקטרוני אינה תקינה")
    form.email.focus()
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("כתובת הדואר האלקטרוני אינה תקינה")
		form.email.focus()
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("כתובת הדואר האלקטרוני אינה תקינה")
    form.email.focus()
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("כתובת הדואר האלקטרוני אינה תקינה")
   form.email.focus()
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
  alert(errStr)
  form.email.focus()
  return false

}

// If we've gotten this far, everything's valid!


if (form.home_phone.value == "") {
alert( "נא להזין מספר טלפון" );
form.home_phone.focus();
return false ;
}


phoneor = -1;
 for (i=form.phoneorder.length-1; i > -1; i--) {
 if (form.phoneorder[i].checked) {
 phoneor = form.phoneorder[i].value;
  }
 }
 if (phoneor == "off") {

		 var listCheck = form.card_type.selectedIndex;
		 if (form.card_type.options[listCheck].value=="") {
		 alert( "נא לבחור את סוג כרטיס האשראי" );
		 form.card_type.focus();
  		 return false ;
		  }



		if (form.cnum.value == "") {
  		alert( "נא להזין את מספר כרטיס האשראי" );
  		form.cnum.focus();
  		return false ;
		}

		var listCheck2 = form.month.selectedIndex;
		if (form.month.options[listCheck2].value=="") {
		alert( "נא לבחור את חודש התוקף של הכרטיס" );
		form.month.focus();
		return false ;
		}

		var listCheck3 = form.year.selectedIndex;
				if (form.year.options[listCheck3].value=="") {
				alert( "נא לבחור את השנה של תוקף הכרטיס" );
				form.year.focus();
				return false ;
		}


		if (form.p_id.value == "") {
		alert( "נא להזין את תעודת הזהות של בעל הכרטיס" );
		form.p_id.focus();
		return false ;
		}
		if (form.fname.value == "") {
		alert( "נא להזין את שם בעל הכרטיס" );
		form.fname.focus();
		return false ;
		}

		if (form.back_digits.value == "") {
  		alert( "נא להזין את הספרות בגב כרטיס האשראי" );
  		form.back_digits.focus();
  		return false ;
		}



	}


if (myOption != 1) {

	if (form.street.value == "") {
	alert( "נא להזין את שם הרחוב" );
	form.street.focus();
	return false ;
	}

	if (form.house_num.value == "") {
	alert( "נא להזין את מספר הבית" );
	form.house_num.focus();
	return false ;
	}

	if (form.city.value == "") {
	alert( "נא להזין את שם העיר או היישוב" );
	form.city.focus();
	return false ;
	}


	if (form.othership.checked== false) {


		if (form.fname2.value == "") {
		alert( "נא להזין את השם הפרטי של מקבל המשלוח" );
		form.fname2.focus();
		return false ;
		}

		if (form.lname2.value == "") {
		alert( "נא להזין את שם המשפחה של מקבל המשלוח" );
		form.lname2.focus();
		return false ;
		}


		if (form.street2.value == "") {
		alert( "נא להזין את שם הרחוב של מקבל המשלוח" );
		form.street2.focus();
		return false ;
		}

		if (form.house_num2.value == "") {
		alert( "נא להזין את מספר הבית של מקבל המשלוח" );
		form.house_num2.focus();
		return false ;
		}

		if (form.city2.value == "") {
		alert( "נא להזין את שם העיר של מקבל המשלוח" );
		form.city2.focus();
		return false ;
		}

	}

}







 if (form.takanon.checked== false) {

  alert( "נא לאשר את הסכמתך לתנאים ותקנון האתר" );
  form.takanon.focus();
  return false ;
 }




return true;
}


//####################################
//####################################
//####################################
//####################################
//####################################
//####################################

function FormCheckAdmin (form)
{
	if (form.f_name.value == "") {
	alert( "Please enter your First Name." );
	form.f_name.focus();
	return false ;
	}

	if (form.l_name.value == "") {
	alert( "Please enter your Last Name." );
	form.l_name.focus();
	return false ;
	}

/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var emailStr=form.email.value

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	form.email.focus()
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    form.email.focus()
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		form.email.focus()
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    form.email.focus()
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a four or three-letter domain, or two letter country.")
   form.email.focus()
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
  alert(errStr)
  form.email.focus()
  return false

}






	form.act.value = "save";
	return true;
}



//####################################
//####################################
//####################################
//####################################
//####################################
//####################################


 function valbutton(thisform) {
   myOption = -1;
 for (i=thisform.Itemcolor.length-1; i > -1; i--) {
 if (thisform.Itemcolor[i].checked) {
 myOption = i;
 }
 }
 if (myOption == -1) {
 alert("נא לבחור את הדגם הרצוי");
 return false;
 }

  return true; // this line submits the form after validation
 }



 function ChangeImageSource( liIndex )
 {
 document.getElementById('ctrlProductPreview_imgProduct').src = '../DBimages/' + liIndex;
 }


function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";

}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"block";

}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"block";
}
}


function toggleLayerrev(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"none";

}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
style2.display = style2.display? "":"none";

}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
style2.display = style2.display? "":"none";
}
}


function show(object,price,total) {
if (document.getElementById && document.getElementById(object) != null)
node = document.getElementById(object).style.display='block';
else if (document.layers && document.layers[object] != null)
document.layers[object].display = 'block';
else if (document.all)
document.all[object].style.display = 'block';

var sumtotal=document.getElementById('sumtotal').value
var pricein=price

document.getElementById('sumtotal').value=parseFloat(total) + parseFloat(pricein);


}

function show2(object) {
if (document.getElementById && document.getElementById(object) != null)
node = document.getElementById(object).style.display='block';
else if (document.layers && document.layers[object] != null)
document.layers[object].display = 'block';
else if (document.all)
document.all[object].style.display = 'block';


}


function hide(object) {
if (document.getElementById && document.getElementById(object) != null)
node = document.getElementById(object).style.display='none';
else if (document.layers && document.layers[object] != null)
document.layers[object].display = 'none';
else if (document.all)
document.all[object].style.display = 'none';

}



function enableCreditCard(what){
if (!what.phoneorder[1].checked) {
document.getElementById('creditcard_panel').style.display="block"
} else {
document.getElementById('creditcard_panel').style.display="none"
}
}

function takanon()
{
window.open("takanon.asp",'preview','left=20,top=20,width=750,height=580,resizable=yes,scrollbars=yes');
}



function emailvalidation(field, alertbox) {
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);
apos=field.value.indexOf("@");
dotpos=field.value.lastIndexOf(".");
lastpos=field.value.length-1;
var badEmail = (apos<1 || dotpos-apos<2 || lastpos-dotpos<2)
if (goodEmail && !badEmail) {
return true;
}
else {
alert(alertbox);
field.focus();
field.select();
return false;
   }
}
function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function formvalidation(thisform)
{
with (thisform)
{

if (emptyvalidation(name,"נא להזין את שמך")==false) {name.focus(); return false;};

if (emailvalidation(email,"נא להזין כתובת דואר אלקטרוני תקינה")==false) {email.focus(); return false;};

}

}




 function formvalidation2(thisform)
 {
 with (thisform)
 {

 if (emptyvalidation(fname,"נא להזין שם פרטי")==false) {fname.focus(); return false;};

 if (emptyvalidation(lname,"נא להזין שם משפחה")==false) {lname.focus(); return false;};

 if (emailvalidation(email,"נא להזין את כתובת הדואר האלקטרוני")==false) {email.focus(); return false;};

 }



 }

