if(typeof window['iQ'] == "undefined"){
	window['iQ'] = new Object();
}

window.iQ['Utils'] = new Object();

var objUtilsFormProcessing=null;

iQ.Utils.getFieldValue = function(sForm,sField){
	var sRetVal = '';
	var objDoc = document;
	var objForm = objDoc.forms[sForm];
	var objField = objForm.elements[sField];
	
	if(typeof objField == 'undefined'){
		return 'undefined';
	}

	var sRetVal = '';
	var arrVals = [];
	var fieldLen = objField.length;
	var fieldType = objField.type;

	if(typeof fieldLen == 'undefined'){
		arrVals.push(objField.value);
	}else{
		switch (fieldType){
			case "select-multiple":
				for(var i = 0; i < objField.length; i++){
					if(objField[i].selected){
						arrVals.push( objField[i].value );
					}
				}

				break;
			
			case "select-one":
				for(var i = 0; i < objField.length; i++){
					if(objField[i].selected){
						arrVals.push( objField[i].value );
						break; //Since we know we only need 1 value break out of the loop to prevent looping for no reason
					}
				}

				break;

			default: //this will happen for checkboxes and radio buttons
				for(var i = 0; i < objField.length; i++){
					if(objField[i].type == 'checkbox' || objField[i].type == 'radio'){
						if(objField[i].checked){
							arrVals.push( objField[i].value);
						}
					}else{
						arrVals.push( objField[i].value);
					}
				}

				break;
		}
	}
	
	return arrVals.join(",");
}

iQ.Utils.setFieldValue = function(sForm, sField, sValue){
	var objDoc = document;
	var objForm = objDoc.forms[sForm];
	var objField = objForm.elements[sField];
	
	if(typeof objField == 'undefined'){
		return 'undefined';
	}

	var fieldLen = objField.length;
	var fieldType = objField.type;

	//alert(sValue);

	var arrValue = sValue.toString().split(",");

	var sCurrValue = ''

	for(var a = 0; a < arrValue.length; a++){
		sCurrValue = arrValue[a];

		if(typeof fieldLen == 'undefined'){
			objField.value = sValue;
		}else{
			switch (fieldType){
				case "select-multiple":
					for(var i = 0; i < fieldLen; i++){
						var tmpValue = ',' + sValue + ',';
						var tmpCurrValue = ',' + objField[i].value + ',';
						
						if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
							objField[i].selected = true;
						}
					}
	
					break;
				
				case "select-one":
					for(var i = 0; i < fieldLen; i++){
						var tmpValue = ',' + sValue + ',';
						var tmpCurrValue = ',' + objField[i].value + ',';
						
						if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
							objField[i].selected = true;
							break; //Since we know we only need 1 value break out of the loop to prevent looping for no reason
						}
					}
	
					break;
	
				default: //this will happen for checkboxes and radio buttons
					for(var i = 0; i < fieldLen; i++){
						if(objField[i].type == 'checkbox' || objField[i].type == 'radio'){
							var tmpValue = ',' + sValue + ',';
							var tmpCurrValue = ',' + objField[i].value + ',';
							
							if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
								objField[i].checked = true;
							}else{
								objField[i].checked = false;
							}
						}else{
							objField[i].value = sCurrValue;
						}
					}
	
					break;
			}
		}
	}
	return true;
}


/*iQ.Utils.setFieldValue = function(sForm, sField, sValue){
	var sRetVal = '';
	var arrElms = iQ.Utils.getInputFields(sForm,sField);

	if(arrElms.length == 0){
		return 'undefined';
	}

	for(var e=0; e<arrElms.length; e++){
		var objCurrInput = arrElms[e];
		var sCurrValue ='';

		switch (objCurrInput.type){
			case "radio":
				if(objCurrInput.value == sValue){
					objCurrInput.checked = true;	
				}
				else{
					objCurrInput.checked = false;
				}
				break;
	
			case "checkbox":	
				
				var tmpValue = ',' + sValue + ',';
				var tmpCurrValue = ',' + objCurrInput.value + ',';
				
				if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
					objCurrInput.checked = true;	
				}
				else{							
					objCurrInput.checked = false;
				}
			
				break;
	
			case "select-one":
				//alert(sValue);
				var optionsLength = objCurrInput.options.length;

				for (var j = 0; j < optionsLength; j++){
					var currOption = objCurrInput.options[j];
					if(currOption.value == sValue){
						currOption.selected = true;
						break;
					}					
				}
				break;				

			case "select-multiple":
				var optionsLength = objCurrInput.options.length;

				for (var j = 0; j < optionsLength; j++){
					var currOption = objCurrInput.options[j];
					
					if(currOption.value != ''){
						//single numeric value will cause 'indexOf' to fail	
						
						var tmpValue = ',' + sValue + ',';
						var tmpCurrValue = ',' + currOption.value + ',';
						
						if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
							currOption.selected = true;							
						}
					}					
				}
				break;				
			
			default:
			
				objCurrInput.value = sValue;
				break;
		}
	}

	return sRetVal;
}
*/

