var forms_ENGLISH = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
var forms_HEBREW = "";
var forms_DIGITS = "0123456789 -";

function doLogin(frm){
//alert(document.forms[frm].email.value)
if (document.forms[frm].enterEmail.value!=""){
	if (document.forms[frm].enterPass.value!=""){
	//	document.forms[frm].action = "?act=login";
		document.forms[frm].submit();
	}else{
		alert("  ");
		document.forms[frm].enterPass.focus();
		return false;
	}
}else{
	alert("    ");
	document.forms[frm].enterEmail.focus();
	return false;
	}
}

function changePrice(id,price,frmname){
	//alert(document.forms[frmname].price.value);
	priceStr=document.forms[frmname].price.value
	str=priceStr.split('-');
	//alert(str[0]+str[1])
	document.getElementById(price).innerHTML=str[1];
	document.forms[frmname].size.value=str[0];
}
	
var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){
			LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
		}
	if(pos=="center"){
			LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){
			LeftPosition=0;TopPosition=20
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

 function IsNumeric(sText){
	return (ChkStrBy(sText,forms_DIGITS));
}

function IsPrice(sText){
	return (ChkStrBy(sText,"0123456789."));
}

function IsHebrew(sText){
	return (ChkStrBy(sText,forms_HEBREW));
}

function IsHebrewHere(sText){
	return (ChkStrByHere(sText,forms_HEBREW));
}

function IsEnglish(sText){
	return (ChkStrBy(sText,forms_ENGLISH));
}

function ChkStrBy(sText, sValidChars){
	var ret = true;
	if (sText.length==0) return (false);
	for (i = 0 ; i < (sText.length) && (ret==true) ; i++){ 
		if (sValidChars.indexOf(sText.charAt(i)) == -1){
			ret = false;
		}
	}
	return (ret);
}

function ChkStrByHere(sText, sValidChars){
	var ret = false;
	if (sText.length==0) return (false);
	for (i = 0 ; i < (sText.length)  ; i++)
	{ 
		if (sValidChars.indexOf(sText.charAt(i)) != -1)
		{
			return true;
		}
	}
	return false;
}

function IsEmail(sText) {
alert("ff")
	var at="@"
	var dot="."
	var lat=sText.indexOf(at)
	var lstr=sText.length
	var ldot=sText.indexOf(dot)
	if (sText=="" || sText==null){ return false }
	if (sText.indexOf(at)==-1 || sText.indexOf(at)==0 || sText.indexOf(at)==lstr){ return false }
	if (sText.indexOf(dot)==-1 || sText.indexOf(dot)==0 || sText.indexOf(dot)+1==lstr){ return false }
	if (sText.indexOf(at,(lat+1))!=-1){ return false }
	if (sText.substring(lat-1,lat)==dot || sText.substring(lat+1,lat+2)==dot){ return false }
	if (sText.indexOf(dot,(lat+2))==-1){ return false }
	if (sText.indexOf(" ")!=-1){ return false }
 	return true					
}

function IsPassword(sText,min,max){
	if ((min>0)&&(sText.length<min)) return (false);
	if ((max>0)&&(sText.length>max)) return (false);
	return (ChkStrBy(sText,forms_ENGLISH + "0123456789_"));
}

function chButt(id){//alert(document.getElementById('a_'+id).className)
	if(document.getElementById('a_'+id).className=='right_norm'){
		document.getElementById('a_'+id).className='right_red'
		document.getElementById('b_'+id).className='mid_red'
		document.getElementById('c_'+id).className='left_red'
	}else{
		//alert(document.getElementById('a_'+id).className);
		document.getElementById('a_'+id).className='right_norm'
		document.getElementById('b_'+id).className='mid_norm'
		document.getElementById('c_'+id).className='left_norm'
		}
}

function doSendFreind() {
	if (IsEmail(document.frmContact.myemail.value)){
		if (document.frmContact.myfname.value!=""){
			if (IsEmail(document.frmContact.uremail.value)){
				if (document.frmContact.urfname.value!=""){
					document.frmContact.submit();
				}else{
					alert('חובה להזין שם מלא');
					document.frmContact.urfname.focus();
				}
			} else {
				alert('חובה להזין כתובת דואר אלקטרוני');
				document.frmContact.uremail.focus();
			}
		}else{
			alert('חובה להזין שם מלא');
			document.frmContact.myfname.focus();
		}
	} else {
		alert('חובה להזין כתובת דואר אלקטרוני');
		document.frmContact.myemail.focus();
	}
}
function printSwf(str){
		document.write(str);
	}

function login(frm,act){
var innerId='login_info'
	original = document.getElementById(innerId).innerHTML;
	if (window.XMLHttpRequest){ try { xmlhttp = new XMLHttpRequest(); }catch(e){ xmlhttp = false; }
	} else if(window.ActiveXObject){ try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp = false; } } }
	if (xmlhttp) xmlhttp.open('POST.html', '_ajax/login.ajax.html', true);
	else{ alert("error init"); return false; }
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200){
				if(act=='do_login'){
					if(xmlhttp.responseText=='loginok'){
						location.href='indexb9a8.html?m=53&amp;s=1&amp;err=[LOGIN]'
					}else {
						document.getElementById(innerId).innerHTML=xmlhttp.responseText;
						document.forms[frm].pass.value='';
					}
				}
					
			}else{
				alert("   ");
				document.getElementById("email").focus();
				document.getElementById(innerId).innerHTML = original;
			} 
		}
	}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//alert(frm)
	var email=document.forms[frm].email.value;
	var pass=document.forms[frm].pass.value;
	str='act='+act+'&email='+email+'&pass='+pass
	xmlhttp.send(str);
}


function do_fav(prod,act){
	var count=document.getElementById('count').innerHTML*1;	
	var innerId='fav_'+prod;
	original = document.getElementById(innerId).innerHTML;
	original = '';
	if (window.XMLHttpRequest){ try { xmlhttp = new XMLHttpRequest(); }catch(e){ xmlhttp = false; }
	} else if(window.ActiveXObject){ try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp = false; } } }
	if (xmlhttp) xmlhttp.open('POST.html', '_ajax/favorites.ajax.html', true);
	else{ alert("error init"); return false; }
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200){
				if(act=='rem')document.getElementById('count').innerHTML=(count-1);
				else if(act=='add')document.getElementById('count').innerHTML=(count+1)	;
				//alert(xmlhttp.responseText)
				try{document.getElementById(innerId).innerHTML = xmlhttp.responseText;}catch(e){}
			}else{
				alert("אירעה תקלה... טוען מקור");
				document.getElementById(innerId).innerHTML = original;
			}
		}
	}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send("prod="+prod+"&act="+act);
}