var hostName = 'http://www.hothomespot.com';

function onLoadAdminCommonFunction() {
	//highlightFormElements();
	highlightsRowsInit();
	MM_preloadImages('../admin_images/topbgyellow.jpg', 
					'../admin_images/topbggreen.jpg', 
					'../admin_images/topbg.jpg', 
					'../admin_images/bg_top_line.jpg', 
					'../admin_images/icon_inactive.gif', 
					'../admin_images/icon_active.gif', 
					'../admin_images/icon_edit.gif', 
					'../admin_images/icon_add.gif', 
					'../admin_images/icon_delete.gif', 
					'../admin_images/delete_image.png', 
					'../admin_images/icon_open.gif', 
					'../admin_images/icon_password.gif', 
					'../admin_images/loader.gif', 
					'../admin_images/icon_error.gif', 
					'../admin_images/icon_changeaccess.gif', 
					'../admin_images/icon_lock.gif', 
					'../admin_images/icon_unlock.gif');
		}

function popupWindowAdmin(path, where, hite, wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2-10;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=1,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(path, i, 'scrollbars=1,toolabars=0,resizable=1,status=0,menubar=0,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}

function popupWindowAdminPrint(path, where, hite, wide){
	if (window.event){ 
		window.event.returnValue = false;   
	}
	var width;
	var height;
	var imgWidth;
	var imgHeight;
	
	if (screen.width<wide){
		width=screen.width-20;
		imgWidth=width-10;
		var windowX = (screen.width-width)/2;
	}
	else{
		var windowX = (screen.width-wide)/2-10;
		width=wide;
	}

	if (screen.height<hite){
		height=screen.height-70;
		imgHeight=height-20;
		var windowY = (screen.height-height)/2-30;
	}
	else{
		var windowY = (screen.height-hite)/2-10;
		height=hite;
	}

	var rand_no = Math.random();
	var i = Math.round(100*Math.random());
	if(screen.height<hite || screen.width<wide){
		var props=window.open(path, i, 'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	else{
		var props=window.open(path, i, 'scrollbars=1,toolabars=1,resizable=1,status=0,menubar=1,directories=0,location=0,height='+(hite+30)+', width='+(wide+30));
	}
	props.moveTo(windowX,windowY);
}

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1){
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1){
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}



/*******************************************************
Highlights table rows
*******************************************************/

var marked_row = new Array;

function highlightsRowsInit() {
	// for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'odd_tr' != rows[i].className.substr(0,6) && 'even_tr' != rows[i].className.substr(0,7) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' mouseHover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' mouseHover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' selected_bg';
            } else {
                this.className = this.className.replace(' selected_bg', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}


function markAllSelectedRows(container_id) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' selected_bg';
                    marked_row[unique_id] = true;
                }
            }
        }
    }
    return true;
}


function unMarkSelectedRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' selected_bg', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
}



/*******************************************************
Highlights input boxes
*******************************************************/

function highlightFormElements() {
    // add input box highlighting
    addFocusHandlers(document.getElementsByTagName("input"));
    addFocusHandlers(document.getElementsByTagName("textarea"));
}

function addFocusHandlers(elements) {
    for (i=0; i < elements.length; i++) {
        if (elements[i].type != "button" && elements[i].type != "submit" &&
            elements[i].type != "reset" && elements[i].type != "checkbox" && elements[i].type != "radio") {
            if (!elements[i].getAttribute('readonly') && !elements[i].getAttribute('disabled')) {
                /*elements[i].onfocus=function() {this.style.backgroundColor='#ffd'; this.select()};
                elements[i].onmouseover=function() {this.style.backgroundColor='#ffd'};
                elements[i].onblur=function() {this.style.backgroundColor='';}
                elements[i].onmouseout=function() {this.style.backgroundColor='';}*/
				
				elements[i].onmouseover=function() {this.style.backgroundColor=''; this.className = 'look_selected';};
                elements[i].onmouseout=function() {this.style.backgroundColor=''; this.className = 'look';}
				elements[i].onfocus=function() {this.style.backgroundColor=''; this.className = 'look_selected'; this.select()};
				elements[i].onblur=function() {this.style.backgroundColor=''; this.className = 'look';}
				elements[i].onkeypress=function() {this.style.backgroundColor=''; this.className = 'look_selected';}
				elements[i].onkeyup=function() {this.style.backgroundColor=''; this.className = 'look_selected';}
            }
        }
    }
}


/*******************************************************
Preloader
*******************************************************/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function roll_over(imgname,imgsrc) {
	document[imgname].src=imgsrc;
}

/*******************************************************
AJAX handler
*******************************************************/


if(window.ActiveXObject) {
	try {
		var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
} else {
	var oHTTP = new XMLHttpRequest();
}

function menuHide(){
	callNewPage(hostName+'/admin/admin_hide_menu.php?mode=chk&uri=');
}

function callNewPage(page) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			
			if (getValue=="none") {
				document.getElementById('menuPortion').style.display = "none";
				document.getElementById('menuDisp').src = "../admin_images/slide_right.jpg";
			}
			else{
				document.getElementById('menuPortion').style.display = "";
				document.getElementById('menuDisp').src = "../admin_images/slide_left.jpg";
			}
		}
	}
	oHTTP.send(null);
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function roll_over(imgname,imgsrc) {
	document[imgname].src=imgsrc;
}


function colorPicker(){
	var obj = document.forms['configManager'];
	if(obj.elements['adminbgColor']) attachColorPicker(obj.elements['adminbgColor']);
	if(obj.elements['borderColor']) attachColorPicker(obj.elements['borderColor']);
	if(obj.elements['adminTopbgColor']) attachColorPicker(obj.elements['adminTopbgColor']);
	if(obj.elements['adminBottombgColor']) attachColorPicker(obj.elements['adminBottombgColor']);
	if(obj.elements['leftTopbgColor']) attachColorPicker(obj.elements['leftTopbgColor']);
	if(obj.elements['leftbgColor']) attachColorPicker(obj.elements['leftbgColor']);
	if(obj.elements['menuColor']) attachColorPicker(obj.elements['menuColor']);
	if(obj.elements['menuHoverColor']) attachColorPicker(obj.elements['menuHoverColor']);
	if(obj.elements['menuTextColor']) attachColorPicker(obj.elements['menuTextColor']);
	if(obj.elements['menuHoverTextColor']) attachColorPicker(obj.elements['menuHoverTextColor']);
	if(obj.elements['adminRowColor']) attachColorPicker(obj.elements['adminRowColor']);
	if(obj.elements['adminRowHoverColor']) attachColorPicker(obj.elements['adminRowHoverColor']);
	if(obj.elements['adminRowSelectColor']) attachColorPicker(obj.elements['adminRowSelectColor']);
	if(obj.elements['adminRowEvenColor']) attachColorPicker(obj.elements['adminRowEvenColor']);
	if(obj.elements['adminRowOddColor']) attachColorPicker(obj.elements['adminRowOddColor']);
}