iQ.Utils.getBrowserObject = function(sID){
	var retOBJ = document.layers ? document.layers[sID] :
	document.getElementById ?  document.getElementById(sID) :
	document.all[sID];
	
	if(retOBJ){
		return retOBJ;
	}else{
		//alert(sID + ' is not an object');
		return false;
	}
}

iQ.Utils.getFormObject = function(sForm,sField,sObject){
	var objFormElms = document.getElementsByTagName('form');

	for (var i=0; i<objFormElms.length; i++){
		var currForm = objFormElms[i];
		if(currForm.name == sForm || currForm.id == sForm){
			var objFormElms = currForm.getElementsByTagName(sObject);
			for (var j=0; j<objFormElms.length; j++){
				var currElm = objFormElms[j];

				if(currElm.name == sField ||currElm.id == sField){
					return currElm;
				}
			}
		}
	}

	return null;
}

/*iQ.Utils.getInputFields = function(sForm,sField){
	var arrElms = new Array();

	if(sForm != ''){
		var objFormElms = document.getElementsByTagName('form');

		var formsLength = objFormElms.length;

		for (var i = 0; i < formsLength; i++){
			var currForm = objFormElms[i];

			if(currForm.name == sForm || currForm.id == sForm){
				var elmsLength = currForm.elements.length;
				for (var j=0; j < elmsLength; j++){

					var currElm = currForm.elements[j];

					if(currElm.name == sField || currElm.id == sField){
						arrElms.push(currElm);
					}
				}
				//Found the Form so break out of the loop
				break;
			}
		}
	}else{
		var arrInputs = new Array("select","input","select-multiple","textarea");
		
		for(var iCurrInput = 0; iCurrInput<arrInputs.length; iCurrInput++){
			var objFormElms = document.getElementsByTagName(arrInputs[iCurrInput]);

			for (var i=0; i<objFormElms.length; i++){
				var currForm = objFormElms[i];
				if(currForm.name == sForm || currForm.id == sForm){
					for (var j=0; j<currForm.elements.length; j++){
						var currElm = currForm.elements[j];
						if(currElm.name == sField || currElm.id == sField){
							arrElms.push(currElm);
						}
					}
				}
			}
		}
	}

	return arrElms;
}*/

iQ.Utils.StringBuffer = function(){ 
   this.buffer = []; 
   this.append = iQ.Utils.StringBufferAppend;
   this.tostring = iQ.Utils.StringBufferToString;
   return this;
} 

iQ.Utils.StringBufferAppend = function(string){
   this.buffer.push(string); 
   return this; 
}

iQ.Utils.StringBufferToString = function() { 
   return this.buffer.join(""); 
}


iQ.Utils.getLabel = function(sLabel){
	if(typeof LABELS == 'undefined'){
		return sLabel;
	}else{
		tLabel = 'LABELS.' + sLabel.toLowerCase();
		if(typeof eval(tLabel) == 'undefined'){
			return sLabel;
		}else{
			tLabel = 'LABELS.' + sLabel.toLowerCase();
			return eval(tLabel);
		}
	}
}

iQ.Utils.SetCookie = function( name, value, expires){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}

	//We have to do this becasue of IE Sucking so BAD
	//If you dont do this then you get duplicate Cookies when you use CF
	var tDomain =  window.location.host.toLowerCase();
	//tDomain = tDomain.replace('www.','');

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name.toUpperCase() + "=" + escape(value) +
		( ( expires ) ? "; expires=" + expires_date.toGMTString() : "" ) + 
		( "; path=/" ) + 
		( "; domain=" + tDomain );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
iQ.Utils.GetCookie = function( name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name.toUpperCase() == name.toUpperCase()){
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}

