
sInputSelected=false;

function checkFirstUse(me){
		if (sInputSelected==false) {document.getElementById(me).value="";}
		else return;
		sInputSelected=true;
	}
function quarySearch() {
             
	sInput=document.getElementById("searchInput").value;
	sArea=document.getElementById("searchArea").value;
		if (sInputSelected==false)
			return;
			
			else {
            		if (sInput!="")
					this.location="./p_search_page.php?rel="+"&main_cat=1&sub_name=1&search_string="+sInput+"&search_region="+sArea;
			}
	}  
	
musicStart = 1;	
function toggle_music(){
if (musicStart==1) { musicStart = 0 ; stop_sound(); }
else
    { musicStart = 1 ; start_sound(); }
}
function stop_sound() {
document.all["music_img_id"].src="images/start_music.jpg";
document.all["BGSOUND_ID"].src="mySound.mid";
}
function start_sound() {
document.all["music_img_id"].src="images/stop_music.jpg";
document.all["BGSOUND_ID"].src="files/alte_sound.wav";
}
	

	function redirectMe(to){
	alert();
		if (to=="give"){
			this.location="http://www.altezahen.com/p_give.php?prod_id=0"
		}else if (to=="take"){
			this.location="./p_main_cat.php"
		}}



	linkOver=new Image();
	linkOver.src="'.$stat_url.'/images/alt_link_over.gif";
	link = new Image();
	link.src= "'.$stat_url.'/images/alt_link.gif";
	closeMe = new Image();
	closeMe.src="'.$stat_url.'/images/alt_close.gif";


	function showMe_main_cat(currentObj){
		currentObj.style.backgroundColor="#000A79";
		currentObj.style.color="#F1B000";
		currentObj.nextSibling.style.backgroundColor="#FEC941";
		currentObj.previousSibling.style.backgroundColor="#000A79";
		currentObj.previousSibling.firstChild.src=linkOver.src;
	}
	function hideMe_main_cat(currentObj){
		currentObj.style.backgroundColor="#98D2E8";
		currentObj.style.color="black";
		currentObj.nextSibling.style.backgroundColor="#000A79";
		//currentObj.previousSibling.style.backgroundColor="white";
		currentObj.previousSibling.firstChild.src=link.src;
	}
	function navigate(stage,nextPage,txt,main_cat_id){
	    if (stage==1){
	                  this.location="?cat_id="+nextPage; }
		if (stage==2){
	                  this.location="./p_search_page.php?rel="+nextPage+"&main_cat="+main_cat_id+"&sub_name="+txt; }
	}



    function showMe(currentObj){
		currentObj.style.backgroundColor="#000A79";
		currentObj.style.color="#F1B000";
		currentObj.nextSibling.style.backgroundColor="#98D2E8";
		currentObj.previousSibling.style.backgroundColor="#98D2E8";
		currentObj.previousSibling.style.color="#98D2E8";
		currentObj.previousSibling.previousSibling.firstChild.src=linkOver.src
		currentObj.previousSibling.previousSibling.style.backgroundColor="#98D2E8";
	}
	function hideMe(currentObj){
		currentObj.style.backgroundColor="#98D2E8";
		currentObj.style.color="black";
		currentObj.nextSibling.style.backgroundColor="#000A79";
		currentObj.previousSibling.style.backgroundColor="#000A79";
		currentObj.previousSibling.style.color="black";
		currentObj.previousSibling.previousSibling.firstChild.src=link.src;
		currentObj.previousSibling.previousSibling.style.backgroundColor="#000A79";
	}
	function focusMe(currentObj){
		if (currentObj.nextSibling.style.display!="inline"){
			thisObj=currentObj.firstChild.firstChild;
			thisObj.childNodes[0].firstChild.src=linkOver.src;
			thisObj.childNodes[0].style.backgroundColor="#000A79";
			for (i=1;i<4;i++){
				thisObj.childNodes[i].style.backgroundColor="#000A79";
				thisObj.childNodes[i].style.color="#F1B000";
			}
			thisObj.childNodes[4].style.backgroundColor="#FEC941";
		}
	}
	function blurMe(currentObj){
		if (currentObj.nextSibling.style.display!="inline"){
			thisObj=currentObj.firstChild.firstChild;
			thisObj.childNodes[0].firstChild.src=link.src;
			thisObj.childNodes[0].style.backgroundColor="#FEC941";
			for (i=1;i<4;i++){
				thisObj.childNodes[i].style.backgroundColor="#FEC941";
				thisObj.childNodes[i].style.color="black";
			}
			thisObj.childNodes[4].style.backgroundColor="#000A79";
		}
	}

