// This function sets the sort order of the Results forms.
function ReSort(sResortURL,sField,sOrderBy,sOrderDir){
	if(sField == sOrderBy){
		if(sOrderDir == "DESC"){
			tmpOrderDir = "ASC";
		}
		if(sOrderDir == "ASC"){
			tmpOrderDir = "DESC";
		}
		sOrderDir = tmpOrderDir;
	}else{
		sOrderDir = "DESC";
	}
	self.location = sResortURL + sField + '&OrderDir=' + sOrderDir;
}

function CheckSelectedList(objForm,sFormAction){
	
	//added 09-08-08 so we can pass string instead
	// (ajax rendering issue)	
	if(typeof(objForm) == 'string'){
		var objForm = getBrowserObject(objForm);
	}
	
	if(CheckAnySelected(objForm)){
		if(sFormAction != ''){
			objForm.Action.value = sFormAction;
		}
		return true;
	}else{
		return false;
	}
}


// This function checks the Results Form to determine if something has
// been selected before doing a delete
function CheckAnySelected(objForm){
	bSelected = false;
	

	if(objForm.SelectedList.length){
		for (i=0;i<objForm.SelectedList.length; i++){
			if(objForm.SelectedList[i].checked){
				bSelected = true;
				break;
			}
		}
	}else{
		if(objForm.SelectedList.checked){
			bSelected = true;
		}
	}		

	if(bSelected){
		var bConfirm = confirm('Are you sure you want to delete?');

		if(bConfirm){
			return true;
		}else{
			return false;
		}
	}else{
		alert("Please make a selection")
		return false;
	}
}

// This function sets all the checkboxes in the Results Form
// to either checked or unchecked
function CheckAll(objForm){
	
	try{
		//added 09-08-08 so we can pass string instead
		// (ajax rendering issue)	
		if(typeof(objForm) == 'string'){
			var objForm = getBrowserObject(objForm);
		}
		
		if(objForm.SelectedList.length){
			for (i=0;i<objForm.SelectedList.length; i++){
				objForm.SelectedList[i].checked = objForm.CheckAllBoxes.checked;
			}
		}else{
			objForm.SelectedList.checked = objForm.CheckAllBoxes.checked;
		}
	}
	catch(e)
 	{		
    	return;
	}
}

function ToggleDiv(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';
		SetSession(szDivID,'none');
		ToggleImage('none',ImageName,NoneImagePath);
	}else{
		obj.display = 'block';
		SetSession(szDivID,'block');
		ToggleImage('block',ImageName,BlockImagePath);
	}
}

//new 02-20-08 - needed one w/o SetSession as above
function ToggleTree(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';			
		ToggleImage('none',ImageName,NoneImagePath);
	}else{
		obj.display = 'block';			
		ToggleImage('block',ImageName,BlockImagePath);
	}
}

function ToggleImage(State,ImageName,ImagePath){
	if (ImageName != ""){
		if (document.images){
			if(State == 'block'){
				document.images[ImageName].src= ImagePath;
			}else{
				document.images[ImageName].src= ImagePath;
			}
		}
	}
}

function SetSession(cookieName,cookieValue){
	if(parent.utilframe){
		parent.utilframe.location = '/?Page=Utils&Cat=SetSession&CookieName=' + cookieName + '&CookieValue=' + cookieValue;
	}
}

function GetFile(sPath,sFile,sDisplayName){
	parent.utilframe.location='/?Page=Utils&Cat=GetFile&FileName=' + sFile + '&Path=' + sPath + '&DisplayName=' + sDisplayName;
}

function GetFileAndDelete(sPath,sFile,sDisplayName,sDeleteFlag){
	parent.utilframe.location='/?Page=Utils&Cat=GetFile&FileName=' + sFile + '&Path=' + sPath + '&DisplayName=' + sDisplayName + '&DeleteFlag=' + sDeleteFlag;
}


function FileCabinetGetFile(sURL,sPath,sFile,sDisplayName){
	parent.utilframe.location= sURL + '?Page=Utils&Cat=GetFile&Action=GetFile&FileName=' + sFile + '&Path=' + sPath + '&DisplayName=' + sDisplayName;
}

