try {document.execCommand("BackgroundImageCache", false, true);} catch(err) {}

var oldRow;
var strOldClassName;
	
function highlightRow(objRow){
	try{
	if (oldRow != void(0)) {
		oldRow.className = strOldClassName;
	}
	try {
		strOldClassName = objRow.className;
		objRow.className = 'gridDataHighlight';
		oldRow = objRow;
	} catch(e) {}
	}catch(e){};
}

function popupWindow(strPage, strWindowName, strProps) {
	return window.open(applyUserSessionInfo(strPage), removeInvalidChars(strWindowName, "_"), strProps);
}		

var objDblClick;

function executeDblClick(){
	try {
		objDblClick.ondblclick();
	} catch(e) {}
}	

function executeParentRefresh(){
	try {
		window.opener.__doPostBack("", "")
	} catch(e) {}
}

function serverWait(){
	tmpMainContentRow.style.display = "none";
	tmpFooterRow.style.display = "none";
	tmpWaitRow.style.display = "block";
}

function modalPopup(strURL, strTitle, strProps){
	if (strProps.length == 0){
		strProps = "dialogHeight: 270px; dialogWidth: 640px; help: No; resizable: No; status: No; scrolling: No;"
	}
	try{
		return window.showModalDialog("systemModalDialog.aspx?Title=" + strTitle, applyUserSessionInfo(strURL), strProps);
	}catch(e){}
}

function removeInvalidChars(string, replaceString) {
	for (var i=0, output='', valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; i<string.length; i++){
		if (valid.indexOf(string.charAt(i)) != -1){
			output += string.charAt(i);
		} else {
			output += replaceString;
		}
	}
	return output;
}

function isWindowOpen(strWindowName) {
	return false;
	strFeatures = "width=1,height=1,left=9999,top=9999";
	testwindow = window.open("", removeInvalidChars(strWindowName, "_"), strFeatures);
	if(testwindow != null){
		if (testwindow.top.screenLeft >= 9999 || testwindow.top.screenLeft == void(0)) {
			testwindow.close();
			return false;
		} else {
			testwindow.focus();
			return true;
		}
	}
	
	return false;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{	
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		if (document.layers[name])
		{
	   		this.obj = document.layers[name];
	   		this.style = document.layers[name];
		}
		else
		{
			this.obj = document.layers.testP.layers[name];
			this.style = document.layers.testP.layers[name];
		}
	}
}

function editFavourite(intDataPageID,intPrimaryID,openQueryString,intFavouriteTypeID){
	if (intFavouriteTypeID == 2){
		//Datapage favourite
		alert('This favourite can not be edited because it is a system favourite.')
	}else{
		//Normal Favourite
		openDatapopup(intDataPageID,intPrimaryID,openQueryString);	
	}
}
function openFavourite(intDataPageID, intPrimaryID, strLink){

	if (strLink.length == 0){
		openDatapopup(intDataPageID, intPrimaryID,'');
	}else{
		window.open(strLink);
	}
}

function messageReply(intPrimaryID, strRecipient, strSubject){
	var queryString = "";
	var recipientList = strRecipient;
	var recipient = "";
		
	recipientList = recipientList.replace(/></g, ",");
	recipientList = recipientList.replace(/</g, "");
	recipientList = recipientList.replace(/>/g, "");
		
	var recipientSplit = recipientList.split(",");
	
	for(n=0; n<recipientSplit.length; n++)
	{
		recipient += "<" + recipientSplit[n] + ">";
	}
	
	if(String(strSubject).substring(0,3) != "RE:"){
		strSubject = "RE: " + strSubject;
	}
	strQueryString = "DEFmessages_intReplyID="+intPrimaryID+"&amp;DEFmessages_strNotify="+recipient+"&amp;DEFmessages_strSubject="+strSubject;
	
	openDatapopup(86,0,strQueryString);
}

