﻿
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"));
setTimeout('startGA();', 500);
function startGA()
{
    var pageTracker = _gat._getTracker("UA-5714464-1");
    pageTracker._initData();
    pageTracker._trackPageview();
}

// rotate slogon on master page
var currentIdx = 0;  
function SetMessage(contentID)
{    
    var area = GetObject(contentID); 
    if (area != null)
    {
        if (currentIdx == 0) 
        {
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"PopupMessageItem('15,000 Items in Stock', '" + rotaterPopup[0] + "', null, null);\">15,000 Items in Stock<a>";
        }
        else if (currentIdx == 1) 
        {
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"PopupMessageItem('Discounted Shipping', '" + rotaterPopup[1] + "', null, null);\">Discounted Shipping<a>";
        }
        else if (currentIdx == 2) 
        {
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"PopupMessageItem('Your Order will Ship Today', '" + rotaterPopup[2] + "', null, null);\">Your Order will Ship Today<a>";
        }
        else 
        { 
            area.innerHTML = "<a style='CURSOR: pointer;' onclick=\"PopupMessageItem('Guaranteed Lowest Prices', '" + rotaterPopup[3] + "', null, null);\">Guaranteed Lowest Prices<a>";
        }
    }   
}   

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

// go to page
function GoTo(page) 
{
    if (page != "" ) 
    {
	    document.location.href = 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
        {
            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)
{
    var digit;
    document.all ? digit = e.keyCode : digit = e.which;
    return ((digit > 47 && digit < 58) || digit == 8 || digit == 37 || digit == 39 || digit == 46 || digit == 0);
} 

// return true if key is digital or carriage return
function IsNumericOrEnterKey(e)
{
    var digit;
    document.all ? digit = e.keyCode : digit = e.which;    
    return ((digit > 47 && digit < 58) || digit == 8 || digit == 13 || digit == 37 || digit == 39 || digit == 46) ;
} 

// 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) 
{
    var trimmed = sString.replace(/^\s+|\s+$/g, '') ;
    return trimmed;
}
	   
// 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;
    }    