function mouseon(currentObj) {
	getElementById(currentObj).style.backgroundColor="red";
}



	function moreInfo(currentObj){
		if (currentObj.nextSibling.style.display!="inline"){
			currentObj.nextSibling.style.display="inline";
			thisObj=currentObj.firstChild.firstChild;
			thisObj.childNodes[0].firstChild.src=closeMe.src;
			thisObj.childNodes[0].style.backgroundColor="#FEC941";
			for (i=1;i<4;i++){
				thisObj.childNodes[i].style.backgroundColor="#FEC941";
				thisObj.childNodes[i].style.color="black";
			}
			thisObj.childNodes[1].innerText="סגור";
			thisObj.childNodes[4].style.backgroundColor="#000A79";
		}else{
			currentObj.nextSibling.style.display="none";
			thisObj=currentObj.firstChild.firstChild;
			thisObj.childNodes[0].firstChild.src=linkOver.src;
			thisObj.childNodes[0].style.backgroundColor="#000A79";
			for (i=1;i<4;i++){
				thisObj.childNodes[i].style.backgroundColor="#000A79";
				thisObj.childNodes[i].style.color="#F1B000";
			}
			thisObj.childNodes[1].innerText="פרטים";
			thisObj.childNodes[4].style.backgroundColor="#FEC941";
		}

	}

	var div_visible = 1; 
	
	function view_div() {
	if (div_visible) div_visible=0;
	else div_visible=1;
	
	alert (div_visible);}
	
	
	function msgPos(prod_id){
	    
		mainWidth=384;
		mainLeft=(document.body.offsetWidth-mainWidth)/2;
		document.getElementById("msgDiv").style.left=mainLeft;
		//dror 14-02
		 //document.getElementById("category").selectedIndex=1;
		 //document.getElementById("category").selectedIndex=0;
	
		      
		//if (prod_id!=0) {  fill_values(); }

	}
function closeMsg(){
		document.getElementById("msgDiv").style.display="none";
		document.getElementById("giveForm").style.visibility="visible";
	}
	
function navigate(stage,nextPage,txt,main_cat_id){
    if (stage==1){
                  this.location="?cat_id="+nextPage; }
	if (stage==2){
                  this.location="./p_search_page.php?rel="+nextPage+"&main_cat="+main_cat_id+"&sub_name="+txt; }
}


	
function IsEmailValid(checkThisEmail)
{
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}

//if (myEMailIsValid == true)
 //{alert("email is VALID")}
//else
// {alert("email is NOT valid!")}


return myEMailIsValid
}
	