function openAdjustStock(strParams){

				var url = 'productAdjust.aspx?intProductID=' + strParams;
				strWindowName = url;
			
				if (!isWindowOpen(strWindowName)){
					popupWindow(url,strWindowName,'height=400,width=350,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
				}

}

function openStockTake(intStockTakeiD){
		var url = 'productStockTake.aspx?intStockTakeID='+intStockTakeiD;
		strWindowName = url;
	
		if (!isWindowOpen(strWindowName)){
			popupWindow(url,strWindowName,'height=700,width=800,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
		}
}

function checkRelatedItemPopup(openPageName, openDataPageID, openPrimaryID, openQueryString)
{
	if(openPageName == 'Document'){
		openDownloadFile(openPrimaryID);
	} else if (openPageName == 'Saved Searches'){
		openSavedSearchPreview(openPrimaryID);
	} else {
		openDatapopup(openDataPageID, openPrimaryID, openQueryString);
	}
}

function checkUserStatus(userStatus, userName)
{
	var strMsg = ' may not reply because his or her status is set to '
	var statusAlert = false
	
	if(userStatus == 'Away'){
		statusAlert = true;
	}
	if(userStatus == 'Offline'){
		statusAlert = true;
	}
	
	if(statusAlert == true){
		alert(userName+strMsg+userStatus);
	}
}

function openSavedSearchPreview(openPrimaryID)
{
	var iheight = 450;
	var iwidth = 700;
	var url = 'systemSavedSearchPreview.aspx?intSearchID=' + openPrimaryID;
	strWindowName = url;

	try{window.event.cancelBubble = true;}catch(e){}

	if (!isWindowOpen(strWindowName)){
		if (iheight.length == 0) iheight = 450;
		if (iwidth.length == 0) iwidth = 700;
		return popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=20,left=20');
	}
}

function openDatagrid(searchID, queryString)
{
	var iheight = 450;
	var iwidth = 700;
	var url = 'search.aspx?GridSearchID=' + searchID + '&amp;' + queryString;
	strWindowName = url;

	try{window.event.cancelBubble = true;}catch(e){}

	if (!isWindowOpen(strWindowName)){
		if (iheight.length == 0) iheight = 450;
		if (iwidth.length == 0) iwidth = 700;
		return popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=20,left=20');
	}
}

function openDatapopup(openDataPageID, openPrimaryID, openQueryString)
{	
	switch (openDataPageID) {
	
		case 'email':
			execFunctionLink('email', openPrimaryID);		
			break;
			
		case 'postcode':
			execFunctionLink('postcode', openPrimaryID);
			break;
			
		default:

			if (openDataPageID > 0){
				var iheight = 10;
				var iwidth = 10;
				var url = 'dataPopup.aspx?DataPageID=' + openDataPageID + '&amp;PrimaryID=' + openPrimaryID + '&amp;' + openQueryString;
				strWindowName = url;

				try{window.event.cancelBubble = true;}catch(e){}

				if (!isWindowOpen(strWindowName)){
					if (iheight.length == 0) iheight = 450;
					if (iwidth.length == 0) iwidth = 700;
					return popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=10,left=10');
				}
			}
			break;
	}
}

function openDatapopupModal(openDataPageID, openPrimaryID, openQueryString)
{
	if (openDataPageID > 0){
		var iheight = 10;
		var iwidth = 10;
		var url = 'dataPopup.aspx?DataPageID=' + openDataPageID + '&amp;PrimaryID=' + openPrimaryID + '&amp;' + openQueryString;
		strWindowName = url;

		try{window.event.cancelBubble = true;}catch(e){}

		if (!isWindowOpen(strWindowName)){
			if (iheight.length == 0) iheight = 450;
			if (iwidth.length == 0) iwidth = 700;
			return modalPopup(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=10,left=10');
		}
	}
}

function deleteDatapopup(openDataPageID, openPrimaryID)
{
	deleteDatapopupPermanent(openDataPageID, openPrimaryID, 0)
}

function openNewsArticle(strLink){
	openFavourite(0, 0, strLink);
	try{window.event.cancelBubble = true;}catch(e){}
}

function deleteDatapopupPermanent(openDataPageID, openPrimaryID, blnPermanent){
	var url = 'dataPopupDelete.aspx?DataPageID=' + openDataPageID + '&amp;PrimaryID=' + openPrimaryID + '&amp;Permanent=' + blnPermanent;
	strWindowName = url;
	if (!isWindowOpen(strWindowName)){
		var iWidth = 300;
		var iHeight = 150;
		var iTop = (screen.availHeight - iHeight)/2;
		var iLeft = (screen.availWidth - iWidth)/2;
		popupWindow(url,strWindowName,'height=' + iHeight + ',width=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
	}
	try{window.event.cancelBubble = true;}catch(e){}
}

function callSkypeUser(strSkypeUsername)
{
	window.location.href = "callto:"+strSkypeUsername;
}

function restoreRecyleItem(intDeleteHistoryID){
	var url = 'dataPopupRestore.aspx?DeleteHistoryID=' + intDeleteHistoryID;
	strWindowName = url;
	if (!isWindowOpen(strWindowName)){
		var iWidth = 300;
		var iHeight = 150;
		var iTop = (screen.availHeight - iHeight)/2;
		var iLeft = (screen.availWidth - iWidth)/2;
		popupWindow(url,strWindowName,'height=' + iHeight + ',width=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
	}
	try{window.event.cancelBubble = true;}catch(e){}
}
	
function openUploadFile(DataPageID, DataPagePrimaryID)
{
	var strProps = "dialogHeight: 200px; dialogWidth: 350px; help: No; resizable: No; status: No; scrolling: No;";
	var strURL = "systemUploadOuter.aspx?DatapageID=" + DataPageID + "&DatapagePrimaryID=" + DataPagePrimaryID;
	return modalPopup(strURL, "Upload file", strProps);
}

function openUploadPublicFile(DataPageID, DataPagePrimaryID)
{
	var strProps = "dialogHeight: 200px; dialogWidth: 350px; help: No; resizable: No; status: No; scrolling: No;";
	var strURL = "systemUploadOuter.aspx?DatapageID=" + DataPageID + "&DatapagePrimaryID=" + DataPagePrimaryID + "&Mode=public";
	return modalPopup(strURL, "Upload file", strProps);
}

function openDownloadFile(FileID)
{
	var url = "systemDownload.aspx?FileID=" + FileID;
	var strWindowName = url;
	if (!isWindowOpen(strWindowName)){
		popupWindow(url,strWindowName,'height=500,width=550,top=10,left=10,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
	}
	try{window.event.cancelBubble = true;}catch(e){}
}

function showToolTip(e,text){ 
	var objTooltip = window.top.document.all.ToolTip;

	objTooltip.innerHTML="<table><tr><td class=ToolTipTD>"+text+"</td></tr></table>"; 

	var tmpLeft = e.screenX-(window.top.screenLeft) + 15; //+15+document.body.scrollLeft;
	var tmpTop = e.screenY-(window.top.screenTop) + 5; //e.screenY; //document.body.scrollTop+5;
    
    if ( (tmpLeft + objTooltip.offsetWidth) > (window.top.document.body.scrollWidth) ){
		tmpLeft = tmpLeft - objTooltip.offsetWidth - 30;
    }

    if ( (tmpTop + objTooltip.offsetHeight) > (window.top.document.body.scrollHeight) ){
		tmpTop = tmpTop - objTooltip.offsetHeight - 10;
    }

	objTooltip.style.pixelLeft=(tmpLeft); 
	objTooltip.style.pixelTop=(tmpTop);
	objTooltip.style.visibility="visible"; 
} 

function hideToolTip(){ 
 	var objTooltip = window.top.document.all.ToolTip;
    objTooltip.style.visibility="hidden"; 
} 

function checkScrolling(strElement){
	if (window.event.srcElement.offsetHeight < window.event.srcElement.scrollHeight){
		try{
			document.all(strElement).style.display = "block"
		}catch(e){}
	} else {
		try{
			document.all(strElement).style.display = "none"
		}catch(e){}	}
}

  function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 
  } 
        
  function formatDate(vDate, vFormat){ 
    var vDay              = addZero(vDate.getDate()); 
    var vMonth            = addZero(vDate.getMonth()+1); 
    var vYearLong         = addZero(vDate.getFullYear()); 
    var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = addZero(vDate.getHours()); 
    var vMinute           = addZero(vDate.getMinutes()); 
    var vSecond           = addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
  } 

function openDatapagePDF(iPDFID)
{
	window.open("systemReportOutput.aspx?PDFID=" + iPDFID + "&PRMintPrimaryID=" + frmPageForm.intPrimaryID.value);
}

function openPDF(iPDFID, iPrimaryID)
{
	window.open("systemReportOutput.aspx?PDFID=" + iPDFID + "&PRMintPrimaryID=" + iPrimaryID);
}



//document.oncontextmenu = oncontextmenuFunction; 

function oncontextmenuFunction(strHTML, intHeight, intWidth) { 
	var oPopup = window.createPopup(); 	
	oPopup.document.body.innerHTML = strHTML; 
	//alert(oPopup.document.body.scrollHeight+2);
	oPopup.show( window.event.clientX, window.event.clientY, 200, 130, document.body); 
	window.event.cancelBubble=true
	return false; 
} 

function dismissReminder(intReminderID){
	var objAWS = new AJAXWebService();
	objAWS.strServiceURL = "WebServices/Alerts.asmx"
	objAWS.strMethod = "DismissReminder"
	objAWS.CallWebService({intReminderID : intReminderID});
	executeFunction('refresh','');
}

function completeTask(intTaskID){
	var objAWS = new AJAXWebService();
	objAWS.strServiceURL = "WebServices/taskFunctions.asmx"
	objAWS.strMethod = "taskMarkAsComplete"
	objAWS.CallWebService({intTaskID : intTaskID});
	executeFunction('refresh','');
}

// 28/04/08 RJS - Add code to set a default address on companies address grid
function setDefaultAddress(intAddressID){
	var objAWS = new AJAXWebService();
	objAWS.strServiceURL = "WebServices/GridFunctions.asmx"
	objAWS.strMethod = "SetDefaultAddress"
	objAWS.CallWebService({intAddressID : intAddressID});
	executeFunction('refresh','');
}

function changeMainPortalSection(sectionID, subLinkID, strQS, bln){
	var intParents = 0;
	
	if (window.opener == void(0)) {
		var objParent = window;
		while (objParent.parent != objParent && intParents < 50){
			objParent = objParent.parent;
			intParents++;
		}
		if(objParent.parent == objParent){
			objParent.leftNavChangeSection(sectionID, subLinkID, strQS);
		}	
		//leftNavChangeSection(sectionID, subLinkID);
	};
}

function executeReport(intReportID, format){
	window.open("systemReportRun.aspx?ReportID=" + intReportID + "&format=" + format);
}

function executeMailingContactPreview(intMailingContactID){
	window.open("systemReportRun.aspx?MailingContactID=" + intMailingContactID);
}
//ReportID

function updateTooltip(){
	if(window.event.srcElement.title=='')
		window.event.srcElement.title=window.event.srcElement.innerText;
}

function showMyDetails(){
	openDatapopup(134,-666,'');
}

function sysChangePassword(){
	var iheight = 150;
	var iwidth = 250;
	var url = 'systemChangePassword.aspx';
	strWindowName = url;
	if (!isWindowOpen(strWindowName)){
		var leftVal = (screen.width - iwidth) / 2;
		var topVal = (screen.height - iheight) / 2;
		popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',left='+leftVal+',top='+topVal+',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
	}
	try{window.event.cancelBubble = true;}catch(e){}
}

function sysLogout(){
	window.location.href="systemLogout.aspx";
}

function switchUser(userID){
	window.location.href="systemSwitchUser.aspx?intUserID=" + userID;
}

function GetEvent (objEvt) {
	
	objEvt = (objEvt) ? objEvt : ((window.event) ? window.event : "")		
	return objEvt;
}
	
function onRightClickOpenDataPopup(intDataPageID, intPrimaryID, openQueryString){
	
	var objEvt = GetEvent();
	
	if(!objEvt || objEvt.button==2){
		openDatapopup(intDataPageID, intPrimaryID, openQueryString);
		return false;
	}
}

function execFunctionLink(strLinkType, fieldVal){
	try{
		//PPL use separate address for their local install
		var link;
		if (window.location.host.toLowerCase().indexOf('pplapp03') == 0)
			link = 'system@prime.3slive.com';
		else
			link = 'mail@mail.3slive.com';
		
		
		
		if (fieldVal.length > 0){
			switch (strLinkType) {
				case 'web':
					openFavourite(0, 0, 'http://' + fieldVal);
					break;
				case 'email':
					//openFavourite(0, 0, 'mailto:' + fieldVal + '&bcc=mail@mail.3slive.com');
					openFavourite(0, 0, 'mailto:' + fieldVal + '&bcc=' + link );
					break;
				case 'skype':
					window.location.href = 'callto:' + fieldVal;
					break;
				case 'news':
					openFavourite(0, 0, fieldVal);
					break;
				case 'postcode':
					openFavourite(0, 0, 'http://maps.google.co.uk/maps?q=' + fieldVal);
					break;
				case 'phone':
					window.location.href = 'call3s:' + fieldVal;
					break;
			}	
		}	
	} catch(e) {}
}

function emailReport(strID){
	window.open('systemEmail.aspx?attachReport=' + strID,'emailReport','height=425,width=700,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
}

function roundDecimals(original_number, decimal_places) {
	if(isNaN(original_number)){
		original_number = 0;
	}
		
	var result1 = original_number * Math.pow(10, decimal_places)
	var result2 = Math.round(result1)
	var result3 = result2 / Math.pow(10, decimal_places)
	return padWithZeros(result3, decimal_places)
}

function padWithZeros(rounded_value, decimal_places) {

	// Convert the number to a string
	var value_string = rounded_value.toString()
	
	// Locate the decimal point
	var decimal_location = value_string.indexOf(".")

	// Is there a decimal point?
	if (decimal_location == -1) {
		
		// If no, then all decimal places will be padded with 0s
		decimal_part_length = 0
		
		// If decimal_places is greater than zero, tack on a decimal point
		value_string += decimal_places > 0 ? "." : ""
	}
	else {

		// If yes, then only the extra decimal places will be padded with 0s
		decimal_part_length = value_string.length - decimal_location - 1
	}
	
	// Calculate the number of decimal places that need to be padded with 0s
	
	var pad_total = decimal_places - decimal_part_length
	
	if (pad_total > 0) {
		
		// Pad the string with 0s
		for (var counter = 1; counter <= pad_total; counter++) 
			value_string += "0"
		}
	return value_string
}

function AddComboOption(combo, optionText, optionValue)
{
	var oOption = document.createElement("OPTION") ;

	combo.options.add(oOption) ;

	oOption.innerHTML = optionText ;
	oOption.value     = optionValue ;
	
	return oOption ;
}

function SystemPrompt(strTitle, strPrompt){
	
	
	var strProps = "dialogHeight: 250px; dialogWidth: 450px; help: No; resizable: No; status: Yes; scrolling: No;";
	var strURL = "systemPrompt.aspx?Title=" + strTitle + "&Prompt=" + strPrompt;
	

	var retVal = modalPopup(strURL, strTitle, strProps);
	
	
	return retVal;
}

function openAdHocDoc(intAdHocDocID){
	var iheight = 10;
	var iwidth = 10;
	
	var url = 'systemViewAdHocDoc.aspx?intAdHocDocID=' + intAdHocDocID 
	strWindowName = url;

	if (!isWindowOpen(strWindowName)){
		popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=yes,toolbars=yes,resizable=yes,top=10,left=10');
	}
}

function openDataWizard(intWizardID, intWizardPrimaryID,intCallingDataPageID, intCallingPrimaryID, strParams){
	var iheight = 10;
	var iwidth = 10;

	var url = 'dataWizard.aspx?intWizardID=' + intWizardID + '&amp;intWizardPrimaryID=' + intWizardPrimaryID + '&amp;intCallingPrimaryID=' + intCallingPrimaryID +'&amp;intCallingDataPageID=' + intCallingDataPageID + '&amp;' +strParams;
	strWindowName = url;

	if (!isWindowOpen(strWindowName)){
		if (iheight.length == 0) iheight = 450;
		if (iwidth.length == 0) iwidth = 700;
		popupWindow(url,strWindowName,'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=10,left=10');
	}
	try{window.event.cancelBubble = true;}catch(e){}
}

function checkDateFromControl(strControl){
	var strDate = document.getElementById(strControl).value ;
	
	if (strDate.length>0){
		if(IsValidDate(strDate).length == 0){
			alert('Invalid date format.');
			document.getElementById(strControl).focus();
		}
	}	
}

function openHelpDoc(strURL)
{
	//window.parent.frames[1].location.href = strURL
	window.open(strURL,"test","location=0,status=1,menubar=0,resizable=1,width=700,height=600");
}

function openImportWizard(){
	var iheight = 550;
	var iwidth = 700;
	var iLeft = 0;
	var iTop = 0;
	
	iLeft = (screen.width - iwidth) / 2;
	iTop = (screen.height - iheight) / 2;
	
	popupWindow("systemImportWizard.aspx", "importWizard", 'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=' + iTop + ',left=' + iLeft);

}

function telesalesUpdate(intTelesaleID){
	var iheight = 550;
	var iwidth = 700;
	var iLeft = 0;
	var iTop = 0;
	
	iLeft = (screen.width - iwidth) / 2;
	iTop = (screen.height - iheight) / 2;
	
	popupWindow("systemTelesalesImport.aspx?intTelesaleID="+intTelesaleID, "telesalesImportWizard", 'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=' + iTop + ',left=' + iLeft);

}

function telesalesListExport(intTelesaleID){
	var iheight = 550;
	var iwidth = 700;
	var iLeft = 0;
	var iTop = 0;
	
	iLeft = (screen.width - iwidth) / 2;
	iTop = (screen.height - iheight) / 2;
	
	popupWindow("search.aspx?GridSearchID=467&WHRtc_intTelesalesID="+intTelesaleID, "Telesales Contacts", 'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=' + iTop + ',left=' + iLeft);

}

function openSalesFunnel(){
	var iheight = 550;
	var iwidth = 700;
	var iLeft = 0;
	var iTop = 0;
	
	iLeft = (screen.width - iwidth) / 2;
	iTop = (screen.height - iheight) / 2;
	
	popupWindow("systemReportPowerpoint.aspx", "salesfunnel", 'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=' + iTop + ',left=' + iLeft);

}

function openMessage(iMsgID){
	openDatapopup(86,iMsgID,'');
}

/*
	Generate a GUID.
*/
function generateGUID()
{
//    var g = "{";
    var g = "";
    for (var i = 0; i < 32; i++)
		g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "")

//    return g + "}";
    return g;
}

/*
	Loads an XML document from the xml string.
*/
function loadXMLDoc(xmlDocPath)
{
	var xmlDoc = null;
	
	if (xmlDocPath)
	{
		// code for IE
		if (window.ActiveXObject)
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = false;
			xmlDoc.loadXML(xmlDocPath);
		}
		// code for Mozilla, Firefox, Opera, etc.
		else 
		{
			var parser = new DOMParser();
			xmlDoc = parser.parseFromString(text, xmlDocPath);
		}
		
		return xmlDoc;
	}
	else
	{
		alert('Your browser was provided with an invalid XML document path.');
		return null;
	}
}

/*
	Adds an event handler for a given event on an element.
	Supports XBrowser compatability.
*/
function XBrowserAddHandler(target,eventName,handlerName)
{
	if ( target.addEventListener ) { 
		target.addEventListener(eventName, function(e){target[handlerName](e);}, false);
	}
	else if ( target.attachEvent ) { 
		target.attachEvent("on" + eventName, function(e){target[handlerName](e);});
	}
	else { 
		var originalHandler = target["on" + eventName]; 
		if ( originalHandler ) { 
			target["on" + eventName] = function(e){originalHandler(e);target[handlerName](e);}; 
		}
		else { 
			target["on" + eventName] = target[handlerName]; 
		} 
	} 
}

function openSourceReport(){
	var iheight = 370;
	var iwidth = 440;
	var iLeft = 0;
	var iTop = 0;
	
	iLeft = (screen.width - iwidth) / 2;
	iTop = (screen.height - iheight) / 2;
	
	popupWindow("systemSourceReport.aspx", "sourcereport", 'height=' + iheight + ',width=' + iwidth + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,top=' + iTop + ',left=' + iLeft);

}

/*
function openReportGenerator(intReportID){
		var url = 'reportGenerator.aspx?intReportID='+intReportID + '&newopen=true';
		strWindowName = url;
	
		if (!isWindowOpen(strWindowName)){
			popupWindow(url,strWindowName,'height=100,width=100,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
		}
}
*/

function openReportGenerator(intReportID, blnCopyNew){
		if (blnCopyNew === undefined){
			blnCopyNew = false;
		}
		
		var url = 'reportGenerator.aspx?intReportID=' + intReportID + '&newopen=true&copynew=' + blnCopyNew;
		strWindowName = url;
	
		if (!isWindowOpen(strWindowName)){
			popupWindow(url,strWindowName,'height=100,width=100,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
		}
}

function openEvaluation(intDataPageID, intRecordID, intParentID){
	
		var url = 'evaluationFeedback.aspx?DatapageID=' + intDataPageID + '&DatapagePrimaryID=' + intRecordID + '&DatapageParentID=' + intParentID;
		strWindowName = url;
		if (!isWindowOpen(strWindowName)){
			popupWindow(url,strWindowName,'height=700,width=800,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
		}
}

function openAuditRecord(intAuditID){
	var url = 'dataPageHistory.aspx?intAuditID='+intAuditID;
	strWindowName = url;

	if (!isWindowOpen(strWindowName)){
		popupWindow(url,strWindowName,'height=400,width=600,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes');
	}
}