function deleteConfirmRecord(path, toDelete){
	if(confirm('Are you sure to delete this '+toDelete+'?')){
		location.href=''+path+'';
	}
	else{
		return false;	
	}
}




function CreatePageValidation() {
	if(document.forms['createPage'].elements['page_name'].value=="") {
		alert ("Please enter file name.");
		document.forms['createPage'].elements['page_name'].focus();
		return false;
	}
	var page_name = document.forms['createPage'].elements['page_name'].value;
	var space = page_name.indexOf(" ", 0);
	var num = page_name.indexOf(".",0);
	var ch = page_name.charAt(num+1);
	var ext = page_name.indexOf(".php", 0);
	if(space>=0) {
		alert ("White space is not allowed...");
		document.forms['createPage'].elements['page_name'].select();
		return false;
	}
	if(num<0 && ext<=0) {
		alert ("File name must be with extension .php ");
		document.forms['createPage'].elements['page_name'].select();
		return false;
	}
	if(ch ==" " || ch == "." || ch =="" || num==0) {
		alert ("File name is not proper...");
		document.forms['createPage'].elements['page_name'].select();
		return false;
	}
}



function changeStatus_M(tableName, idField, changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
			changeStatusResponse_M(hostName+'/admin/admin_change_status.php?tableName='+tableName+'&idField='+idField+'&mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion, tableName, idField);
	}
}

