//TO set the Current Page for pagination control
function SetCurrentPage(objIdCurPage, objEvent, objIdDopaging) {
    objCurPage = document.getElementById(objIdCurPage);
    objDopaging = document.getElementById(objIdDopaging)
    objDopaging.value = "true"
    var CurPage = parseInt(objCurPage.value);

    if (objEvent == "Next") {
        objCurPage.value = CurPage + 1
    }
    else if (objEvent == "Prev") {
        objCurPage.value = CurPage - 1
    }
    else {
        objCurPage.value = objEvent
    }
    var cur = document.getElementById('ctl00_ContentPlaceHolder1_hdnCurrentPagePaging');
    cur.value = objCurPage.value
}
function hoverstyle(evt) {
    if (window.event)
        evt = window.event.srcElement
    else
        evt = evt.target
    if (evt.tagName == "A") {
        if (evt.style.backgroundColor != "highlight" && evt.style.backgroundColor == "") {
            evt.style.backgroundColor = "#DCDCDC"
            evt.style.color = "#6F7A81"
        }
    }
}
function unhoverstyle(evt) {
    if (window.event)
        evt = window.event.srcElement
    else
        evt = evt.target
    if (evt.tagName == "A") {
        if (evt.style.backgroundColor != "highlight") {
            evt.style.backgroundColor = ""
            evt.style.color = "#6F7A81"
        }
    }
}
//Added by Ramya for opening windows using javascript
function ExpandCollapse(event, eleType) {
    var evtTree, tblClientId
    if (window.event) evtTree = window.event.srcElement
    else evtTree = evt.target
    if (eleType.toUpperCase() == "CAD" && evtTree.id.indexOf("ibtnCADPlusMinus") != -1) tblClientId = evtTree.id.replace("ibtnCADPlusMinus", "tblCADThumbNails")
    else if (eleType.toUpperCase() == "SPEC" && evtTree.id.indexOf("ibtnPlusMinus") != -1) tblClientId = evtTree.id.replace("ibtnPlusMinus", "tblSpecsViewAllCaption")
    else return true
    var tblViewAll = document.getElementById(tblClientId)
    if (evtTree.src.indexOf("plus.gif") == -1) {
        evtTree.src = evtTree.src.substring(0, evtTree.src.indexOf("minus.gif")) + "plus.gif"
        tblViewAll.style.display = "none"
    }
    else {
        evtTree.src = evtTree.src.substring(0, evtTree.src.indexOf("plus.gif")) + "minus.gif"
        tblViewAll.style.display = ""
    }
    return false
}

function OpenCadDownload_CPRT(sourceId, fileOrUrlFlag, contentType) {
    var ddlCadFileTypeCmb = document.getElementById(sourceId)
    var Url
    if (fileOrUrlFlag == "U") {
        Url = ddlCadFileTypeCmb.value;        
    }
    else {
        Url = document.getElementById("ctl00_ContentPlaceHolder1_txtUriPath").value + ddlCadFileTypeCmb.value        
    }
    var valUser = document.getElementById("ctl00_ContentPlaceHolder1_txtValidateUser").value
    if (valUser == 'True') OpenDownLoadWindow_CPRT(Url, contentType)
}
function OpenDownLoadWindow_CPRT(URL, contentType, action) {
    var options = 'left=0,top=0,width=800,height=500,menubar=yes,resizable=yes'
    try {
        if (URL != undefined && URL.length > 0) //window.open(URL,'',options)
        {
            // Arun changes for Download tracking code for Resolute starts...
            var pageAction;
            if (contentType == "CAD")
                pageAction = "1615";
            else if (contentType == "3D")
                pageAction = "1616";

            //trackAction(pageAction);

            if (action == "view")
                window.open(URL)
            else {
                callDownloadPage(URL);
                //setTimeout("window.open('" + URL + "');", 2000)
                window.open(URL);
            }
            //            callDownloadPage(URL);
            //            setTimeout("DelayPopup('" + URL + "');", 1800)
            //window.open(URL) 
            // Arun changes for Download tracking code for Resolute ends...
        }
    }
    catch (ex) {
    }
}
//Start: TA 44 CAD links causing IE to crash if file not found
function ShowMessagetoUser() {
    alert("File Not Found");
}
//End: TA 44 CAD links causing IE to crash if file not found