// this deletes the cookie when called
iQ.Utils.DeleteCookie = function( name, path, domain ) {
	if ( iQ.Utils.GetCookie( name ).toUpperCase()) document.cookie = name.toUpperCase() + "=" +
	( ( path ) ? ";path=" + path : ";path=/") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

iQ.Utils.Left = function(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

iQ.Utils.Right = function(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

iQ.Utils.Mid = function(str, start, len){
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}

iQ.Utils.IsNumeric = function(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
	   Char = sText.charAt(i); 
	   if (ValidChars.indexOf(Char) == -1) 
	   {
	      IsNumber = false;
	   }
   }

   return IsNumber;   
}

iQ.Utils.PadLeft = function(val, ch, num) {
     var re = new RegExp(".{" + num + "}$");
     var pad = "";
     if (!ch) ch = " ";
     do  {
         pad += ch;
     }while(pad.length < num);
     return re.exec(pad + val);
}

iQ.Utils.PadRight = function(val, ch, num){
     var re = new RegExp("^.{" + num + "}");
     var pad = "";
     if (!ch) ch = " ";
     do {
         pad += ch;
     } while (pad.length < num);
     return re.exec(val + pad);
}

iQ.Utils.NumberFormat = function(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

iQ.Utils.DecimalFormat = function(intNum){
	return Math.round(intNum*100)/100;
}

iQ.Utils.ShortenString = function(str, n){
	if (n <= 0)
	    return str;
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n) + '...';
}

iQ.Utils.getContentsWidth = function(obj){
	var iWidth = 0;

	if (document.layers) {
		iWidth = obj.document.width;
	}else if(document.all) {
		iWidth = obj.clientWidth;
	}else{
		iWidth = obj.clientWidth;
	}

	return iWidth;
}

iQ.Utils.getContentsHeight = function(obj){
	var iHeight = 0;

	if (document.layers) {
		iHeight = obj.document.height;
	}else if(document.all) {
		iHeight = obj.clientHeight;
	}else{
		iHeight = obj.clientHeight;
	}

	return iHeight;
}

iQ.Utils.getLeft = function(obj){
	var iLeft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			iLeft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		iLeft += obj.x;
	return iLeft;
}

iQ.Utils.getTop = function(obj){
	var iTop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			iTop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		iTop += obj.y;
	return iTop;
}

iQ.Utils.GetTimeFromSeconds = function(time){
	if(time == null){
	   return("");
	}

	if(time > 60){                                 // if time == 100
	   var seconds = time % 60;       // seconds == 40
	   var minutes = time - seconds;  // minutes == 60
	   minutes = minutes / 60;    // minutes == 1

	   if(minutes > 60){                                     // if minutes == 100
		  var minLeft = minutes % 60;        // minLeft    == 40
		  var hours = minutes - minLeft;   // hours      == 60
		  hours = hours / 60;          // hours      == 1

		  return(hours + ' hour(s)<br>' + minLeft + ' min(s)');
	   }else{
		  return(minutes + ' min(s)');
	   }
	}else{
	   return('< 1 min');
	}
}

iQ.Utils.toggleDropDown = function(sID,sText){
	var objDD = iQ.Utils.getBrowserObject(sID);
	var objDDLabel = iQ.Utils.getBrowserObject(sID + '_Text');

	if(objDD.className == 'iQ_DropDown_Menu iQ_Visible'){
		objDD.className = 'iQ_DropDown_Menu iQ_Hidden';
	}else{
		objDD.className = 'iQ_DropDown_Menu iQ_Visible';
	}
	
	if(sText){
		objDDLabel.innerHTML = sText;
	}
}

iQ.Utils.ShowLeadForm = function(sourcename,ml_number,publicid){
	
	var render_sourcename = 'Src_' + sourcename;
	//replace space - g = global
	render_sourcename = render_sourcename.replace(/ /g, '_');
	
	try{
		iQ.Utils.setFieldValue(render_sourcename + '_Form','ML_Number',ml_number);
		iQ.Utils.setFieldValue(render_sourcename + '_Form','PublicID',publicid);
	}
	catch(e)
 	{		

	}

	eval("obj" + render_sourcename + "_Panel.center()");
	eval("obj" + render_sourcename + "_Panel.show()");	
}

iQ.Utils.HideLeadForm = function(sourcename){
	
	var render_sourcename = 'Src_' + sourcename;
	//replace space - g = global
	render_sourcename = render_sourcename.replace(/ /g, '_');
		
	eval("obj" + render_sourcename + "_Panel.hide()");	
}

iQ.Utils.BuildAjaxParamStruct = function(formid)
{
	var frm = iQ.Utils.getBrowserObject(formid);				
	
	var rtn = ''
    
    var arrInputs = new Array("select","input","select-multiple","textarea");
		
    for(var iCurrInput = 0; iCurrInput < arrInputs.length; iCurrInput++){
    
        var inputs = frm.getElementsByTagName(arrInputs[iCurrInput]); 

        for (var i = 0; i < inputs.length; i++) {                	
        	if(i > 0 && inputs[i].name == inputs[i-1].name) continue;
            
            if(rtn != '') rtn += ',';
            rtn += '"' + inputs[i].name + '"'; 
            rtn += ':';
            rtn += '"' + encodeURIComponent(iQ.Utils.getFieldValue(formid,inputs[i].name)) + '"';
        }    
    }
	return rtn;
}

var objUtilsProcessing = null

iQ.Utils.doShowProcessing = function(){	
	if(!objUtilsProcessing){
		objUtilsProcessing = 
			new YAHOO.widget.Panel("FormProcessing",  
					{
						width:"240px",
						height:"60px",
						close:false, 
						draggable:false, 
						zindex:520,
						modal: true,
						visible: false					
					} 
				);
	
		objUtilsProcessing.setHeader('Processing data, please wait...');
		objUtilsProcessing.setBody('<img src="/js/iQ/Assets/loading.gif"/>');
		objUtilsProcessing.render(document.body);
	}

	objUtilsProcessing.center();
	objUtilsProcessing.show();
}

iQ.Utils.doHideProcessing = function(){
	objUtilsProcessing.hide();
}

var objUtilsAudioPanel = null;
var objUtilsAudioPlayer = null;

iQ.Utils.doPlayAudioFile = function(sAudioFile){
	if(objUtilsAudioPanel == null){

		var objStringBuffer = new iQ.Utils.StringBuffer();
		objStringBuffer.append('<div id="AudioPanel">');
			objStringBuffer.append('<div class="hd">Audio Player</div>');
			objStringBuffer.append('<div class="bd">');
				objStringBuffer.append('<object id="AudioPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" height="45" width="200">');
					objStringBuffer.append('<param name="autoStart" value="false">');
					objStringBuffer.append('<param name="ShowDisplay" value="false">');
					objStringBuffer.append('<param name="URL" value="' + sAudioFile + '">');
				objStringBuffer.append('</object>');
			objStringBuffer.append('</div>');	
		objStringBuffer.append('</div>');

		var onClose = function() {
			objUtilsAudioPlayer.controls.stop();
			this.cancel()
		};

		objUtilsAudioPanel =
			new YAHOO.widget.Dialog("AudioPanelWrapper",
				{	
					disply:"table",
					width:"320px",
					visible:false,
					draggable:true,
					close:false,
					constraintoviewport:false,				
					modal:false,
					zindex:520,
					fixedcenter:true,
					buttons : [ { text:"Close", handler:onClose } ]
				}
			);        

		objUtilsAudioPanel.setHeader('Audio Player');
		objUtilsAudioPanel.setBody(objStringBuffer.tostring());
		
		objUtilsAudioPanel.render(document.body);
		objUtilsAudioPlayer = iQ.Utils.getBrowserObject('AudioPlayer').object;
	}

	objUtilsAudioPanel.show();
	objUtilsAudioPlayer.controls.play();	
}

var objUtilsMessagePanel = null;

iQ.Utils.doMessagePanel = function(sTitle,sMessage){
	if(objUtilsMessagePanel == null){
		var onOk= function() {
			this.cancel()
		};

		objUtilsMessagePanel =
			new YAHOO.widget.SimpleDialog("MessagePanel",
				{
					width:"300px",
					visible:false,
					draggable:true,
					close:false,
					constraintoviewport:false,				
					modal:false,
					zindex:540,
					fixedcenter:true,
					text: sMessage,
					icon: YAHOO.widget.SimpleDialog.ICON_INFO,
					buttons : [ { text:"Ok", handler:onOk } ]
				}
			);

		objUtilsMessagePanel.setHeader(sTitle);
		objUtilsMessagePanel.render(document.body);
	}
	else{
		objUtilsMessagePanel.setHeader(sTitle);
		//we have to do this this way or the icon gets removed.
		objUtilsMessagePanel.cfg.setProperty("text", sMessage);
	}

	objUtilsMessagePanel.show();
}

var objMessageOverlay = null;

iQ.Utils.doHideMessageOverlay = function(){
	if(objMessageOverlay != null){
	   objMessageOverlay.hide();
   }
}

iQ.Utils.doShowMessageOverlay = function(sMessage,sParent,sWidth,sLR,iLRPad,sTB,iTBPad){
	var objParent = iQ.Utils.getBrowserObject(sParent);
	
	var iLeft = iQ.Utils.getLeft(objParent);
	var iTop = iQ.Utils.getTop(objParent);

	var iWidth = iQ.Utils.getContentsWidth(objParent);
	var iHeight = iQ.Utils.getContentsHeight(objParent);

	objMessageOverlay =
		new YAHOO.widget.Overlay("IQ_Overlay",
			{
				visible:false,
				width: sWidth
			}
		);

	objMessageOverlay.setBody('<div onclick="iQ.Utils.doHideMessageOverlay();">' + sMessage + '</div>');
	objMessageOverlay.render(document.body);

	var objOverlayDiv = iQ.Utils.getBrowserObject("IQ_Overlay");
	var iOverlayWidth = iQ.Utils.getContentsWidth(objOverlayDiv);
	var iOverlayHeight = iQ.Utils.getContentsHeight(objOverlayDiv);

	//Set the default to center the overlay from left to right
	var iX = iLeft + (iWidth / 2) - iOverlayWidth / 2;

	if(sLR.toLowerCase() == 'left'){
		var iX = iLeft;	
	}

	if(sLR.toLowerCase() == 'right'){
		var iX = iLeft + iWidth - iOverlayWidth;
	}

	//Set the default to center the overlay from top to bottom
	var iY = iTop + (iHeight / 2) - iOverlayHeight / 2;

	if(sTB.toLowerCase() == 'top'){
		var iY = iTop;	
	}

	if(sTB.toLowerCase() == 'bottom'){
		var iX = iTop + iHeight - iOverlayHeight;
	}

	objMessageOverlay.cfg.setProperty("xy", [iX + iLRPad,iY + iTBPad]);
	objMessageOverlay.show();
}

iQ.Utils.doErrorPanel = function(sMessage){
	var ErrorWindow = window.open('about:blank','resizeable=true');

	ErrorWindow.document.writeln(sMessage);
}

iQ.Utils.ToggleDiv = function(szDivID,ImageName,BlockImagePath,NoneImagePath) {
	//get correct object per browser
	var obj = document.layers ? document.layers[szDivID] :
	document.getElementById ?  document.getElementById(szDivID).style :
	document.all[szDivID].style;

	if(obj.display == 'block'){
		obj.display = 'none';			
		iQ.Utils.ToggleImage('none',ImageName,NoneImagePath);
	}else{
		obj.display = 'block';			
		iQ.Utils.ToggleImage('block',ImageName,BlockImagePath);
	}
}

iQ.Utils.ToggleImage = function(State,ImageName,ImagePath){
	if (ImageName != ""){
		if (document.images){
			if(State == 'block'){
				document.images[ImageName].src= ImagePath;
			}else{
				document.images[ImageName].src= ImagePath;
			}
		}
	}
}


iQ.Utils.doAjaxResultPaging = function(numeralcount,iqversion,startpage,totalrows,maxrows,nextpagefunction,pagingdivid){
	var intTotalPages = Math.ceil(totalrows / maxrows);
	var intStartLoop = 0;
	var intEndLoop = 0;

	if(intTotalPages <= numeralcount){
		intStartLoop = 1;
		intEndLoop = intTotalPages;
	}else{
		var middlePage = Math.floor(numeralcount / 2);

		if(startpage <= middlePage){
			intStartLoop = 1;
		}else{
			intStartLoop = startpage - middlePage;
		}

		intEndLoop = intStartLoop + eval(numeralcount - 1);

		if(intEndLoop >= intTotalPages){
			intStartLoop = intTotalPages - eval( numeralcount - 1);
			intEndLoop = intTotalPages;
		}
	}
	
	//alert(intStartLoop);
	
	var theData = '<ul class="iQ_Paging">';
		
		if(startpage > 1 ){
			theData += '<li><a href="javascript:void(0);" class="iQ_First_On"><img border="0" src="/Images/spacer.gif" onClick="' + nextpagefunction + '(1);" /></a></li>';
			theData += '<li><a href="javascript:void(0);" class="iQ_Previous_On"><img border="0" src="/Images/spacer.gif" onClick="' + nextpagefunction + '(' + eval(startpage - 1) + ');" /></a></li>';				
		}else{
			theData += '<li><a class="iQ_First_Off" href="javascript:void(0);"><img border="0" src="/Images/spacer.gif" /></a></li>';
			theData += '<li><a class="iQ_Previous_Off" href="javascript:void(0);"><img border="0" src="/Images/spacer.gif" /></a></li>';
		}

		theData += '<li width="15" class="iQ_Blank">&nbsp;</li>';

		for(i=intStartLoop; i <= intEndLoop;  i++){
			if(i == startpage){
				theData += '<li><a class="iQ_On" href="javascript:void(0);">' + startpage + '</a></li>';
			}else{
				theData += '<li><a href="javascript:void(0);" onMouseOver="this.className=\'iQ_Over\'" onMouseOut="this.className=\'iQ_Off\'" class="iQ_Off" onClick="' + nextpagefunction + '(' + i + ');">' + i + '</a></li>';
			}
		}

		if(intTotalPages - 1 > i){
			theData += '<li class="iQ_Blank">...</li>';
			theData += '<li><a href="javascript:void(0);" onMouseOver="this.className=\'iQ_Over\'" onMouseOut="this.className=\'iQ_Off\'" class="iQ_Off" class="iQ_Off" onClick="' + nextpagefunction + '(' + eval(intTotalPages - 1) + ');">' + eval(intTotalPages - 1) + '</a></li>';
			theData += '<li><a href="javascript:void(0);" onMouseOver="this.className=\'iQ_Over\'" onMouseOut="this.className=\'iQ_Off\'" class="iQ_Off" class="iQ_Off" onClick="' + nextpagefunction + '(' + intTotalPages + ');">' + intTotalPages + '</a></li>';
		}

		theData += '<li width="15" class="iQ_Blank">&nbsp;</li>';
		
		if(startpage < intTotalPages){
			theData += '<li><a href="javascript:void(0);" class="iQ_Next_On" onClick="' + nextpagefunction + '(' + eval(parseInt(startpage,10) + 1) + ');"><img border="0" src="/Images/spacer.gif" /></a></li>';
			theData += '<li><a href="javascript:void(0);" class="iQ_Last_On" onClick="' + nextpagefunction + '(' + intTotalPages + ');"><img border="0" src="/Images/spacer.gif" /></a></li>';
		}else{
			theData += '<li><a class="iQ_Next_Off" href="javascript:void(0);"><img border="0" src="/Images/spacer.gif" /></a></li>';
			theData += '<li><a class="iQ_Last_Off" href="javascript:void(0);"><img border="0" src="/Images/spacer.gif" /></a></li>';
		}
		
	theData += '</ul>';

	//alert(theData);
	
	var objPagingDiv = iQ.Utils.getBrowserObject(pagingdivid);
	objPagingDiv.innerHTML = theData;
	objPagingDiv.style.display = 'block';
}

var objUtilsPropertyDetailsPanel = null;
var strUtilsPropertyDetailsML = null;

iQ.Utils.doPropertyDetailsPanel = function(sPropertyType,sML_Number,sDisplayML_Number){
	if(objUtilsPropertyDetailsPanel == null){

		objUtilsPropertyDetailsPanel =
			new YAHOO.widget.Panel("DetailsPanel",
				{	
					disply:"table",
					width:"600px",
					visible:false,
					draggable:true,
					close:true,
					constraintoviewport:true,				
					modal:false,
					zindex:530
				}
			);        

		objUtilsPropertyDetailsPanel.setHeader('Property Details: ' + sDisplayML_Number);
		objUtilsPropertyDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Property Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');
		objUtilsPropertyDetailsPanel.render(document.body);
	}

	//This will prevent a call to server if someone clicks the same property twice
	if(strUtilsPropertyDetailsML != sML_Number){
		strUtilsPropertyDetailsML = sML_Number;
		objUtilsPropertyDetailsPanel.setHeader('Property Details: ' + sDisplayML_Number);
		objUtilsPropertyDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Property Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');	
		iQ.Utils.doPropertyDetailsPanelData(sPropertyType,sML_Number,sDisplayML_Number);
	}
	
	objUtilsPropertyDetailsPanel.center();
	objUtilsPropertyDetailsPanel.show();
}

iQ.Utils.doPropertyDetailsPanelData = function(sPropertyType,sML_Number,sDisplayML_Number){
	var params = '"SelectedLanguage":"' + encodeURIComponent(iQ.Utils.GetCookie('SelectedLanguage')) + '",'
	params += '"ML_Number":"' + encodeURIComponent(sML_Number) + '",';
	params += '"PropertyType":"' + encodeURIComponent(sPropertyType) + '",';
	params += '"ReturnType":"BOTH"';
	
	var _Ajax = new iQ.Ajax();
	_Ajax.CFCMethod = 'getPropertyDetails';
	_Ajax.URL = '/websvc/Listings.cfc';        
    _Ajax.Params = {Params:'{' + params + '}'};	
	_Ajax.CallbackHandler = "iQ.Utils.onPropertyDetailsPanelData";	
	_Ajax.Send();	

	var hitparams = '"ML_Number":"' + encodeURIComponent(sML_Number) + '",';
	hitparams += '"PropertyType":"' + encodeURIComponent(sPropertyType) + '",';
	hitparams += '"Refer":"Property Quick Details",';	
	hitparams += '"TrackingID":"' + encodeURIComponent(iQ.Utils.GetCookie('TrackingID')) + '"';

	var _AjaxHit = new iQ.Ajax();
	_AjaxHit.CFCMethod = 'AddMLHit';
	_AjaxHit.URL = '/websvc/Hits.cfc';        
    _AjaxHit.Params = {Params:'{' + hitparams + '}'};	
	_AjaxHit.Send();
}

iQ.Utils.onPropertyDetailsPanelData = function(jsonData){
	objUtilsPropertyDetailsPanel.setBody(jsonData.HTML);
	objUtilsPropertyDetailsPanel.center();

	$.iqListingImages('iQ_PropertyPhoto','photo');
}

iQ.Utils.ClearForm = function(sForm){
	
	var objForm = iQ.Utils.getBrowserObject(sForm);
		
	var arrInputs = new Array("select","input","select-multiple","textarea");
		
	for(var iCurrInput = 0; iCurrInput<arrInputs.length; iCurrInput++){
	
		var objInputs = objForm.getElementsByTagName(arrInputs[iCurrInput]);
		
		for (var i=0; i<objInputs.length; i++){
			var objCurrInput = objInputs[i];
	
			switch (objCurrInput.type){
				case "radio":
					objCurrInput.checked = false;			
					break;
		
				case "checkbox":
					objCurrInput.checked = false;			
					break;
				
				case "select-multiple":
					if(objCurrInput.options.length){
						objCurrInput.options[0].selected = true;
						for (j=1;j<objCurrInput.options.length; j++){
							objCurrInput.options[j].selected = false;					
						}
					}
				
					break;	
				
				case "select-one":
					if(objCurrInput.options.length){
						objCurrInput.options[0].selected = true;
						for (j=1;j<objCurrInput.options.length; j++){
							objCurrInput.options[j].selected = false;					
						}
					}
				
					break;	
							
				default:
					objCurrInput.value = '';
					break;
			}
			
			
		}
			
	}
	
	return;	
}	

iQ.Utils.GetGUID = function(){
	var result, i, j;
	result = '';
	for(j=0; j<32; j++)
	{
		if( j == 8 || j == 12|| j == 16|| j == 20)
		result = result + '-';
		i = Math.floor(Math.random()*16).toString(16).toUpperCase();
		result = result + i;
	}
	return result
}

iQ.Utils.GetTrackingID = function(){
	if(iQ.Utils.GetCookie('TrackingID') == null || iQ.Utils.GetCookie('TrackingID') == ''){
		//it is not there let's set it
		var tID = iQ.Utils.GetGUID();
		iQ.Utils.SetCookie('TrackingID', tID, '', '/', '', false);
	}else{
		var tID = iQ.Utils.GetCookie('TrackingID');
	}

	return tID;
}

iQ.Utils.HidePopupDiv = function(sID){
	var dvUploadID = "div_" + sID;
	var ifUploadID = "iframe_" + sID;

	var elmDIV = iQ.Utils.getBrowserObject(dvUploadID).style;
	var elmIFRAME = iQ.Utils.getBrowserObject(ifUploadID).style;

	elmDIV.left = -1000;
	elmDIV.top = -1000;
	elmDIV.visibility = 'hidden';
	elmDIV.display = 'none';		

	elmIFRAME.left = 1000;
	elmIFRAME.top = -1000;
	elmIFRAME.visibility = 'hidden';
	elmIFRAME.display = 'none';		
}

iQ.Utils.ShowPopupDiv = function(sID,iWidth,iHeight){
	var dvUploadID = "div_" + sID;
	var ifUploadID = "iframe_" + sID;

	var formWidth = iWidth;
	var formHeight = iHeight;

	var screenWidth = 0, screenHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		screenWidth = window.innerWidth; screenHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		screenWidth = document.documentElement.clientWidth; screenHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		screenWidth = document.body.clientWidth; screenHeight = document.body.clientHeight;
	}

	var scrollWidth = 0, scrollHeight = 0;
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrollHeight = window.pageYOffset; scrollWidth = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrollHeight = document.body.scrollTop; scrollWidth = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrollHeight = document.documentElement.scrollTop; scrollWidth = document.documentElement.scrollLeft;
	}

	var elmDIV = iQ.Utils.getBrowserObject(dvUploadID).style;
	var elmIFRAME = iQ.Utils.getBrowserObject(ifUploadID).style;

	var sLeft = (scrollWidth - (formWidth / 2)) + (screenWidth / 2)
	var sTop = (scrollHeight - (formHeight / 2)) + (screenHeight / 2);
	
	elmDIV.width = iWidth + 'px';
	elmDIV.height = iHeight + 'px';
	
	elmDIV.left = sLeft;
	elmDIV.top = sTop;
	elmDIV.visibility = 'visible';
	elmDIV.display = 'block';

	elmIFRAME.width = iWidth + 'px';
	elmIFRAME.height = iHeight + 'px';

	elmIFRAME.left =  sLeft;
	elmIFRAME.top = sTop;
	elmIFRAME.visibility = 'visible';
	elmIFRAME.display = 'block';
}