function changeStatusResponse_M(page, changeMode, ID, statusPortion, tableName, idField) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;			
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_inactive.gif" align="absmiddle" alt="Inactive" border="0" onclick="javascript: changeStatus_M(\''+tableName+'\',\''+idField+'\',\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_active.gif" align="absmiddle" alt="Active" border="0" onclick="javascript: changeStatus_M(\''+tableName+'\',\''+idField+'\',\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}



function changeStatus(changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeStatusResponse(hostName+'/admin/admin_change_status.php?mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion);
		
		
	}
}

function changeStatusResponse(page, changeMode, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_inactive.gif" align="absmiddle" alt="Inactive" border="0" onclick="javascript: changeStatus(\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_active.gif" align="absmiddle" alt="Active" border="0" onclick="javascript: changeStatus(\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}

/**********************************************************************************************/


function changeStatus_p(changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeStatusResponse_p(hostName+'/admin/admin_change_status.php?mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion);
	}
}

function changeStatusResponse_p(page, changeMode, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_inactive.gif" align="absmiddle" alt="Inactive" border="0" onclick="javascript: changeStatus_p(\''+changeMode+'\', \''+ID+'\', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_active.gif" align="absmiddle" alt="Active" border="0" onclick="javascript: changeStatus_p(\''+changeMode+'\', \''+ID+'\', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}




function setFeaturedProperty(changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		setFeaturedPropertyResponse(hostName+'/admin/admin_change_status.php?mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion);
	}
}

function setFeaturedPropertyResponse(page, changeMode, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_inactive.gif" align="absmiddle" alt="Not Featured" border="0" onclick="javascript: setFeaturedProperty(\''+changeMode+'\', \''+ID+'\', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_active.gif" align="absmiddle" alt="Featured" border="0" onclick="javascript: setFeaturedProperty(\''+changeMode+'\', \''+ID+'\', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}








function changeStatus_M(tableName, idField, changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeStatusResponse_M(hostName+'/admin/admin_change_status.php?tableName='+tableName+'&idField='+idField+'&mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion, tableName, idField);
	}
}

function changeStatusResponse_M(page, changeMode, ID, statusPortion, tableName, idField) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;			
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_inactive.gif" align="absmiddle" alt="Inactive" border="0" onclick="javascript: changeStatus_M(\''+tableName+'\',\''+idField+'\',\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_active.gif" align="absmiddle" alt="Active" border="0" onclick="javascript: changeStatus_M(\''+tableName+'\',\''+idField+'\',\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}



function changeSSLStatus(changeMode, ID, statusPortion){
	if(changeMode!="" && ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeSSLStatusResponse(hostName+'/admin/admin_change_status.php?mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion);
	}
}

function changeSSLStatusResponse(page, changeMode, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_unlock.gif" align="absmiddle" alt="Inactive" border="0" onclick="javascript: changeSSLStatus(\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_lock.gif" align="absmiddle" alt="Active" border="0" onclick="javascript: changeSSLStatus(\''+changeMode+'\', '+ID+', \''+statusPortion+'\');" title="Change Status" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}

function deleteImage(changeMode, ID, statusPortion, type){
	if(confirm('Are you sure to delete this '+type+'?')){
		if(changeMode!="" && ID!="" && statusPortion!=""){
			document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" /> Please wait';
			deleteImageResponse(hostName+'/admin/admin_delete_image.php?mode='+changeMode+'&id='+ID+'', changeMode, ID, statusPortion);
		}
	}
}

function deleteImageResponse(page, changeMode, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="done") {
				document.getElementById(statusPortion).innerHTML = '';
			}
		}
	}
	oHTTP.send(null);
}



function openSchoolInformation(frmName, fieldName, id){
	var obj = document.forms[frmName];
	if(obj.elements[fieldName].value!=""){
		document.getElementById(id).style.display = '';	
	}
	else{
		document.getElementById(id).style.display = 'none';	
	}
}


function listArcesCalculation(frmName, priceField, acresField, dispField){
	var obj = document.forms[frmName];
	var listPrice = parseInt(obj.elements[priceField].value);
	var acres = parseInt(obj.elements[acresField].value);
	var priceAcres = 0.00;
	if(listPrice>0){
		priceAcres = listPrice/acres;
		document.forms[frmName].elements[dispField].value = priceAcres.toFixed(2);
	}
	else{
		document.forms[frmName].elements[dispField].value = priceAcres.toFixed(2);
	}
}

/*******************************************************
Text field counter 
*******************************************************/

function textCounter(frmnm, field, countfield, maxlimit) {
	if (document.forms[frmnm].elements[field].value.length > maxlimit){
		document.forms[frmnm].elements[field].value = document.forms[frmnm].elements[field].value.substring(0, maxlimit);
	}
	else{
		document.getElementById(countfield).innerHTML = maxlimit - document.forms[frmnm].elements[field].value.length;
	}
}




function changeContentPortion(frmName){
	if(document.forms[frmName].elements['email_type'][0].checked==true){
		document.getElementById('uploadButton').style.display = '';
		document.getElementById('uploadImagePortion').style.display = '';
		document.getElementById('htmlText').style.visibility = 'visible';
		document.getElementById('plainText').style.visibility = 'hidden';
	}
	else{
		document.getElementById('uploadButton').style.display = 'none';
		document.getElementById('uploadImagePortion').style.display = 'none';
		document.getElementById('htmlText').style.visibility = 'hidden';
		document.getElementById('plainText').style.visibility = 'visible';
	}
}



/*******************************************************
Popupimage Upload
*******************************************************/

function popupImageUpload(imageType, ID, frmName, elementName){
	if(ID=='' && document.forms[frmName].elements[elementName].value!=''){
		ID = document.forms[frmName].elements[elementName].value;
	}
	var popupPath = hostName+'/admin/admin_upload_picture.php?type='+imageType+'&ID='+ID+'&formName='+frmName+'&fieldName='+elementName+'';
	popupWindow(popupPath, 1, 500, 500);
}


/*******************************************************
CMA Popupimage Upload
*******************************************************/

function popupCMAImageUpload(imageType, ID, frmName, elementName){
	if(ID=='' && document.forms[frmName].elements[elementName].value!=''){
		ID = document.forms[frmName].elements[elementName].value;
	}
	var popupPath = hostName+'/admin/admin_cma_upload_picture.php?mlsID='+imageType+'&ID='+ID+'&formName='+frmName+'&fieldName='+elementName+'';
	popupWindow(popupPath, 1, 500, 500);
}

function popupCMAGoogleMap(imageType, ID, frmName, elementName){
	if(ID=='' && document.forms[frmName].elements[elementName].value!=''){
		ID = document.forms[frmName].elements[elementName].value;
	}
	var popupPath = hostName+'/admin/admin_cma_upload_picture.php?mlsID='+imageType+'&ID='+ID+'&formName='+frmName+'&fieldName='+elementName+'&cma='+ID+'';
	popupWindow(popupPath, 1, 500, 500);
}

function popupCMAAddClient(){
	var popupPath = hostName+'/admin/admin_cma_add_client.php';
	popupWindow(popupPath, 1, 500, 600);
}

function popupAdminNotes(show_page, ID, note_type){
	var popupPath = hostName+'/admin/'+show_page+'?ID='+ID+'&nType='+note_type+'';
	popupWindow(popupPath, 1, 500, 600);
}

/*************************************************************
Select city for service provider
*************************************************************/
function fetchServiceCity(stateID, stateName){
	location.href='#location';
	var topPos = parseInt(findPosY(document.getElementById('stateDisplayPortion')))+2;
	document.getElementById('textContentHTML').innerHTML = '<br><div style="text-align: center;"><img src="'+hostName+'/images/login_loader.gif"  border="0" vspace="5" /><div class="bold_text">Please wait</div></div><br>';
	document.getElementById('theLayer').style.top=(topPos)+"px";
	document.getElementById('theLayer').style.visibility = "visible";
	fetchServiceCityResponse(hostName+'/ajax_call.php?mode=service_provider_city&state_id='+stateID+'&state_name='+stateName+'');
}

function fetchServiceCityResponse(page, dispPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if(getValue!=""){
				document.getElementById('textContentHTML').innerHTML = getValue;
			}
			//document.getElementById('ajax_loader').style.display = "none";
		}
	}
	oHTTP.send(null);
}



/*************************************************************
Add or Delete City for service Provider
**************************************************************/

function addCityID(frmName, fieldName, ID, cityName) {
	document.getElementById('selectedCityPortion').style.display = "";
	document.getElementById('buttonPortion').style.display = "";
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentLength = parseInt(ddObject.length);
	var flag;
	flag = true;
	for (j=0; j<currentLength; j++) {
		if(ddObject[j].value == ID) flag = false;
	}
	
	if(flag == true) ddObject.options[(currentLength)] = new Option(cityName, ID);
	
	/*for(n=0; n < ddObject.length; n++){
		ddObject.options[n].selected = true;
	}*/
}

function removeCityID(frmName, fieldName) {
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentLength = parseInt(ddObject.length);
	var optionValue =new Array();
	var optionText =new Array();
	var counter;
	counter = 0;
	for (i=0; i<currentLength; i++) {
		if(ddObject[i].selected == false) {
			optionText[counter] = ddObject[i].text;
			optionValue[counter++] = ddObject[i].value;
		}
	}
	ddObject.length = 0;
	if(optionValue.length == 0){
		document.getElementById('selectedCityPortion').style.display = "none";
	}
	else{
		for (n=0; n<optionValue.length; n++) {
			ddObject.options[n] = new Option(optionText[n], optionValue[n]);
			//ddObject.options[n].selected = true;
		}
	}
}


/*************************************************************
Add or Delete State for service Provider
**************************************************************/

function addStateID(frmName, fieldName, ID, stateName) {
	document.getElementById('selectedStatePortion').style.display = "";
	document.getElementById('buttonPortion').style.display = "";
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentTotalState = parseInt(ddObject.length);
	var flag;
	flag = true;
	for (j=0; j<currentTotalState; j++) {
		if(ddObject[j].value == ID) flag = false;
	}
	
	if(flag == true) ddObject.options[(currentTotalState)] = new Option(stateName, ID);
	
	/*for(n=0; n < ddObject.length; n++){
		ddObject.options[n].selected = true;
	}*/
	document.getElementById('theLayer').style.visibility = 'hidden';
}

function removeStateID(frmName, fieldName) {
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentTotalState = parseInt(ddObject.length);
	var optionValue =new Array();
	var optionText =new Array();
	var counter;
	counter = 0;
	for (i=0; i<currentTotalState; i++) {
		if(ddObject[i].selected == false) {
			optionText[counter] = ddObject[i].text;
			optionValue[counter++] = ddObject[i].value;
		}
	}
	ddObject.length = 0;
	if(optionValue.length == 0){
		document.getElementById('selectedStatePortion').style.display = "none";
	}
	else{
		for (n=0; n<optionValue.length; n++) {
			ddObject.options[n] = new Option(optionText[n], optionValue[n]);
			//ddObject.options[n].selected = true;
		}
	}
}


function selectAllStateCity(frmName, stateField, cityField){
	var stateObj = document.forms[frmName].elements[stateField];
	var cityObj = document.forms[frmName].elements[cityField];
	
	for(n=0; n < stateObj.length; n++){
		stateObj.options[n].selected = true;
	}
	for(n=0; n < cityObj.length; n++){
		cityObj.options[n].selected = true;
	}
}

function checkForCountry(){
	var countryID = document.forms['basicInformation'].elements['country_id'].value;
	if(countryID == 178){
		document.getElementById('intr_st_ct').style.display = "none";
		document.getElementById('intr_st_ct_dd').style.display = "";
	}else{
		document.getElementById('intr_st_ct').style.display = "";
		document.getElementById('intr_st_ct_dd').style.display = "none";
	}
}

function userCheckForCountry(){
	var countryID = document.forms['basicInformation'].elements['country_id'].value;
	if(countryID == 178){
		document.getElementById('intr_st_ct').style.display = "none";
		document.getElementById('intr_st_ct_dd').style.display = "";
	}else{
		document.getElementById('intr_st_ct').style.display = "";
		document.getElementById('intr_st_ct_dd').style.display = "none";
	}
}

function adminSpChargesDiscDisp(val){
	if(val == 'yes'){
		document.getElementById('spDisc1').style.display = "";
		document.getElementById('spDisc2').style.display = "";
	}else{
		document.getElementById('spDisc1').style.display = "none";
		document.getElementById('spDisc2').style.display = "none";
	}
}

function pagecontent_display(){
	var newVal;
	var tmpArr = new Array();
	if(document.forms['add_sitemap'].elements['pagecontent_id'].value!=""){
		tmpArr = document.forms['add_sitemap'].elements['pagecontent_id'].options[document.forms['add_sitemap'].elements['pagecontent_id'].selectedIndex].text.split(' ');
		newVal = tmpArr[0];
		document.forms['add_sitemap'].elements['site_target'].value = hostName+'/'+newVal;
	}
}

function showAdminUserNote(val){
	if(document.getElementById(val).style.display = "none"){
		document.getElementById(val).style.display = "";
	}
}

function hideAdminUserNote(val){
	document.getElementById(val).style.display = "none";
}

/*****************************************************
Admin Email Help Section
******************************************************/

function showAdminPoolInvestorDetails(){
	if(document.getElementById('poolinvestor').style.display = "none"){
		document.getElementById('poolinvestor').style.display = "";
	}
}

function hideAdminPoolInvestorDetails(){
	document.getElementById('poolinvestor').style.display = "none";
}

/****************************************************************
Change Stat Mail Status
****************************************************************/

function changeStartEmailStatus(ID){
	if(ID!=""){
		document.getElementById('start_id_'+ID).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		changeStartEmailStatus_response(hostName+'/admin/admin_change_status.php?mode=changeStartEmailStatus&id='+ID+'', ID);
	}
}

function changeStartEmailStatus_response(page, ID) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById('start_id_'+ID).innerHTML = '<img src="'+hostName+'/images/yellowstar_blank.gif" align="absmiddle" alt="" border="0" onclick="javascript: changeStartEmailStatus('+ID+');" title="" class="changeStatus" />';
			}
			else{
				document.getElementById('start_id_'+ID).innerHTML = '<img src="'+hostName+'/images/yellowstar.gif" align="absmiddle" alt="" border="0" onclick="javascript: changeStartEmailStatus('+ID+');" title="" class="changeStatus" />';
			}
		}
	}
	oHTTP.send(null);
}

/****************************************************************
Make New Lead As Read
****************************************************************/

function makeLeadAsRead(ID, type){
	if(ID!=""){
		document.getElementById(type+'_'+ID).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		makeLeadAsRead_response(hostName+'/admin/admin_change_status.php?mode=makeLeadAsRead&id='+ID+'&type='+type, ID, type);
	}
}

function makeLeadAsRead_response(page, ID, type) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="done") {
				document.getElementById(type+'_'+ID).innerHTML = '&nbsp;';
			}
		}
	}
	oHTTP.send(null);
}