function DisplayLoginAlert_CPRT(urlMessage, nLeft, nTop, nWidth, nHeight) {
    window.open(urlMessage, 'CustomPopUp', 'left=' + nLeft + ',top=' + nTop + ',width=' + nWidth + ',height=' +
    nHeight + ',menubar=no,resizable=no')
}
//Added by Arunachalam. K for GreenChanges
function OpenWindow(CelId, webMetricsAction, webMetricsContentType, fileorUrlflag, Url, entityID, Caption, bpmAccountNo, leadType, dAction) {
    SetWebmetricsParams(CelId, webMetricsAction, webMetricsContentType, fileorUrlflag, Url, entityID)

    // green Download tracking code for Resolute starts...
    var pageAction = "1620";
    //trackAction(pageAction);
    if (dAction == "down") {
        callDownloadPage(Url);
        setTimeout("DelayPopup('" + Url + "');", 1800)
    }
    else
    { window.open(Url); }
    // green Download tracking code for Resolute ends...
}
//functions ends. 
function LoginAlert(strOpenWindowMsg, nLeft, nTop, nWidth, nHeight) {
    window.open(strOpenWindowMsg, 'CustomPopUp', 'left=' + nLeft + ',top=' + nTop + ',width=' + nWidth + ',height=' + nHeight + ',menubar=no,resizable=no')
}

//Added by Arunachalam. K for Bookmark
function addBookmark_CPRT(title, urlAdd) {
    vTitle = title.replace("^", "'");
    var url = window.location.href // + '/email'
    if (url.indexOf("#") != -1) {
        url = url.substring(0, url.indexOf("#"));
    }
    if (url.substring(url.lastIndexOf("/") + 1) == "C") {
        url = url.substring(0, url.lastIndexOf("/"));
    }
    if (urlAdd != "" && urlAdd != undefined && urlAdd != "undefined") {
        var mIndex = url.toLowerCase().indexOf("manufacturer")
        if (mIndex != -1) {
            var urlSplit = url.substring(mIndex);
            var urlArr = urlSplit.split("/")
            if (urlArr.length != 0) {
                var contentType = urlArr[2];
                if (urlArr.length == 4)
                    url = url.substring(0, url.lastIndexOf("/"));                
                //if (url.toLowerCase().indexOf("/" + contentType) != -1)
                  //  url = url.substring(0, url.toLowerCase().indexOf("/" + contentType) + contentType.length + 1);               
            }
        }
        url = url + urlAdd
    }

    // Arun changes for Browser Compatibility starts
    var ua = navigator.userAgent.toLowerCase();
    var isKonq = (ua.indexOf('konqueror') != -1);
    var isSafari = (ua.indexOf('webkit') != -1);
    var isMac = (ua.indexOf('mac') != -1);
    var buttonStr = isMac ? 'Command/Cmd' : 'CTRL';

    if (window.external && (!document.createTextNode ||
      (typeof (window.external.AddFavorite) == 'unknown'))) {
        window.external.AddFavorite(url, vTitle); // IE/Win //Rally Task TA 1: US265: Apostrophe in Company name Issue Fix(for book mark only for IE)
    } else if (window.sidebar) {
        window.sidebar.addPanel(vTitle, url, "")
    } else if (isKonq) {
        alert('You need to press CTRL + B to bookmark this page.');
    } else if (window.opera) {
        var a = document.createElement("A");
        a.rel = "sidebar";
        a.target = "_search";
        a.title = vTitle;
        a.href = url;
        a.click();
        // void (0); // do nothing here (Opera 7+)
    } else if (window.home || isSafari) { // Firefox, Netscape, Safari, iCab
        alert('You need to press ' + buttonStr + ' + D to bookmark this page.');
    } else if (!window.print || isMac) { // IE5/Mac and Safari 1.0
        alert('You need to press Command/Cmd + D to bookmark this page.');
    } else {
        alert('In order to bookmark this page you need to do so manually ' +
        'through your browser.');
    }
    // Arun changes for Browser Compatibility ends
}

//added by Ujjwala for invoking catalog download if url contains cellid
//Function to Invoke Catalog Download at Runtime
function InvokeCatalogDownload(aDownloadClientId) {
    var objADownload = document.getElementById(aDownloadClientId);
    objADownload.click();
}