function IsPhoneValid( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  in 9 digit or 10 digit
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{9}$)|(^\d{10}$)|(^\d{2}-\d{7}$)|(^\d{3}-\d{7}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

function containGereshBoded( strValue ) {
var test1 = String.fromCharCode(39);// .. single quote
var test2 = String.fromCharCode(47); //.. backslash
var test3 = String.fromCharCode(92); //.. slash
if(( strValue.indexOf(test1) > -1)||( strValue.indexOf(test2) > -1)||( strValue.indexOf(test3) > -1)) {
  return true;
}
else 
   return false;

}


function alert_for_geresh(what){
  if (containGereshBoded(what.value)){
      alert ("ערך לא יכול להכיל גרש בודד או  סלש /\ ");
      what.value="";}
}

	function validateForm(prod_id){
		errorStr="";
		counter=1;
		if (document.getElementById("category").value=="0"){
			errorStr+=counter+". קטגוריה"+"<br>"
			counter++;
		}
		if (document.getElementById("sub_category").value=="0"){
			errorStr+=counter+". תת קטגוריה"+"<br>"
			counter++;
		}
		if (document.getElementById("product_name").value==""){
			errorStr+=counter+". שם המוצר"+"<br>"
			counter++;
		}
		if (document.getElementById("donner_name").value==""){
			errorStr+=counter+". שם הצדיק"+"<br>"
			counter++;
		}
		if (document.getElementById("donner_address").value==""){
			errorStr+=counter+". כתובת הצדיק"+"<br>"
			counter++;
		}
		if ((document.getElementById("donner_phone1").value=="")&&(document.getElementById("donner_email").value=="")){
			errorStr+=counter+". טלפון או אימייל"+"<br>"
			counter++;
		}
		// validate Telephone 
		if (document.getElementById("donner_phone1").value!="") {
		var tmp = document.getElementById("donner_phone1").value;
		if (!IsPhoneValid(tmp)){
		 errorStr+=counter+".  מספר טלפון לא חוקי"+"<br>"
		counter++;
		}}
		// validate Email Address 
		if (document.getElementById("donner_email").value!="") {
		var tmp = document.getElementById("donner_email").value;
		if (!IsEmailValid(tmp)){
		 errorStr+=counter+".  כתובת דואר אלקטרוני שגוייה"+"<br>"
		counter++;
		}}
		
		
		//if (document.getElementById("donner_email").value==""){
		//	errorStr+=counter+". דואר אלטרוני (email)"+"<br>"
		//	counter++;
		//}
//		if (errorStr !=""){
//			document.getElementById("errMsg").innerHTML=errorStr;
//			document.getElementById("msgDiv").style.display="inline";
//			document.getElementById("giveForm").style.visibility="hidden";
// roy added - output the errors of the form to the page in a div called errMsgWindow
		if (errorStr !=""){
			document.getElementById("errMsgWindow").innerHTML="אנא מלא:<br>	"+errorStr;
			document.getElementById("errMsgWindow").style.display="block";
			//document.getElementById("giveForm").style.visibility="hidden";
		}else{
			sendFRM(prod_id);
		}
	}
	
function validateRequestForm(prod_id){
		errorStr="";
		counter=1;
		if (document.getElementById("category").value=="0"){
			errorStr+=counter+". קטגוריה"+"<br>"
			counter++;
		}
		if (document.getElementById("sub_category").value=="0"){
			errorStr+=counter+". תת קטגוריה"+"<br>"
			counter++;
		}
		if (document.getElementById("product_name").value==""){
			errorStr+=counter+". שם המוצר"+"<br>"
			counter++;
		}
		if (document.getElementById("contact_name").value==""){
			errorStr+=counter+". שם המבקש/ת"+"<br>"
			counter++;
		}
		if (document.getElementById("contact_address").value==""){
			errorStr+=counter+". כתובת המבקש/ת"+"<br>"
			counter++;
		}
		if ((document.getElementById("contact_phone1").value=="")&&(document.getElementById("contact_email").value=="")){
			errorStr+=counter+". טלפון או אימייל"+"<br>"
			counter++;
		}
		// validate Telephone 
		if (document.getElementById("contact_phone1").value!="") {
		var tmp = document.getElementById("contact_phone1").value;
		if (!IsPhoneValid(tmp)){
		 errorStr+=counter+".  מספר טלפון לא חוקי"+"<br>"
		counter++;
		}}
		// validate Email Address 
		if (document.getElementById("contact_email").value!="") {
		var tmp = document.getElementById("contact_email").value;
		if (!IsEmailValid(tmp)){
		 errorStr+=counter+".  כתובת דואר אלקטרוני שגוייה"+"<br>"
		counter++;
		}}
		
		
		//if (document.getElementById("contact_email").value==""){
		//	errorStr+=counter+". דואר אלטרוני (email)"+"<br>"
		//	counter++;
		//}
//		if (errorStr !=""){
//			document.getElementById("errMsg").innerHTML=errorStr;
//			document.getElementById("msgDiv").style.display="inline";
//			document.getElementById("giveForm").style.visibility="hidden";
// roy added - output the errors of the form to the page in a div called errMsgWindow
		if (errorStr !=""){
			document.getElementById("errMsgWindow").innerHTML="אנא מלא:<br>	"+errorStr;
			document.getElementById("errMsgWindow").style.display="block";
			//document.getElementById("giveForm").style.visibility="hidden";
		}
		else{
			pCataID=document.getElementById("category").value
			pSubName=document.getElementById("sub_category").value
			pProdName=document.getElementById("product_name").value
			pProdDesc=document.getElementById("product_desc").value
			pContactName=document.getElementById("contact_name").value
			pContactAdress=document.getElementById("contact_address").value
			pContactTel1=document.getElementById("contact_phone1").value
			pContactTel2=document.getElementById("contact_phone2").value
			pContactEmail=document.getElementById("contact_email").value
			pDesc=document.getElementById("product_desc").value
		
				this.location="./add_request.php?cat_id="+pCataID+"&sub_name="+pSubName+"&req_name="+pProdName+"&req_desc="+pProdDesc+"&c_name="+pContactName+"&c_region="+pContactAdress+"&c_tel1="+pContactTel1+"&c_tel2="+pContactTel2+"&c_email="+pContactEmail;
	
		}
	}



    
function sendFRM(prod_id){
			pCataID=document.getElementById("category").value
			pSubName=document.getElementById("sub_category").value
			pProdName=document.getElementById("product_name").value
			pProdDesc=document.getElementById("product_desc").value
			pMadeIn=document.getElementById("product_madeIn").value
			pYear=document.getElementById("product_year").value
			pContactName=document.getElementById("donner_name").value
			pContactAdress=document.getElementById("donner_address").value
			pContactTel1=document.getElementById("donner_phone1").value
			pContactTel2=document.getElementById("donner_phone2").value
			pContactEmail=document.getElementById("donner_email").value
			pImage_path=document.getElementById("image_path").value
	if (prod_id != 0) {
										
		this.location="./p_edit_product.php?prod_id="+prod_id+"&cat_id="+pCataID+"&sub_name="+pSubName+"&P_NAME="+pProdName+"&P_DESC="+pProdDesc+"&P_VENDOR="+pMadeIn+"&P_YEAR="+pYear+"&P_PERIOD=45&P_PRICE=0&S_NAME="+pContactName+"&S_REGION="+pContactAdress+"&S_TEL1="+pContactTel1+"&S_TEL2="+pContactTel2+"&S_EMAIL="+pContactEmail+"&S_REMARK="+prod_id+"&P_IMAGE_PATH="+pImage_path;
	}
	
	
	if (prod_id==0) { 
		this.location="./p_add_product.php?cat_id="+pCataID+"&sub_name="+pSubName+"&P_NAME="+pProdName+"&P_DESC="+pProdDesc+"&P_VENDOR="+pMadeIn+"&P_YEAR="+pYear+"&P_PERIOD=45&P_PRICE=0&S_NAME="+pContactName+"&S_REGION="+pContactAdress+"&S_TEL1="+pContactTel1+"&S_TEL2="+pContactTel2+"&S_EMAIL="+pContactEmail+"&S_REMARK="+prod_id+"&P_IMAGE_PATH="+pImage_path;
	}
	else {
		pStat=document.getElementById("stat").checked;
		//alert(pStat);
		this.location="./p_edit_product.php?prod_id="+prod_id+"&cat_id="+pCataID+"&sub_name="+pSubName+"&P_NAME="+pProdName+"&P_DESC="+pProdDesc+"&P_VENDOR="+pMadeIn+"&P_YEAR="+pYear+"&P_PERIOD=45&P_PRICE=0&S_NAME="+pContactName+"&S_REGION="+pContactAdress+"&S_TEL1="+pContactTel1+"&S_TEL2="+pContactTel2+"&S_EMAIL="+pContactEmail+"&S_REMARK="+prod_id+"&stat="+pStat+"&P_IMAGE_PATH="+pImage_path;	
	}
}



	
function checkPass() {

		if (document.getElementById("pass").value!=""){
		this.location="./p_give?prod_id="+document.getElementById("pass").value;

		}
}
		
function openAttach() {
id = new Date().getTime();
id = ''+id ;
id1 = id.substr(3);
 
 // open a new window for attachment 
 window.open("upload1.php?id="+id1,null,
    "height=200,width=400,status=no,toolbar=no,menubar=no,location=no");
 //setPicExists();
}
 
 function setPicExists(picPath) {
 
 document.getElementById("picExists").innerHTML = "<img src=\"images/loaded.gif\" />";
 document.getElementById("donner_phone2").value = picPath;
 document.getElementById("image_path").value = picPath;
 }


		
var state = "none";

function showhide(divId) {

	if (state == "block") {
		state = "none";
	}
	else {
		state = "block";
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[divId].display = state;
	}
	if (document.getElementById ) {
		hza = document.getElementById(divId);
		hza.style.display = state;
	}

}
		
function	modifylast(res)
	{
		curr = document.getElementById(res);
		if(curr.nextSibling.style.display != "block")
		{
			curr.nextSibling.style.display = "block";
			curr.next		("addStatus").innerHtml="d";
		}
		else
		{
			curr.nextSibling.style.display = "none";
		}
	}
	
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   //   myfield.form.submit();
	quarySearch()
   return false;
   }
else
   return true;
}	

function populateForm() {
	
//	alert("do");
	ajaxHandler('getSubCategoryFromCategory','sub_category',1);	
	
//	alert(http);
	ajaxHandler('getCategory','category','1');
}

function rollImage(id,state) {
	roll=document.getElementById(id);
	ext="";
	if (state==1) {
		ext="_omo" ;
	}

	if (id=="take" ) {
	roll.src="images/main_lower_take"+ext+".png";
	}
	if (id=="give" ) {
		roll.src="images/main_lower_give"+ext+".png";
	}
}  
