﻿
var CommonTimer;
var CloseImageTimer;

window.onload = function(){
          document.body.appendChild(document.createElement('div'))
        }

// search
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
var hndl = window.setTimeout('startGA();', 100);
function startGA()
{
    if (typeof(_gat) == 'object')
    {
        window.clearTimeout(hndl);
        var pageTracker = _gat._getTracker("UA-5714464-1");
        pageTracker._initData();
        pageTracker._trackPageview();
    }
    else
    {
        hndl = window.setTimeout('startGA();', 500);
    }
}

// rotate slogon on master page
var rotaterTitle = new Array();
rotaterTitle[0] = '15,000 Items in Stock';
rotaterTitle[1] = 'Discounted Shipping';
rotaterTitle[2] = 'Your Order will Ship Today';
rotaterTitle[3] = 'Guaranteed Lowest Prices';

var currentIdx = 0;  
function SetMessage(contentID)
{    
    var area = GetObject(contentID); 
    if (area != null)
    {
        if (currentIdx == 0) 
        {
             area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"FAQService.GetFAQContent(5, PopUpItemInStockContent, ServiceErrorHandler);\">" + "Select from " + document.getElementById('ctl00_hdnNumItems').value + " Items " + "<a>";
        }
        else if (currentIdx == 1) 
        {
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"FAQService.GetFAQContent(6, PopUpDisShipContent, ServiceErrorHandler);\">" + rotaterTitle[currentIdx] + "<a>";
        }
        else if (currentIdx == 2) 
        {
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"FAQService.GetFAQContent(7, PopUpShipTodayContent, ServiceErrorHandler);\">" + rotaterTitle[currentIdx] + "<a>";
        }
        else 
        { 
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"FAQService.GetFAQContent(8, PopUpLowPriceContent, ServiceErrorHandler);\">" + rotaterTitle[currentIdx] + "<a>";
        }
     }   
   }   
    
    function PopUpItemInStockContent(content)
    {
        rotaterTitle[0] = "Select from " + document.getElementById('ctl00_hdnNumItems').value + " Items ";
        PopupMessage(rotaterTitle[0], content, null, null);
    }
    function PopUpDisShipContent(content)
    {
        PopupMessage(rotaterTitle[1], content, null, null);
    }
    function PopUpShipTodayContent(content)
    {
        PopupMessage(rotaterTitle[2], content, null, null);
    }
    function PopUpLowPriceContent(content)
    {
        PopupMessage(rotaterTitle[3], content, null, null);
    }

function RotateContent(contentID)
{
    if ( currentIdx < 3 ) 
    {
        currentIdx ++;
        SetMessage(contentID);
    }
    else         // first 
    {
        currentIdx = 0;
        SetMessage(contentID);
    }    
    
    setTimeout("RotateContent('" + contentID +"');", 3000);
}
// end of rotate slogon on master page


// pup up loading image
function PopLoadingImage()
{
    $find('loadingImagePopup').show();  
}

function CloseLoadingImage()
{
    $find('loadingImagePopup').hide();   
}

function PopupByUrl(AreaID, imageName)
{	
    clearTimeout(CloseImageTimer);
    if (imageName == null )
    {
        $find(AreaID).hide();   
    }
    else
    {
        ShowImageByID('largeImagePopUp', imageName);
        $find(AreaID).show();  
    }
}

function CloseImageArea(AreaID)
{
    clearTimeout(CommonTimer);
    ShowImageByID('largeImagePopUp', '/Images/Misc/1x1-transp.gif');
    
    $find(AreaID).hide();   
}

// go to page
function GoTo(page) 
{
    if (page != "" ) 
    {
        if (document.location)
        {
	        document.location.href = page;
	    }
	    else
	    {	    
            window.location = page;
	    }
    }
    return false;
}
// go to product page
function GoToProduct(groupID) 
{
    if (groupID != null && groupID.length > 0 && groupID != "") 
    {
        if (groupID.indexOf("SeePatterns") > 0) {
            GoTo("/SeeAll/SeeITAll.aspx?GroupID=" + groupID);
        }
        else if (groupID.indexOf("Static") > 0) {
            GoTo("/CustomItem/StaticCustom.aspx");
        }
        else if (groupID.indexOf("GroupType") > 0)
        {
            GoTo("/Product Pages/CustomProduct.aspx?GroupID=" + groupID);
        }     
        else
        {
            GoTo("/Product Pages/Product.aspx?GroupID=" + groupID);
        }
    }
}
function GoToProductName(groupName) 
{
    if (groupName != null && groupName.length > 0 && groupName != "")
    {
        GoTo("/Product Pages/Product.aspx?GroupName=" + groupName);
    }
}
    
