//Calling ContentPresentation Page
function CallContentPresentationPage(contentPresentationURL) {    
    document.location.href = contentPresentationURL
}
//Email
function OpenEmail(sourceURL, companyID, productID, strCelID) {
    var arrProduct = productID.split('|')
    if (arrProduct[0] == 'P' || arrProduct[0] == 'F')
        sourceURL += "&src=" + arrProduct[0] + "&companyId=" + companyID + "&celId=" + arrProduct[1]
    else if (arrProduct[0] == 'PG' || arrProduct[0] == 'FG' || arrProduct[0] == 'PC' || arrProduct[0] == 'FC' ||
	  arrProduct[0] == 'PGI' || arrProduct[0] == 'FGI' || arrProduct[0] == 'PGIC' || arrProduct[0] == 'FGIC')
        sourceURL += "&src=" + arrProduct[0] + "&companyId=" + companyID + "&celId=" + strCelID + "&entityKey=" + arrProduct[1]
    else if (arrProduct[0] == 'CG' || arrProduct[0] == 'CGI' || arrProduct[0] == 'CGIC' || arrProduct[0] == 'CC')
        sourceURL += "&src=" + arrProduct[0] + "&companyId=" + companyID + "&celId=" + strCelID
    //else if(arrProduct[0] == 'CC'||arrProduct[0] == 'PC'||arrProduct[0] == 'FC')
    //sourceURL += "&src="+arrProduct[0]+"&companyId="+companyID+"&celId="+strCelID			
    else
        sourceURL += "&src=" + arrProduct[0] + "&companyId=" + companyID
    PTPortlet.setSessionPref("EmailSrcUrl", sourceURL)
    PTPortlet.setSessionPref("EmailCompanyId", companyID)
    PTPortlet.setSessionPref("EmailProductId", productID)
    PTPortlet.setSessionPref("EmailMessageBody", '')
    PTPortlet.setSessionPref("EmailContentId", strCelID)
    PTPortlet.setSessionPref("EmailSourcePage", 'Workspace')
}
//Setting clip position based on the resolution
var clipTop = 0
var clipLeft = -10

if (screen.availWidth == 800)
    var clipWidth = 400
else if (screen.availWidth == 1024)
    var clipWidth = 995
else if (screen.availWidth > 1024)
    var clipWidth = 995
var clipRight = clipWidth;
var clipBottom = 110
var topper = 0
var lyrwidth = 0
var time, amount, theTime, theHeight, DHTML
var loop, sum = 0
//Space adjustments during scrolling
var MaxSpaceAdj = "<br/><br/><br/><br/><br/><br/><br/><br/><br/>"
var MinSpaceAdj = "<br/><br/>"
//Added by Arunachalam. K for Maximize functionality
function Maximize(bMaxMin, strHrfWKSMinMax, strTblWKSDataInner, strHdnWS) {
	var tblWKSDataInner = document.getElementById(strTblWKSDataInner.toString())
    var hiddenWS = document.getElementById(strHdnWS.toString())
    if (bMaxMin == 'true') {
        document.getElementById(strHrfWKSMinMax.toString()).innerHTML = 'minimize window'
        document.getElementById('hrfMoveRight').style.display = ""
        document.getElementById('hrfMoveLeft').style.display = ""
        document.getElementById('divBg').style.display = ""
        tblWKSDataInner.style.height = "130px"
        document.getElementById('SpaceAdjustment').innerHTML = MaxSpaceAdj
        hiddenWS.value = 'minimize window'
        init()
    }
    else {
        document.getElementById('SpaceAdjustment').innerHTML = MinSpaceAdj
        hiddenWS.value = 'maximize window'
    }
    processScroll()
}
//Added by Arunachalam. K for alternateively Maximize and Minimize
function MaximizeOrMinimize(strHrfWKSMinMax, strTblWKSDataInner, strHdnWS) {
	var hrfMaximizeMinimize = document.getElementById(strHrfWKSMinMax.toString())
    var tblWKSDataInner = document.getElementById(strTblWKSDataInner.toString())
    var hiddenWS = document.getElementById(strHdnWS.toString())
    if (hiddenWS.value == null || hiddenWS.value == "")
        hiddenWS.value = 'maximize window'
    if (hiddenWS.value == 'maximize window') {
        document.getElementById(strHrfWKSMinMax.toString()).innerHTML = 'minimize window'
        document.getElementById('hrfMoveRight').style.display = ""
        document.getElementById('hrfMoveLeft').style.display = ""
        document.getElementById('divBg').style.display = ""
        tblWKSDataInner.style.height = "130px"
        document.getElementById('SpaceAdjustment').innerHTML = MaxSpaceAdj
        hiddenWS.value = 'minimize window'
        init()
    }
    else {
        document.getElementById('SpaceAdjustment').innerHTML = MinSpaceAdj
        hiddenWS.value = 'maximize window'
    }
    processScroll()
    return false
}
//Used to initialize clip positions
function init() {
    try {
        //Check for supported browsers
        DHTML = (document.getElementById || document.all || document.layers)
        if (!DHTML)
            return;
        var x = new getObj('divBg');
        if (document.layers) {
            lyrwidth = x.style.clip.right;
            lyrwidth += 20;
            x.style.clip.top = clipTop;
            x.style.clip.left = clipLeft;
            x.style.clip.right = clipWidth;
            x.style.clip.bottom = clipBottom;
        }
        else if (document.getElementById || document.all) {
            var theParagraph = document.getElementById('ScrollTR');
            
            for (var temp = 0; temp < theParagraph.childNodes.length; temp++)
                if (theParagraph.childNodes[temp].offsetWidth != null)
                sum += (theParagraph.childNodes[temp].offsetWidth);
            if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0)
                lyrwidth = x.obj.offsetWidth;
            else
                lyrwidth = x.obj.offsetWidth;

            var clipstring = 'rect(' + clipTop + 'px,' + clipWidth + 'px,' + clipBottom + 'px,' + clipLeft + 'px)';
            x.style.clip = clipstring;
        }
    }
    catch (ex) {
        //alert("init"+ex.description)
    }
}