/****************************************************************
CMA portion start here
****************************************************************/

function selectCMAName(frmName, clientName, cmaNameField, cmaTypeField){
	var typeObj = document.forms[frmName].elements[cmaTypeField];
	var nameObj = document.forms[frmName].elements[cmaNameField];
	if(typeObj[0].checked == true){
		cmaType = typeObj[0].value;
	}
	else{
		cmaType = typeObj[1].value;
	}
	if(clientName != ""){
		nameObj.value = cmaType+' CMA for '+clientName;
	}
}


function selectSubjectProperty(){
	var obj = document.forms['subjectPropertySearch'].elements['propertyIDs[]'];
	var cma = document.forms['subjectPropertySearch'].elements['cma'].value;
	var action = document.forms['subjectPropertySearch'].elements['action'].value;
	var fields = document.forms['subjectPropertySearch'].elements['fields'].value;
	var type = document.forms['subjectPropertySearch'].elements['type'].value;
	var propID = document.forms['subjectPropertySearch'].elements['prop_ids'].value;
	var pageParameters = '';
	if(type == "subject"){
		var chkCounter = 0;
		for(n=0; n<obj.length; n++){
			if(obj[n].checked == true){
				chkCounter = chkCounter + 1;
				ID = obj[n].value;
			}
			if(chkCounter>1) break;
		}
		if(obj.length){
			if(chkCounter == 0){
				alert("Please select atleast one property.");
				return false;
			}
			if(chkCounter>1){
				alert("Sorry! You can not select more than one property for subject property.");
				return false;
			}
			else{
				document.getElementById('ajax_loader_mail').style.display = '';
				pageParameters = 'mode=delete_previous_images&cma='+cma+'&action='+action+'&ID='+ID+'&fields='+fields+'';
				refreshLink = hostName+'/admin/admin_add_cma.php?mode=subject_property&cma='+cma+'&action='+action+'&ID='+ID+'&fields='+fields+'';
				opener.focus();
				deletePreviousInformation(pageParameters, refreshLink);
				/*opener.location.href = hostName+'/admin/admin_add_cma.php?mode=subject_property&cma='+cma+'&action='+action+'&ID='+ID+'&fields='+fields+'';
				window.close();
				*/
			}
		}
		else{
			ID = obj.value;
			document.getElementById('ajax_loader_mail').style.display = '';
			pageParameters = 'mode=delete_previous_images&cma='+cma+'&action='+action+'&ID='+ID+'&fields='+fields+'';
			refreshLink = hostName+'/admin/admin_add_cma.php?mode=subject_property&cma='+cma+'&action='+action+'&ID='+ID+'&fields='+fields+'';
			opener.focus();
			deletePreviousInformation(pageParameters, refreshLink);
		}
		
	}
	else if(type == "comparable"){
		if(propID!="") propID = propID+",";
		chkCounter = 0;
		if(obj.length){
			for(n=0; n<obj.length; n++){
				if(obj[n].checked == true){
					chkCounter = chkCounter + 1;
					propID = propID+obj[n].value+",";
				}
			}
			propID = propID.substring(0, (propID.length-1));
		}
		else{
			propID = propID+obj.value;
		}
		
		/*if(chkCounter == 0){
			alert("Please select atleast one property.");
			return false;
		}
		else{*/
			opener.location.href = hostName+'/admin/admin_add_cma.php?mode=comparable&cma='+cma+'&action='+action+'&prop_ids='+propID+'';
			window.close();
			opener.focus();
		//}
	}
}


