﻿
function validateCNP(source,value)
{
    var val = value.Value;
    var suma=0;
    if(val.length==13)
    {
        suma= parseInt(val.charAt(0))*2+ parseInt(val.charAt(1))*7+ parseInt(val.charAt(2))*9+ parseInt(val.charAt(3))*1+ parseInt(val.charAt(4))*4+ parseInt(val.charAt(5))*6+ parseInt(val.charAt(6))*3+ parseInt(val.charAt(7))*5+ parseInt(val.charAt(8))*8+ parseInt(val.charAt(9))*2+ parseInt(val.charAt(10))*7+ parseInt(val.charAt(11))*9; 
        suma=suma%11; 
        if(suma==10) suma=1;
        if(suma==parseInt(val.charAt(12))) { value.IsValid = true; return true; }
        else { value.IsValid = false; return false; }
    }
    else { value.IsValid = false; return false; }
}

function validateFaxEmail(source,value)
{
    var val = value.Value;
    fax = document.getElementById("ctl00_hld_txtFax");
    email = document.getElementById("ctl00_hld_txtEmailFacturing");
    if ((fax.value != "") || (email.value != ""))
    {
        value.IsValid = true;
        return true;
    }
    else 
    {
        value.IsValid = false;
        return false;
    }
}

function validateFloor(source,value)
{
    var val = value.Value;
    floor = document.getElementById("ctl00_hld_building_ddlFloor");
    floorCount = document.getElementById("ctl00_hld_building_ddlFloorCount");
    floorvalue = 0;
    if (floor.value!="Parter") floorvalue = floor.value*1;
    floorcountvalue = 0;
    if (floorCount.value!="Parter") floorcountvalue = floorCount.value*1;
    if (floorvalue*1 <= floorcountvalue*1)
    {
        value.IsValid = true;
        return true;
    }
    else 
    {
        value.IsValid = false;
        return false;
    }
}

function UpdateImageGrid()
{
    o = document.getElementById(triggername);
    d = new Date();
    o.value = d.getTime();
}

function search(id)
{
    var prefix = "";
    if (document.URL.indexOf("Administration") > 0) prefix = "../";
    city = document.getElementById("ctl00_cities2").value;
    if (id=='btnSearchBanner')
    {
        val = document.getElementById('bannerSearch').value;
        location.href = prefix + 'SearchResults.aspx?code='+val+"&city="+city;
    }
    else if (id=='btnSearchPhone')
    {
        try
        {
            val = document.getElementById('telephoneSearch').value;
            location.href = prefix + 'SearchResults.aspx?phone='+val+"&city="+city;
            return false;
        } catch(e) {}
    }
    else if (id=='btnSearchSurface')
    {
        from = document.getElementById('ctl00_surfaceFrom').value;
        to = document.getElementById('ctl00_surfaceTo').value;
        if ((from != '') && (to !='') && (from < to))
        {
            location.href= prefix + 'SearchResults.aspx?surfaceFrom='+from+'&surfaceTo='+to+"&city="+city;
            return false;
        }
    }
    else if (id=='btnSearchPrice')
    {
        from = document.getElementById('ctl00_priceFrom').value;
        to = document.getElementById('ctl00_priceTo').value;
        window.location.href = prefix + 'SearchResults.aspx?priceFrom='+from+'&priceTo='+to+"&city="+city;
        return false;
    }
    else if (id=='ddlCategorie')
    {
        val = document.getElementById('ddlCategorie').value;
        switch(val)
        {
            case '1': location.href  = prefix + 'SearchResults.aspx'+"?city="+city; break;
            case '2': location.href  = prefix + 'SearchResults.aspx?buildingType=0'+"&city="+city; break;
            case '3': location.href  = prefix + 'SearchResults.aspx?buildingType=2'+"&city="+city; break;
            case '4': location.href  = prefix + 'SearchResults.aspx?buildingType=3'+"&city="+city; break;
            case '5': location.href  = prefix + 'SearchResults.aspx?buildingType=4'+"&city="+city; break;
            case '6': location.href  = prefix + 'SearchResults.aspx?buildingType=5'+"&city="+city; break;
            case '7': location.href  = prefix + 'SearchResults.aspx?buildingType=6'+"&city="+city; break;
            case '8': location.href  = prefix + 'SearchResults.aspx?buildingType=7'+"&city="+city; break;
            case '9': location.href  = prefix + 'SearchResults.aspx?buildingType=1'+"&city="+city; break;
            case '10': location.href  = prefix + 'SearchResults.aspx?buildingType=8'+"&city="+city; break;
            case '11': location.href  = prefix + 'SearchResults.aspx?buildingType=10'+"&city="+city; break;
            case '12': location.href  = prefix + 'SearchResults.aspx?buildingType=9'+"&city="+city; break;
        }
    }
    else if (id=='ddlCategoryTerrain')
    {
        val = document.getElementById('ddlCategoryTerrain').value;
        if (val == '1') location.href  = prefix + 'SearchResults.aspx?terrain=1'+"&city="+city; 
    }
    else alert('Not implemented yet!');
}

