﻿function addLoadEvent(func) {

    var oldonload = window.onload;

    if (typeof window.onload != 'function') {

        window.onload = func;

    }

    else {

        window.onload = function() {

            if (oldonload) {

                oldonload();

            }

            func();

        }

    }

}

var timer=new Array();
		var browser = navigator.appName;
		var ver=0;
		if(browser=="Netscape" || browser=="Opera")
			ver=1;
		function scroller(asd,updown,aaa){
			var thediv=document.getElementById(asd);
			if(updown==1){
				var thehight=thediv.childNodes[ver].offsetHeight-parseInt(thediv.style.height);
				if(aaa==1)
					thediv.scrollTop=thehight;
				aaa=0;
				if(thediv.scrollTop==0)
					thediv.scrollTop=thehight;
				thediv.scrollTop=thediv.scrollTop-1;
			}
			else{
				if(aaa==document.getElementById(asd).scrollTop)
					thediv.scrollTop=0;
				aaa=thediv.scrollTop;
				thediv.scrollTop=thediv.scrollTop+1;
			}
				timer[asd]=setTimeout("scroller('"+asd+"',"+updown+","+aaa+")",40);
		}
		function stopscroller(asd2){
					clearTimeout(timer[asd2]);
		}
		
function changeImage(src)
{
	document.getElementById("main_pic").src = src;	
}

function open_submenu(id)
{
	var ul = document.getElementById("submenu"+id);
	
	if (ul)
	{
			ul.style.display = '';
	}
}

function close_submenu(id)
{
	var ul = document.getElementById("submenu"+id);
	
	if (ul)
	{
			ul.style.display = 'none';
	}
}

function openWindow(url, winName, width, height)
{
	//winName = str.replace(/ /i, "")
	//window.open(url, winName ,"location=1,status=1,scrollbars=1, width="+width+",height="+height);
	
	if(height=='' || !height)
		height=screen.height/2;
		height_factor = ((screen.height/100)*85);
		if(height>=height_factor)
			height=height_factor;

 
		if(width=='' || !width)
			width=screen.width/2;
		width_factor = ((screen.width/100)*95);
		if(width>=width_factor)
			width=width_factor;

		var top=((screen.height-height)/2)-(screen.height/20);
		var left=(screen.width - width) / 2;

var win = window.open(url, winName, 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=yes,resizable=1,copyhistory=no,width='+width+',height='+height+',top='+top+',left='+left);
			win.focus();
			
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function check_contact()
{
	var name = document.getElementById('name');
	var phone = document.getElementById('phone');
	var subject = document.getElementById('subject');
	var content= document.getElementById('content');
	var phone2= document.getElementById('phone2');
	var email= document.getElementById('email');
	var city= document.getElementById('city');
	
	if (trim(name.value) == "")
	{
		alert("חובה למלא שם");
		name.focus();
	}
	else if (trim(phone.value) == "")
	{
		alert("חובה למלא טלפון");
		phone.focus();
	}
	else if (trim(subject.value) == "")
	{
		alert("חובה למלא נושא פניה");
		subject.focus();
	}
	else
	{
		Write("index.php/contact/send", "name="+name.value+"&email="+email.value+"&phone="+phone.value+"&phone2="+phone2.value+"&city="+city.value+"&body="+content.value+"&subject="+subject.value);
		document.getElementById('contact').innerHTML = '<h3 style="margin: 0px;padding-top: 10px; padding-right: 10px;">הפניה התקבלה בהצלחה, ניצור איתך קשר בהקדם.</h3>';
		
		return false;
	}
	
	return false;
}
