function toggleCheckBoxes( form_name, text_div ){

	if( 'Select All' == document.getElementById(text_div).innerHTML ){
		document.getElementById('selection_status').innerHTML = 'Deselect All';

		var loop_count = 1;

		for ( x = 0; x < document.forms[form_name].elements.length ; x++ ){
			if ( document.forms[form_name].elements[x].type == 'checkbox' ){
				document.forms[form_name].elements[x].checked = true;
				loop_count++;
			}
		}

	} else if ( 'Deselect All' == document.getElementById(text_div).innerHTML ){
		document.getElementById(text_div).innerHTML = 'Select All';

		for ( x = 0; x < document.forms[form_name].elements.length ; x++ ){
			if ( document.forms[form_name].elements[x].type == 'checkbox' ){
				document.forms[form_name].elements[x].checked = false;
			}
		}
	}
}

function switchCheckBoxes( arrobjCheckboxes, strSelectTag ) {

	 var arrobjDocumets = document.getElementsByName(arrobjCheckboxes);
	 var intLength		= arrobjDocumets.length,i;
	 var strVal 		= document.getElementById( strSelectTag ).innerHTML;

	 if( 'Deselect All' == strVal ) {
	  	document.getElementById( strSelectTag ).innerHTML = 'Select All';
		 if( intLength > 1 ) {
		 	for(i=0;i<intLength;i++) { arrobjDocumets[i].checked = false;  }
		 } else {
		 	arrobjDocumets[0].checked=false;
		 }
	  } else if ( 'Select All' == strVal ) {
	  	document.getElementById( strSelectTag ).innerHTML = 'Deselect All';
		 if(intLength > 1) {
			for( i=0;i<intLength;i++) { arrobjDocumets[i].checked = true; }
		 }
		 else {
		 	arrobjDocumets[0].checked = true;
	  	 }
	  }
}

// this functions are for general_settings of the property of resident works
function allowFloorplanSelection() {
	fps = document.getElementById('FORCE_FLOORPLAN_SELECTION');
	aus = document.getElementById('ALLOW_UNIT_SPACE_SELECTION');
	fus = document.getElementById('FORCE_UNIT_SPACE_SELECTION');
	aps = document.getElementById('ALLOW_FLOORPLAN_SELECTION');
		if( aps.checked ) {
			fps.disabled = false;
		} else {
			fps.checked = false;
			aus.checked = false;
			fus.checked = false;
			fus.disabled = true;
			fps.disabled = true;
		}
}

function allowUnitSelection() {
	fus = document.getElementById('FORCE_UNIT_SPACE_SELECTION');
	fps = document.getElementById('FORCE_FLOORPLAN_SELECTION');
	aps = document.getElementById('ALLOW_FLOORPLAN_SELECTION');
	aus = document.getElementById('ALLOW_UNIT_SPACE_SELECTION');
		if( aus.checked ) {
			fus.disabled = false;
			aps.checked = true;
			fps.disabled = false;
		} else {
			fus.checked = false;
			fus.disabled = true;
		}
}

function requireVariableRecurringPayment() {
	apca = document.getElementById('DISALLOW_RECURRING_PAYMENT_CEILING');
	ava  = document.getElementById('FORCE_VARIABLE_RECURRING_PAYMENT');

	if( ava.checked ) {
		apca.disabled	= false;
	} else {
		apca.checked 	= false;
		ava.checked 	= false;
		apca.disabled	= true;
	}
}

function summarizeImportedFloorplans() {
	sif = document.getElementById('SUMMARIZE_IMPORTED_FLOORPLANS');

	if( sif.checked == true && false == confirm( 'Warning: Selecting this box may modify or delete all units, floorplans, and related information (e.g. photos, pricing, amenities).\n\nIf you do not import floor plan information from an external Property Management System, this setting will have no affect.\n\nPlease contact your help desk or call Property Solutions support (801-375-5522 x 2) if you are unsure how to proceed.\n\nWould you like to continue?' ) ) {
		if ( true == sif.checked ) {
			sif.checked = false;
		}else if( false == sif.checked ) {
			sif.checked = true;
		}
	}

}

function dontImportPropertyFloorplans() {
	ipf = document.getElementById('DONT_IMPORT_PROPERTY_FLOORPLANS');

	if( ipf.checked == true && false == confirm( 'Warning: Selecting this box may cause all floorplans and related information (e.g. photos, pricing, amenities, etc) to be changed or deleted.\n\nIf you do not import floor plan information from an external Property Management System, this setting will have no affect.\n\nPlease contact your help desk or call Property Solutions support (801-375-5522 x 2) if you are unsure how to proceed.\n\nWould you like to continue?' ) ) {
		if ( true == ipf.checked ) {
			ipf.checked = false;
		} else if( false == ipf.checked ) {
 			ipf.checked = true;
		}
	}
}

function showWaitingImage( divId ) {

	var strBumperImage = '<div class="section_container" style="background-color:#B5B5B5;';

  	if( 0 < document.getElementById(divId).clientWidth )
  	 	strBumperImage += ' width:' + document.getElementById(divId).clientWidth + 'px;';

  	if( 0 < document.getElementById(divId).clientHeight )
  	 	strBumperImage += ' height:' + document.getElementById(divId).clientHeight + 'px;';

  	 	strBumperImage += '"><img src="/images/_common/bumper/thumper.gif" width="20" height="20" border="0" >';
		strBumperImage += '</div>';

  		document.getElementById(divId).innerHTML = strBumperImage;
}