function InsertWebMetricsDataCEU_CPRT(ExtURL, Role, FirmType, LIC, CompanyID, ContentElementID, Action) {
    var parameterNames = "role|firm|lic|mid|cid|act"
    var parameterValues = Role + '|' + FirmType + '|' + LIC + '|' + CompanyID + '|' + ContentElementID + '|' + Action
    InsertWebMetricsDataCommon(parameterNames, parameterValues, ExtURL, "|")
}


//**********************added by Ujjwala on 03-07-2008*********************************
function DownloadRHSContentElementId(Url, Caption, CelId, bpmAccountNo, fileorUrlflag, leadType, webMetricsAction, webMetricsContentType, webMetricsEntityId) {
    if (Caption == '' || Caption == 'undefined') alert('Please Check : ' + CelId + '  ' + Caption)
    //var valUser=document.getElementById("txtValidateUser").value
    //if(valUser=='True')
    SetWebmetricsParams(CelId, webMetricsAction, webMetricsContentType, fileorUrlflag, Url, webMetricsEntityId)
}
//************************end by ujjjwala*************************************************

// Arun changes for calling the download page.
function callDownloadPage(title) {
    var browserUrl = window.location.href
    var browserUrl = browserUrl.substring(0, browserUrl.toUpperCase().indexOf("MANUFACTURER")) + "Webpages/Download.aspx";
    var detailUrl = browserUrl + '?title=' + title
    window.open(detailUrl, 'Downloads', 'left=250,top=300,width=250,height=75,menubar=no,resizable=yes');
}

function OpenWindowCatalogDownload(Url, dAction) {
    // Arun changes for Resolute - Catalogs starts
    var pageAction = "1617";
    //trackAction(pageAction);
    
    if (dAction == "down") {
        callDownloadPage(Url);
        setTimeout("DelayPopup('" + Url + "');", 1800)
    }
    else
    { window.open(Url); }
    // Arun changes for Resolute - Catalogs end
}

//added venkat for Spec on 31-jul-2008
function OpenWindowSpec(Url) {    
    // Arun changes for Resolute - Spec starts
    var pageAction = "1619";

    //trackAction(pageAction);
    //window.open(Url);    
    // Arun changes for Resolute - Spec end
}

function handleSpecResponse_CPRT() {

}



/* for Add to Contact Baiju added on 08 Aug 2008 */ //"contacts";
function RefreshAddToContact(RefreshContact) {
    document.getElementById('ctl00_ContentPlaceHolder1_hdnContentType').value = RefreshContact;
    __doPostBack('ctl00_ContentPlaceHolder1_upCPRHS');
}
function onNavigate(sender, e) {
    //            var customerID = e.get_state().Id;
    var productID = e.get_state().Id;
    if (productID != undefined) {
        document.getElementById('ctl00_ContentPlaceHolder1_hdnContentType').value = "products";
        document.getElementById('ctl00_ContentPlaceHolder1_hdnProductValueFrmHis').value = productID
    }
    else
        document.getElementById('ctl00_ContentPlaceHolder1_hdnProductValueFrmHis').value = ''
    __doPostBack('ctl00_ContentPlaceHolder1_upCPRHS');
}
//Function name modified to fix the js error in QA.
// Function appends the enityID in the url on update panle post back.
function RefreshUpdatePanel(pid, groupType) {
    //    Sys.Application.addHistoryPoint({ Id: pid }, "Action" + pid)
    //    Sys.Debug.trace("HistroyPointAddted" + pid);
    //    alert(pid);
    //    Sys.Application.add_navigate(onNavigate);
    var val = pid + ',' + groupType
    Sys.Application.addHistoryPoint({ Id: val })
    Sys.Debug.trace("HistroyPointAdded" + val);
    Sys.Application.add_navigate(onNavigate);
}

// Added by Arun for Browser Compatibility Pop-up blocker warning message.
var bWin = null;
function DelayPopup(Url) {
    bWin = window.open(Url);
    if ((bWin == null)
     || (typeof (bWin) == "undefined")) {
        alert("Please turn off Pop-up blocker.", "Warning...");
    }
    window.focus();

}
function MobiusRedirect(alerttype, url) {
    if (alerttype == "1") {
        alert("Please login to view this content.")        
    }
    else
    {
        alert("You are not authorized to view this content.")
    }
    window.location = url; 
}