//Added by Arunachalam. K for Scrolling
var thelayer;
function scrollayer(layername, amt, tim) {
    if (!DHTML)
        return;
    thelayer = new getObj(layername);
    if (!thelayer)
        return;
    amount = amt;
    theTime = tim;
    loop = true;
    realscroll();
}
//Added by Arunachalam. K for Stop scrolling
function stopScroll() {
    loop = false;
    if (time) {
        clearTimeout(theTime);
    }
}
//Added by Arunachalam. K for real scroll
function realscroll() {
    if (!DHTML) return;
    clipLeft += amount;
    clipRight += amount
    topper -= amount;
    if (clipLeft < -20 || clipRight > sum) {
        clipLeft -= amount;
        clipRight -= amount
        topper += amount;
        return;
    }
    if (document.getElementById || document.all) {
        clipstring = 'rect(' + clipTop + 'px,' + clipWidth + 'em,' + clipBottom + 'px,' + clipLeft + ')';
        thelayer.style.clip = clipstring;
        thelayer.style.left = topper + 'px';
    }
    else if (document.layers) {
        thelayer.style.clip.left = clipLeft;
        thelayer.style.clip.right = clipRight;
        thelayer.style.left = topper
    }
    if (loop)
        setTimeout('realscroll()', theTime);
}
//Added by Arunachalam. K for Getting an object from the name
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) {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}

// Added by Arun for hiding DropDownLists during scrolling.
function processScroll() {
    var ie4 = (document.all) ? true : false
    try {
        var lnkMaxSelect = document.getElementById('lnkMaxSelect')
        var tblWKSLinks = document.getElementById('ctl00_tblWKSLinks')
        var CPWorkspace = document.getElementById('dWorkSpace')
        if (ie4) {
            if ((tblWKSLinks.offsetTop + 20) >= CPWorkspace.offsetTop)
                lnkMaxSelect.style.display = "none"
            else
                lnkMaxSelect.style.display = ""
        }
    }
    catch (ex) {
    }
        
}

//Open related sites
function OpenOtherSitesLinks(elementId) {
    var cboSelect = document.getElementById(elementId)
    if (cboSelect.selectedIndex > 0)
        if (cboSelect.selectedIndex != 1 && cboSelect.selectedIndex != 12 && cboSelect.selectedIndex != 11) {
        //<pt:transformer pt:fixurl="off" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' />
        window.open(cboSelect.value, "")
        //<pt:transformer pt:fixurl="on" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' />
    }
}

//Contact Us Page
function contactus() {
    //<pt:transformer pt:fixurl="off" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' />
    window.open("http://costest.construction.com/cest/emailus/form2test.asp?rd=http://sweets.construction.com/", "CustomPopUp", "width=510,height=620,menubar=yes,resizable=no")
    //<pt:transformer pt:fixurl="on" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' />
}
//CP Breadcrumb "'" and "\"" issue
var BreadCrumbText = document.getElementById("aBreadCrumb");
if (BreadCrumbText != null) {
    BreadCrumbText.innerHTML = BreadCrumbText.innerHTML.replace(/bslash567/g, "\"").replace(/sslash765/g, "'")
}