var _sRoot = "/MMM";
var p;
/*Code added by Umair to make life easey whiel traversing elements*/
var MMM_js = MMM_js || {};
MMM_js.dom = { addEvent: function(obj, type, fn) { if (obj.addEventListener) obj.addEventListener(type, fn, false); else if (obj.attachEvent) { obj["e" + type + fn] = fn; obj[type + fn] = function() { obj["e" + type + fn](window.event); }; obj.attachEvent("on" + type, obj[type + fn]); } }, srctarget: function(e) { if (!e) e = window.event; return (e.target) ? e.target : e.srcElement; }, stopEvent: function(e) { if (!e) e = window.event; if (e.stopPropagation) e.stopPropagation(); if (e.preventDefault) e.preventDefault(); e.cancelBubble = true; e.returnValue = false; return false; },
    getElementsByAttribute: function(oElm, strTagName, strAttributeName, strAttributeValue) {
        var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = []; var oAttributeValue = (typeof strAttributeValue != "undefined") ? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null; var oCurrent; var oAttribute; for (var i = 0; i < arrElements.length; i++) { oCurrent = arrElements[i]; oAttribute = (oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName)) || (strAttributeName == 'class' ? oCurrent.className : null); if (typeof oAttribute == "string" && oAttribute.length > 0) { if (typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))) { arrReturnElements.push(oCurrent); } } }
        return arrReturnElements;
    }, removeEvent: function(obj, type, fn) { if (obj.removeEventListener) obj.removeEventListener(type, fn, false); else obj.detachEvent('on' + type, fn); return obj; },
    getElementsByClassName: function(oElm, strTagName, strClassName) { return (this.getElementsByAttribute(oElm, strTagName, 'class', strClassName)); }, addClassName: function(oElm, strClassName) { var strCurrentClass = oElm.className; if (!new RegExp(strClassName, "i").test(strCurrentClass)) { oElm.className = strCurrentClass + ((strCurrentClass.length > 0) ? " " : "") + strClassName; } },
    removeClassName: function(oElm, strClassName) { var oClassToRemove = new RegExp((strClassName + "\s?"), "i"); oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, ""); },
    $: function(el) { return document.getElementById(el); }, $$: function(className) { return (this.getElementsByClassName(document, '*', className)); }, find_parent: function(element, name) {
        var ret = element.parentNode; name = name.toLowerCase(); while (ret && ret.nodeName.toLowerCase() != name) { ret = ret.parentNode; }
        return (ret);
    }, find_sibling: function(element, name) {
        var ret = element.nextSibling; name = name.toLowerCase(); while (ret && ret.nodeName.toLowerCase() != name) { ret = ret.nextSibling; }
        return (ret);
    } 
};
MMM_js.each = function(collection, fn) {
    for (var i = 0; i < collection.length; i++) {
        fn(collection[i]);
    }
}
MMM_js.dom.has_attr = function(el, attr, value) {
    return (' ') ? (' ' + el[attr] + ' ').indexOf(' ' + value + ' ') > -1 : el[attr].indexOf(value) > -1;
}
MMM_js.dom.find_prev_sibling = function(element, name) {
    var ret = element.previousSibling; name = name.toLowerCase();
    while (ret && ret.nodeName.toLowerCase() != name) { ret = ret.previousSibling; }
    return (ret);
}
function getAbsolutePosition(element) {
var r = { x: element.offsetLeft, y: element.offsetTop };
	  if (element.offsetParent) {
     var tmp = getAbsolutePosition(element.offsetParent);
   r.x += tmp.x;
	   r.y += tmp.y;
		 }
		  return r;
		};

function getoffset(event, ref) {
 	var x, y;							 
   var pos = getAbsolutePosition(ref);
	  x = event.clientX  - pos.x;
	  y = event.clientY - pos.y;
		return { x: x, y: y };
}

var documentChanged = false;

function openHTMLBuilder(openingMode) {
    var params = new Object();
    params.parentDoc = this;
    return window.showModalDialog('/MMM/MMMAdmin/Home/HTMLTemplate/MMMHTMLBuilder.aspx?mode=' + openingMode, params, "dialogWidth:" + 850 + "px;dialogHeight:" + 650 + "px;help:0;status:0;scroll:0;center:0;resizable:1;");

    //openStdWin('/MMM/MMMAdmin/Home/HTMLTemplate/MMMHTMLBuilder.aspx?mode='+ openingMode,'',750,650);
}

