// 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){
	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){
	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;
	}
}

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 = 675;
	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 = 500;
	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(){
	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", "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(sLeadID){
	
	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&LeadID=" + sLeadID + "&ReportName=Reports.Leads.SingleLead", "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", "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 = 400;
	
	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 = 400;
	
	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){
	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, "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,sFormName,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 + "&FormName=" + sFormName + "&TemplateType=" + sTemplateType, "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 = 780;
    var sHeight = 580;

    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 + ",resizable=yes,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 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){
	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=Create&PublicID=" + sPublicID, "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 = 800;
	var sHeight = 500;

	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){
	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, "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);								
}


// *************************************
// 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;
	}
}

//10-14-06 JDH
function iqLeft(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function iqRight(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);
    }
}


//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);
					objTab.className = 'Tabs_Selected';
					objDiv.className = 'Tabs_Selected';
				}else{
					var objTab = document.getElementById('tab' + tmpID);
					var objDiv = document.getElementById('div' + tmpID);			
					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[szDivID];
	
	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 iqNumberFormat(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;
}

function iqDecimalFormat(intNum){
	return Math.round(intNum*100)/100;
}

function iqShortenString(str, n){
	if (n <= 0)
	    return str;
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n) + '...';
}

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;	
	}
}

function getFieldValue(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 = ''
			
	switch (objInput.type){
		case "radio":
			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":
			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":
			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:
			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, path, domain, secure ){
	// 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;
	}

	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function GetCookie( check_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.toLowerCase() == check_name.toLowerCase()){
			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 ( GetCookie( name ).toLowerCase()) document.cookie = name.toLowerCase() + "=" +
	( ( 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);								
}

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 ShowPropertiesExportWindow(){
	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=Properties.Export", "PropertyIDWin", "Width=" + sWidth + ",Height=" + sHeight + ",toolbar=no,scrollbars=no,menubar=no,left=" + sLeft + ",top=" + sTop);								
}