function buttonOver(obj) 
{
    obj.style.borderBottomColor = 'black';
	obj.style.borderRightColor = 'black';
    obj.style.borderTopColor = '#A0A0A0';
    obj.style.borderLeftColor = '#A0A0A0';
}
	  
function buttonOut(obj) 
{
    obj.style.borderColor = 'white';
}

function lowlight(event) 
{
    event.style.filter = '';
}

function highlight(event) 
{
    event.style.filter = 'Light';
    
    if (event.filters)
    {
        event.filters.Light.Addpoint (60, 0, 40, 215, 215, 215, 85);
        event.filters.Light.Addpoint (0, 60, 40, 215, 215, 215, 85);
        event.filters.Light.Addpoint (30, 30, 40, 215, 215, 215, 85);
        event.filters.Light.Addpoint (60, 60, 40, 255, 200, 200, 100);
    }
}

// return true if key is digital
function IsNumericKey(e)
{
    if (!e) e = window.event;
    var digit;
    document.all ? digit = e.keyCode : digit = e.which;
    return ((digit > 47 && digit < 58) || (digit > 95 && digit < 106) || digit == 8 || digit == 37 || digit == 39 || digit == 46 || digit == 0 || digit == 9);
} 

// return true if key is digital or carriage return
function IsNumericOrEnterKey(e)
{
    if (!e) e = window.event;
    var digit;
    document.all ? digit = e.keyCode : digit = e.which;    
    return ((digit > 47 && digit < 58) || (digit > 95 && digit < 106) || digit == 8 || digit == 13 || digit == 37 || digit == 39 || digit == 46 || digit == 0 || digit == 9);
} 

// block go back
function BlockGoBack()
{
    window.history.forward();
    if (window.history.forward(1) != null) 
    {
        window.history.forward(1);
    }
    else if (window.history.go(1) != null)
    {
        window.history.go(1);
    }
}

// switch image url
function SwithImageUrl(imageID, newUrl)
{       
    if (dom) 
    {
        document.getElementById(imageID).src = newUrl;
    }
    else
    {
        document.images.imageID.src = newUrl;
    }
}

// block carriage return key
function CheckEnter(e)
{ //e is event object passed from function invocation
    var characterCode;
    document.all ? characterCode = e.keyCode : characterCode = e.which;

    if(characterCode == 13)
    { 
        return false;
    }
    else
    {
        return true;
    }
}
    

// trim string    
function TrimAll(sString) 
{
    if (sString)
    {
        var trimmed = sString.toString().replace(/^\s+|\s+$/g, '');
        return trimmed;
    }
    return "";
}
	   
// get object
function GetObject(ID)
{
    var obj;
    if (dom) 
    {
        obj = document.getElementById(ID);
    }
    else if (document.layers)
    {       
        obj = document.layers[ID];
    }    
    else if (document.all) 
    {
        obj = document.all[ID];
    }
    return obj;
}
	   
// get image
function GetImage(imageID)
{
    var image;
    if (dom) 
    {
        image = document.getElementById(imageID);
    }
    else
    {
        image = document.images.imageID;
    }
    return image;
}

// get object by id
function GetObjectByID(ID)
{
    var obj;    
    if (dom)  
    {
        obj = document.getElementById(ID);
    }
    else if (document.all) 
    {
        obj = document.all[ID];
    }
    else if (document.layers) 
    {
        obj = document.layers[ID];
    }
    return obj;
}

// get objects z index
function GetObjectZindex(areaID)
{
    var obj = GetObject(areaID);
    if (obj)
    {
        if (obj.style)
        {
	        return obj.style.zIndex;
	    }
	    else
	    {
	        return obj.zIndex;
	    }
	}
	return 0;
}

// get objects top
function GetObjectHeight(areaID)
{
    var obj = GetObject(areaID);
    if (obj)
    {
	    return obj.clientHeight;
	}
	return 0;
}


function getElementWidth(areaID) 
{
    var obj = GetObject(areaID);
    
	return obj.clientWidth;
}

// get objects top
function GetObjectTop(areaID)
{
    var obj = GetObjectByID(areaID);
    
    var objTop = 0;
    
    if (obj != null)
    {
        if(obj.offsetParent)
        {
            while(1) 
            {
                objTop += obj.offsetTop;
                if(!obj.offsetParent)
                {
                    break;
                }
                obj = obj.offsetParent;
            }
        }
        else if (obj.parent)
        {
            objTop = parseInt(obj.offsetTop);
            while (obj.parent)
            {
                obj = obj.parent;
                objTop += parseInt(obj.offsetTop);
            }
        }
        else if(obj.Y)
        {
            objTop += obj.Y;
        }
    }
    
    return objTop;
}

