﻿var SiteParams = {
	UploadFolder:"/Data/Uploads/",
	SiteUrl:"http://noproblem.co.il/",
	ResourceFolder:"/Resources/Global/Image/"
};


function bookmark(){
	if (window.sidebar) {
		//location.href
		window.sidebar.addPanel("Noproblem.co.il", "http://www.noproblem.co.il","");
	} else if( window.external ) {
		external.AddFavorite("http://www.noproblem.co.il", "Noproblem.co.il" );
	}
}

function OpenOutside(oLink){
	//window.open(oLink.href);
}

function OpenOutside2(link){
	window.open(link);
}
// refers to the "searchform.ascx" form
var ContactStripForm = {
	Validate:function(){
	var errCount = 0;
    		
		    //reset the errors
		    $("ValidationSummary").innerHTML = "";
    		
		    
		    if (errCount==0 && $("FullName").value==""){
			    errCount++;
			    $("FullName").focus();
			    $("ValidationSummary").innerHTML = "נא להזין שם מלא";
		    }
		    
    		
		   
		    if (errCount==0 && $("PhoneNumber").value==""){
			    errCount++;
			    $("PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין מספר טלפון";
		    }
    		
		    if (errCount==0 && !/^0\d{1,2}[\.|\-|\+]?\d{6,7}$/.test($("PhoneNumber").value)){
			    errCount++;
			    $("PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין טלפון תקין";
		    }
    		
		    return errCount==0;	    
	    /*
	    if(page=='defaultPage')
	    {	        
	        
		    var errCount = 0;
    		
		    //reset the errors
		    $("ValidationSummary").innerHTML = "";
    		
		    
		    if (errCount==0 && $("FullName").value==""){
			    errCount++;
			    $("FullName").focus();
			    $("ValidationSummary").innerHTML = "נא להזין שם מלא";
		    }
		    
    		
		   
		    if (errCount==0 && $("PhoneNumber").value==""){
			    errCount++;
			    $("PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין מספר טלפון";
		    }
    		
		    if (errCount==0 && !/^0\d{1,2}[\.|\-|\+]?\d{6,7}$/.test($("PhoneNumber").value)){
			    errCount++;
			    $("PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין טלפון תקין";
		    }
    		
		    return errCount==0;
		  
		}
		
		else
		{
		*/
		    //alert("here");
		    
		    /*
		    if ($("txt_PhoneNumber").value==""){			
			    $("txt_PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין מספר טלפון";
			    return 0;
		    }
    		
		    if (!/^0\d{1,2}[\.|\-|\+]?\d{6,7}$/.test($("txt_PhoneNumber").value)){			
			    $("txt_PhoneNumber").focus();
			    $("ValidationSummary").innerHTML = "נא להזין טלפון תקין";
			    return 0;
		    }
		  
    		//alert("here2");
		    return 1;	
		      */
		//}
	},
	
	Send:function(){	    
		if (!ContactStripForm.Validate())return;
		
		var professionFromPage = typeof(professionName)!="undefined" ? professionName : "";
		var sentFromPage = typeof(professionalRecommendationsFolder)=="undefined" ? "home" : "profession";
		var file = sentFromPage=="profession" ? location.pathname : "index.aspx";
		
		var logId = 0;
		//if (matches!=null && matches.length>0)logId = matches[1];
		var destUrl = file + "?searchsent=" + sentFromPage + "&id=" + (logId * 718);
		location.href = destUrl;
		
		// email is not used in this form
		
		var dataStr = "searchSource="+encodeURIComponent($(sourceFieldId).value)+
						"&proffesionField=" + encodeURIComponent(professionFromPage) + 
						"&fullname=" + encodeURIComponent($("FullName").value) +
						"&phone=" + encodeURIComponent($("PhoneNumber").value) +
						"&email=" + 
						"&returnDay=" + encodeURIComponent($(ddlDayId).value) + 
						"&returnHours=" + encodeURIComponent($(ddlTimeId).value) + 
						"&referer_url="+encodeURIComponent($(refererFieldId).value)+
						"&comments=" + encodeURIComponent($(commentsId).value) + 
						"&pageUrl="+encodeURIComponent(location.href);		
		
		new Ajax(webServiceUrl,
			{
			method: 'post',
			//proffesionField is mispelled, but already used by other external sites - keep it that way
			data:dataStr,
			onComplete:function (response)
			{
				if (response!=null && response != "")
				{					
					// parameter  that exists only in the landnig pages
					var sentFromPage = typeof(professionalRecommendationsFolder)=="undefined" ? "home" : "profession";
					var file = sentFromPage=="profession" ? location.pathname : "index.aspx";
					// redirect for statistics needs
					
					
					//sample - <?xml version="1.0" encoding="utf-8"?><int xmlns="http://www.noproblem.co.il/services/">34419</int>

				 
					var matches = /^.+>(\d+)<\/int>$/m.exec(response);
					var logId = 0;
					if (matches!=null && matches.length>0)logId = matches[1];
					var destUrl = file + "?searchsent=" + sentFromPage + "&id=" + (logId * 718);
					location.href = destUrl;

				}
			}
		}).request();
		
		
		
	}

}

function showDivProfessionCity2()
{
    alert("nnnn");
}

var counter_ContactStripSend;
counter_ContactStripSend=-1;

function showDivProfessionCity()
{
  
    alert("showDivProfessionCity");
    //if (!ContactStripForm.Validate())return;
    var professionId = $("<%=DropDownListProfessionList.ClientID %>").value;
    alert(professionId);
    var cityId = $("<%=DropDownListCities.ClientID %>").value;
    alert(cityId);
    
        //alert($("TopBar").style.display);
        //alert($("ContactForm").style.display);
        
        counter_ContactStripSend++;
       
       /*
        if(counter_ContactStripSend % 2==0)
        {
            $("ContactForm").style.display='none';
            $("FilterWrapper").style.display='none';
            //alert($("ContactForm").style.display);
            $("PhoneCity").style.display='inline';
        }
        
        else
        {
            $("ContactForm").style.display='inline';
            $("FilterWrapper").style.display='inline';
            //alert($("ContactForm").style.display);
            $("SearchFormResponse").style.display='none';
            $("PhoneCity").style.display='none';
        }
        */
        
    //var ifValid;
    //ifValid=ContactStripForm.Validate();
    //if (ifValid)
    //ContactStripForm.Send;
}

function sendForm()
{
    //if (!ContactStripForm.Validate('defaultPage'))return;
    
    ContactStripForm.Send;
}

$DL(function(){
    OnSiteLoad();    
    
});

function OnSiteLoad(){
    
	if($("FullName"))$("FullName").addEvent("keydown",function(e){
		e = new Event(e);
		if (e.key=="tab"){
			$("PhoneNumber").focus();
			e.stop();
		}	
		if (e.key=="enter"){		   
			ContactStripForm.Send();
			e.stop();
		}
	});
	
	/*
	if($("PhoneNumber"))$("PhoneNumber").addEvent("keydown",function(e){
	    
	    
		e = new Event(e);
		if (e.key=="tab"){
			$("ContactStripSend").focus();
			e.stop();
		}	
		if (e.key=="enter"){
		    //alert("baaa");
			//ContactStripForm.Send();
			showDivProfessionCity();
			e.stop();
		}
	});
	*/
	
	if($("txt_PhoneNumber"))$("txt_PhoneNumber").addEvent("keydown",function(e){
	    
	   
		e = new Event(e);
		if (e.key=="tab"){
			$("ContactStripSend").focus();
			e.stop();
		}	
		if (e.key=="enter"){		        
			//ContactStripForm.Send();
			//showDivProfessionCity();
			FilterButtonValidation(3);
			e.stop();
		}
	});
	
	
	
	
	if($("ContactStripSend")){
		/*
		$("ContactStripSend").disabled = false;
		if (location.search.toLowerCase().indexOf("searchsent=")>-1){
			$("ContactStripSend").addClass("orderMore");			
			$("ContactStripSend").addEvent("click",function(){
				// display the form and the send button
				
				$("SearchFormResponse").style.display='none';
				$("ContactForm").style.display='inline';
					$("ContactStripSend").removeClass("orderMore");
				$("ContactStripSend").removeEvent("click");
				$("ContactStripSend").title = "שלח";
				//$("ContactStripSend").addEvent("click",ContactStripForm.Send);
				$("ContactStripSend").addEvent("click",showDivProfessionCity);
				
				
			});
		}else{			      
			
			//$("ContactStripSend").addEvent("click",showDivProfessionCity);
			$("ContactStripSend").addEvent("click",showDivProfessionCity);
			
		}
		*/
		
	}		
	
	if($("ContactStripSendDefaultPage"))
	{	
	   $("ContactStripSendDefaultPage").disabled=false;   
	   if (location.search.toLowerCase().indexOf("searchsent=")>-1)
	   {
			$("ContactStripSendDefaultPage").addClass("orderMore");			
			$("ContactStripSendDefaultPage").addEvent("click",function(){
				// display the form and the send button
				$("SearchFormResponse").hide();
				$("ContactForm").show();
				$("ContactStripSendDefaultPage").removeClass("orderMore");
				$("ContactStripSendDefaultPage").removeEvent("click");
				$("ContactStripSendDefaultPage").title = "שלח";
				$("ContactStripSendDefaultPage").addEvent("click",ContactStripForm.Send);
				
		});
		}
		else
		{ 	       
	        $("ContactStripSendDefaultPage").addEvent("click",ContactStripForm.Send);  
	       
	    }
	}	
	
	
    if(typeof(ValidationSummaryOnSubmit)!="undefined" && ValidationSummaryOnSubmit.toString){

		// disable scroll and rename the function to avoid scope problems
		var rep = ValidationSummaryOnSubmit.toString().replace(/window.scrollTo/g,"//window.scrollTo").replace(/ValidationSummaryOnSubmit/,"ValidationSummaryOnSubmit_NEW");
		eval(rep);
		
		//itay: causing errors, need to check why...
		//ValidationSummaryOnSubmit=ValidationSummaryOnSubmit_NEW;
	}
	
	//causes error :"[Exception... "'Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)"
    //http://geekswithblogs.net/shahedul/archive/2006/08/14/87910.aspx
    var eleObjArr=document.getElementsByTagName("input");
    for(var i=0; i<eleObjArr.length; i++)
    {
        if( eleObjArr[i].getAttribute("autocomplete") )
        {
        eleObjArr[i].setAttribute('autocomplete','off');
        }
    }
}

function showMe(divId)
{
//alert("divId:" + divId);    
 document.getElementById(divId).style.display='inline';
   
}

 function hideMe(divId)
{
    document.getElementById(divId).style.display='none';
}
