﻿// JScript File
function getParam(strParamName)
{
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 )
    {
         var strQueryString = strHref.substr(strHref.indexOf("?")+1).toLowerCase();
         var aQueryString = strQueryString.split("&");
         var lastArray;
         for ( var iParam = 0; iParam < aQueryString.length; iParam++)
         {
            lastArray = aQueryString[iParam].split("=");
            if(lastArray[0]==strParamName) 
            {
                  strReturn = lastArray[1];
                  break;
            }
        }
    } 
            return strReturn;
}

function DeleteOpenHouse(seqNum)
{
    if(confirm("delete ? למחוק"))
    {
        document.getElementById("ctl00_ContentPlaceHolder1_hidDelete").value=seqNum;
        __doPostBack("","");
    }    
}
function HideDeleteRepeater()
{
    var wTable = document.getElementById("tblRepeater");
    for(i=1;i<wTable.rows.length;i++)
    {
        //alert(wTable.rows[i].cells[6].innerHTML+"  "+document.getElementById("ctl00_ContentPlaceHolder1_hidMediator").value);
        if(wTable.rows[i].cells[7])
            if(parseInt(wTable.rows[i].cells[7].innerHTML)!=parseInt(document.getElementById("ctl00_ContentPlaceHolder1_hidMediator").value))
            {
                //alert(wTable.rows[i].cells[6].innerHTML!=document.getElementById("ctl00_ContentPlaceHolder1_hidMediator").value);
                
                if(wTable.rows[i].cells[8].children[0])
                {
                    wTable.rows[i].cells[8].children[0].style.display="none";
                }
            }
    }
}
function hideDivPicture()
{
    document.getElementById("ctl00_ContentPlaceHolder1_divShowImage").style.display="none";
}
function showArticlePicture(img)
{
    document.getElementById("ctl00_ContentPlaceHolder1_divShowImage").innerHTML = "<img src='../pictures/ArticlesPics/"+img+"'>";
    document.getElementById("ctl00_ContentPlaceHolder1_divShowImage").style.display="";
    //alert(img);
}
//------------- AJAX START ---------------//
    var httpRequest;
    function makeRequest(url) {
        

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                               } 
                             catch (e) {}
                          }
                                       }

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() { return alertContents(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');

    }

    function alertContents(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) 
            {
                var answer = httpRequest.responseText;
                document.getElementById("ctl00_ContentPlaceHolder1_divMoreDetails").innerHTML = answer;
                document.getElementById("ctl00_ContentPlaceHolder1_divMoreDetails").style.display="";
                
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
//------------- END AJAX -----------------//
function isLegalLength(obj, minimalLength)
{
    if(obj.value.length < minimalLength && obj.value.length>0)
    {
        alert("ערך לא חוקי");
        obj.focus();
    }
}
function IsNumeric(obj)
{
   var sText = obj.value;
   var ValidChars = "0123456789,-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i);
      if ((ValidChars.indexOf(Char) == -1) && (Char!=" ")) 
      {
        alert("ערך לא חוקי");
        obj.focus();
        IsNumber = false;
      }
   }
   return IsNumber;
}

function checkAppartType(obj)
{
    objSelectedIndex=obj.selectedIndex;
    if((obj.options[objSelectedIndex].text=="מגרש")||(obj.options[objSelectedIndex].text=="משק"))
    {
        document.getElementById("ctl00_ContentPlaceHolder1_ddlRooms").value="1";
        document.getElementById("ctl00_ContentPlaceHolder1_ddlFloor").selectedIndex="0";
        document.getElementById("ctl00_ContentPlaceHolder1_ddlFloor").disabled = true;
        document.getElementById("ctl00_ContentPlaceHolder1_ddlRooms").disabled = true;
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_ddlFloor").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_ddlRooms").value="";
        document.getElementById("ctl00_ContentPlaceHolder1_ddlFloor").disabled = "";
        document.getElementById("ctl00_ContentPlaceHolder1_ddlRooms").disabled = "";
    }
}
function showStreet()
{
    document.getElementById("ctl00_ContentPlaceHolder1_lblStreet").className="visibleClass";
    document.getElementById("ctl00_ContentPlaceHolder1_ddlStreet").className="visibleClass";
}
function hideStreet()
{
    document.getElementById("ctl00_ContentPlaceHolder1_lblStreet").className="hiddenClass";
    document.getElementById("ctl00_ContentPlaceHolder1_ddlStreet").className="hiddenClass";
}
function InitPopup(sURLPage, width, height)
{
    var sFeatures = "menubar=no,titlebar=no,top=10,left=50,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=" + width + "px,height=" + height + "px;";
    PopLuz = window.open(sURLPage,'aa',sFeatures);
}
function searchersList(relativePath)
{
    //alert();
    window.open(relativePath+"WebForms/SearchersList.aspx","_self");
}
function disconnect(relativePath)
{
    window.open(relativePath+"Main.aspx?clearMaster=1","_self");
}
function checkMail(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
	    return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 )//|| str.indexOf(at)==lstr)
	{
	    return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 )//|| str.indexOf(dot)==lstr)
	{
	    return false
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
	    return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
	    return false
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false
	}
		
    if (str.indexOf(" ")!=-1)
    {
		return false
	}
 	return true	
}
function openMain(relativePath)
{
    window.open(relativePath+"index.aspx","_self");
}
function openNewAppart(relativePath)
{
    window.open(relativePath+"WebForms/newAppart.aspx","_self");
}
function openPrivate(relativePath)
{
    window.open(relativePath+"WebForms/login.aspx","_self");
}
function fixSize()
{
    if(screen.width=="800")
    {
        if(document.getElementById("leftBanner"))
        {
            document.getElementById("leftBanner").src="./pictures/blank.jpg";
            document.getElementById("leftBanner").width="0";
        }
        if(document.getElementById("rightBanner"))
        {
            document.getElementById("rightBanner").src="./pictures/blank.jpg";
            document.getElementById("rightBanner").width="0";
        }
    }        
    document.getElementById("mainTable").style.height = screen.height-180+"px";
}
function mediatorsList(relativePath)
{
    window.open(relativePath+"WebForms/MediatorsList.aspx","_self");
}
function NewSearcher(relativePath)
{
    window.open(relativePath+"WebForms/NewSearcher.aspx","_self");
}
function openMyPrivate(relativePath)
{
    window.open(relativePath+"WebForms/private.aspx","_self");
}
function disconnect(relativePath)
{
    window.open(relativePath+"WebForms/Main.aspx?clearMaster=1","_self");
}
function stlmntsList()
{
    window.open("stlmntsList.aspx","_self");
}
function streetsList()
{
    window.open("streetsList.aspx","_self");
}
function Save(obj)
{
    document.getElementById("ctl00_ContentPlaceHolder1_btnSave").click();
}
//hideSaveButton()
//{
//    document.getElementById("ctl00_ContentPlaceHolder1_imgSave").style.display="none";
//}
//showSaveButton()
//{
//    document.getElementById("ctl00_ContentPlaceHolder1_imgSave").style.display="";
//}
function SaveAppartment(obj)
{
    var a;// = confirm("אני מצהיר כי איני מתווך וכי הפרסום הוא למטרה פרטית בלבד");
    switch (document.getElementById("ctl00_lnkLanguage").innerText)
    {
    case "עברית":
        a = confirm("I am not a realtor and my advertisement is for private purpose only!");
        break
    case "english":
        a = confirm("אני מצהיר כי איני מתווך וכי הפרסום הוא למטרה פרטית בלבד");
        break;
    }
    if(a)
     {
            //hideSaveButton()
            Save(obj);
     }
}
function openExpertsList(relativePath,ExpertTypeC,ExpertTypeN)
{
    window.open(relativePath+"WebForms/ExpertsList.aspx?ExpertTypeC="+ExpertTypeC+"&ExpertTypeN="+ExpertTypeN,"_self");
}
function openArticle(relativePath,expertId)
{
    window.open(relativePath+"WebForms/ExpertArticle.aspx?expertId="+expertId,"_self")
}
function beforeDeleteExpert(obj)
{
    if(confirm("האם למחוק אותו מהמערכת?"))
        Delete(obj);
}
function Delete(obj)
{
    document.getElementById("ctl00_ContentPlaceHolder1_btnDelete").click();
}
function openNewMediator(relativePath)
{
    window.open(relativePath+"WebForms/newMediator.aspx","_self")
}
function openSendMeMails(relativePath)
{
    window.open(relativePath+"WebForms/SendMeMails.aspx","_self")
}
function openDollar(relativePath)
{
    window.open(relativePath+"WebForms/Dollar.aspx","_self")
}
function openInfo(relativePath)
{
    window.open(relativePath+"WebForms/info.aspx","_self")
}
function openBuyOrNot(relativePath)
{
    window.open(relativePath+"WebForms/BuyOrNot.aspx","_self")
}
function beforeDelete(msg)
{
    var answer = confirm("האם למחוק נכס זה מהמערכת ?");
    if(answer)
    {
        document.getElementById("ctl00_ContentPlaceHolder1_hidDelete").value="1";
        __doPostBack('','');            
    }
}     
function Jump(obj) 
{
    document.getElementById("ctl00_ContentPlaceHolder1_btnSave").click();
}
function updateAppartDetails(seqNum,Mediation)
{
    var ln = getParam("ln");
    window.open("updateAppartDetails.aspx?SeqNum=" + seqNum + "&Mediation=" + Mediation + "&ln=" + ln,"_self");
}
function CheckRequiredEmail(source,args)
{          
    var mailAddress = document.getElementById("ctl00_ContentPlaceHolder1_txtMail").value;
    var answer = checkMail(mailAddress);
    if (!answer)
    {
        args.IsValid =false;
        source.errormessage="שדה אימייל לא תקין" ;
    }                             
}
function getMediatorDetails(mediatorC)
{
    window.open("mediatorDetails.aspx?mediatorC="+mediatorC, "_self");
}
function mediatorPublishedApparts(mediatorC)
{
    var ln = getParam("ln");
    window.open("mediatorPublishedApparts.aspx?mediatorC="+mediatorC+"&ln="+ln, "_self");
}
function beforeDeleteMediator()
{
    var answer = confirm("האם למחוק מתווך זה ואת כל הנכסים שלו ?");
    if(answer)
    {
        document.getElementById("ctl00_ContentPlaceHolder1_hidDelete").value="1";
        document.getElementById("ctl00_ContentPlaceHolder1_btnDelete").click();
    }
}
function getAppartDetails(relativePath,seqNum)
{ 
    var ln = getParam("ln");
    makeRequest(relativePath+"WebForms/GetAppartDetails.aspx?SeqNum="+seqNum+"&ln="+ln);
}
function getExpertCard(ExpertId)
{ // FOR USER
    var ln = getParam("ln");
    window.open("ExpertCard.aspx?ExpertId="+ExpertId+"&ln="+ln, "_self");
}
function getExpertDetails(ExpertId)
{  // FOR MANAGER
    window.open("ExpertDetails.aspx?ExpertId="+ExpertId, "_self");
}
function hideDivMoreDetails()
{
    document.getElementById("ctl00_ContentPlaceHolder1_divMoreDetails").style.display="none";
}
function openImages(relativePath,seqNum)
{
    InitPopup(relativePath+"WebForms/appartPics.aspx?seqNum="+seqNum,600,600);
}
function ifMediation(mediatorC)
{
    if(mediatorC!="0")
        return "תיווך";
} 
function Search(obj)
{
    var deal = document.getElementById("ctl00_ContentPlaceHolder1_ddlDeal").value;
    var stlmnt = document.getElementById("ctl00_ContentPlaceHolder1_ddlStlmnt").value;
    if(deal == "") 
    {
        alert("נא לבחור סוג עסקה ");
    }
//    else
//    {
//        if(stlmnt == "")
//        {
//            alert("נא לבחור יישוב ");
//        }
        else
        {    
            document.getElementById("ctl00_ContentPlaceHolder1_btnSearch").click();
        }
//    }
}