function deletePreviousInformation(pageParameters, refreshLink){
	oHTTP.open('POST', hostName+'/admin/admin_search_subject_property.php', true);
	oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			opener.location.href = refreshLink;
			document.getElementById('ajax_loader_mail').style.display = 'none';
			opener.focus();
			window.close();
		}
	}
	oHTTP.send(pageParameters);
}




function deleteComparableProperty(pageMode, cma, pageAction, frmName){
	var obj = document.forms[frmName].elements['propertyIDs[]'];
	var propID = "";
	var chkCounter = 0;
	for(n=0; n<obj.length; n++){
		if(obj[n].checked == false){
			propID = propID+obj[n].value+",";
		}
		else{
			chkCounter = chkCounter + 1;
		}
	}
	if(chkCounter == 0){
		alert("Please select atleast one proprty.");
		return false;
	}
	else{
		propID = propID.substring(0, (propID.length-1));
		location.href = hostName+'/admin/admin_add_cma.php?mode='+pageMode+'&cma='+cma+'&action='+pageAction+'&prop_ids='+propID+'';
	}
}



function changeComparableOrder(cma, actionValue, frmName, fieldName, mode){
	var obj = document.forms[frmName].elements[fieldName];
	var temp = '';
	var chkIndex = 0;
	var returnOrder = '';
	
	for(n=0; n<obj.length; n++){
		if(obj[n].checked == true){
			temp = temp+obj[n].value+',';
		}
	}
	temp = temp.substring(0, (temp.length-1));
	if(mode == "up"){
		for(n=0; n<obj.length; n++){
			if(obj[n].checked == true){
				chkIndex = n;
				break;
			}
		}
		for(n=0; n<chkIndex-1; n++){
			returnOrder = returnOrder+obj[n].value+',';
		}
		returnOrder = returnOrder+temp+',';
		for(n=0; n<obj.length; n++){
			if(returnOrder.indexOf(obj[n].value)<0){
				returnOrder = returnOrder+obj[n].value+',';
			}
		}
		returnOrder = returnOrder.substring(0, (returnOrder.length-1));
	}
	
	if(mode == "down"){
		for(n=(obj.length-1); n>=0; n--){
			if(obj[n].checked == true){
				chkIndex = n;
				break;
			}
		}
		for(n=obj.length-1; n>chkIndex+1; n--){
			returnOrder = ','+obj[n].value+returnOrder;
		}
		returnOrder = temp+returnOrder;
		var tmp = '';
		for(n=0; n<obj.length; n++){
			if(returnOrder.indexOf(obj[n].value)<0){
				tmp = tmp+obj[n].value+',';
			}
		}
		tmp = tmp.substring(0, (tmp.length-1));
		returnOrder = tmp+','+returnOrder ;
	}
	location.href = hostName+'/admin/admin_add_cma.php?mode=comparable&cma='+cma+'&action='+actionValue+'&prop_ids='+returnOrder+'&checked='+temp+'';
}



function changeAdjusment(frmName, fieldName, totalFields){
	var actualListPrice = RemoveCommaNumber(document.forms[frmName].elements['list_price'].value);
	var actualSoldPrice = RemoveCommaNumber(document.forms[frmName].elements['sold_price'].value);
	var totalSqFt = RemoveCommaNumber(document.forms[frmName].elements['totalSqFt'].value);
	
	var netAdjustObj = document.forms[frmName].elements['total_net_adjustment'];
	var listPriceObj = document.forms[frmName].elements['adjusted_list_price'];
	var salePriceObj = document.forms[frmName].elements['adjusted_sale_price'];
	var lpSqftObj = document.forms[frmName].elements['adjusted_lp_sqft'];
	var spSqftObj = document.forms[frmName].elements['adjusted_sp_sqft'];
	var ratioObj = document.forms[frmName].elements['accessed_tax_value_ratio'];
	
	var totalAdjustment = 0.00;
	for(n=1; n<=totalFields; n++){
		fieldObj = document.forms[frmName].elements[fieldName+n];
		if(fieldObj.value!="") {
			totalAdjustment = totalAdjustment + RemoveCommaNumber(fieldObj.value);
		}
	}
	
	netAdjustObj.value = CommaFormatNumber(totalAdjustment);
	if(RemoveCommaNumber(listPriceObj.value)>0) listPriceObj.value = CommaFormatNumber(actualListPrice+totalAdjustment);
	if(RemoveCommaNumber(salePriceObj.value)>0) salePriceObj.value = CommaFormatNumber(actualSoldPrice+totalAdjustment);
	if(RemoveCommaNumber(listPriceObj.value)>0 && totalSqFt>0) lpSqftObj.value = CommaFormatNumber((actualListPrice+totalAdjustment)/totalSqFt);
	if(RemoveCommaNumber(salePriceObj.value)>0 && totalSqFt>0) spSqftObj.value = CommaFormatNumber((actualSoldPrice+totalAdjustment)/totalSqFt);
	if(RemoveCommaNumber(salePriceObj.value)>0 && salePriceObj.value>0) ratioObj.value = CommaFormatNumber(listPriceObj.value/salePriceObj.value);
	return false;
}

function changeComparableDisplay(cmaID, mlsID){
	var obj = document.getElementById('ajax_loader_mail');
	obj.style.display = '';
	parameterString = saveAdjustmentInformation('Adjustable', 8);
	responseChangeComparableDisplay('mode=fetch_comparable&cma='+cmaID+'&mlsID='+mlsID+'&'+parameterString);
}

function responseChangeComparableDisplay(pageParameters) {
	oHTTP.open('POST', hostName+'/admin/admin_fetch_comparable_property.php', true);
	oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById('display_section').innerHTML = getValue;
			document.getElementById('ajax_loader_mail').style.display = 'none';
		}
	}
	oHTTP.send(pageParameters);
}

function saveAdjustmentInformation(frmName, totalFields){
	var parameterString = '';
	parameterString = '&mls_id='+document.forms[frmName].elements['mls_id'].value;
	parameterString += '&cma='+document.forms[frmName].elements['cma'].value;
	parameterString += '&total_fields='+totalFields;
	parameterString += '&comments='+document.forms[frmName].elements['adjustment_comments'].value;
	for(n=1; n<=totalFields; n++){
		fieldObj = document.forms[frmName].elements['amount_'+n];
		descObj = document.forms[frmName].elements['adjust_desc_'+n];
		parameterString = parameterString+'&dese_'+n+'='+descObj.value+'&value_'+n+'='+fieldObj.value;
	}
	return parameterString;
	//responseSaveAdjustmentInformation(parameterString);
}