function openNewPicklist() {
    openObj(3001);
}

function openNewPicklistAttribute() {
    openObj(3002);
}


function openNewCampaign() {

    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/Campaign/Campaign/CampaignEditNew/NewCampaign.aspx','',380,300);
    //if(okClicked==true)
    //{
    openObj(1003);
    //}

}

function openNewPickList() {
    openStdWin('PickListEditNew/PickListAddNew.aspx', '', 750, 550);
}

function getProspectInUseMessageForTmLookUp() {
    return "This Telescript is complete for this prospect.\n\nAre you sure you want to re-run script for this prospect?";
}

function openNewEmail() {
    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/Campaign/Email/EmailEditNew/NewEmail.aspx','',380,300);

    //if(okClicked==true){
    openObj(1001);
    //}

}

// this function is added by Ali Khan on 23 Nov 2004, 12:32 PM
// this function open a new SMS Vechile
function openNewSMS() {
    openObj(1010);
}

// this function is added by Ali Khan on 04 Nov 2004, 08:46 AM
// this function open a SMS Configuration
function openNewSmsConfiguration() {
    openObj(1011);
}

// this function is added by Ali Khan on 24 Nov 2004, 16:39 AM
// this function open a Gateway Configuration
function openNewGatewayConfiguration() {
    openObj(1012);
}


// this function is added by Ali Khan on 04 Nov 2004, 08:46 AM
// this function open a new HTML Template
function openNewHTMLTemplate() {
    openObj(2001);
}

// this function is added by Ali Khan on 04 Nov 2004, 08:46 AM
// this function open a new Content section
function openNewContentSection() {
    openObj(2002);
}

// this function is added by Ali Khan on 04 Nov 2004, 08:46 AM
// this function open a new Content block
function openNewContentBlock() {
    openObj(2003);
}

function openNewTeleScript() {
    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/Campaign/Telemarketing/TelemarketingEditNew/NewTeleScript.aspx','',380,300)
    //if(okClicked==true){
    openObj(1002);
    //}
}


function openNewWebForm() {
    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/Campaign/WebForm/WebFormEditNew/NewWebForm.aspx','',380,300)

    //if(okClicked==true){
    openObj(1004);
    //}
}

function openNewList() {
    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/People/Lists/NewListEdit/NewListElement.aspx','',500,250);

    //	if(okClicked==true){
    openObj(1006,"?type=static");
    //	}

}

function openDynamicList()
{
  openObj(1016,"?type=dynamic");
}
function openResourceManager() {
    //var okClicked=openStdDlg(_sRoot+'/AccoutUser/People/Lists/NewListEdit/NewListElement.aspx','',500,250);

    //	if(okClicked==true){
    openObj(3004);
    //	}

}

function openNewDedupeQuery() {
    openObj(1013);
}


function document.onkeypress() {
    var target = event.srcElement;
    if (target.tagName == 'INPUT' || target.tagName == 'TEXTAREA') {
        documentChanged = true;
    }
}

function trim(objString) {
    return objString.replace(/^\objString+/, '').replace(/\objString+$/, '');

}

