﻿tmpBody = "";

timerid = 0;

function GetWindowSize(w, what) {
        w = w ? w : window;
        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
	if(what="w"){       
		return width;
	}else{
		return height;
	}
}

function sett(){
	timerid = setTimeout("$('search_box_on').style.display = 'none'",1000);
}

function cleart(){
	clearTimeout(timerid);
}

function showResults(){
	$('searchResults').innerHTML = tmpBody;
}

subs_timerid = 0;
function showSubs(sub){
	clearTimeout(subs_timerid);
	for(i=1;i<9;i++){
		if(i==sub){
			$('sub'+i).style.display = "";
		}else{
			$('sub'+i).style.display = "none";
		}
	}
}

function hideSubs(sub){
	subs_timerid = setTimeout("$('sub"+sub+"').style.display = 'none'",2000);
}

cur_pic = 0;
total_pics = 0;
pt = 0

side_pics = 1;

function showHPPics(){
	if(pics.length>0){
		cur_pic = 1;
		total_pics = pics.length;
		$('ifrm_HP_pics').src = "/show_pic.php?pic=" + pics[0]+"&w=437&h=207&type=1";
		$('hp_pics_title').innerHTML = pics_alt[0];
		pt = setTimeout("autonav()",5000);
	}
	showSidePic();
}

function showSidePic(){
	var randomnumber = 1 + Math.floor(Math.random()*side_pics);
	
	$('side_pic_td1').style.width = Math.floor((GetWindowSize('', 'width')-901)/2) + "px";
	$('side_pic_td2').style.width = Math.floor((GetWindowSize('', 'width')-901)/2) + "px";
	
	$('side_pic').innerHTML = "<div style='width:"+Math.floor((GetWindowSize('', 'width')-901)/2) + "px;overflow:hidden;'<img src='/images/side_pic"+randomnumber+".png' /></div>";
}

function processPagePics(){
	showSidePic();
	if(pics.length>0){
		img = "<a href='javascript:;' onclick='showInnerPics(\"show\")' title='"+pics_alt[0]+"'><img src='/pics/thumbs/"+pics[0]+"' class='InnerPic' title='"+pics_alt[0]+"' /><br>"+pics_alt[0]+"<br><span class='morePics'>לחצו להגדלה</span></a>";
		
		$('pagePics').innerHTML = img;
		$('pagePics').style.display = "";
		LIs = "";
		for(i=0;i<pics.length;i++){
			LIs += "<li><a href='/show_pic.php?pic="+pics[i]+"&w=562&h=375&type=3' target='InnerPicsBigPicIFRM' onclick='updateInnerPicTitle("+i+")'><img src='/pics/thumbs/"+pics[i]+"' class='InnerPicLI' /></a></li>"
		}
		$('InnerPicsUL').innerHTML = "<ul>"+LIs+"</ul>";
		$('InnerPicsBigPicIFRM').src = "/show_pic.php?pic="+pics[0]+"&w=562&h=375&type=3" ;
		$('InnerPicsTitle').innerHTML = "<div style='padding: 5px; text-align:center;'>" + pics_alt[0] + "</div>";
	}
}

function updateInnerPicTitle(pic){
	$('InnerPicsTitle').innerHTML = "<div style='padding: 5px; text-align:center;'>" + pics_alt[pic] + "</div>";
}

function showInnerPics(what){
	if(what=="show"){
		$("InnerPics").style.display = "";
	}else{
		$("InnerPics").style.display = "none";
	}
}

function autonav(){
	hp_pics_nav("+");
	pt = setTimeout("autonav()",5000);
}

function hp_pics_nav(what){
	switch(what){
		case "+":
			//move forward
			cur_pic++;
			if(cur_pic>total_pics){
				cur_pic = 1;
			}
			break;
			
		case "-":
			//rewind
			cur_pic--
			if(cur_pic<1){
				cur_pic = total_pics;
			}
			break;
	}
	
	
	$('ifrm_HP_pics').src = "/show_pic.php?pic=" + pics[cur_pic-1]+"&w=437&h=207&type=1";
	$('hp_pics_title').innerHTML = pics_alt[cur_pic-1];
}

function doOnFocus(event){
	switch(event){
		case "focus":
			$('txtSearch').style.color = "#1A1A1A";
			if($('txtSearch').value == "הקלידו טקסט לחיפוש"){
				$('txtSearch').value = "";
				$('txtSearch').style.color = "#1A1A1A";
			}
			break;
			
		case "blur":
			if($('txtSearch').value == ""){
				$('txtSearch').value = "הקלידו טקסט לחיפוש";
				$('txtSearch').style.color = "#afd2dd";
			}
			break;
	}
}

function doOnChange(){
	inp_txt = $('txtSearch').value+"";
	if(inp_txt.length>1){
		var url = "/include/searchAjax.php?sid="+Math.random();
		new Ajax.Request(url, {   
			method: 'get', 
			parameters:{ 
				s: inp_txt
			},  
			onSuccess: function(transport) {   
				result = transport.responseText;
				result = result.substr(1,result.length)
				if(result.length>1){
					$('search_results').innerHTML = result;
					$('search_box_on').style.display = "";
				}else{
					$('search_box_on').style.display = "none";
				}
			}
		});
	}else{
		$('search_box_on').style.display = "none";
	}
}

function chkForm(menu){
	$('frmErrors').style.display = "none";
	tmpErr = "";
	$('fname').style.backgroundColor = "#e1dfe0";
	$('phone').style.backgroundColor = "#e1dfe0";
	$('email').style.backgroundColor = "#e1dfe0";
	$('subject').style.backgroundColor = "#e1dfe0";

	if($('fname').value.length<3){
		tmpErr += "<li>נא מלאו שם מלא</li>";
		$('fname').style.backgroundColor = "#d33223";
	}
	if($('phone').value.length<9){
		tmpErr += "<li>נא מלאו מספר טלפון מלא כולל קידומת</li>";
		$('phone').style.backgroundColor = "#d33223";
	}
	if(check_email($('email').value)== false || $('email').value.length<7){
		tmpErr += "<li>נא מלאו כתובת אימייל חוקית</li>";
		$('email').style.backgroundColor = "#d33223";
	}
	if($('subject').value.length<2){
		tmpErr += "<li>נא מלאו נושא פניה</li>";
		$('subject').style.backgroundColor = "#d33223";
	}
	if(tmpErr!=""){
		$('frmErrors').style.display = "";
		$('frmErrors').innerHTML = "<ul>"+tmpErr+"</ul>";
		return false;
	}else{
		return true;
	}
}

function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 

	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

function goSearch(){
	if($('txtSearch').value.length>1){
		location = "/p,4333,0.php?s="+$('txtSearch').value;
	}
}

function setFocus(w, elm, val){
	switch(w){
		case "focus":
			$(elm).style.color = "#1A1A1A";
			if($(elm).value == val){
				$(elm).value = "";
			}
			break;
		case "blur":
			if($(elm).value == ""){
				$(elm).style.color = "#afd2dd";
				$(elm).value = val;
			}
			break;
	}
}