var objUtilsPropertyManagementDetailsPanel = null;
var strUtilsPropertyManagementDetailsML = null;

iQ.Utils.doPropertyManagementDetailsPanel = function(sPropertyType,sML_Number,sDisplayML_Number){
	if(objUtilsPropertyManagementDetailsPanel == null){

		objUtilsPropertyManagementDetailsPanel =
			new YAHOO.widget.Panel("DetailsPanel",
				{	
					disply:"table",
					width:"560px",
					visible:false,
					draggable:true,
					close:true,
					constraintoviewport:true,				
					modal:false,
					zindex:530
				}
			);        

		objUtilsPropertyManagementDetailsPanel.setHeader('Property Details: ' + sDisplayML_Number);
		objUtilsPropertyManagementDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Property Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');
		objUtilsPropertyManagementDetailsPanel.render(document.body);
	}

	//This will prevent a call to server if someone clicks the same property twice
	if(strUtilsPropertyManagementDetailsML != sML_Number){
		strUtilsPropertyManagementDetailsML = sML_Number;
		objUtilsPropertyManagementDetailsPanel.setHeader('Property Details: ' + sDisplayML_Number);
		objUtilsPropertyManagementDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Property Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');	
		iQ.Utils.doPropertyManagementDetailsPanelData(sPropertyType,sML_Number,sDisplayML_Number);
	}
	
	objUtilsPropertyManagementDetailsPanel.center();
	objUtilsPropertyManagementDetailsPanel.show();
}