/*function responseSaveAdjustmentInformation(pageParameters){
	oHTTP.open('POST', hostName+'/admin/admin_fetch_comparable_property.php', true);
	oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
		}
	}
	oHTTP.send(pageParameters);
}*/



function changePricing(frmName, fieldName){
	var obj = document.forms[frmName].elements[fieldName];
	if(obj[0].checked){
		document.forms[frmName].elements['suggested_price'].disabled = false;
		document.forms[frmName].elements['min_suggested_price'].disabled = false;
		document.forms[frmName].elements['max_suggested_price'].disabled = false;
	}
	else{
		document.forms[frmName].elements['suggested_price'].disabled = true;
		document.forms[frmName].elements['min_suggested_price'].disabled = true;
		document.forms[frmName].elements['max_suggested_price'].disabled = true;
	}
}



function addReportID(frmName, fieldName, menuDD) {
	var flag;
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentLength = parseInt(ddObject.length);
	var newLen = currentLength;
	
	newObj = document.forms[frmName].elements[menuDD];
	counter = 0;
	for(n=0; n<newObj.length; n++){
		if(newObj[n].selected == true){
			ID = newObj[n].value;
			objName = newObj[n].text;
			flag = true;
			for (j=0; j<newLen; j++) {
				if(ddObject[j].value == ID) flag = false;
			}
			if(flag == true){
				ddObject.options[(newLen)] = new Option(objName, ID);
				newLen = newLen+1;
			}
		}
	}
	ddObject.size = newLen;
}


function removeReportID(frmName, fieldName) {
	var ddObject = document.forms[frmName].elements[fieldName];
	var currentLength = parseInt(ddObject.length);
	var optionValue =new Array();
	var optionText =new Array();
	var counter;
	counter = 0;
	for (i=0; i<currentLength; i++) {
		if(ddObject[i].selected == false) {
			optionText[counter] = ddObject[i].text;
			optionValue[counter++] = ddObject[i].value;
		}
	}
	ddObject.length = 0;
	if(optionValue.length == 0){
		document.getElementById('selectedCityPortion').style.display = "none";
	}
	else{
		for (n=0; n<optionValue.length; n++) {
			ddObject.options[n] = new Option(optionText[n], optionValue[n]);
			//ddObject.options[n].selected = true;
		}
	}
	ddObject.size = parseInt(ddObject.length);
}



function changeDisplayOrder(frmName, fieldName, orderMode){
	var obj = document.forms[frmName].elements[fieldName];
	var total = parseInt(obj.length);
	var selectedItem;
	var temp = '';
	if(total>0){
		counter = 0;
		for(n=0; n<total; n++){
			if(obj[n].selected == true){
				selectedItem = n;
				counter++;
			}
		}
		if(counter>1) {
			alert('Please select only one item.');
			return false;
		}
		else{
			if(orderMode == 'up'){
				if(selectedItem == 0){
					return false;
				}
				else{
					temp = obj[selectedItem].text+'@'+obj[selectedItem].value;
					obj.options[selectedItem] = new Option(obj[(selectedItem-1)].text, obj[(selectedItem-1)].value);
					obj.options[(selectedItem-1)] = new Option(temp.split('@')[0], temp.split('@')[1]);
					obj[(selectedItem-1)].selected = true;
				}
			}
			if(orderMode == 'down'){
				if(selectedItem == (total-1)){
					return false;
				}
				else{
					temp = obj[selectedItem].text+'@'+obj[selectedItem].value;
					obj.options[selectedItem] = new Option(obj[(selectedItem+1)].text, obj[(selectedItem+1)].value);
					obj.options[(selectedItem+1)] = new Option(temp.split('@')[0], temp.split('@')[1]);
					obj[(selectedItem+1)].selected = true;
				}
			}
		}
	}
	else{
		return false;
	}
}


function selectAllValues(frmName, fieldName){
	if(fieldName!=""){
		var obj = document.forms[frmName].elements[fieldName];
		for(n=0; n < obj.length; n++){
			obj.options[n].selected = true;
		}
	}
}



function RemoveCommaNumber(p_sString){
	var sText = new String(p_sString);
	var pos=sText.indexOf(",");
	while (pos >= 0){
		sText = sText.substring(0, pos) + sText.substring(pos+1, sText.length);
		pos=sText.indexOf(",");
	}
	return CvtNum(sText);
}

function CommaFormatNumber(NumValue){
	NumValue = RemoveCommaNumber(NumValue);
	var Result, decimal, pos;
	Result = "";
	NumValue = NumValue.toFixed(2);
	NumValue = NumValue.toString();
	floatPart = NumValue.split(".")[1];
	NumValue = NumValue.split(".")[0];
	actualValue = NumValue;
	if(actualValue.indexOf("-") == 0) NumValue = NumValue.substring(1,NumValue.length);
	while (NumValue.length > 3){
		Result = "," + NumValue.substring(NumValue.length-3,NumValue.length)+ Result;
		NumValue = NumValue.substring(0,NumValue.length-3)
	}
	Result = NumValue + Result;
	if(actualValue.indexOf("-") == 0) Result = '-'+Result;
	Result = Result+'.'+floatPart;
	return Result;
}

function CvtNum(Text){
	if (Text.length == 0) { return 0; }
	else { return parseFloat(Text,10); }
}




function cmaMouseoverRows(ID) {
	var obj = document.getElementById(ID);
	obj.className += ' cma_mouseHover';
	return false;
}

function cmaMouseoutRows(ID) {
	var obj = document.getElementById(ID);
	obj.className = obj.className.replace( ' cma_mouseHover', '' );
	return false;
}

function cmaMousedownRows(ID) {
	cmaDeselectRows();
	var obj = document.getElementById(ID);
	obj.className += ' cma_selected_bg';
	document.forms['netSheet'].elements['selected_row'].value = ID;
	return false;
}


function cmaDeselectRows(){
	var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        if ( 'cma_odd_tr' != rows[i].className.substr(0,10) && 'cma_even_tr' != rows[i].className.substr(0,11) ) {
            continue;
        }
		rows[i].className =  rows[i].className.replace( ' cma_selected_bg', '' );
	}
}