inlogin = false;
inlogin2 = false;

function processKey()
{
    if (event.keyCode == 13)
    {
        if (inlogin)
        {
             document.getElementById('ctl00_loginControl_LoginButton').click();
             event.cancelBubble = true;
             return;
        }
    }
}

function FocusIn()
{
    document.getElementById("aspnetForm").onkeypress = processKey;
    inlogin = true;
}

function attachEvent()
{
    var d = document.getElementById('ctl00_loginControl_Password');
    if (d) { d.onfocus = FocusIn; d.onblur = new Function("inlogin = false;"); }
}

/*************Admin***************/
function processClickAnouncements(ev, id)
{
    var result;

    if (ev.srcElement)
    {
        if (ev.srcElement.value == "Sterge") result = confirm("Esti sigur ca vrei sa stergi acest anunt?");
        else result = confirm("Esti sigur ca vrei sa recuperezi acest anunt?");
        if (result == true) __doPostBack('ctl00$hld$grdAnouncements','DeleteProperty$'+id)
        return result;
    }
    else
    {
        // ff
        if (ev.originalTarget.value == "Sterge") result = confirm("Esti sigur ca vrei sa stergi acest anunt?");
        else result = confirm("Esti sigur ca vrei sa recuperezi acest anunt?");
        if (result == true) __doPostBack('ctl00$hld$grdAnouncements','DeleteProperty$'+id)
        return result;
    }
}

function processClickAnouncements2(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi de tot acest anunt?");
    if (result == true) __doPostBack('ctl00$hld$grdAnouncements','DeleteProperty2$'+id)
    return result;
}

function processClickAnouncements3(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi de tot acest anunt?");
    if (result == true) __doPostBack('ctl00$hld$grdAnouncements','DeleteProperty2$'+id)
    return result;
}
function processClickAnouncementsWk(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi de tot acest anunt?");
    if (result == true) __doPostBack('ctl00$hld$grdOffers','Delete$'+id)
    return result;
}
function processClickUsers(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi acest user?");
    if (result == true) __doPostBack('ctl00$hld$grdUsers','DeleteProperty$'+id)
    return result;
}

function processClickResidentials(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi acest proiect?");
    if (result == true) __doPostBack('ctl00$hld$grdAnouncements','DeleteProject$'+id)
    return result;
}

function processClickUsersApprove(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa aprobi acest user?");
    if (result == true) __doPostBack('ctl00$hld$grdUsers','Activate$'+id)
    return result;
}

function processClickAccount2(ev, id)
{
    var result = confirm("Esti sigur ca vrei sa stergi de tot acest anunt?");
    if (result == true) __doPostBack('ctl00$hld$grdAnouncements','Sterge$'+id)
    return result;
}

function positionOffer()
{
    try
    {
        img = document.getElementById("ctl00_offerHolder");
        if (img)
        {
            img.style.position = "absolute";
            img.style.top = (document.body.clientHeight - 581)/2 + "px";
            img.style.left = (document.body.clientWidth - 671)/2 + "px";
            img.style.zIndex = 12222;
            
            drop = document.getElementById("ctl00_cities");
            drop.style.position = "absolute";
            drop.style.top = 70 + "px";
            drop.style.left = (671/2 - 190)+"px";
            
            bl = document.getElementById("ctl00_blockingDiv");
            s = getPageSize2();
            bl.style.width = s[0] + "px";
            bl.style.height = s[1] + "px";
            
            ar = document.getElementsByTagName('select');
            for (i=0; i<ar.length; i++)
            {
                if (ar[i].id != "ctl00_cities")
                {
                    if (ar[i].style.visibility == 'hidden')
                        ar[i].style.visibility = 'visible';
                    else ar[i].style.visibility = 'hidden';
                }
            }
        }
        else 
        {
            fr = document.getElementById("ctl00_hidFrame");
            fr.style.visibility = "hidden";
        }
    } catch(e) 
    {
    }

}

