function comEdit()
{
	var str;
	str = document.form1.com_ppt.value;
	if(str == ""){
	alert ("Please select the property you wish to edit from the drop down list.");
	document.form1.com_ppt.focus();
	return true;
	}

	document.form1.action = "edit/com01.html";
	document.form1.submit();
	return true;
}

function resEdit()
{
	var str;
	str = document.form1.res_ppt.value;
	if(str == ""){
	alert ("Please select the property you wish to edit from the drop down list.");
	document.form1.res_ppt.focus();
	return true;
	}
	
	document.form1.action = "edit/res01.html";
	document.form1.submit();
	return true;
}
function contEdit()
{
	var str;
	str = document.form1.add_ppt.value;
	if(str == ""){
	alert ("Please Select..");
	document.form1.add_ppt.focus();
	return true;
	}
	
	document.form1.action = "edit/add02.php";
	document.form1.submit();
	return true;
}
function billEdit()
{
	document.form1.action = "edit/billing.html";
	document.form1.submit();
	return true;
}

function res_view()
{
	if(document.form1.saved_res.selectedIndex < 1)
	{
		alert("Please select a listing.");
		return;
	}
	//window.open("../../search/res03.html?resid="+document.form1.saved_res.options[document.form1.saved_res.selectedIndex].value,"mywin",'top=0,left=0,toolbar=0 status=0,resizable=0,Width=' + screen.width + ',height=' + screen.height + ',scrollbars=yes');
	window.open("../../search/residential01.html?resid="+document.form1.saved_res.options[document.form1.saved_res.selectedIndex].value,"mywin",'top=0,left=0,toolbar=0 status=0,resizable=0,Width=' + screen.width + ',height=' + screen.height + ',scrollbars=yes');
}

function com_view()
{
	if(document.form1.saved_com.selectedIndex < 1)
	{
		alert("Please select a listing.");
		return;
	}
	//window.open("../../search/com03.html?comid="+document.form1.saved_com.options[document.form1.saved_com.selectedIndex].value,"mywin",'top=0,left=0,toolbar=0 status=0,resizable=0,Width=' + screen.width + ',height=' + screen.height + ',scrollbars=yes');	
	window.open("../../search/business01.html?comid="+document.form1.saved_com.options[document.form1.saved_com.selectedIndex].value,"mywin",'top=0,left=0,toolbar=0 status=0,resizable=0,Width=' + screen.width + ',height=' + screen.height + ',scrollbars=yes');	
}

function res_remove()
{
	if(document.form1.saved_res.selectedIndex < 1)
	{
		alert("Please select a listing.");
		return;
	}
	
	check = confirm("Are you sure?");
	if(check != true)
		return;
	location.href = "saved-listings/res-del.php?resid="+document.form1.saved_res.options[document.form1.saved_res.selectedIndex].value;
}

function com_remove()
{
	if(document.form1.saved_com.selectedIndex < 1)
	{
		alert("Please select a listing.");
		return;
	}
	
	check = confirm("Are you sure?");
	if(check != true)
		return;
	location.href = "saved-listings/com-del.php?comid="+document.form1.saved_com.options[document.form1.saved_com.selectedIndex].value;
}

function comRemove()
{
	var str;
	str = document.form1.com_ppt.value;
	if(str == ""){
	alert ("Please select the property you wish to remove from the drop down list.");
	document.form1.com_ppt.focus();
	return true;
	}
	
	window.open('/a-popup/delete-popup-com.html?del_propid='+str,'mywin','top='+((screen.height - 140) / 2)+',left='+((screen.width - 420) / 2)+'+,toolbar=0 status=0,resizable=0,Width=420,height=220');
	return false;
}

function  resRemove()
{
	var str;
	str = document.form1.res_ppt.value;
	if(str == ""){
	alert ("Please select the property you wish to remove from the drop down list.");
	document.form1.res_ppt.focus();
	return true;
	}
	
	window.open('/a-popup/delete-popup-res.html?del_propid='+str,'mywin','top='+((screen.height - 140) / 2)+',left='+((screen.width - 420) / 2)+'+,toolbar=0 status=0,resizable=0,Width=420,height=220');
	return false;
}

/*function comRemove()
{
	var str;
	str = document.form1.com_ppt.value;
	if(str == ""){
	alert ("Please Select..");
	document.form1.com_ppt.focus();
	return true;
	}
	
	check = confirm("Are you sure?");
	if(check != true)
		return true;
	
	document.form1.action = "delete/com.php";
	document.form1.submit();
	return true;
}*/

/*function resRemove()
{
	var str;
	str = document.form1.res_ppt.value;
	if(str == ""){
	alert ("Please Select..");
	document.form1.res_ppt.focus();
	return true;
	}
	
	
	check = confirm("Are you sure?");
	if(check != true)
		return true;	
	
	document.form1.action = "delete/res.php";
	document.form1.submit();
	return true;
}*/

function uplload_img()
{
	window.open("image-upload/add-image.php","mywin","width=402 height=138");
}


function resAddNew()
{
	var str;
	str = document.form1.res_ppt.value;
	if(str == ""){
	alert ("Please Select..");
	document.form1.res_ppt.focus();
	return true;
	}
	
	document.form1.action = "add/res01.html";
	document.form1.submit();
	return true;
}

function sqls_run()
{
	if(document.form1.sqlid.value == ""){
		alert ("Please Select..");
		document.form1.sqlid.focus();
		return;
	}
	
	document.form1.action = "saved-queries/sqls_run.php";
	document.form1.submit();
}

function sqls_remove()
{
	if(document.form1.sqlid.value == ""){
		alert ("Please Select..");
		document.form1.sqlid.focus();
		return;
	}
	
	
	check = confirm("Are you sure?");
	if(check != true)
		return;
		
	document.form1.action = "saved-queries/sqls_remove.php";
	document.form1.submit();
}

function sqls_update()
{
	if(document.form1.sqlid.value == ""){
		alert ("Please Select..");
		document.form1.sqlid.focus();
		return;
	}
	
	document.form1.action = "saved-queries/sqls_update.php";
	window.open('saved-queries/edit.html?sqlid=' + document.form1.sqlid.options[document.form1.sqlid.selectedIndex].value,'mywin','top='+((screen.height - 124) / 2)+',left='+((screen.width - 380) / 2)+'+,toolbar=0 status=0,resizable=0,Width=380,height=124');
	return;
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function utf8_decode ( str_data ) {
    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    str_data += '';
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return tmp_arr.join('');
}


function base64_decode( data ) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
    if (!data) {
        return data;
    }
    data += '';
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);
    dec = tmp_arr.join('');
    dec = this.utf8_decode(dec);
    return dec;
}


function file_exists (url) {
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {throw new Error('XMLHttpRequest not supported');}
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200){
        return true;
    }
    return false;
}