/*
function netSheetDisplayOrder(frmName, orderMode, total){
	var obj = document.forms[frmName].elements['display_order[]'];
	var selectedItem = parseInt(document.forms[frmName].elements['selected_row'].value);
	if(selectedItem){
		var descObj = document.forms[frmName].elements['desc_'+selectedItem];
		var valueObj = document.forms[frmName].elements['value_'+selectedItem];
		var descTemp = '';
		var valueTemp = '';
		var temp = 0;
		var changeID;
		if(total>0){
			if(orderMode == 'up'){
				if(selectedItem == 1){
					return false;
				}
				else{
					changeID = parseInt(selectedItem-1);
					temp = obj[(selectedItem-1)].value;
					descTemp = descObj.value;
					valueTemp = valueObj.value;
					obj[(selectedItem-1)].value = obj[(changeID-1)].value;
					obj[(changeID-1)].value = temp;
					descObj.value = document.forms[frmName].elements['desc_'+changeID].value;
					valueObj.value = document.forms[frmName].elements['value_'+changeID].value;
					document.forms[frmName].elements['desc_'+changeID].value = descTemp;
					document.forms[frmName].elements['value_'+changeID].value = valueTemp;
					cmaMousedownRows(changeID);
				}
			}
			if(orderMode == 'down'){
				if(selectedItem == total){
					return false;
				}
				else{
					changeID = parseInt(selectedItem+1);
					temp = obj[(selectedItem-1)].value;
					descTemp = descObj.value;
					valueTemp = valueObj.value;
					obj[(selectedItem-1)].value = obj[(changeID-1)].value;
					obj[(changeID-1)].value = temp;
					descObj.value = document.forms[frmName].elements['desc_'+changeID].value;
					valueObj.value = document.forms[frmName].elements['value_'+changeID].value;
					document.forms[frmName].elements['desc_'+changeID].value = descTemp;
					document.forms[frmName].elements['value_'+changeID].value = valueTemp;
					cmaMousedownRows(changeID);
				}
			}
		}
		else{
			return false;
		}
	}
	else{
		alert("Please select one settlement charge.");
		return false;
	}
}*/


function netSheetDisplayOrder(frmName, orderMode, total){
	var obj = document.forms[frmName];
	var selectedItem = parseInt(document.forms[frmName].elements['selected_row'].value);
	if(selectedItem){
		var descObj = document.getElementById('desc_'+selectedItem);
		var valueObj = document.getElementById('value_'+selectedItem);
		var descTemp = '';
		var valueTemp = '';
		var temp = 0;
		var changeID;
		if(total>0){
			if(orderMode == 'up'){
				if(selectedItem == 1){
					return false;
				}
				else{
					changeID = parseInt(selectedItem-1);
					temp = obj.elements['netsheet_id_'+selectedItem].value;
					descTemp = descObj.innerHTML;
					valueTemp = valueObj.innerHTML;
					obj.elements['netsheet_id_'+selectedItem].value = obj.elements['netsheet_id_'+changeID].value;
					obj.elements['netsheet_id_'+changeID].value = temp;
					descObj.innerHTML = document.getElementById('desc_'+changeID).innerHTML;
					valueObj.innerHTML = document.getElementById('value_'+changeID).innerHTML;
					document.getElementById('desc_'+changeID).innerHTML = descTemp;
					document.getElementById('value_'+changeID).innerHTML = valueTemp;
					cmaMousedownRows(changeID);
				}
			}
			if(orderMode == 'down'){
				if(selectedItem == total){
					return false;
				}
				else{
					changeID = parseInt(selectedItem+1);
					temp = obj.elements['netsheet_id_'+selectedItem].value;
					descTemp = descObj.innerHTML;
					valueTemp = valueObj.innerHTML;
					obj.elements['netsheet_id_'+selectedItem].value = obj.elements['netsheet_id_'+changeID].value;
					obj.elements['netsheet_id_'+changeID].value = temp;
					descObj.innerHTML = document.getElementById('desc_'+changeID).innerHTML;
					valueObj.innerHTML = document.getElementById('value_'+changeID).innerHTML;
					document.getElementById('desc_'+changeID).innerHTML = descTemp;
					document.getElementById('value_'+changeID).innerHTML = valueTemp;
					cmaMousedownRows(changeID);
				}
			}
		}
		else{
			return false;
		}
		
	}
	else{
		alert("Please select one settlement charge.");
		return false;
	}
}



function netSheetCalculation(frmName, fieldName){
	var salePrice = parseFloat(RemoveCommaNumber(document.forms[frmName].elements['suggested_price'].value));
	var fmObj = document.forms[frmName].elements['fist_mortgage'];
	var smObj = document.forms[frmName].elements['second_mortgage'];
	var dpObj = document.forms[frmName].elements['down_payment'];
	var dppObj = document.forms[frmName].elements['down_payment_percentage'];
	var bmObj = document.forms[frmName].elements['buyer_mortgage'];
	var tcObj = document.forms[frmName].elements['total_charges'];
	var stmObj = document.forms[frmName].elements['seller_total_mortgage'];
	var epObj = document.forms[frmName].elements['estimated_price'];
	var totalChargeObj = document.forms[frmName].elements['total_charge'];
	
	var totalCharge = parseFloat(RemoveCommaNumber(totalChargeObj.value));
	var sellerMortgage = 0;
	var buyerMortgage = 0;
	var downPaymentPercentage = parseFloat(RemoveCommaNumber(dppObj.value));
	var netPrice = 0;
	var downPayment = parseFloat(RemoveCommaNumber(dpObj.value));
	
	if(fieldName == "down_payment_percentage"){
		downPayment = salePrice*(parseFloat(RemoveCommaNumber(dppObj.value))/100);
		buyerMortgage = salePrice-downPayment;
		if(dppObj.value!=""){
			dpObj.value = CommaFormatNumber(downPayment);
			bmObj.value = CommaFormatNumber(buyerMortgage);
		}
	}
	else{
		downPaymentPercentage = (parseFloat(RemoveCommaNumber(dpObj.value))/salePrice)*100;
		buyerMortgage = salePrice-downPayment;
		if(dpObj.value!=""){
			dppObj.value = CommaFormatNumber(downPaymentPercentage);
			bmObj.value = CommaFormatNumber(buyerMortgage);
		}
	}
	
	sellerMortgage = parseFloat(RemoveCommaNumber(fmObj.value)) + parseFloat(RemoveCommaNumber(smObj.value));
	netPrice = salePrice - totalCharge - sellerMortgage;
	
	tcObj.value = CommaFormatNumber(totalCharge);
	stmObj.value = CommaFormatNumber(sellerMortgage);
	epObj.value = CommaFormatNumber(netPrice);
}


function updateNetSheet(cma){
	var selectedItem = parseInt(document.forms['netSheet'].elements['selected_row'].value);
	var netSheetID = document.forms['netSheet'].elements['netsheet_id_'+selectedItem].value;
	popupWindowAdmin(hostName+'/admin/admin_netsheet.php?mode=update&cma='+cma+'&netsheet_id='+netSheetID+'', 1, 276, 380);
	return false;
}

function deleteNetSheet(cma){
	var selectedItem = parseInt(document.forms['netSheet'].elements['selected_row'].value);
	var netSheetID = document.forms['netSheet'].elements['netsheet_id_'+selectedItem].value;
	if(netSheetID.indexOf("default")>0) {
		document.getElementById(selectedItem).style.display = 'none';
	}
	else{
		popupWindowAdmin(hostName+'/admin/admin_netsheet.php?mode=delete&cma='+cma+'&netsheet_id='+netSheetID+'', 1, 276, 380);
	}
	return false;
}