iQ.Utils.doPropertyManagementDetailsPanelData = function(sPropertyType,sML_Number,sDisplayML_Number){
	var params = '"SelectedLanguage":"' + encodeURIComponent(iQ.Utils.GetCookie('SelectedLanguage')) + '",'
	params += '"ML_Number":"' + encodeURIComponent(sML_Number) + '",';
	params += '"PropertyType":"' + encodeURIComponent(sPropertyType) + '",';
	params += '"ReturnType":"BOTH"';
	
	var _Ajax = new iQ.Ajax();
	_Ajax.CFCMethod = 'getPropertyDetails';
	_Ajax.URL = '/websvc/Leasing.cfc';        
    _Ajax.Params = {Params:'{' + params + '}'};	
	_Ajax.CallbackHandler = "iQ.Utils.onPropertyManagementDetailsPanelData";	
	_Ajax.Send();	

	var hitparams = '"ML_Number":"' + encodeURIComponent(sML_Number) + '",';
	hitparams += '"PropertyType":"' + encodeURIComponent(sPropertyType) + '",';
	hitparams += '"Refer":"Property Quick Details",';	
	hitparams += '"TrackingID":"' + encodeURIComponent(iQ.Utils.GetCookie('TrackingID')) + '"';

	var _AjaxHit = new iQ.Ajax();
	_AjaxHit.CFCMethod = 'AddMLHit';
	_AjaxHit.URL = '/websvc/Hits.cfc';        
    _AjaxHit.Params = {Params:'{' + hitparams + '}'};	
	_AjaxHit.Send();
}