function getPageSize2() {	
	var xScroll, yScroll, windowWidth, windowHeight;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = this.document.scrollWidth;
		yScroll = (this.isFrame ? parent.innerHeight : self.innerHeight) + (this.isFrame ? parent.scrollMaxY : self.scrollMaxY);
	} else if (this.document.body.scrollHeight > this.document.body.offsetHeight){
		xScroll = this.document.body.scrollWidth;
		yScroll = this.document.body.scrollHeight;
	} else {
		xScroll = this.document.getElementsByTagName("html").item(0).offsetWidth;
		yScroll = this.document.getElementsByTagName("html").item(0).offsetHeight;
		xScroll = (xScroll < this.document.body.offsetWidth) ? this.document.body.offsetWidth : xScroll;
		yScroll = (yScroll < this.document.body.offsetHeight) ? this.document.body.offsetHeight : yScroll;
	}
	if (self.innerHeight) {
		windowWidth = (this.isFrame) ? parent.innerWidth : self.innerWidth;
		windowHeight = (this.isFrame) ? parent.innerHeight : self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = this.document.documentElement.clientWidth;
		windowHeight = this.document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = this.document.getElementsByTagName("html").item(0).clientWidth;
		windowHeight = this.document.getElementsByTagName("html").item(0).clientHeight;
		windowWidth = (windowWidth == 0) ? this.document.body.clientWidth : windowWidth;
		windowHeight = (windowHeight == 0) ? this.document.body.clientHeight : windowHeight;
	}
	var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
	var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
	return new Array(pageWidth, pageHeight, windowWidth, windowHeight);
};

function clickOffer(evt)
{
    try
    {
        if (evt.srcElement) ref = evt.srcElement;
        else ref = evt.target;
        if (ref)
        {
            if (ref.id != "ctl00_cities")
            {
                if (document.getElementById("ctl00_cities").value == "0") alert("Selectati va rugam un oras");
                else
                {
                    if (document.getElementById('ctl00_offerHolder'))
                    {
                        document.getElementById('ctl00_offerHolder').style.visibility='hidden';
                        document.getElementById('ctl00_blockingDiv').style.visibility='hidden';
                    }
                }
            }
        }
    } catch (e) {}
}

function download(id) { window.open("../download.aspx?id="+id, "_blank", "height=100,width=100"); }

function citiesSelectAll()
{
    var chk = document.getElementsByTagName("input");
    for (i=0; i<chk.length; i++)
    {
        if (chk[i].type == "checkbox")
            chk[i].checked = true;    
    }
}

function citiesDeselectAll()
{
    var chk = document.getElementsByTagName("input");
    for (i=0; i<chk.length; i++)
    {
        if (chk[i].type == "checkbox")
            chk[i].checked = false;
    }
}

function enforceFloors(evt)
{
    var fireOnThis = document.getElementById('ctl00_hld_building_ddlFloor');
    
    if(fireOnThis.fireEvent)
    {
        fireOnThis.fireEvent('onchange');
    }
    //On Gecko based browsers
    if(document.createEvent)
    {
        var evt = document.createEvent('HTMLEvents');
        if(evt.initEvent)
        {
            evt.initEvent('change', true, true);
        }
        if(fireOnThis.dispatchEvent)
        {
            fireOnThis.dispatchEvent(evt);
        } 
    }
}

function isMaxLength(txtBox) 
{
    if(txtBox) 
    {
        return ( txtBox.value.length < 500 );
    }
}

function CheckActive(obj)
{
    res = true;
    if (!document.getElementById("ctl00_hld_chkActive").checked)
       res = confirm("Anuntul nu este setat ca fiind activ. Ca urmare el nu va aparea in lista de proiecte.Vreti sa continuati?");
    return res;
}