function editComparable(cma, mlsListingID, type){
	popupWindowAdmin(hostName+'/admin/admin_edit_comparable.php?cma='+cma+'&mls_listing_id='+mlsListingID+'&type='+type+'', 1, 365, 400);
}



function changeSubjectPhoto(){
	sub_index = parseInt(sub_index)+1;
	if(sub_index == sub_maxphoto) sub_index = 0;
	document.getElementById('sub_image').src = sub_photo_urls[sub_index].src;
}

function changeComparablePhoto(){
	com_index = parseInt(com_index)+1;
	if(com_index == com_maxphoto) com_index = 0;
	document.getElementById('com_image').src = com_photo_urls[com_index].src;
}

function changeComparablePhotoReport(mlsID){
	com_index[mlsID] = parseInt(com_index[mlsID])+1;
	if(com_index[mlsID] == com_maxphoto[mlsID]) com_index[mlsID] = 0;
	document.getElementById('com_image_'+mlsID).src = com_photo_urls[mlsID][com_index[mlsID]].src;
}

function changeComparablePhotoJS(){
	com1_index = parseInt(com1_index)+1;
	if(com1_index == com1_maxphoto) com1_index = 0;
	document.getElementById('com1_image').src = com1_photo_urls[com1_index].src;
}

/****************************************************************
CMA portion end here
****************************************************************/

/*******************************************************
Pool Investor
********************************************************/


function adminShowPoolInvestorInvestmentDetails(val){
	var rowID = 'view_poolinvestor_details_'+val;
	if(document.getElementById('view_poolinvestor_details_container_'+val).style.display = "none"){
		document.getElementById('view_poolinvestor_details_container_'+val).style.display = "";
	}
	document.getElementById(rowID).innerHTML = '<img src="'+hostName+'/images/login_loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
	adminFetchPoolInvestorInvestmentDetails(hostName+'/admin/admin_change_status.php?mode=view_poolInvestorInvestDetails&id='+val, rowID);
}

function adminFetchPoolInvestorInvestmentDetails(page, rowID) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			document.getElementById(rowID).innerHTML = getValue;
		}
	}
	oHTTP.send(null);
}

function adminHidePoolInvestorInvestmentDetails(val){
	document.getElementById('view_poolinvestor_details_container_'+val).style.display = "none";
}

/********************************************************
Pool Investor New Investment
********************************************************/

function showAdminPoolInvestorNewInvestment(){
	document.getElementById('new_pool_investment').style.display = "";
}

function hideAdminPoolInvestorNewInvestment(val){
	document.getElementById('new_pool_investment').style.display = "none";
}



function selectAllUnsubscribeMail(frmName, fieldName, chkField){
	var obj = document.forms[frmName].elements[fieldName];
	var chkObj = document.forms[frmName].elements[chkField];
	var textObj = document.getElementById('check_uncheck');
	if(chkObj.checked == true){
		if(obj.length>0){
			for(n=0; n<obj.length; n++){
				obj[n].checked = true;
			}
		}
		textObj.innerHTML = 'Uncheck All';
		chkObj.checked = true;
	}
	else{
		if(obj.length>0){
			for(n=0; n<obj.length; n++){
				obj[n].checked = false;
			}
		}
		textObj.innerHTML = 'Check All';
		chkObj.checked = false;
	}
}

/*************************************************************************
FSBO property assign to admin
**************************************************************************/
function assignFsboPropToAdmin(ID, statusPortion){
	if(ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		assignFsboPropToAdminResponse(hostName+'/admin/admin_change_status.php?mode=assignFsboPropToAdmin&id='+ID+'', ID, statusPortion);
		
		
	}
}

function assignFsboPropToAdminResponse(page, ID, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="none") {
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/btn_acceptnow.gif" align="absmiddle" alt="Accept Now" border="0" onclick="javascript: assignFsboPropToAdmin(\''+ID+'\', \''+statusPortion+'\');" title="Accept Now" class="changeStatus" />';
			}
			else{
				document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/icon_accepted.gif" align="absmiddle" alt="Accept Now" border="0" title="Accept Now" />';
			}
		}
	}
	oHTTP.send(null);
}

/*********************************************************
Admin Banner Section (Make an banner Paid)
*********************************************************/
function adminPayForBanner(ID, statusPortion){
	if(ID!="" && statusPortion!=""){
		document.getElementById(statusPortion).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		adminPayForBannerResponse(hostName+'/admin/admin_change_status.php?mode=adminMakeBannerPaid&id='+ID+'', statusPortion);
	}
}

function adminPayForBannerResponse(page, statusPortion) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="done") {
				document.getElementById(statusPortion).innerHTML = 'Paid';
			}
			else{
				document.getElementById(statusPortion).innerHTML = 'Unpaid';
			}
		}
	}
	oHTTP.send(null);
}

/******************************************
Mark / Removed User As Stared
*******************************************/

function markUserAsStar(mode, ID, pos_name){
	if(mode!="" && ID!=""){
		document.getElementById(pos_name).innerHTML = '<img src="'+hostName+'/admin_images/loader.gif" align="absmiddle" alt="Loader" border="0" title="Please Wait" class="changeStatus" />';
		markUserAsStarResponse(hostName+'/admin/admin_change_status.php?mode='+mode+'&id='+ID+'', mode, ID, pos_name);
		
		
	}
}

function markUserAsStarResponse(page, mode, ID, pos_name) {
	oHTTP.open("GET", page, true);
	oHTTP.onreadystatechange=function() {
		if (oHTTP.readyState==4) {
			var getValue=oHTTP.responseText;
			if (getValue=="done") {
				document.getElementById(pos_name).innerHTML = '<img src="'+hostName+'/admin_images/yellowstar.gif" border="0" alt="*" title="" class="changeStatus" onclick="javascript: markUserAsStar(\'user_unstar\', '+ID+', \''+pos_name+'\')" />';
			}
			else{
				document.getElementById(pos_name).innerHTML = '<img src="'+hostName+'/admin_images/yellowstar_blank.gif" border="0" alt="*" title="" class="changeStatus" onclick="javascript: markUserAsStar(\'user_star\', '+ID+', \''+pos_name+'\')" />';
			}
		}
	}
	oHTTP.send(null);
}

function showMarkToDoPortion() {
	document.getElementById('markToDoPortion').style.display = "";
	document.getElementById('mailUserToDoPortion').style.display = "none";
}

function hideMarkToDoPortion() {
	document.getElementById('markToDoPortion').style.display = "none";
	document.getElementById('mailUserToDoPortion').style.display = "";
}