function strtrim(str) {
    //Match spaces at beginning and end of text and replace
    //with null strings
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function document.onclick() {
    var target = event.srcElement;
    if (target.tagName == 'INPUT') {
        documentChanged = true;
    }
}

function document.onselectstart() {
    var s = event.srcElement.tagName;
    if (s != "INPUT" && s != "TEXTAREA") event.returnValue = false;
}
function document.ondragstart() {
    event.returnValue = false;
}

function openStdWin(sPath, sName, iX, iY) {

    if (!iX) iX = 750;
    if (!iY) iY = 515;
    try {
        var childwin = window.open(sPath, sName, "width=" + iX + ",height=" + iY + ",status=1,resizable=1");
        childwin.focus();
    }
    catch (e) { }
}

function openStdDlg(sPath, oArgs, iX, iY) {
    var params = new Object();
    params.parentDoc = this;
    return window.showModalDialog(sPath, params, "dialogWidth:" + iX + "px;dialogHeight:" + iY + "px;help:0;status:0;scroll:0;center:1");
}

function copyVehicle(vehicleId, vehicleType) {
    if (vehicleId == -1) {
        alert(getTooManyRecordsMessage());
        return;
    }
    var path = '/MMM/Common/XmlForwarderForVehicleCopy.aspx?vid=' + vehicleId + "&vtype=" + vehicleType;

    objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    objXMLHTTP.Open("POST", path, false);
    objXMLHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    objXMLHTTP.Send(null);
    var response = objXMLHTTP.responseText;
    objXMLHTTP = null;
    objXMLDOM = new ActiveXObject("Microsoft.XMLDOM");
    objXMLDOM.loadXML(response);
    var ActionNode = objXMLDOM.getElementsByTagName("action");
    var DetailsNode = objXMLDOM.getElementsByTagName("details");
    switch (ActionNode(0).text) {
        case "error":
            if (!DetailsNode) {
                alert('Error Occured While Copying The Vehicle.');
            }
            else {
                if (DetailsNode(0).text == "") {
                    alert('Error Occured While Copying The Vehicle.');
                }
                else {
                    alert(DetailsNode(0).text);
                }
            }
            break;
        case "copy":
            window.location.href = window.location.href;
            break;
    }
    objXMLDOM = null;
}

function copyCampaign(campaignId) {
    if (campaignId == -1) {
        alert(getTooManyRecordsMessage());
        return;
    }
    var path = '/MMM/AccoutUser/Campaign/Campaign/CampaignXmlForwarder.aspx?id=' + campaignId + "&type=copy";

    objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    objXMLHTTP.Open("POST", path, false);
    objXMLHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    objXMLHTTP.Send(null);
    var response = objXMLHTTP.responseText;
    objXMLHTTP = null;
    objXMLDOM = new ActiveXObject("Microsoft.XMLDOM");
    objXMLDOM.loadXML(response);
    var ActionNode = objXMLDOM.getElementsByTagName("action");
    switch (ActionNode(0).text) {
        case "error":
            alert('Error Occured While Copying The Campaign.');
            break;
        case "copy":
            window.location.href = window.location.href;
            break;
    }
    objXMLDOM = null;
}

function openObj(objNo, qryString) {
    var path = '';
    switch (Number(objNo)) {
        case 1001: 	// E-Mail EditNew.aspx
            path = _sRoot + '/AccoutUser/Campaign/Email/EmailEditNew/EmailEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 950, 660);
            break;

        case 1002: 	// Telemarketing EditNew.aspx
            path = _sRoot + '/AccoutUser/Campaign/Telemarketing/TelemarketingEditNew/TelemarketingEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 880, 610);
            break;

        case 1003: 	// Campaign EditNew.aspx
            path = _sRoot + '/AccoutUser/Campaign/Campaign/CampaignEditNew/CampaignEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 950, 650);
            break;

        case 1004: 	// WebForm EditNew.aspx
            path = _sRoot + '/AccoutUser/Campaign/WebForm/WebFormEditNew/WebFormEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 940, 610);
            break;



        case 1005: 	// MMMAdmin /Client EditNew.aspx
            path = _sRoot + '/MMMAdmin/Home/MMMAdmin/Client/ClientEditNew.aspx';
            if (qryString)
                path = path + qryString;            
            openStdWin(path, '', 750, 650);
            break;

        case 1006:
            path = _sRoot + '/AccoutUser/People/Lists/NewListEdit/ListEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 950, 655);
            break;

        case 1007: 	// MMMAdmin/Client/Contact/ContactEditNew.aspx
            path = _sRoot + '/MMMAdmin/Home/MMMAdmin/Client/Contact/ContactEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 750, 555);
            break;

        case 1008: 	// AccoutUser/People/Prospects/NewProspects/ProspectEditNew.aspx
            path = _sRoot + '/AccoutUser/People/Prospects/NewProspects/ProspectEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 950, 705);
            break;

        case 1009:
            path = _sRoot + '/AccoutUser/People/ManageLeads/LeadsEditNew/LeadsEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 770, 570);
            break;

        case 1010:
            path = _sRoot + '/AccoutUser/Campaign/SMS/SMSEditNew/SMSEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 750, 600);
            break;

        case 1011:
            path = _sRoot + '/MMMAdmin/Home/Configuration/SMSConfiguration/SMSConfigurationEditNew/SMSConfigurationEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 750, 610);
            break;

        case 1012:
            path = _sRoot + '/MMMAdmin/Home/Configuration/GatewayConfiguration/GatewayConfigurationEditNew/GatewayConfigurationEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 750, 610);
            break;

        case 1013:
            path = _sRoot + '/AccoutUser/People/DeDupe/DeDupeEditNew/DeDupeEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 900, 680);
            break;

        case 1014:
            path = _sRoot + '/MMMAdmin/Home/Configuration/CustomAttributesConfiguration/CustomAttributes/CustomAttributes.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 940, 600);
            break;

        case 1015:
            path = _sRoot + '/MMMAdmin/Home/Configuration/CustomAttributesConfiguration/CustomAttributes/CustomAttributeEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 750, 625);
            break;
            
        case 1016:
            path = _sRoot + '/AccoutUser/People/Lists/NewListEdit/NewListDynamicEdit/DynamicListEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 950, 655);
            break;
            
        case 2001:
            path = _sRoot + '/MMMAdmin/Home/HTMLTemplate/HTMLTemplate/HTMLTemplateEditNew/HTMLTemplateEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 940, 600);
            break;

        case 2002:
            path = _sRoot + '/MMMAdmin/Home/HTMLTemplate/ContentSection/ContentSectionEditNew/ContentSectionEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 770, 570);
            break;

        case 2003:
            path = _sRoot + '/MMMAdmin/Home/HTMLTemplate/ContentBlock/ContentBlockEditNew/ContentBlockEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 780, 610);
            break;

        case 3001:
            path = _sRoot + '/MMMAdmin/Home/PickList/PickListEditNew/PickListAddNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 780, 610);
            break;

        case 3002:
            path = _sRoot + '/MMMAdmin/Home/PickList/PickListEditNew/PickListInfo/NewPickListAttribute.aspx';
            if (qryString)
                path = path + qryString;
            return openStdDlg(path, '', 375, 250);
            break;

        case 3003:
            path = _sRoot + '/MMMAdmin/Home/PickList/PickListEditNew/PickListItem/NewPickListItem.aspx';
            if (qryString)
                path = path + qryString;
            return openStdDlg(path, '', 375, 265);
            break;

        case 3004:
            path = _sRoot + '/common/ResourceManager/rscManager.aspx';
            if (qryString)
                path = path + qryString;
            return openStdWin(path, '', 1100, 610);
            break;

        case 3005:
            path = _sRoot + '/common/ResourceManager/rscManager.aspx';
            if (qryString)
                path = path + qryString;
            return openStdDlg(path, '', 1200, 610);
            break;

        case 4001:
            path = _sRoot + '/MMMAdmin/Home/CRMPublishers/PublisherEditNew/PublisherAddNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 780, 610);
            break;

        case 4002:
            path = _sRoot + '/MMMAdmin/Home/CRMPublishers/PublisherEditNew/Subscribers/Subscriber/SubscriberEditNew.aspx';
            if (qryString)
                path = path + qryString;
            openStdWin(path, '', 850, 555);
            break;
    }
}


function openPopup() {
    return window.createPopup();
}

function Popup()
{

    this.divElement = "";
    this.isOpen = false;
    this.show = function(x, y, width, height, el, menuDiv) {
        this.isOpen = true;
        this.divElement.style.position = "absolute";
        this.divElement.style.left = x + el.getBoundingClientRect().left;
        this.divElement.style.top = y + el.getBoundingClientRect().top;
        this.divElement.style.width = width;
        var aviableHeight = document.body.clientHeight - parseInt(this.divElement.style.top);
        if (height < aviableHeight) {
            this.divElement.style.height = height;
        }
        else {
            if (menuDiv) {

                this.divElement.style.top = el.getBoundingClientRect().top - height;
            }
            else {
                if (aviableHeight <= 54) {
                    height = 54;
                }
                this.divElement.style.height = aviableHeight;
                this.divElement.firstChild.style.height = (aviableHeight - 2);
                if (aviableHeight < 54) {
                    var top = parseInt(this.divElement.style.top) - 16;
                    height = (top > 121) ? 121 : top;
                    this.divElement.style.height = height;
                    this.divElement.firstChild.style.height = (height - 2);
                    this.divElement.style.top = (top - height) + "px"
                }
            }
        }

        this.divElement.style.background = "white";
        document.body.appendChild(this.divElement);
        this.divElement.style.display = "";
        return true;
    };
    
    this.showCalendar = function(x, y, width, height, el) {
        this.isOpen = true;
        this.divElement.style.position = "absolute";          
        
        var availableDownHeight = document.body.clientHeight - parseInt(el.getBoundingClientRect().bottom);
        var availableUpHeight = parseInt(el.getBoundingClientRect().top);
        var availableLeftWidth = parseInt(el.getBoundingClientRect().left);
        var availableRightWidth = document.body.clientWidth - parseInt(el.getBoundingClientRect().right);
        
        this.divElement.style.height = height;
        this.divElement.style.width = width;
        
        if( height < availableDownHeight)
        {
            this.divElement.style.top = y + availableUpHeight;
            
            if(width < availableRightWidth)
            {
                this.divElement.style.left = x + parseInt(el.getBoundingClientRect().left);
            }
            else if(width < availableLeftWidth)
            {
                this.divElement.style.right = x + availableRightWidth;
            }
            else if(width < (availableLeftWidth + availableRightWidth))
            {
                this.divElement.style.right = x + (availableRightWidth - width/2);
            }
        }
        else if( height < availableUpHeight)
        {
            this.divElement.style.bottom = availableDownHeight + y; 
            
            if(width < availableRightWidth)
            {
                this.divElement.style.left = x + parseInt(el.getBoundingClientRect().left);
            }
            else if(width < availableLeftWidth)
            {
                this.divElement.style.right = x + availableRightWidth;
            }
            else if(width < (availableLeftWidth + availableRightWidth))
            {
                this.divElement.style.right = x + (availableRightWidth - width/2);
            }
        }
        else if(height < (availableDownHeight + availableUpHeight))
        {
            this.divElement.style.top = y;
            
            if(width < availableRightWidth)
            {
                this.divElement.style.left = parseInt(el.getBoundingClientRect().right);
            }
            else if(width < availableLeftWidth)
            {
                this.divElement.style.left = parseInt(el.getBoundingClientRect().left) - width;
            }
            else if(width < (availableLeftWidth + availableRightWidth))
            {
                this.divElement.style.right = x + (availableRightWidth - width/2);
            }
        }
        
              
        //this.divElement.style.zIndex = "999";
        this.divElement.style.background = "white";
        document.body.appendChild(this.divElement);
        this.divElement.style.display = "";
        return true;
    };

    this.hide = function()
    {
       this.isOpen = false;
       this.divElement.parentNode.removeChild(this.divElement);  
    };

    this.SetHTML = function(content) {
        this.divElement.innerHTML = content;
        if (this.divElement.firstChild.childNodes.length == 2) {
            this.divElement.firstChild.removeChild(this.divElement.firstChild.childNodes[0]);
        }
        this.divElement.firstChild.firstChild.id = "_" + this.divElement.firstChild.firstChild.id;
    };
}

function IsPopupDivClicked(src)
{
    
    while(src.parentElement != null)
    {       
        if(src.parentElement.className == "selectBox")
        {
            return true;
        }
       else if(src.className == "dtm")
       {
            return true;
       }
       else if(src.className == "timeBox")
       {
            return true;
       }
      
        
        src = src.parentElement;
    }
    
    return false;
}


function openPopupDiv() {
        
        if(p != null)
        {
             p.hide();
             p = null;
        }        
        
        p = new Popup(); 
        popwindow = window.document.createElement("div");
        //popwindow.id = "popupDiv"; 
        p.divElement = popwindow; 
        
        window.document.onclick  = function()
        {        
            if(IsPopupDivClicked(event.srcElement) == false)
            {
                p.isOpen = false;
                p.hide(); 
            }
           
        }; 
        window.onresize  = function()
        { 
            p.isOpen = false;
            p.hide();
        }
        return p;
}


var ERROR_STOP = 0;
var ERROR_NONE = 1;
var ERROR_CONTINUE = 2;
function handleXMLErr(xml, bContinue) {
    if (bContinue == null) bContinue = false;
    if (xml.parseError.errorCode != 0) {
        alert("XML Parser Error: " + xml.parseError.reason);
        if (!bContinue) {
            return ERROR_STOP;
        }
        else {
            return ERROR_CONTINUE;
        }
    }
    var node = xml.selectSingleNode("/error");
    if (node) {
        if (!bContinue) {
            openStdDlg("/_common/error/dlg_error.aspx?hresult=" + node.selectSingleNode("number").text, null, 400, 200);
            return ERROR_STOP;
        }
        else {
            return ERROR_CONTINUE;
        }
    }
    return ERROR_NONE;
}
function loadHelp(sArea) {
    var x = 0;
    var y = 0;
    var iWidth = 285;
    if ((top.screenLeft + top.document.body.clientWidth) < (top.screen.width - 250)) {
        x = top.screenLeft + top.document.body.clientWidth + 3;
    }
    else {
        x = top.screen.width - 300;
    }
    if ((top.screenTop + top.document.body.clientHeight) < top.screen.height) {
        y = top.screenTop - 23;
    }
    else {
        y = top.screen.height - 450;
    }
    if (sArea) {
        var s = sArea;
        iWidth = 565;
    }
    else {
        var s = window.location.pathname;
    }

    switch (s) {
        case "/stage.aspx":
            s = window.frmPlatform.location.pathname;
            break;
    }
    switch (s) {
        case "/tools/home_tools.aspx":
        case "/reports/home_sales.aspx":
        case "/reports/home_admin.aspx":
        case "/reports/home_service.aspx":
            s += window.frmPlatform.location.search;
            break;
    }

    var iY = top.document.body.clientHeight - 5;
    if (iY < 300) {
        iY = 300;
    }
    window.open("/help/default.aspx?area=" + escape(s), "MSCRMHelp", "resizable=1,width=" + iWidth + ",height=" + iY + ",left=" + x + ",top=" + y);
}
function IsActivityTypeCode(iObjTypeCode) {
    switch (parseInt(iObjTypeCode, 10)) {
        case EmailActivity:
        case FaxActivity:
        case PhoneCallActivity:
        case LetterActivity:
        case AppointmentActivity:
        case Activity: return true;
        default: return false;
    }
}
function auto(iObjectTypeCode) {
    for (var i = 0; i < document.frames.length; i++) {
        var o = document.frames[i].frameElement;
        if (IsActivityTypeCode(iObjectTypeCode)) {
            iObjectTypeCode = Activity;
        }

        if (o.className == "grid" && iObjectTypeCode == o.ObjectTypeCode) {
            o.Refresh();
        }
        else if (o.isArea) {

            for (var ii = 0; ii < document.frames[i].frames.length; ii++) {
                o = document.frames[i].frames[ii].frameElement;
                if (o.className == "grid" && iObjectTypeCode == o.ObjectTypeCode) {
                    o.Refresh();
                    return;
                }
            }
        }
    }
}
function HtmlEncode(s) {
    s = s.replace(/&/g, "~amp;");
    s = s.replace(/</g, "~lt;");
    s = s.replace(/>/g, "~gt;");
    return s.replace(/\"/g, "~quot;");

}
function EncodeHtml(s) {
    s = s.replace(/&/g, "&amp;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    return s.replace(/\"/g, "&quot;");
}
function decodeXml(s) {

    try {
        s = eval('"' + s.replace(/&#x(\w\w\w\w);/g, "\\u$1").replace(/"/g, '\\"') + '"');
    }
    catch (e) { ; }

    s = s.replace(/&lt;/g, "<");
    s = s.replace(/&apos;/g, "'");
    s = s.replace(/&quot;/g, "\"");
    s = s.replace(/&amp;/g, "&");
    s = s.replace(/&gt;/g, ">");
    return s;
}

function decodeXmlTilda(s) {

    try {
        s = eval('"' + s.replace(/&#x(\w\w\w\w);/g, "\\u$1").replace(/"/g, '\\"') + '"');
    }
    catch (e) { ; }

    s = s.replace(/~lt;/g, "<");
    s = s.replace(/~apos;/g, "'");
    s = s.replace(/~quot;/g, "\"");
    s = s.replace(/~amp;/g, "&");
    s = s.replace(/~gt;/g, ">");
    return s;
}

function URLEncode(s) {
    s = s.replace(" ", "%20");
    s = s.replace("\"", "%22");
    s = s.replace("#", "%23");
    s = s.replace("&", "%26");
    s = s.replace("'", "%27");
    return s.replace("+", "%2B");
}

function notOperationalMessage() {
    var message = 'Not operational.' +
			'\n------------------------------------------------------------------------------' +
			'\n' +
			'The function you have selected is currently not operational' +
			'\nin the current version of  Zoomio Campaigner, but is planned' +
			'\nfor a future release. ' +
			'\n------------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'For more details on upcoming features in ' +
            '\nMyMarketingMachine, please contact proddev@zoomio.com' +
			'\n';
    return message;
}

function showErrorsMessage() {
    var message = 'Errors in data file.' +
			'\n----------------------------------------------------------' +
			'\n' +
			'There are errors in the file you are trying to upload.' +
			'\nPlease correct the errors and try again.' +
			'\n----------------------------------------------------------' +
			'\n' +
			'\n' +
			'Click OK to view errors.' +
			'\n';
    return message;
}

function getLeadCriteriaErrorMessage() {
    var message = 'Syntax error in criteria expression.' +
			'\n--------------------------------------------------------------' +
			'\n' +
			'There are syntax error(s) in the criteria expression.' +
			'\nPlease correct the error(s) and try again.' +
			'\n--------------------------------------------------------------' +
			'\n' +
			'\n' +
			'Click OK to view errors.' +
			'\n';
    return message;
}

function getTooManyRecordsMessage() {
    var message = 'Too many records selected!' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action can be performed on one item' +
			'\nat a time.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'Please select only one record and try again' +
			'\n';
    return message;
}

function getNoRecordSelectedMessage() {
    var message = 'No records selected!' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action can be performed on one item' +
			'\nat a time.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'Please select at least one record and try again' +
			'\n';
    return message;
}

function getCloseDialogMessage() {
    var message = 'Your data has not been saved!' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'To save you changes,click Cancel, and then click Save or Save & Close.' +
			'\n' +
			'To close this record without saving your changes, click OK' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n';
    return message;
}
function getDeletionMessage(rec) {
    var message = 'Delete ' + rec + ' Record(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action will permanently remove these records from.' +
			'\n' +
			'your Zoomio Campaigner database. This action is not recoverable.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}


function getUnbindMessage(rec) {
    var message = 'Unbind ' + rec + ' Record(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action will permanently unbind these records from.' +
			'\n' +
			'your Zoomio Campaigner database. This action is not recoverable.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}

function getProspectDeletionMessage() {
    var message = 'Delete Prospect(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action will permanently remove prospect(s) from.' +
			'\n' +
			'your Zoomio Campaigner database. This action is not recoverable.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}

function getProspectRemovalMessage() {
    var message = 'Remove Prospect(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action will remove prospect(s) from the.' +
			'\n' +
			'selected list. This action is not recoverable.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}


function getRemovalMessage(rec) {
    var message = 'Remove ' + rec + ' Vehicle(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'This action will remove these vehicle(s)' +
			'\n' +
			'from your campaign.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}
//---------------------------------------------------------------------------------------
function getCustomAttributeDeletionMessage(rec) {
    var message = 'Delete ' + rec + ' Custom Attribute(s)?' +
			'\n' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'Deleting a custom field will also delete the values that are stored in the database for the custom field. ' +
			'' +
			'Deleted custom fields and values cannot be restored.' +
			'\n' +
			'---------------------------------------------------------------------------' +
			'\n' +
			'\n' +
			'\n' +
			'Press OK to continue, or Cancel to stay on the current page.';
    return message;
}

function getVehicleRunningMessage(vName) {
    var message = 'This ' + vName + ' is part of a running campaign and can not be edited';
    return message;
}


function getVehicleLockedMessage(vName) {
    var message = 'This ' + vName + ' is locked and can not be edited';
    return message;
}

function document.onmousedown() {
    var message = '----------------------------------' +
				'\n' +
				'Sorry! Right Click is disabled.' +
				'\n' +
				'----------------------------------';

    if (event.button == 2) {
        var elm = event.srcElement;
        if (elm.tagName != 'INPUT' && elm.tagName != 'TEXTAREA') {
            alert(message);
            window.event.cancleBubble = true;
            window.event.returnValue = false;
        }
    }
}