iQ.Utils.onPropertyManagementDetailsPanelData = function(jsonData){
	objUtilsPropertyManagementDetailsPanel.setBody(jsonData.HTML);
	objUtilsPropertyManagementDetailsPanel.center();	
}

var objUtilsOpenHouseDetailsPanel = null;
var strUtilsOpenHouseDetailsML = null;

iQ.Utils.doOpenHouseDetailsPanel = function(sML_Number){
	if(objUtilsOpenHouseDetailsPanel == null){

		objUtilsOpenHouseDetailsPanel =
			new YAHOO.widget.Panel("DetailsPanel",
				{	
					disply:"table",
					width:"300px",
					visible:false,
					draggable:true,
					close:true,
					constraintoviewport:true,				
					modal:false,
					zindex:530
				}
			);        

		objUtilsOpenHouseDetailsPanel.setHeader('Open House Details');
		objUtilsOpenHouseDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Open House Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');
		objUtilsOpenHouseDetailsPanel.render(document.body);
	}

	//This will prevent a call to server if someone clicks the same property twice
	if(strUtilsOpenHouseDetailsML != sML_Number){
		strUtilsOpenHouseDetailsML = sML_Number;
		objUtilsOpenHouseDetailsPanel.setHeader('Open House Details');
		objUtilsOpenHouseDetailsPanel.setBody('<h6 style="text-align:center; margin:5px 0 5px 0;">Retrieving Open House Details</h6><div style="margin:auto; text-align:center;"><img src="/js/iQ/Assets/loading.gif"/></div>');
		iQ.Utils.doOpenHouseDetailsPanelData(sML_Number);
	}
	
	objUtilsOpenHouseDetailsPanel.center();
	objUtilsOpenHouseDetailsPanel.show();
}

iQ.Utils.doOpenHouseDetailsPanelData = function(sML_Number){
	var params = '"SelectedLanguage":"' + encodeURIComponent(iQ.Utils.GetCookie('SelectedLanguage')) + '",'
	params += '"ML_Number":"' + encodeURIComponent(sML_Number) + '",';
	params += '"ReturnType":"BOTH"';

	var _Ajax = new iQ.Ajax();
	_Ajax.CFCMethod = 'getOpenHouseDetails';
	_Ajax.URL = '/websvc/OpenHouse.cfc';        
    _Ajax.Params = {Params:'{' + params + '}'};	
	_Ajax.CallbackHandler = "iQ.Utils.onOpenHouseDetailsPanelData";	
	_Ajax.Send();	
}

iQ.Utils.onOpenHouseDetailsPanelData = function(jsonData){
	objUtilsOpenHouseDetailsPanel.setBody(jsonData.HTML);
	objUtilsPropertyDetailsPanel.center();
}