function showWaitingImageClientAdmin( divId ) {

	var strBumperImage = '<div class="section_container" style="background-color:#FCF2E5;';

  	if( 0 < document.getElementById(divId).clientWidth )
  	 	strBumperImage += ' width:' + document.getElementById(divId).clientWidth + 'px;';

  	if( 0 < document.getElementById(divId).clientHeight )
  	 	strBumperImage += ' height:' + document.getElementById(divId).clientHeight + 'px;';

  	 	strBumperImage += '"><img src="/Common/images/processing.gif" width="175" height="60" border="0" >';
		strBumperImage += '</div>';

  		document.getElementById(divId).innerHTML = strBumperImage;
}

//this function is used in the website_preference for the HIDE_CUSTOMISED_GMAP_MARKERS

function allowCustomisedGoogleMapMarkersSelection() {

	var psud = document.getElementById('PROPERTY_SEARCH_UNFILTERED_DISPLAY');
	var psfd = document.getElementById('PROPERTY_SEARCH_FILTERED_DISPLAY');
	var hcgm = document.getElementById('HIDE_CUSTOMISED_GMAP_MARKERS');

		if( 'google_maps' == psud.value || 'google_maps' == psfd.value ) {
			hcgm.disabled = false;
		}else {
			hcgm.disabled = true;
			hcgm.checked = false;
		}
}

/***** Print Content *****/

function printContent(id,cssFile,printImmediately, headerHTML, footerHTML) {

	var contentID = unescape(id);

	var cssFile = unescape(cssFile);
	var headerHTML = unescape(headerHTML);
	var footerHTML = unescape(footerHTML);
	if (document.getElementById)
	var contentTag = document.getElementById(id);
	else if (document.all)

	var contentTag = document.all[id];
	else if (document.layers)
	var contentTag = document.layers[id];

	if (! contentTag) contentTag = document.body;

	printWin = window.open( '#' ,'','')

	printWin.document.writeln('<html><head>');
	printWin.document.writeln('<title>Print</title>');

	if (cssFile){
		if('application_css' == cssFile ) {
			printWin.document.writeln('<link href="/Common/css/common.css" rel="stylesheet" type="text/css" />')	;
			printWin.document.writeln('<link href="/Common/css/grid_engine/common_components.css" rel="stylesheet" type="text/css" />')	;
			printWin.document.writeln('<link href="/Common/css/grid_engine/common_application_components.css" rel="stylesheet" type="text/css" />')	;

		} else {
			printWin.document.writeln('<link href="/css/'+cssFile+'" rel="stylesheet" type="text/css" />')	;
		}
	}

	printWin.document.writeln('</head><body><table><tr><td style="width:750px;">');
	printWin.document.writeln(headerHTML);
	strContent = contentTag.innerHTML.replace('id="paginationTable"','style="display:none";');

	/*for hiding 2 print buttons*/
	strContent = strContent.replace('print_application.gif','1x1pix.gif');
	strContent = strContent.replace('print_application.gif','1x1pix.gif');
	/*hiding select on ledger page*/
	strContent = strContent.replace('>Select<','');
	/*for hiding back button in all browsers*/
	strContent = strContent.replace('id=backButton','style="display:none;"');
	strContent = strContent.replace('id="backButton"','style="display:none;"');
	strContent = strContent.replace('id=logos','style="display:block;"');
	strContent = strContent.replace('id="logos"','style="display:block;"');
	strContent = strContent.replace("FILTER: progid:DXImageTransform.Microsoft.Gradient(endColorstr='#dfdfdf', startColorstr='#ffffff', gradientType='0');",'');
	printWin.document.writeln(strContent)
	printWin.document.writeln(footerHTML);
	printWin.document.writeln('</td></tr></table></body></html>')	;
	printWin.document.close();
	if(window.focus) printWin.focus();
	if(printImmediately) printWin.print();
}

/** we will eventully replacing the "showWaitingImage" with the following one function. KAL **/
function showLoadingImage( divId ) {
	
	var strBumperImage = '<div style="background: url(/Common/images/loading_img.gif) center center no-repeat;';
	var objDiv = document.getElementById(divId);

	if( objDiv && 0 < objDiv.clientWidth )
	strBumperImage += ' width:' + objDiv.style.width + 'px;';

	if( objDiv && 0 < objDiv.clientHeight ) {
		strBumperImage += ' height:' + objDiv.clientHeight + 'px;';
	} else {
		strBumperImage += ' height:50px;';
	}
	
	strBumperImage += '">';
	strBumperImage += '</div>';

	if( objDiv ) {
		objDiv.innerHTML = strBumperImage;
	}	
}

ajaxRequest = function(strDivId, strRequestUrl, options) {
	options = options || {};
	var defaultOptions = {url: strRequestUrl, type: 'POST', beforeSend: function(request,options){showLoadingImage(strDivId)}, success: function(html){jQuery('#'+strDivId).html(html)}};
	options = jQuery.extend({},defaultOptions,options);
	jQuery.ajax(options);
}
this.ajaxRequest = ajaxRequest;
