
function openPhoto(photourl) {
	window_width = 600;
	window_height = 400;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=no,location=no,resizable=yes,status=no';
//	window.open(photourl, "_blank", windowFeatures);
	W=window.open('', "_blank", windowFeatures);
	W.document.write("<html><head><title>Photo Preview</title></head><body><table border='0' cellspacing='0' cellpadding='0' style='width:100%; height:100%'><tr><td style='text-align:center; vertical-align:middle;'><img src='" + photourl + "'></td></tr></table></body></html>");
}

function openPhotos(photo1,photo2,photo3,photo4,photo5) {
	window_width = 600;
	window_height = 400;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=no,location=no,resizable=yes,status=no';
	doccontents = "<html><head><title>View Map</title></head><body><table border='0' cellspacing='5' cellpadding='0' style='width:100%; height:100%'>"
	if(photo1 && photo2) {
		doccontents += "<tr><td style='text-align:center; vertical-align:middle;'><img src='" + photo1 + "'></td><td style='text-align:center; vertical-align:middle;'><img src='" + photo2 + "'></td></tr>";
		if(photo3 && photo4) {
			doccontents += "<tr><td style='text-align:center; vertical-align:middle;'><img src='" + photo3 + "'></td><td style='text-align:center; vertical-align:middle;'><img src='" + photo4 + "'></td></tr>";
			if(photo5) doccontents += "<tr><td style='text-align:center; vertical-align:middle;' colspan='2'><img src='" + photo5 + "'></td></tr>";
		} else if(photo3) doccontents += "<tr><td style='text-align:center; vertical-align:middle;' colspan='2'><img src='" + photo3 + "'></td></tr>";
	} else if(photo1) doccontents += "<tr><td style='text-align:center; vertical-align:middle;' colspan='2'><img src='" + photo1 + "'></td></tr>";
	doccontents += "</table></body></html>";
	W=window.open('', "_blank", windowFeatures);
	W.document.write(doccontents);
}

function openFile(fileurl) {
	window_width = 600;
	window_height = 400;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=no,location=no,resizable=yes,status=no';
//	window.open(photourl, "_blank", windowFeatures);
	window.open(fileurl, "_blank", windowFeatures);
}

function sendEnquiry(property_id) {
	window_width = 600;
	window_height = 530;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("enquiry.php?prop_id="+property_id, "_blank", windowFeatures);
}

function sendBooking(package_id,package_type,package_name) {
	window_width = 600;
	window_height = 530;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("booking.php?package_id="+package_id+"&package_type="+package_type+"&package_name="+package_name, "_blank", windowFeatures);
}

function countOccurance(str, charecter)
{
        var j;
        var count;
        for(j = -1, count = 0; -1 != (j = str.indexOf(charecter, j + 1)); count++);
        return count;
}
function checkAllowedChars(strToCheck, allowedChars)
{
        var acLen        = allowedChars.length;
        var stcLen        = strToCheck.length;
        strToCheck        = strToCheck.toLowerCase();
        var i;
        var j;
        var rightCount = 0;
        for(i = 0; i < acLen; i++)
        {
                switch(allowedChars.charAt(i))
                {
                case 'A':
                        for(j = 0; j< stcLen; j++)
                        {
                                rightCount += strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z';
                        }
                        break;
                case 'N':
                        for(j = 0; j< stcLen; j++)
                        {
                                rightCount += strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9';
                        }
                        break;
                default:
                        for(j = -1; -1 != (j = strToCheck.indexOf(allowedChars.charAt(i), j + 1)); rightCount++);
                        break;
                }
        }
        if(rightCount == stcLen)
        {
                return true;
        }
        return false;
}
function checkEmail(email, mandatory)
{
        if((mandatory && !(email.length))
         || (email.length && !(checkAllowedChars(email, 'AN@-_.<>')
                && countOccurance(email, '@') == 1
                && email.indexOf('@') != 0
                && email.lastIndexOf('@') != (email.length - 1)
                && countOccurance(email, '<') <= 1
                && countOccurance(email, '>') <= 1
                && ((email.lastIndexOf('>') == (email.length - 1) && email.indexOf('<') != -1)
                        || (email.indexOf('>') == -1 && email.indexOf('<') == -1))
                && countOccurance(email, '.') >= 1
                && email.indexOf('..') == -1
                && email.indexOf('.') != 0
                && email.lastIndexOf('.') != (email.length - 1))))
        {
                return false;
        }

        afterAt = email.substring(email.indexOf('@') + 1);
        if(!(afterAt.indexOf('.') != 0 && afterAt.lastIndexOf('.') != (afterAt.length - 1)))
                return false;

        beforeAt = email.substring(0, email.indexOf('@'));
        if(!(beforeAt.indexOf('_') != 0
         && beforeAt.indexOf('-') != 0
         && beforeAt.indexOf('.') != 0
         && beforeAt.lastIndexOf('.') != (beforeAt.length - 1)))
        {
                return false;
        }
        return true;
}