// get objects left
function GetObjectLeft(areaID)
{
    var obj = GetObjectByID(areaID);
    
    var objLeft = 0;
    if (obj != null)
    {
        if(obj.offsetParent)
        {
            while(1) 
            {
                objLeft += obj.offsetLeft;
                if(!obj.offsetParent)
                {
                    break;
                }
                obj = obj.offsetParent;
            }
        }
        else if(obj.X)
        {
            objLeft += obj.X;
        }
    }
    
    return objLeft;
}

// get page left
function GetPageLeft()
{
    var scrollX = 0;
      
    if (document.all)
    {
         if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
         else
            scrollX = document.documentElement.scrollLeft;
    }   
    else
    {
         scrollX = window.pageXOffset;
    }  
    
    return scrollX;
}

// get page top
function GetPageTop()
{
    var scrollY = 0;
      
    if (document.all)
    {
        if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
        else
            scrollY = document.documentElement.scrollTop;
    }   
    else
    {
        scrollY = window.pageYOffset;
    }  
    
    return scrollY;
}

// get inner window size
function GetPageInnerSize()
{      
    var viewportwidth = 0;
    var viewportheight = 0;
    if (typeof window.innerWidth != 'undefined')
    {
        viewportwidth = window.innerWidth;
        viewportheight = window.innerHeight;
    }
     
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0)
    {
        viewportwidth = document.documentElement.clientWidth;
        viewportheight = document.documentElement.clientHeight;
    }
     
    // older versions of IE     
    else
    {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
    
    arrayPageInnerSize = new Array(viewportheight,viewportwidth);     
    return arrayPageInnerSize; 
} 