function FileCabinetRename(sProcessPage,sRootDir,sCurrDir,sItem,sType){
	self.name='Main';
	var sWidth = 350;
	var sHeight = 75;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	fileWindow = window.open("/?Page=Utils&Cat=FileCabinetRename&ProcessPage=" + sProcessPage + "&RootDir=" + sRootDir + "&CurrDir=" + sCurrDir + "&Item=" + sItem + "&Type=" + sType, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function FileCabinetGetDir(sPage,sCurrDir,sRootDir){
	self.location = "/?Page=" + sPage + "&CurrDir=" + sCurrDir + "&RootDir=" + sRootDir;
}

function ChangeActingAs(){
	self.name='Main';
	var sWidth = 350;
	var sHeight = 75;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	fileWindow = window.open("/?Page=PopUp&Cat=ActingAs", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
}

//use full path and make sure your backslashes are flipped to forward slashes
function ShowFullImage(sImage){
	self.name='Main';
	var sWidth = 750;
	var sHeight = 550;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpRemoteWindow = window.open("/?Page=Utils&Cat=ShowFullImage&Image=" + sImage, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
}


//had to put this here - called from many pages
function Publish(sPublicationID){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpRemoteWindow = window.open("/?Page=Utils&Cat=AdManagerPublish&PublicationID=" + sPublicationID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=no,left=" + sLeft + ",top=" + sTop);
}

//had to put this here - called from many pages
function PublishPreview(sPublicationID,sCategoryID){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpRemoteWindow = window.open("/?Page=Utils&Cat=AdManagerPublish&PublicationID=" + sPublicationID + "&CategoryID=" + sCategoryID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=no,left=" + sLeft + ",top=" + sTop);
}


//Report functions

//this one called by all report wizards
function RunReport(){

	//notice how to post to a new window
	// and still control window properties
	
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);	
			
	var newWin = window.open("about:blank", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
		
	document.WizardForm.Page.value='PopUp';
	document.WizardForm.Cat.value='ReportViewer';										
	document.WizardForm.target='newWin';
	document.WizardForm.action='/Default.cfm';
	
	document.WizardForm.submit();	
	
	window.close();
}	

//these launch the wizards
function ShowVoiceReportWindow(){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=Voice", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowMLHitsReportWindow(){			
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=MLHits", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowProfileHitsReportWindow(){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=ProfileHits", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowLeadsReportWindow(){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=Leads", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowAgentsReportWindow(){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=Agents", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowContactsReportWindow(){
	self.name='Main';
	var sWidth = 700;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=ContactManagement", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowCampaignsReportWindow(PublicID){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=Campaigns&PublicID=" + PublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowChatReportWindow(){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Reports&SubCat=Chat", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}


//these run specific reports

function PrintAgent(sPublicID){

	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&PublicID=" + sPublicID + "&ReportName=Reports.Agents.SingleAgent", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
			
}	

function PrintLead(sContactID){
	
	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&ContactID=" + sContactID + "&ReportName=Reports.Leads.SingleLead&Display=SkipToPDF", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);	
		
}	

function PrintLeadHistory(sPublicID){
	
	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&PublicID=" + sPublicID + "&ReportName=Reports.Leads.AgentHistory&Display=SkipToPDF", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);	
		
}	

function PrintContact(sContactID){
	
	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&ContactID=" + sContactID + "&ReportName=Reports.ContactManagement.SingleContact&Display=SkipToPDF", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);	
		
}	

function PrintOrderSummary(sItemID){
	
	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&ItemID=" + sItemID + "&ReportName=Reports.Marketing.OrderSummary", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);	
		
}	

function PrintOrderInvoice(sItemID,sOrderID){
	
	var sWidth = 800;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	var newWin = window.open("/?Page=PopUp&Cat=ReportViewer&ItemID=" + sItemID + "&OrderID=" + sOrderID + "&ReportName=Reports.Marketing.OrderInvoice", "newWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes,menubar=no,left=" + sLeft + ",top=" + sTop);	
		
}	

//end report functions

function ChangePublicIDWindow(sPublicID){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Agents&SubCat=ChangePublicID&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ChangeUserIDWindow(sPublicID){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Agents&SubCat=ChangeUserID&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowAgentHistoryWindow(sPublicID){
	self.name='Main';
	var sWidth = 700;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=PopUp&Cat=Agents&SubCat=History&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowPropertyHistoryWindow(sML_Number,sPropertyType){
	self.name='Main';
	var sWidth = 700;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=PopUp&Cat=Properties&SubCat=History&ML_Number=" + sML_Number + "&PropertyType=" + sPropertyType, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowEmail(sFirstName,sLastName,sEmailAddress,sNoteTableName,sKeyField,sKeyValue,sReturnURL){			
	self.name='Main';
	var sWidth = 700;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
		
	tmpwin = window.open("/?Page=PopUp&Cat=Email&FirstName=" + sFirstName + "&LastName=" + sLastName + "&EmailAddress=" + sEmailAddress + '&NoteTableName=' + sNoteTableName + '&KeyField=' + sKeyField + '&KeyValue=' + sKeyValue + '&ReturnURL=' + escape(sReturnURL), "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
			
}

function ShowiQMessage(sFirstName,sLastName,sUserID,sNoteTableName,sKeyField,sKeyValue,sReturnURL){			
	self.name='Main';
	var sWidth = 700;
	var sHeight = 500;
	
	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
		
	tmpwin = window.open("/?Page=PopUp&Cat=iQMessage&SubCat=Send&FirstName=" + sFirstName + "&LastName=" + sLastName + "&UserID=" + sUserID + '&NoteTableName=' + sNoteTableName + '&KeyField=' + sKeyField + '&KeyValue=' + sKeyValue + '&ReturnURL=' + escape(sReturnURL), "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
			
}

function ShowMailMergeWindow(sPublicID,sContactID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=MailMerge&PublicID=" + sPublicID + "&ContactID=" + sContactID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function doMailMergeFromTemplate(sPublicID,sTemplateName){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=MailMerge&PublicID=" + sPublicID + "&TemplateName=" + sTemplateName, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}	

function ShowLabelMergeWindow(sPublicID){
	self.name='Main';
	var sWidth = 700;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=LabelMerge&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowUpdateRequestWindow(sPublicID){
    self.name='Main';
    var sWidth = 800;
    var sHeight = 500;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=UpdateRequest&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowLeadUpdateRequestWindow(sAction,sLeadID,sRequestDateTime){
    self.name='Main';
    var sWidth = 700;
    var sHeight = 400;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=Leads&SubCat=UpdateRequest&Action=" + sAction + "&LeadID=" + sLeadID + "&RequestDateTime=" + sRequestDateTime, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowLeadNotificationWindow(sSourceName,sTemplateType){
    self.name='Main';
    var sWidth = 800;
    var sHeight = 500;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=PopUp&Cat=Leads&SubCat=NotificationTemplates&SourceName=" + sSourceName + "&TemplateType=" + sTemplateType, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowContactPurgeWindow(sPublicID){
    self.name='Main';
    var sWidth = 700;
    var sHeight = 400;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=Purge&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowContactExportWindow(sPublicID){
    self.name='Main';
    var sWidth = 700;
    var sHeight = 400;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=Export&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowContactImportWindow(sPublicID){
    self.name='Main';
    var sWidth = 700;
    var sHeight = 400;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=ContactManagement&SubCat=Import&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowOpenHousesWindow(sAction,sPublicID,sML_Number,sDate,sStartTime){
    self.name='Main';
    var sWidth = 800;
    var sHeight = 600;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=OpenHouses&Action=" + sAction + "&PublicID=" + sPublicID + "&ML_Number=" + sML_Number + "&Date=" + sDate + "&StartTime=" + sStartTime, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowOpenHousesPromoteWindow(){
    self.name='Main';
    var sWidth = 800;
    var sHeight = 600;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=PromoteOpenHouses", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}


function ShowAgentExportWindow(){
    self.name='Main';
    var sWidth = 700;
    var sHeight = 400;

    var sLeft = ((screen.width - sWidth) / 2);
    var sTop = ((screen.height - sHeight) / 2);
    
    tmpwin = window.open("/?Page=Wizard&Cat=Agents&SubCat=Export", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);                                                                                                                                
}

function ShowFlyerWindow(sFlyerType,sML_Numbers){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Marketing&SubCat=Flyers&FlyerType=" + sFlyerType + "&ML_Numbers=" + sML_Numbers, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowOrderWindow(sOrderID,sAction){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=Orders&OrderID=" + sOrderID + '&Action=' + sAction, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowOrderZipImagesWindow(sItemID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=Marketing&SubCat=ZipImages&ItemID=" + sItemID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowOrderExportItemsWindow(sItemID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=Marketing&SubCat=ExportItems&ItemID=" + sItemID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowAdsWindow(){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=Wizard&Cat=AdManager&SubCat=Ads", "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowDirectionsWindow(sFrom,sTo){
	self.name='Main';
	var sWidth = 720;
	var sHeight = 960;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);

	tmpwin = window.open("/?Page=PopUp&Cat=Directions&To=" + sTo + "&From=" + sFrom, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=yes,menubar=no,left=" + sLeft + ",top=" + sTop);
}

function ShowCreateCampaignWindow(sPublicID,sCampaignPublicID){
	self.name='Main';
	var sWidth = 1000;
	var sHeight = 720;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=Create&PublicID=" + sPublicID + "&CampaignPublicID=" + sCampaignPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowSelectCampaignsWindow(sPublicID, sRecipientID){
	self.name='Main';
	var sWidth = 500;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=SelectCampaigns&PublicID=" + sPublicID + "&RecipientID=" + sRecipientID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowCreateCampaignTemplateWindow(sPublicID){
	self.name='Main';
	var sWidth = 1000;
	var sHeight = 720;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=CreateTemplate&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowAddRecipientWindow(sPublicID, sCampaignID, sCampaignPublicID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 500;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=Recipients&PublicID=" + sPublicID + "&CampaignID=" + sCampaignID + "&CampaignPublicID=" + sCampaignPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowCampaignCategoryWindow(sPublicID, sTable, sFormName, sFieldName){
	self.name='Main';
	var sWidth = 250;
	var sHeight = 350;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Popup&Cat=Campaigns&SubCat=Categories&PublicID=" + sPublicID + "&Table=" + sTable + "&FormName=" + sFormName + "&FieldName=" + sFieldName, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function ShowCampaignContentWindow(sPublicID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 600;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Popup&Cat=Campaigns&SubCat=Content&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=yes,left=" + sLeft + ",top=" + sTop);								
}

function ShowImageHistoryDeletionWindow(){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	window.open("/?Page=Wizard&Cat=SystemAdmin&SubCat=ImageHistory", "PropertyIDWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}


function ShowCampaignEventWindow(sCampaignID,sPublicID,sCampaignPublicID){
	self.name='Main';
	var sWidth = 1000;
	var sHeight = 720;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=CreateEvent&PublicID=" + sPublicID + "&CampaignID=" + sCampaignID + "&CampaignPublicID=" + sCampaignPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=yes,left=" + sLeft + ",top=" + sTop);								
}

function ShowCampaignTemplateEventWindow(sTemplateID,sPublicID){
	self.name='Main';
	var sWidth = 800;
	var sHeight = 600;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Wizard&Cat=Campaigns&SubCat=CreateTemplateEvent&PublicID=" + sPublicID + "&TemplateID=" + sTemplateID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=yes,left=" + sLeft + ",top=" + sTop);								
}

function ShowAgentDetailsWindow(sPublicID){
	self.name='Main';
	var sWidth = 400;
	var sHeight = 180;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
	
	tmpwin = window.open("/?Page=Popup&Cat=Agents&SubCat=Details&PublicID=" + sPublicID, "NewWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,resizable=no,left=" + sLeft + ",top=" + sTop);								
}

// *************************************
// iQWeb Functions
// *************************************

function ProfileImageSwap(ProfileImageDocName,ProfileImageSource) {
	document[ProfileImageDocName].src = ProfileImageSource;
	}

function DocsWindowResize(sTable){

	var iScreenWidth = screen.width;
	var iScreenHeight = screen.height;
	var iTableWidth = 0;
	var iTableHeight = 0;
	var iToWidth = 0;
	var iToHeight = 0;

	var obj = getBrowserObject(sTable)

	if (document.layers) {
		iTableWidth = obj.document.width + 60;
		iTableHeight = obj.document.height + 140;
	}else if(document.all){
		iTableWidth = obj.clientWidth + 60;
		iTableHeight = obj.clientHeight + 140;
	}else{
		iTableWidth = obj.clientWidth + 60;
		iTableHeight = obj.clientHeight + 140;
	}

	//if the screen width is greater then the width of the table then
	//set the width to the table width otherwise set the width to the screen width
	if(iScreenWidth > iTableWidth){
		iToWidth = iTableWidth;
	}else{
		iToWidth = iScreenWidth;
	}

	//if the screen height is greater then the height of the table then
	//set the height to the table height otherwise set the width to the screen height
	if(iScreenHeight > iTableHeight){
		iToHeight = iTableHeight;
	}else{
		iToHeight = iScreenHeight;
	}

	if(iToWidth > 0 && iToHeight > 0){
		window.resizeTo(iToWidth,iToHeight)
	}

}
// added  + '&Display=T' to the popup windows to keep the ISAPI filter from doing a search
function DocsWindow(sCat,sParams){
	self.name = 'main';

	if(sCat != ''){
		if(sParams != ''){
			sParams = '&' + sParams;
		}
		window.open('/?Page=Docs&Cat=' + sCat + sParams + '&Display=T', 'NewWin', 'width=550,height=600,toolbar=no,scrollbars=yes,menubar=no,resizable=yes');
	}
}


// ************ Just Because this is cool ***********
// function to get the width of the content
function setLabelWidth(){
	if (document.layers) {
		var Width = document.layers['TB'].document.width + "px"
		document.layers['TD'].style.width = Width;
	} else if (document.all) {
		var Width = document.all['TB'].clientWidth + "px"
		document.all['TD'].style.width = Width;
	}
}






//AJAX functions
function ajaxPost(sURL,sToPost,retFunction,bSync){
	var xmlHttpReq = false;
	var self = this;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	// IE
	}else if(window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	self.xmlHttpReq.open('POST', sURL, bSync);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			//This makes sure what ever is coming back is in between xml tags
			//This strips any site design or unwanted HTML from the return page
			var str = self.xmlHttpReq.responseText;
			var len = 0;
			var start=str.indexOf('<xml>') + 5;
			var end=str.indexOf('</xml>');
		
			if(start >= 5){
				if(end >= start){
					len = end - start;
				}
			}
		
			// Make sure start and len are within proper bounds
			if (start < 0 || len < 0){
				return "No Data Found";
			}
		
			var iEnd, iLen = String(str).length;
		
			if(start + len > iLen){
				iEnd = iLen;
			}else{
				iEnd = start + len;
			}
		
			var xmlData = String(str).substring(start,iEnd);			

			if(retFunction != ''){
				eval(retFunction + '(xmlData)');
			}else{
				return xmlData;	
			}
		}
	}
	self.xmlHttpReq.send(sToPost);
}

/*
This post is a little different you can pass it a comma seporated list of vals
they are called as part of the return function
example:
	ajaxPostAndReturn(/default.cfm,Page=Ajax,onReturn,'val1,val2,val3',false);
	
	would it is done would return function like this
		onReturn('xmlData','val1','val2'.'val3');
		
*/
		
function ajaxPostAndReturn(sURL,sToPost,retFunction,retVals,bSync){
	var xmlHttpReq = false;
	var self = this;
	var ret = ''
	
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	// IE
	}else if(window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	self.xmlHttpReq.open('POST', sURL, bSync);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			//This makes sure what ever is coming back is in between xml tags
			//This strips any site design or unwanted HTML from the return page
			var str = self.xmlHttpReq.responseText;
			var len = 0;
			var start=str.indexOf('<xml>') + 5;
			var end=str.indexOf('</xml>');
		
			if(start >= 5){
				if(end >= start){
					len = end - start;
				}
			}
		
			// Make sure start and len are within proper bounds
			if (start < 0 || len < 0){
				return "No Data Found";
			}
		
			var iEnd, iLen = String(str).length;
		
			if(start + len > iLen){
				iEnd = iLen;
			}else{
				iEnd = start + len;
			}
		
			var xmlData = String(str).substring(start,iEnd);			

			if(retFunction != ''){
				ret = retFunction;
				
				if(retVals != ''){
					var arrVals = retVals.split(',');
					if(arrVals.length > 0){
						var tmp = ''
						for (i=0;i<arrVals.length;i++){
							if(tmp == ''){
								tmp = "'" + arrVals[i] + "'";
							}else{
								tmp = tmp + ",'" + arrVals[i] + "'";
							}
						}
						eval(retFunction + '(xmlData,' + tmp + ')');
					}else{
						eval(retFunction + '(xmlData,retVals)');
					}
				}else{
					eval(retFunction + '(xmlData)');
				}
			}else{
				return xmlData;	
			}
		}
	}
	self.xmlHttpReq.send(sToPost);
}							


//not the same as from a file
function LoadXMLFromString(text){
	var doc = null;
	try{		
		// code for IE
		if (window.ActiveXObject){
		   doc=new ActiveXObject("Microsoft.XMLDOM");
		   doc.async="false";
		   doc.loadXML(text);
		}else{
		    var parser=new DOMParser();
		    doc=parser.parseFromString(text,"text/xml");
	  	}
	}

catch(e)
 	{		
    	return doc;
	}
	return doc;
}

function ShowDiv(dvID,ifID,formWidth,formHeight){
	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;
	}
	
	if (document.layers) {
		var elmDIV = document.layers[dvID].style;
		var elmIFRAME = document.layers[ifID].style;
	} else if (document.all) {
		var elmDIV = document.all[dvID].style;
		var elmIFRAME = document.all[ifID].style;
	} else if (document.getElementById) {
		var elmDIV = document.getElementById(dvID).style;
		var elmIFRAME = document.getElementById(ifID).style;
	}

	var sLeft = (scrollWidth - (formWidth / 2)) + (screenWidth / 2)
	var sTop = (scrollHeight - (formHeight / 2)) + (screenHeight / 2);
	
	elmDIV.left = sLeft;
	elmDIV.top = sTop;
	elmDIV.visibility = 'visible';
	elmDIV.display = 'block';

	elmIFRAME.left =  sLeft;
	elmIFRAME.top = sTop;
	elmIFRAME.visibility = 'visible';
	elmIFRAME.display = 'block';
}

function ShowDivByPosition(dvID,ifID,formWidth,formHeight,formLeft,formTop){
	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;
	}
	
	if (document.layers) {
		var elmDIV = document.layers[dvID].style;
		var elmIFRAME = document.layers[ifID].style;
	} else if (document.all) {
		var elmDIV = document.all[dvID].style;
		var elmIFRAME = document.all[ifID].style;
	} else if (document.getElementById) {
		var elmDIV = document.getElementById(dvID).style;
		var elmIFRAME = document.getElementById(ifID).style;
	}

	var sLeft = formLeft;
	var sTop = formTop;
	
	elmDIV.left = sLeft;
	elmDIV.top = sTop;
	elmDIV.visibility = 'visible';
	elmDIV.display = 'block';

	elmIFRAME.left =  sLeft;
	elmIFRAME.top = sTop;
	elmIFRAME.visibility = 'visible';
	elmIFRAME.display = 'block';
}


function HideDiv(dvID,ifID){
	
	try
	{				
		
		if (document.layers) {
			var elmDIV = document.layers[dvID].style;
			var elmIFRAME = document.layers[ifID].style;
		} else if (document.all) {
			var elmDIV = document.all[dvID].style;
			var elmIFRAME = document.all[ifID].style;
		} else if (document.getElementById) {
			var elmDIV = document.getElementById(dvID).style;
			var elmIFRAME = document.getElementById(ifID).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';
	}
	catch(e)
 	{	
		//alert('err');
		return;
	}		
}

function getContentsWidth(obj){
	var iWidth = 0;

	if (document.layers) {
		iWidth = obj.document.width;
	}else if(document.all) {
		iWidth = obj.clientWidth;
	}else{
		iWidth = obj.clientWidth;
	}

	return iWidth;
}

function getContentsHeight(obj){
	var iHeight = 0;

	if (document.layers) {
		iHeight = obj.document.height;
	}else if(document.all) {
		iHeight = obj.clientHeight;
	}else{
		iHeight = obj.clientHeight;
	}

	return iHeight;
}

function getLeft(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;
}

function getTop(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;
}

function getLat(tmpLatLong){
	if(tmpLatLong != ''){
		tmpArr = tmpLatLong.split(',');
		return tmpArr[0];
	}else{
		return tmpLatLong;
	}
}

function getLong(tmpLatLong){
	if(tmpLatLong != ''){
		tmpArr = tmpLatLong.split(',');
		return tmpArr[1];
	}else{
		return tmpLatLong;
	}
}

function RunAgentReport(){
	var sLeft = ((screen.width - 500) / 2);
	var sTop = ((screen.height - 350) / 2);	
	
	tmpwin = window.open("/?Page=Utils&Cat=AgentsRoster", "NewWin", "Width=500,Height=355,toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
			
}

function RunSingleAgentReport(sPublicID){			
	tmpwin = window.open("/?Page=Utils&Cat=AgentsRosterProcess&PublicID=" + sPublicID, "NewWin");				
}

function toggleTab(sID){
	var obj = document.getElementsByTagName('li');

	if(obj.length > 0){
		for(i=0; i < obj.length; i++){
			if(obj[i].id.indexOf('tab') > -1){
				tmpID = obj[i].title;
				
				if(obj[i].title == sID){
					var objTab = document.getElementById('tab' + sID);
					var objDiv = document.getElementById('div' + sID);					
					if(objTab){
						objTab.className = 'Tabs_Selected';
						objDiv.className = 'Tabs_Selected';
					}
				}else{
					var objTab = document.getElementById('tab' + tmpID);
					var objDiv = document.getElementById('div' + tmpID);
					if(objTab){			
						objTab.className = 'Tabs_Not_Selected';
						objDiv.className = 'Tabs_Not_Selected';
					}
				}
			}
		}
	}
}

function toggleSubTab(sID,sParentID){
	var obj = document.getElementsByTagName('li');

	if(obj.length > 0){
		for(i=0; i < obj.length; i++){
			if(obj[i].id.indexOf('subtab') > -1){
				tmpID = obj[i].title;
				if(obj[i].parentNode.id == sParentID){
					if(obj[i].title == sID){
						var objTab = document.getElementById('subtab' + sID);
						var objDiv = document.getElementById('subdiv' + sID);
						if(objTab){	
							objTab.className = 'Tabs_Selected';
							objDiv.className = 'Tabs_Selected';
						}
					}else{
						var objTab = document.getElementById('subtab' + tmpID);
						var objDiv = document.getElementById('subdiv' + tmpID);
						if(objTab && objDiv){				
							objTab.className = 'Tabs_Not_Selected';
							objDiv.className = 'Tabs_Not_Selected';
						}
					}
				}
			}
		}
	}
}


	
function getBrowserObject(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;
	}
	
}

function getPageCoords (element) {
	var coords = { x: 0, y: 0 };
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	return coords;
}


function StripSiteID(sMLN,n){
	if(n){
		if(sMLN.length >n){
			var intMLLength = sMLN.length - n;
			return iqRight(sMLN,intMLLength);
		}else{
			return sMLN;
		}
	}else{
		return sMLN;	
	}
}

//jdh - modified 09-17-08 to accept form
function getFieldValue(sField, sForm){

	//alert(sField);
	
	var objInput = getBrowserObject(sField);
	//we need this becauser for some reason you can not get the length of the fields
	// nless you do it this way
	var sOptionValues = ''
	
	if(sForm != ''){
		var objForm = getBrowserObject(sForm);
	}
			
	switch (objInput.type){
		case "radio":
			if(objForm){
				var objInputs = objForm.getElementsByTagName('input');
			}else{
				var objInputs = document.getElementsByTagName('input');
			}
			for (var i=0; i<objInputs.length; i++){
				var objCurrInput = objInputs[i];
	
				var sValue = '';

				if(objCurrInput.type == 'radio' && objCurrInput.name == sField){
					if(objCurrInput.checked){
						var sValue = objCurrInput.value;
	
						if(sOptionValues == ''){
							sOptionValues = sValue
						}else{
							sOptionValues = sOptionValues + ',' + sValue
						}					
					}			
				}
			}

			sRet = sOptionValues;	
			break;

		case "checkbox":		
			
			if(objForm){
				var objInputs = objForm.getElementsByTagName('input');
			}else{
				var objInputs = document.getElementsByTagName('input');
			}

			for (var i=0; i<objInputs.length; i++){
				var objCurrInput = objInputs[i];
	
				var sValue = '';
	
				if(objCurrInput.name == sField){
					if(objCurrInput.checked){
						var sValue = objCurrInput.value;
	
						if(sOptionValues == ''){
							sOptionValues = sValue
						}else{
							sOptionValues = sOptionValues + ',' + sValue
						}					
					}			
				}
			}						

			sRet = sOptionValues;
			break;

		case "select-multiple":
		
			if(objForm){
				var objInput = getBrowserObjectByForm(sField, sForm);				
			}

			for (j=0;j<objInput.options.length; j++){
				if(objInput.options[j].selected){
					var sValue = objInput.options[j].value;

					if(sOptionValues == ''){
						sOptionValues = sValue
					}else{
						sOptionValues = sOptionValues + ',' + sValue
					}
				}
			}
			sRet = sOptionValues;
			break;				
		
		default:
			
			if(objForm){
				var objInput = getBrowserObjectByForm(sField, sForm);				
			}
			
			
			sRet = objInput.value;
			break;
	}

	return sRet;
}

function ShowWindow(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 = getBrowserObject(dvUploadID).style;
	var elmIFRAME = 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';
}

function HideWindow(sID){
	var dvUploadID = "div_" + sID;
	var ifUploadID = "iframe_" + sID;

	var elmDIV = getBrowserObject(dvUploadID).style;
	var elmIFRAME = 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';		
}

function SetCookie( 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 + "=" );
function GetCookie( 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
function Delete_Cookie( 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";
}

function GetGUID(){
	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
}

function GetTrackingID(){
	if(GetCookie('TrackingID') == null || GetCookie('TrackingID') == ''){
		//it is not there let's set it
		var tID = GetGUID();
		SetCookie('TrackingID', tID, '', '/', '', false);
	}else{
		var tID = GetCookie('TrackingID');
	}

	return tID;
}

function ShowChatUsersWindow(){
	self.name='Main';
	var sWidth = 400;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	window.open("/?Page=Popup&Cat=Chat&SubCat=ChatUsers", "ChatUsersWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}

function iQChat_js(sURL,sImageID){
	var sRandNum=Math.random();
	var objHead = document.getElementsByTagName('head');
	var objScriptOld  = document.getElementById('iQChat');

	//there is already a script for iQ Chat
	if (objScriptOld){
		if (objScriptOld.readyState=="loading"){
			//if the script is still loading return out
			return;
		}

		// remove the old script so we can recreate it.
		objHead.removeChild(objScriptOld);
	}

	try{
		var js = document.createElement('script');
		js.setAttribute('language', 'javascript');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src','http://' + sURL + '/iQChat.cfm?ImageID=' + sImageID + '&UserID=' + GetTrackingID() + '&Random=' + sRandNum);
		js.setAttribute('id','iQChat');
		void(objHead.item(0).appendChild(js));

	}catch(e){
		return;
	}
}


function ShowPropertyIDUpdateWindow(){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 400;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	window.open("/?Page=Wizard&Cat=SystemAdmin&SubCat=PropertyID", "PropertyIDWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}


//jdh - you must declare the height in-line for this to work
function ElementDisappear(elementID) {

	try {
		var element = getBrowserObject(elementID);
		
		var elementheight = element.style.height.split('px')[0];
		
		if( element.style.MozOpacity != undefined ) { //Moz and older		
			var elementopacity = element.style.MozOpacity;
			var reduceOpacityBy = 0.15;		
		}
		else if( element.style.filter != undefined ) { //IE
			var elementopacity = element.filters.alpha.opacity;
			var reduceOpacityBy = 15;		
		}
		else if( element.style.opacity != undefined ) { //Opera
			var elementopacity = element.style.opacity;
			var reduceOpacityBy = 0.15;
		}
			
		
		var reduceHeightBy = 4;
		var rate = 30;	// 15 fps
				
		if (elementopacity > 0) {
			elementopacity -= reduceOpacityBy;
			if (elementopacity < 0) {
				elementopacity = 0;
			}
			
			if( element.style.MozOpacity != undefined ) { //Moz and older		
				element.style.MozOpacity = elementopacity;		
			}
			else if( element.style.filter != undefined ) { //IE		
				element.filters.alpha.opacity = elementopacity;
			}
			else if( element.style.opacity != undefined ) { //Opera
				element.style.opacity = elementopacity;
			}
		}
	
		if (elementheight > 0) {
			elementheight -= reduceHeightBy;
			if (elementheight < 0) {
				elementheight = 0;
			}		
	
			element.style.height = elementheight + 'px';
		}
	
		if (elementheight > 0 || elementopacity > 0) {		
			setTimeout((function(){ElementDisappear(elementID);}), rate);		
		} else {
			element.style.display = "none";			
		}
	
	} catch (e) {
	
	}
}

function getBrowserObjectByForm(sID, sForm){
	
	var f = getBrowserObject(sForm);
			
	for( var i = 0; i < f.elements.length; i++ )
	{
		if(f.elements[i].id == sID){
			return f.elements[i];
		}			
	} 
		
	return false;	
}	


function ClearForm(sForm){
	
	var objForm = getBrowserObject(sForm);
	
	var objInputs = objForm.getElementsByTagName('input');
	
	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;	
}	

function setFieldValue(sField, sForm, sValue){

	var objInput = getBrowserObjectByForm(sField, sForm);
		
				
	switch (objInput.type){
		case "radio":
					
			var objInputs = objForm.getElementsByTagName('input');
			
			for (var i=0; i<objInputs.length; i++){
				var objCurrInput = objInputs[i];	

				if(objCurrInput.type == 'radio' && objCurrInput.name == sField){
					if(objCurrInput.value == sValue){
						objCurrInput.checked = true;	
					}
					else{
						objCurrInput.checked = false;
					}
				}
			}

			break;

		case "checkbox":		
			
			var objInputs = objForm.getElementsByTagName('input');
			
			for (var i=0; i<objInputs.length; i++){
				var objCurrInput = objInputs[i];	

				if(objCurrInput.type == 'checkbox' && objCurrInput.name == sField){
					
					var tmpValue = ',' + sValue + ',';
					var tmpCurrValue = ',' + objCurrInput.value + ',';
					
					if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
						objCurrInput.checked = true;	
					}
					else{
						objCurrInput.checked = false;
					}
				}
			}

			break;
			
		case "select-one":
						
			for (j=0;j<objInput.options.length; j++){
						
				if(sValue == objInput.options[j].value){
					objInput.options[j].selected = true;
					break;
				}			
			}
			
			break;		
			
		case "select-multiple":
					
			if(sValue == ''){
				if(objInput.options.length){
					objInput.options[0].selected = true;
				}
			}else{
		
				for (j=0;j<objInput.options.length; j++){
					if(objInput.options[j].value != ''){
						//single numeric value will cause 'indexOf' to fail	
						var tmpValue = ',' + sValue + ',';
						var tmpCurrValue = ',' + objInput.options[j].value + ',';
						
						if(tmpValue.toString().indexOf(tmpCurrValue) > -1){
							objInput.options[j].selected = true;							
						}
					}			
				}
			}
			
			break;	
					
		
		default:
			
			objInput.value = sValue;
			
			break;
	}

	return;
}



function toggleAjaxTab(sID){
	var obj = document.getElementsByTagName('li');

	if(obj.length > 0){
		for(i=0; i < obj.length; i++){
			if(obj[i].id.indexOf('tab') > -1){
				tmpID = obj[i].title;
				
				if(obj[i].title == sID){
					var objTab = document.getElementById('tab' + sID);
					var objDiv = document.getElementById('div' + sID);					
					if(objTab){
						objTab.className = 'AjaxTabs_Selected';
						objDiv.className = 'AjaxTabs_Selected';
					}
				}else{
					var objTab = document.getElementById('tab' + tmpID);
					var objDiv = document.getElementById('div' + tmpID);
					if(objTab){			
						objTab.className = 'AjaxTabs_Not_Selected';
						objDiv.className = 'AjaxTabs_Not_Selected';
					}
				}
			}
		}
	}
}

function toggleAjaxSubTab(sID,sParentID){
	var obj = document.getElementsByTagName('li');

	if(obj.length > 0){
		for(i=0; i < obj.length; i++){
			if(obj[i].id.indexOf('subtab') > -1){
				tmpID = obj[i].title;
				if(obj[i].parentNode.id == sParentID){
					if(obj[i].title == sID){
						var objTab = document.getElementById('subtab' + sID);
						var objDiv = document.getElementById('subdiv' + sID);
						if(objTab){	
							objTab.className = 'AjaxSubTabs_Selected';
							objDiv.className = 'AjaxSubTabs_Selected';
						}
					}else{
						var objTab = document.getElementById('subtab' + tmpID);
						var objDiv = document.getElementById('subdiv' + tmpID);
						if(objTab && objDiv){				
							objTab.className = 'AjaxSubTabs_Not_Selected';
							objDiv.className = 'AjaxSubTabs_Not_Selected';
						}
					}
				}
			}
		}
	}
}

function ShowPropertyIDMaintainWindow(PropertyID,SerialNumber){
	self.name='Main';
	var sWidth = 600;
	var sHeight = 600;

	var sLeft = ((screen.width - sWidth) / 2);
	var sTop = ((screen.height - sHeight) / 2);
			
	window.open("/?Page=Wizard&Cat=PropertyID&SubCat=Maintain&PropertyID=" + PropertyID + "&SerialNumber=" + SerialNumber, "PropertyIDWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}