/*
function get_suboptions(obj,sub_obj,optionarray,defaultstr){
	var sel_text = obj.options[obj.selectedIndex].text;
	while (sub_obj.options.length) sub_obj.options[0] = null;
	if(!defaultstr) defaultstr="Select";
	sub_obj.options[0]=new Option(defaultstr,"",true,true);
	if (optionarray[sel_text]) {
		for(j=0;j<optionarray[sel_text].length;j++){
			if(optionarray[sel_text][j]!=""){
				var sub_val = optionarray[sel_text][j]=="Doesn't matter"?"":optionarray[sel_text][j];
				sub_obj.options[j+1]=new Option(optionarray[sel_text][j],optionarray[sel_text][j],true,false);
			}
		}
	}
	return true;
}

function get_suboptions2(obj,sub_obj,optionarray,defaultstr){
	var sel_text = obj.value;
	while (sub_obj.options.length) sub_obj.options[0] = null;
	if(!defaultstr) defaultstr="Select";
	sub_obj.options[0]=new Option(defaultstr,"",true,true);
	for(j=0;j<optionarray[sel_text].length;j++){
		if(optionarray[sel_text][j]!=""){
			var sub_val = optionarray[sel_text][j]=="Doesn't matter"?"":optionarray[sel_text][j];
			sub_obj.options[j+1]=new Option(optionarray[sel_text][j],optionarray[sel_text][j],true,false);
		}
	}
	return true;
}
*/
function get_subs(obj,sub_obj,optionarray,extra_obj,defaultstr){
	var sel_text = obj.options[obj.selectedIndex].text;
	while (sub_obj.options.length) sub_obj.options[0] = null;
	if(!defaultstr) defaultstr="Select";
	sub_obj.options[0]=new Option(defaultstr,"",true,true);
	if (extra_obj) {
		var extraarg = extra_obj.options[extra_obj.selectedIndex].text;
		if (optionarray[extraarg+"-"+sel_text]) {
			for(j=0;j<optionarray[extraarg+"-"+sel_text].length;j++){
				if(optionarray[extraarg+"-"+sel_text][j]!=""){
					var sub_val = optionarray[extraarg+"-"+sel_text][j]=="Doesn't matter"?"":optionarray[extraarg+"-"+sel_text][j];
					sub_obj.options[j+1]=new Option(optionarray[extraarg+"-"+sel_text][j],optionarray[extraarg+"-"+sel_text][j],true,false);
				}
			}
		}
	} else {
		if (optionarray[sel_text]) {
			for(j=0;j<optionarray[sel_text].length;j++){
				if(optionarray[sel_text][j]!=""){
					var sub_val = optionarray[sel_text][j]=="Doesn't matter"?"":optionarray[sel_text][j];
					sub_obj.options[j+1]=new Option(optionarray[sel_text][j],optionarray[sel_text][j],true,false);
				}
			}
		}
	}
	return true;
}

function taLimit() {
	var taObj=event.srcElement;
	if (taObj.maxLength*1>0 && taObj.value.length==taObj.maxLength*1) {
		alert("You can enter only "+taObj.maxLength+" characters");
		return false;
	}
}

function taCount(counterobj) { 
	var taObj=event.srcElement;
	if (taObj.maxLength*1>0 && taObj.value.length>taObj.maxLength*1) {
		taObj.value=taObj.value.substring(0,taObj.maxLength*1);
		counterobj.value=taObj.value.length;
		alert("You can enter only "+taObj.maxLength+" characters");
	} else counterobj.value=taObj.value.length;
}



function addoption(objtext,objlist,listarray,objbutton) {
	objlist.options[objlist.length] = new Option(objtext.value,objtext.value,true,true);
	objtext.value = "";
	objtext.focus();
}

function removeoption(objlist,objtext,objbutton,objbutton2) {
	if (objlist.selectedIndex>=0) {
		objtext.value = objlist.options[objlist.selectedIndex].text;
		objlist.options[objlist.selectedIndex] = null;
	} else {
		alert ("Select an item from the list.");
	}
	if (objbutton) activatebutton(objlist,objbutton);
	if (objbutton2) activatebutton(objlist,objbutton2);
}


function activatebutton(objlist,objbutton) {
	if (objlist.selectedIndex>=0) {
		objbutton.disabled = false;
	} else {
		objbutton.disabled = true;
	}
}




function openAddDevProSubWindow(argumentname, argumentlist) {
	window_width = 700;
	window_height = 500;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("addremdevprosub.php?" + argumentname + argumentlist.options[argumentlist.selectedIndex].text, "_blank", windowFeatures);
}

function openAddCityWindow(argumentname, argumentlist) {
	window_width = 450;
	window_height = 300;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("addremcity.php?" + argumentname + argumentlist.options[argumentlist.selectedIndex].text, "_blank", windowFeatures);
}



function bakuplst(objlist,objarray) {
	var i;
	if (objlist.length>0) objarray.value = objlist.options[0].text.replace(",","");
	for(i=1;i<objlist.length;i++) {
		objarray.value += "," + objlist.options[i].text.replace(",","");
	}
}

function viewProperty(id) {
	window_width = 1000;
	window_height = 850;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("viewproperty.php?prop_id=" + id, "_blank", windowFeatures);
}

function viewPropertyAdmin(id) {
	window_width = 650;
	window_height = 300;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("admin/viewproperty.php?prop_id=" + id, "_blank", windowFeatures);
}

function viewPackage(type,id) {
	window_width = 450;
	window_height = 250;
	window_top = (screen.availHeight-window_height)/2;
	window_left = (screen.availWidth-window_width)/2;
	windowFeatures = "width=" + window_width + ",height=" + window_height + ",top=" + window_top + ",left=" + window_left;
	windowFeatures += ',scrollbars=yes,menubar=no,toolbar=no,statusbar=yes,location=no,resizable=yes,status=yes';
	window.open("viewpackage.php?package_id=" + id + "&package_type=" + type, "_blank", windowFeatures);
}
function gogallery(project) {
	var compurl = "thegallery.php?project="+project; 
	window.open(compurl,"","width=750, height=600, left=20, top=20, status=no, toolbar=no,menubar=no,location=no,scrollbars=no");
}
function gopartners(project) {
	var compurl = "partner.php?project="+project; 
	window.open(compurl,"","width=680, height=600, left=20, top=20, status=no, toolbar=no,menubar=no,location=no,scrollbars=yes");
}