function ifMediation(mediatorC)
{
    if(mediatorC!="0")
        return "תיווך";
} 
function getPics(seqNum)
{
    var currImage = document.getElementById("currImage");
    var tmb1 = document.getElementById("tmb1");
    var tmb2 = document.getElementById("tmb2");
    var tmb3 = document.getElementById("tmb3");
    currImage.src = "getPicture.aspx?seqNum=" + seqNum + "&imageName=image1";
    tmb1.src = "getPicture.aspx?seqNum=" + seqNum + "&imageName=thumb1";
    tmb2.src = "getPicture.aspx?seqNum=" + seqNum + "&imageName=thumb2";
    tmb3.src = "getPicture.aspx?seqNum=" + seqNum + "&imageName=thumb3";
}
function mainPicture(innerHTML)//seqNum, imageName)
{
    //var currImage = document.getElementById("currImage");
    //currImage.src = "getPicture.aspx?seqNum=" + seqNum + "&imageName=" + imageName;
    //var divMain = document.getElementById("divMain");
    //divMain.inner="<img src="+innerHTML+">";
    document.getElementById("mainImg").src = document.getElementById(innerHTML).src;
    //alert(innerHTML);
}
/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
function pausescroller(content, divId, divClass, delay){
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer=1 //index of message array for hidden div
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
    var scrollerinstance=this
    if (window.addEventListener) //run onload in DOM2 browsers
    window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
    else if (window.attachEvent) //run onload in IE5.5+
    window.attachEvent("onload", function(){scrollerinstance.initialize()})
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
    setTimeout(function(){scrollerinstance.initialize()}, 500)
}
// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------
pausescroller.prototype.initialize=function(){
    this.tickerdiv=document.getElementById(this.tickerid)
    this.visiblediv=document.getElementById(this.tickerid+"1")
    this.hiddendiv=document.getElementById(this.tickerid+"2")
    this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility="visible"
    var scrollerinstance=this
    document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
    document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
    if (window.attachEvent) //Clean up loose references in IE
    window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
    setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}
// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------
pausescroller.prototype.animateup=function(){
    var scrollerinstance=this
    if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+1)){
    this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-1+"px"
    this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-1+"px"
    setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
    this.getinline(this.hiddendiv, this.visiblediv)
    this.swapdivs()
    setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
    }
}
// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------
pausescroller.prototype.swapdivs=function(){
    var tempcontainer=this.visiblediv
    this.visiblediv=this.hiddendiv
    this.hiddendiv=tempcontainer
}
pausescroller.prototype.getinline=function(div1, div2){
    div1.style.top=this.visibledivtop+"px"
    div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}
// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
    var scrollerinstance=this
    if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
    setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
    var i=this.hiddendivpointer
    var ceiling=this.content.length
    this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
    this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
    this.animateup()
    }
}
pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
    if (tickerobj.currentStyle)
    return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
    return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
    return 0
}
function GetScrolling()
{
    var pausecontent=new Array();
    var newsArr = document.getElementById("ctl00_hidNewsDiv").innerHTML.split("|");
    var j = 0;
    var ln = getParam("ln");
    if(ln=="")
        ln="he";
    for(i=0 ; i<newsArr.length-2 ; i++)
    {
        if(newsArr[j])
        {
            pausecontent[i]='<a href="'+newsArr[j]+'&ln='+ln+'" ><font color="#524e4a">'+ newsArr[j+1] +'</font></a>';
        }
        j+=2;
    }
    return new pausescroller(pausecontent, "pscroller2", "someclass", 4000);
}