var User = {

	name : "",
	
	zoneArr : [] ,

	isLogin : false ,

	addToFavorites : function(ajaxUrl,callback)
	{
		if(this.isLogin)
		{
			Ajax.HTTPServerRequest(ajaxUrl,null,false,callback ? callback : addToFavorites_CALLBACK);
			return false;
		}
		return true;

	} ,

	readFavorites : function(hCode, isCustomerWrapper)
	{	    
		var ajaxUrl = "/";
		var params = "headingCode=" + hCode +"&page=Business-Ajax-MYD-AjaxGetFavorites&isXML=1";
		if (!isCustomerWrapper & !this.isLogin)
		    if (!this.isLogin || vPageName != 'Business-Results')return;
		//Ajax.HTTPServerRequest(ajaxUrl,params,false,readFavorites_CALLBACK);		
		
	} ,
	
	Login : function(url ,userNameInput, userPasswordInput, callback)
	{
		if ($(userNameInput).value == 'שם משתמש' || $(userPasswordInput).value == 'סיסמה' || $(userNameInput).value == '' || $(userPasswordInput).value == '')
        {
			if($('loginErrMsgDiv'))
			{
				$('loginErrMsgDiv').innerHTML = "אנא הכנס שם משתמש וסיסמה.";
				$('loginErrMsgDiv').style.display = 'block';
			}
			
            document.getElementById("myd_loginErrMsg").innerHTML = "אנא הכנס שם משתמש וסיסמה.";
            document.getElementById("myd_loginErrMsg").style.display = "block";
        }
        else
        {
			var	params ='&UserEmail=' +$(userNameInput).value + '&UserPassword=' + $(userPasswordInput).value;
            Ajax.HTTPServerRequest(url,params,false,callback);
            }
	} ,
	
	ForgetPassword : function(url , userNameInput , callback)
	{
		var params ='&FPUserEmail=' +$(userNameInput).value;
		Ajax.HTTPServerRequest(url,params,false,callback);       
	} ,

	WriteLinkToGradeCoockie : function()
	{
		var href = self == parent ? window.location.href : parent.window.location.href;		
		setCookie("sGradeLink",href,1);		
	} ,

	ReadLinkToGradeCoockie : function()
	{
		return getCookie("sGradeLink");
	} ,

	DeleteLinkToGradeCoockie : function()
	{
		setCookie("sGradeLink",window.location.href,-1);
	} ,

	Innit : function()
	{
		this.name = myd_getCookie("loginUserName");		
		if(this.name) this.isLogin = true;				
	}

}

function setCookie(c_name,value,expiredays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function readFavorites_CALLBACK(AjaxPage)
{	
	var docElem = getXmlDoc(AjaxPage);
	var i=0;
	var nodes = docElem.childNodes;
	var fav;
	for(i=0;i< nodes.length;i++)
	{
		var cId='';
		if(browser == 'FF')
			 cId = nodes[i].getAttribute ? nodes[i].getAttribute("cId") : '';
		else
			cId = nodes[i].getAttribute("cId");
		if ($('addToFavoriteLink')!=null && vCustId != null && cId == vCustId) fav = $('addToFavoriteLink')
		else fav = $("myd_Favorits" + cId);
		if(fav)
		{
			fav.onclick = return_false;
			fav.className = 'selected';
			if (fav.getAttribute('isdmap') == '1')
                fav.title = "נמצא במועדפים"
            else
            {
                fav.innerHTML = "נמצא במועדפים";
			    fav.style.fontWeight = "bold";
			}
		}
	}
}


