var preloadFlag = false;
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function preloadImages() {
	if (document.images) {
		nav1 = newImage("images/hananOver_04.jpg");
		nav2 = newImage("images/hananOver_06.jpg");
		nav3 = newImage("images/hananOver_08.jpg");
		nav4 = newImage("images/hananOver_10.jpg");
		nav5 = newImage("images/hananOver_12.jpg");
		preloadFlag = true;
	}
}


function isDigit(strNum)
{
	return /^\-?\d+(\.\d+)?$/.test(strNum);
}

function checkEmail(strEmail)
{
	return /^\w+([\.]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})$/.test(strEmail);
}

function varifyLogin() {
	flag = true
	if (document.getElementById('userName').value=='')  {
		document.getElementById('userName').style.backgroundColor='red';
		document.getElementById('userName').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('userName').style.backgroundColor='';
		document.getElementById('userName').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('userPassword').value=='')  {
		document.getElementById('userPassword').style.backgroundColor='red';
		document.getElementById('userPassword').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('userPassword').style.backgroundColor='';
		document.getElementById('userPassword').style.color='';
		if(flag) flag = true;
	}


	if (flag==true) { 
		document.getElementById('loginForm').action = 'login.asp';
		document.getElementById('loginForm').submit();
	}
}

function varifyContact() {
	flag = true
	if (document.getElementById('txtName').value=='')  {
		document.getElementById('txtName').style.backgroundColor='red';
		document.getElementById('txtName').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtName').style.backgroundColor='';
		document.getElementById('txtName').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtPhone').value=='')  {
		document.getElementById('txtPhone').style.backgroundColor='red';
		document.getElementById('txtPhone').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtPhone').style.backgroundColor='';
		document.getElementById('txtPhone').style.color='';
		if(flag) flag = true;
	}


	if (flag==true) { 
		document.getElementById('contactForm').action='sendMail.asp';
		document.getElementById('contactForm').submit();
	}
}

function varifyRegister() {
	flag = true
	if (document.getElementById('userName').value=='')  {
		document.getElementById('userName').style.backgroundColor='red';
		document.getElementById('userName').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('userName').style.backgroundColor='';
		document.getElementById('userName').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('userPassword').value=='')  {
		document.getElementById('userPassword').style.backgroundColor='red';
		document.getElementById('userPassword').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('userPassword').style.backgroundColor='';
		document.getElementById('userPassword').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('userEmail').value=='')  {
		document.getElementById('userEmail').style.backgroundColor='red';
		document.getElementById('userEmail').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('userEmail').style.backgroundColor='';
		document.getElementById('userEmail').style.color='';
		if(flag) flag = true;
	}
	if (!document.getElementById('agreement').checked)  {
		alert('נא לקרוא את תנאי השימוש ולאשר את הסכמתך');
		document.getElementById('labelAgreement').style.color='red';
		flag = false;
	}
	else {
		document.getElementById('labelAgreement').style.color='';
		if(flag) flag = true;
	}

	if (flag==true) { 
		document.getElementById('signForm').action='sign.asp';
		document.getElementById('signForm').submit();
	}
}

function validateUserEdit() {
	flag = true
	if (document.getElementById('txtName').value=='')  {
		document.getElementById('txtName').style.backgroundColor='red';
		document.getElementById('txtName').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtName').style.backgroundColor='';
		document.getElementById('txtName').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtPassword').value=='')  {
		document.getElementById('txtPassword').style.backgroundColor='red';
		document.getElementById('txtPassword').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtPassword').style.backgroundColor='';
		document.getElementById('txtPassword').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtPhone').value=='')  {
		document.getElementById('txtPhone').style.backgroundColor='red';
		document.getElementById('txtPhone').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtPhone').style.backgroundColor='';
		document.getElementById('txtPhone').style.color='';
		if(flag) flag = true;
	}

	if (flag==true) { 
		document.getElementById('form1').submit();
	}
}

function validateEstateAdd() {
	flag = true
	if (document.getElementById('txtAddress').value=='')  {
		document.getElementById('txtAddress').style.backgroundColor='red';
		document.getElementById('txtAddress').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtAddress').style.backgroundColor='';
		document.getElementById('txtAddress').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtCity').value=='')  {
		document.getElementById('txtCity').style.backgroundColor='red';
		document.getElementById('txtCity').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtCity').style.backgroundColor='';
		document.getElementById('txtCity').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtAge').value=='')  {
		document.getElementById('txtAge').style.backgroundColor='red';
		document.getElementById('txtAge').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtAge').style.backgroundColor='';
		document.getElementById('txtAge').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtFloors').value=='')  {
		document.getElementById('txtFloors').style.backgroundColor='red';
		document.getElementById('txtFloors').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtFloors').style.backgroundColor='';
		document.getElementById('txtFloors').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtName').value=='')  {
		document.getElementById('txtName').style.backgroundColor='red';
		document.getElementById('txtName').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtName').style.backgroundColor='';
		document.getElementById('txtName').style.color='';
		if(flag) flag = true;
	}
	if (document.getElementById('txtPhone').value=='')  {
		document.getElementById('txtPhone').style.backgroundColor='red';
		document.getElementById('txtPhone').style.color='white';
		flag = false;
	}
	else {
		document.getElementById('txtPhone').style.backgroundColor='';
		document.getElementById('txtPhone').style.color='';
		if(flag) flag = true;
	}
	
	if (flag==true) { 
		//document.getElementById('form1').action='userEstateAdd.asp';
		document.getElementById('form1').submit();
	}
}

function scrollhpArticles(theWin,down) {
	cur = parseInt(document.getElementById('hp'+theWin+'Container').scrollTop);
	for(x=1;x<50;x++) {
		document.getElementById('hp'+theWin+'Container').scrollTop = cur + (down*parseInt(x));
	};
};
function switchBox(hideBox,showBox) {
	document.getElementById('box'+hideBox).style.display='none';
	document.getElementById('box'+showBox).style.display='inline';
};

//Cross browser attach event function. For 'evt' pass a string value with the leading "on" omitted
//e.g. AttachEvent(window,'load',MyFunctionNameWithoutParenthesis,false);

function AttachEvent(obj,evt,fnc,useCapture){
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 

//The following are for browsers like NS4 or IE5Mac which don't support either
//attachEvent or addEventListener
function MyAttachEvent(obj,evt,fnc){
	if (!obj.myEvents) obj.myEvents={};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}
function MyFireEvent(obj,evt){
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}
AttachEvent(window,'load',preloadImages,false);