// get scroll window size
function GetPageSizeWithScroll()
{     
    if (window.innerHeight && window.scrollMaxY) 
    {
        // Firefox         
        yWithScroll = window.innerHeight + window.scrollMaxY;         
        xWithScroll = window.innerWidth + window.scrollMaxX;     
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { 
        // all but Explorer Mac         
        yWithScroll = document.body.scrollHeight;         
        xWithScroll = document.body.scrollWidth;     
    } 
    else 
    { 
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
        yWithScroll = document.body.offsetHeight;         
        xWithScroll = document.body.offsetWidth;       
    }     
    arrayPageSizeWithScroll = new Array(yWithScroll, xWithScroll);     
    return arrayPageSizeWithScroll; 
} 

// update area height
function ChangeAreaHeight(areaID, height)
{
    if (dom && document.getElementById(areaID) && document.getElementById(areaID).style) 
    {
        document.getElementById(areaID).style.height = height+ 'px';
    }
    else if (document.layers && document.layers[areaID])
    {
        document.layers[areaID].height = height;
    }
    else if (document.all && document.all[areaID] && document.all[areaID].style)
    {
        document.all[areaID].style.height = height;
    }
}
// update area width
function ChangeAreaWidth(areaID, width)
{
    if (dom && document.getElementById(areaID) && document.getElementById(areaID).style) 
    {
        document.getElementById(areaID).style.width = width+ 'px';
    }
    else if (document.layers && document.layers[areaID])
    {
        document.layers[areaID].width = width;
    }
    else if (document.all && document.all[areaID] && document.all[areaID].style)
    {
        document.all[areaID].style.width = width;
    }
}

   
    // Nov 26, 2008 - p.Gargantiel
    // set focus to control  
    function SetFocus(ID) 
    {  
        var control;
        control = document.getElementById(ID);
        if(control != null){
            control.focus();
        }
    }
    
    // Dec 11, 2008 - p.Gargantiel
    // disable/enable element
    function toggleEnable(objID, val)
    {
        var control;
        control = document.getElementById(objID);
        control.disabled=!val;
    }
    
    function toggleHighlight(objID, val, cforeground, cbackground, cborder)
    {
        var control;
        control = document.getElementById(objID);
        control.style.color = cforeground;
        control.style.backgroundColor = cbackground;
        control.style.borderColor = cborder;
        
    }
    
    // 03/25/2009 - p.Gargantiel
    // validates string literal; verifies that all characters in the literal are among:
    //     - lower and upper case alpha 'A' to 'Z'
    //     - numeric '0' to '9'
    //     - symbols {hyphen, comma, period, whitespace}
    function validateLiteral(literal)
    {
        var valid;
        
        // instantiate to false
        valid = false;
        
        // verify string literal
        if(literal.match(/^[a-zA-Z0-9\s-,.]+$/))
        {
            valid = true;    
        }
        
        // return value
        return valid;
    }    
    
    // check text length
    function CheckStringLength(textBox, e, maxLen)
    {
        if (!e) e = window.event;
        var key;
        document.all ? key = e.keyCode : key = e.which;
        
        var content = textBox.value;
        if (content.length >= maxLen && 
            key != 8 && key != 9 && key != 13 && key != 16 && 
            key != 17 && key != 18 && key != 19 && key != 20 &&
            key != 27 && key != 33 && key != 34 && key != 35 && key != 36 &&
            key != 37 && key != 38 && key != 39 && key != 40 && key != 45 && key != 46)
        {
            PopupMessage('Excede maximun length', 'Please enter ' + maxLen + ' characters or less.<br/><br/>Thanks!', null, null);  
            
            if (content.length >= maxLen)
            {
                textBox.value = content.substring(0, maxLen - 1);
            }
            
            return false;
        }
        else
        {
            return true;
        }
    }

    function toggleDisplayExpediteTable(tbl) {
        var isImageExpand = false;
        var rowVisible = false;
        var tblRows = tbl.rows;
        for (i = 0; i < tblRows.length; i++) {
            var tblCells = tblRows[i].cells;
            if (tblCells.length > 0) {
                var strCell = tblCells[0].innerHTML;
                if (strCell.indexOf("FX3DY") > 0 || strCell.indexOf("FX2DY") > 0 || strCell.indexOf("FX1PM") > 0 || strCell.indexOf("FX1AM") > 0 || strCell.indexOf("FX2AM") > 0) {
                    //tblRows[i].style.display = (rowVisible) ? "none" : "";
                    if (tblRows[i].style.display == "none") {
                        tblRows[i].style.display = "";
                        isImageExpand = true;
                    }
                    else
                        tblRows[i].style.display = "none";
                }
            }
        }
        rowVisible = !rowVisible;

        //check if image should be "plus" or "min"
        var imageExpand = document.getElementById('imgExpand');
        if (imageExpand != null) {
            if (isImageExpand)
                imageExpand.src = '/Images/Misc/minus.gif'
            else
                imageExpand.src = '/Images/Misc/plus.gif'
        }
    }

    function toggleDisplayExpediteTableShow(tbl, isShow) {
        var tblRows = tbl.rows;
        for (i = 0; i < tblRows.length - 1; i++) {
            //alert(tblRows[i].id);
            //if (tblRows[i].className != "headerRow") {
            //    tblRows[i].style.display = (rowVisible) ? "none" : "";
            //}
            var tblCells = tblRows[i].cells;
            var strCell = tblCells[0].innerHTML;
            if (strCell.indexOf("FX3DY") > 0 || strCell.indexOf("FX2DY") > 0 || strCell.indexOf("FX1PM") > 0 || strCell.indexOf("FX1AM") > 0 || strCell.indexOf("FX2AM") > 0) {
                if (isShow)
                    tblRows[i].style.display = "";
                else
                    tblRows[i].style.display = "none";
            }
        }
        //rowVisible = !rowVisible;

        //check if image should be "plus" or "min"
        var imageExpand = document.getElementById('imgExpand');
        if (imageExpand != null) {
            if (isShow)
                document.getElementById('imgExpand').src = '/Images/Misc/minus.gif'
            else
                document.getElementById('imgExpand').src = '/Images/Misc/plus.gif'
        }
    }

    function checkShippingResultRadio() {
        var form1 = document.forms[0];
        alert("start");
        for (var i = 0; i < form1.elements.length; i++) {
            var temp = form1.elements[i].type;
            if (temp == "radio") {
                var strCell = form1.elements[i].id;
                alert(strCell);
                if (form1.elements[i].checked) {
                    alert(strCell);
                    if (strCell.indexOf("FX3DY") > 0 || strCell.indexOf("FX2DY") > 0 || strCell.indexOf("FX1PM") > 0 || strCell.indexOf("FX1AM") > 0 || strCell.indexOf("FX2AM") > 0)
                        toggleDisplayExpediteTableShow(document.getElementById('tableShippingCost'), true);
                    else
                        toggleDisplayExpediteTableShow(document.getElementById('tableShippingCost'), false);
                }
                //alert(form1.elements[i].id);

            }
        }
    }
    
    function chat() {
        var bNetscape4 = !((navigator.userAgent.substring(0, 9) == "Mozilla/5") || (navigator.userAgent.indexOf("MSIE") != -1));
        // this opens the chat in a frameset with coBrowse with a size of 0, it is hidden until a cobrowse request is accepted
        if (bNetscape4)
            window.open("http://chat.papermart.com/", "", "height=450,width=425,menubar=no,location=no,resizable=no,status=yes,toolbar=no;scrollbars=no");
        else
            window.open("http://chat.papermart.com/", "", "height=450,width=425,menubar=no,location=no,resizable=yes,status=yes,toolbar=no;scrollbars=no;");
    }
    
    function IsEnter(e) {
        document.all ? characterCode = e.keyCode : characterCode = e.which;
        if (characterCode == 13) {
            return true;
        }
        else {
            return false;
        }
    }
