function contact_overImage(obj)
{
	obj.src = eval(obj.name + "_On.src");
	obj.style.cursor = 'hand';
}

function contact_outImage(obj)
{
	obj.src = eval(obj.name + "_Off.src");
}

/*function contact_init(obj)
{
	document.all('txtSenderName').focus();
}

function contact_initPostback(obj)
{

}*/

var contact_strContactUsUniqueID = "";
function contact_getUniqueID()
{
	var input = document.all.tags('INPUT');
	
	for (var i=0 ; i<input.length ; i++) 
	{
		for (var j in input[i])
		{
			if (input[i].id.indexOf("txtUcContactUsID") != -1)
			{
				return input[i].id.replace("_txtUcContactUsID", "");
			}
		}	
	}
}

function contact_resetForm(obj)
{
	if (contact_strContactUsUniqueID == "")
	{
		contact_strContactUsUniqueID = contact_getUniqueID();
	}
	
	document.all(contact_strContactUsUniqueID + '_txtFirstName').value	= "";
	document.all(contact_strContactUsUniqueID + '_txtLastName').value	= "";
	document.all(contact_strContactUsUniqueID + '_txtCity').value = "";
	document.all(contact_strContactUsUniqueID + '_txtPhone').value = "";
	document.all(contact_strContactUsUniqueID + '_txtCellular').value = "";
	document.all(contact_strContactUsUniqueID + '_txtEmail').value	= "";
	document.all(contact_strContactUsUniqueID + '_txtSubject').value = "";
	document.all(contact_strContactUsUniqueID + '_txtComment').innerHTML = "";
	document.all(contact_strContactUsUniqueID + '_txtSubject').focus();
}

// check form
function contact_checkForm(obj)
{
	if (contact_strContactUsUniqueID == "")
	{
		contact_strContactUsUniqueID = contact_getUniqueID();
	}

	// get form content
	var objFirstName = document.all(contact_strContactUsUniqueID + '_txtFirstName');
	var objLastName = document.all(contact_strContactUsUniqueID + '_txtLastName');
	var objCity = document.all(contact_strContactUsUniqueID + '_txtCity');
	var objPhone = document.all(contact_strContactUsUniqueID + '_txtPhone');
	var objCellular = document.all(contact_strContactUsUniqueID + '_txtCellular');
	var objEmail = document.all(contact_strContactUsUniqueID + '_txtEmail');
	var objComment = document.all(contact_strContactUsUniqueID + '_txtComment');
	var objSubject = document.all(contact_strContactUsUniqueID + '_txtSubject');
	var objMessage = document.all(contact_strContactUsUniqueID + '_tdClientMessage')
	var objBtnSend = document.all(contact_strContactUsUniqueID + '_btnSend')

	// check subject
	if (send_popup_isEmpty(objSubject.value) == true)
	{
		alert(arrMessages['subject_empty']);	
		objSubject.focus();
		return;
	}
	
	// check first name
	if (send_popup_isEmpty(objFirstName.value) == true)
	{
		alert(arrMessages['first_name_empty']);	
		objFirstName.focus();
		return;
	}
	
	if (send_popup_validName(objFirstName.value) == false)
	{
		alert(arrMessages['first_name_error']);	
		objFirstName.focus();
		return;
	}
	
	// check last name
	if (send_popup_isEmpty(objLastName.value) == true)
	{
		alert(arrMessages['last_name_empty']);	
		objLastName.focus();
		return;
	}
	
	if (send_popup_validName(objLastName.value) == false)
	{
		alert(arrMessages['last_name_error']);	
		objLastName.focus();
		return;
	}

	// check reciver email
	if (send_popup_isEmpty(objEmail.value) == true)
	{
		alert(arrMessages['email_empty']);
		objEmail.focus();
		return;
	}
	
	if (send_popup_validEmail(objEmail.value) == false)
	{
		alert(arrMessages['email_error']);
		objEmail.focus();
		return;
	}
	
	// check comment
	if (send_popup_isEmpty(objComment.innerText) == true)
	{
		alert(arrMessages['comment_empty']);	
		objComment.focus();
		return;
	}
	
	objBtnSend.click();
}

function send_popup_isEmpty(strValue)
{
	// if the field value is empty, return true (error)
	if (strValue == "")
	{
		return true;
	}
	
	return false;	
		
}

var arrValidNameChars = ["'","-", " "];
function send_popup_validName(strValue)
{
	for (var i=0 ; i<strValue.length ; i++)
	{
		var ch = strValue.charAt(i);
		
		if ( isBigLetter(ch) == false  && isSmallLetter(ch) == false && isHebrewLetter(ch) == false && isNumber(ch) == false && isValidChar(ch) == false)
		{
			return false;
		}
	}
	
	return true;
	
	function isBigLetter(ch)
	{
		return (ch >= 'A' && ch <= 'Z')
	}
	
	function isSmallLetter(ch)
	{
		return (ch >= 'a' && ch <= 'z')
	}
	
	function isHebrewLetter(ch)
	{
		return (ch.charCodeAt(0) >= 1488 && ch.charCodeAt(0) <= 1514)
	}

	function isNumber(ch)
	{
		return (ch >= '0' && ch <= '9')
	}
	
	
	function isValidChar(ch)
	{
		for (var i=0 ; i<arrValidNameChars.length ; i++)
		{
			if (ch == arrValidNameChars[i])
			{
				return true;
			}
		}
		
		return false;
	}
}

var arrNotValidEMailChars = ["/",":",";"," ","^","$","(",")","[","]","{","}","+","=","|","\\","*","~","`","'","#","!",",","?"];
function send_popup_validEmail(strValue)
{
	var strValue = new String (strValue);
	
	// check if '@' is exist
	arrValue = strValue.split("@");
		
	if (arrValue.length != 2)
	{
		return false;
	}
	
	var strLeftSection = arrValue[0];
	var strRightSection = arrValue[1];
	
	if (strLeftSection == "")
	{
		return false;
	}	
			
	if (strRightSection == "")
	{
		return false;	
	}
	
	// check if there is one dot or two dots in the second section
	arrRightSection = strRightSection.split(".");
	if (arrRightSection.length != 2 && arrRightSection.length != 3)
	{
		return false;	
	}	
			
	// check there 	are no two dots one beside other
	for (var i=0 ; i<arrRightSection.length ; i++)
	{
		if (arrRightSection[i] == "")
		{
			return false;
		}
	}
	
	// check all chars are valid
	for (var i=0 ; i<arrNotValidEMailChars.length ; i++)
	{
		if (strValue.indexOf(arrNotValidEMailChars[i]) > -1)
		{
			return false;
		}
	}		
	
	if (strValue.indexOf('"') > -1)
	{
		return false;
	}
	
	for (var i=0 ; i<strValue.length ; i++)
	{
		// 1488 = 'à', 1514 = 'ú', 
		
		var ch = strValue.charAt(i);
		if (ch.charCodeAt(0) >= 1488 && ch.charCodeAt(0) <= 1514)
		{
			return false
		}
	}
	
	return true;	
}
 
function send_popup_validPhone(obj)
{
	// if the field has 'maxLength' attribute, check if the field value length is equal to the 'maxLength'
	if (obj.maxLength != 2147483647)
	{
		if (obj.value.length != obj.maxLength)
		{
			return false;
		}	
	}
	
	// if the field value is not numeric return false
	return !isNaN(obj.value)
} 

function send_popup_validSelect(obj)
{
	// if the field value is '0' return false
	return (obj.value != '0')
}
 

