function a(value){
	alert(value);
}

function ButtonsAddRemove(obj, state){
	var buttAdd = document.getElementById("Add");
	var buttRem = document.getElementById("Remove");
	buttAdd.disabled = state || (obj.options.length == 0);
	buttRem.disabled = !state || (obj.options.length == 0);
}


function CenterWindow(){
	if (document.layers) {
		theleft = (screen.availWidth - window.outerWidth) / 2;
		thetop = (screen.availHeight - window.outerHeight) / 2;
	}
	else {
		theleft = (screen.availWidth - document.body.clientWidth) / 2;
		thetop = (screen.availHeight - document.body.clientHeight) / 2;
	}
	window.moveTo(theleft,thetop);
}


function ResizeWindow(width, height){
	//window.moveTo(0,0);
	thewidth = (screen.availWidth > width ? width:screen.availWidth)    
	theheight = (screen.availHeight > height ? height:screen.availHeight)    
	window.resizeTo(thewidth,theheight);
}


function MaximizeBrowser()  {
	self.moveTo(0,0)
	self.resizeTo(screen.width,screen.height)

	//window.innerWidth = screen.width;
	//window.innerHeight = screen.height;
	//window.screenX = 0;
	//window.screenY = 0;
	//alwaysLowered = false;
}

function Popup(url, w, h) {
    l = (screen.width) ?( screen.width-w) / 2:100;
	t =( screen.height) ? (screen.height-h) / 2:100;
	
    handle = window.open (url, "rhoapopup","location=0,status=1,resizable=0,toolbar=0,menubar=0,scrollbars=1,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l); 
}

function popup(url,name,windowWidth,windowHeight){
    myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=yes, top="+mytop+",left="+myleft;
    window.open(url,name,properties)
}

function ResizeIframes(frame){
	eval("window.parent.document.getElementById('"+frame+"').style.height=document.getElementById('Contract').clientHeight");
}



function GotoPage(oGoto) {
    if (oGoto == null) {
        oGoto = document.getElementById("Goto");
    }
    
	var id = oGoto.value;
	id = parseInt(id);
	if (id.toString() == "NaN" || id == 0) {
		document.getElementById("Goto").value = "";
		return false;
	} else {
	    
        var objL = document.getElementById("ctl00_ContentEmployeesMaster_frmLandlords_GotoUrl");
        var objC = document.getElementById("ctl00_ContentEmployeesMaster_frmClients_GotoUrl");
        var objP = document.getElementById("ctl00_ContentEmployeesMaster_frmProperties_GotoUrl");
    	
        if (objL == null && objC == null && objP == null) {
	        return false;
        }
    	
        if (objL != null) {
	        var link = objL.value;
        }
    	
        if (objC != null) {
	        var link = objC.value;
        }
    	
        if (objP != null) {
	        var link = objP.value;
        }
		window.location.href = link + id;
	}
		
	return true;
}

function CaptureEnterKey(event) {
    var oEvent;
    if (window.event) {
        oEvent = window.event;
    } else if (event) {
        oEvent = event;
    } else {
        return true;
    }
	if (oEvent.keyCode == "13"){
	    if (oEvent.srcElement) {
	        if (oEvent.srcElement.id == "Goto") {
	            GotoPage(oEvent.srcElement);
	        } 
	    } else if (oEvent.target) {
	        if (oEvent.target.id == "Goto") {
	            GotoPage(oEvent.target);
	        } 
	    } 
		return false;
	}
	return true;
}

function CreateMatchesRedirect(link, type, id, url) {

	var rent = "&rent=" + document.getElementById("ctl00_ContentEmployeesMaster_frmClients_RentRange").options[document.getElementById("ctl00_ContentEmployeesMaster_frmClients_RentRange").selectedIndex].text;
	var bed = "&bed=" + document.getElementById("ctl00_ContentEmployeesMaster_frmClients_Bed").options[document.getElementById("ctl00_ContentEmployeesMaster_frmClients_Bed").selectedIndex].text;
	var rental = "&rental=" + BuildSelectedCheckBoxList(document.getElementById("ctl00_ContentEmployeesMaster_frmClients_LblRentalTypes"), "LblRentalTypes");
	var areas = "&areas=" + BuildSelectedCheckBoxList(document.getElementById("ctl00_ContentEmployeesMaster_frmClients_LblAreas"), "LblAreas");
	
	var redirect = url + type + id + rent + bed + rental + areas
	//alert(redirect);
	link.href = redirect;
}

function BuildSelectedCheckBoxList(obj, typeControl) {
	var tbl = obj.getElementsByTagName("INPUT");
	var results = ""; //ctl00_RentalTypes_12  frmClients_RentalTypes_0
	for(i = 0; i < tbl.length; i++) {
		if(tbl[i].tagName == "INPUT" && tbl[i].type == "checkbox") {
			var array = tbl[i].id.split("_");
			if (typeControl == array[1]) {
				if (tbl[i].checked) {
					results += array[2] + ",";
				}
			}
		}
	}
	if (results.length > 1) {
		results = results.substr(0, results.length-1);
	}
	return results;
}

function Hide(obj, sign) {
	if (sign.childNodes[0].nodeValue == "[-]") {
		obj.style.display = "none";
		sign.childNodes[0].nodeValue = "[+]";
	} else {
	    if (document.all) {
	        obj.style.display = "block";
		    sign.childNodes[0].nodeValue = "[-]";
	    } else {
		    obj.style.display = "table-row";
		    sign.childNodes[0].nodeValue = "[-]";
		}
	}
}

function CheckAll(tbl, obj) {
	var childs = tbl.getElementsByTagName("*");
	for(i = 0; i < childs.length; i++) {
		if(childs[i].tagName == "INPUT" && childs[i].type == "checkbox") {
			childs[i].checked = obj.checked;
		}
	}
}



function SetDate(obj, chk) {
	if (chk.checked) {
		var date = new Date();
		obj.value = (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear();
	} else {
		obj.value = "";
	}
}


var arraySources = new Array();


function IsRented(obj, aDate, eDate, rDate, aRow, eRow, rRow, now, noteYes, noteNo) {
    //alert(rented.id);
    if (obj === null) {
        return false;
    }

    var aObjDate = document.getElementById(aDate);
    var eObjDate = document.getElementById(eDate);
    var rObjDate = document.getElementById(rDate);
    var objNoteYes = document.getElementById(noteYes);
    var objNoteNo = document.getElementById(noteNo);
    var aObjRow = document.getElementById(aRow);
    var eObjRow = document.getElementById(eRow);
    var rObjRow = document.getElementById(rRow);

    if (obj.id.indexOf("propavaNo") > 1) {
        aObjDate.value = "1/1/1900";
        aObjRow.style.display = "none";
        
        rObjDate.value = now;
        rObjRow.style.display = "inline";
        
        var objDate = new Date(now)
        eObjDate.value = (objDate.getMonth()+1) + "/" + objDate.getDate() + "/" + (objDate.getYear() + 1);
        eObjRow.style.display = "inline";
        
        objNoteYes.style.display = "none";
        objNoteNo.style.display = "block";
    } else {
        aObjDate.value = now;
        aObjRow.style.display = "inline";
        
        eObjDate.value = "1/1/1900";
        eObjRow.style.display = "none";
        
        rObjDate.value = "1/1/1900";
        rObjRow.style.display = "none";
        
        objNoteYes.style.display = "block";
        objNoteNo.style.display = "none";
    }
}


function Source() {
    //alert(1)
	var obj;
	var objC = document.getElementById("ctl00_ContentEmployeesMaster_frmClients_SourceTypeID");
	var objR = document.getElementById("ctl00_ContentRentersMaster_frmRenters_SourceTypeID");
	var objH = document.getElementById("ctl00_ContentHomeMaster_frmRenters_SourceTypeID");
	//alert(2)
	if (objC == null && objR == null && objH == null) {
		return;
	}
	
	if (objC != null) {
		var id = document.getElementById("ctl00_ContentEmployeesMaster_frmClients_Metro").value;
		obj = objC;
	}
	
	if (objR != null) {
		var id = document.getElementById("ctl00_ContentRentersMaster_frmRenters_Metro").value;
		obj = objR;
	}
	
	if (objH != null) {
		var id = document.getElementById("ctl00_ContentHomeMaster_frmRenters_Metro").value;
		obj = objH;
	}
	
	
	if (arraySources.length == 0) {
		for (var i=0; i < obj.options.length; i++) {
			if (obj.options[i].selected) {
				arraySources[i] = obj.options[i].value +";"+ obj.options[i].text +";1";
			} else {
				arraySources[i] = obj.options[i].value +";"+ obj.options[i].text +";0";
			}
		}
	}
	
	for (var i = obj.options.length-1; i >= 0; i--) {
		obj.options[i] = null;
		//obj.options.remove(i);
	}

	// load
	for (var i=0; i < arraySources.length; i++) {
		var oOption = document.createElement("OPTION");
		var parts = arraySources[i].toString().split(";");
		if (parts[2] == 1) {
			oOption.selected = true;
		}
		oOption.text = parts[1];
		oOption.value = parts[0];
		obj.options.add(oOption);
	}

	
	for (var i = obj.options.length-1; i >= 0; i--) {
		var split = obj.options[i].value.toString().split("_");
		if (split[0] != id && split[0] != 0) {
			obj.options[i] = null;
			//obj.options.remove(i);
		} 
	}
}

function Close() {

	window.opener.location.reload();
	window.close();
}



function CloseWindow() {
    window.open('', '_self', '');
    window.close();
    return false;
}

function CloseRefreshWindow() {
    var url = window.opener.location.href;
    window.opener.location.href = url + "&x=0";
    window.open('', '_self', '');
    window.close();
    return false;
}


function WeeklyMessage(cmbo) {
    if (cmbo.options[cmbo.selectedIndex].value == "0") {
        document.getElementById("WeeklyLeaseNote").style.display = "block";
    } else {
        document.getElementById("WeeklyLeaseNote").style.display = "none";
    }
}


