//Global Dropdown and 3 Box Model on Home Page

var timerID = null;
var timerOn = false;
var timecount = 1000;

function hideAll(){

	showSelects();

	//Office Home Box Mods
	if(document.getElementById('Lbox1')) { hide('Lbox1'); }
	if(document.getElementById('Lbox2')) { hide('Lbox2'); }
	if(document.getElementById('Lbox3')) { hide('Lbox3'); }
	
	//Office Dropdown Nav
	if(document.getElementById('servOfferings')) { hide('servOfferings'); }	
	if(document.getElementById('knowCenter')) { hide('knowCenter'); }
	if(document.getElementById('aboutAll')) { hide('aboutAll'); }
	
	//Synergy Dropdown Nav
	if(document.getElementById('s_servOfferings')) { hide('s_servOfferings'); }
	if(document.getElementById('s_knowCenter')) { hide('s_knowCenter'); }	
	if(document.getElementById('s_aboutAll')) { hide('s_aboutAll'); }
	if(document.getElementById('s_orderManage')) { hide('s_orderManage'); }	
	if(document.getElementById('s_dealerMark')) { hide('s_dealerMark'); }
	
	//Office Home Box Mods
	if (document.images) {
		
		if (document.getElementById('threeBoxShell')) { 
			document.getElementById('box1').src = box1on.src;
			document.getElementById('box2').src = box2on.src;
			document.getElementById('box3').src = box3on.src;		
		}		
	}
}

function startTime() {
	if (timerOn == false) {
		timerID=setTimeout( "hideAll()" , timecount);
		timerOn = true;
	}
}

function stopTime() {
	if (timerOn) {
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
}

function hideSelects() {	
	if(document.getElementById('content')) {
		var thisContent=document.getElementById('content').getElementsByTagName('select');	  
		for (var i=0; i < thisContent.length; i++) {
			//alert(i);
	       	thisContent[i].style.visibility = "hidden";
		}
	}
}

function showSelects() {	
	if(document.getElementById('content')) {
		var thisContent=document.getElementById('content').getElementsByTagName('select');	
		for (var i=0; i < thisContent.length; i++) {
       		thisContent[i].style.visibility = "visible";
		}
	}
}

function hide(layerName) {
	document.getElementById(layerName).style.visibility="hidden";	
	showSelects();
}

function show(layerName) {
	document.getElementById(layerName).style.visibility="visible";
	hideSelects();
}

var emailWindow;
function pop(url)
{
	emailWindow=window.open(url,'name','height=500,width=400,scrollbars=yes,top=50,left=200');
	if (window.focus) {emailWindow.focus()}
}

// Synergy Home

function high(layerName) {
	document.getElementById(layerName).className="outerColumnOn";
}

function low(layerName) {
	document.getElementById(layerName).className="outerColumnOff";	
}

//Form Clear and Replace

function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text') {  
            /* Add event handlers */          
            //addEvent(theInput, 'focus', clearDefaultText, false);
            //addEvent(theInput, 'blur', replaceDefaultText, false);
			
       /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    if (target.value == '' && target.defaultText && target.name.indexOf('NoFill') == -1) {
        target.value = target.defaultText;
    }
}			

//Showroom Preload
function preloading() {
	for (x=0; x<preloading.arguments.length; x++) 
	{
		var oImgPath = new Object();
		oImgPath.roomImages = "/allsteel/img/showrooms/" + showRoom;	
		heroImages[x] = new Image();
		heroImages[x].src = oImgPath['roomImages'] + preloading.arguments[x];
	}
}

//function preloadingEvents() {
//	for (x=0; x<preloadingEvents.arguments.length; x++) 
//	{
//		var oImgPath = new Object();
//		oImgPath.roomImages = "/allsteel/img/about/events/";	
//		heroImages[x] = new Image();
//		heroImages[x].src = oImgPath['roomImages'] + preloadingEvents.arguments[x];
//	}
//}

function imageSelect(num) { 
	document.images.hero.src = heroImages[num].src;
}

// Form Pulldown Submit
function sendPull() {
	window.location = this.options[this.selectedIndex].value;
}

 function getElmtRef(strElmtId) { 
      if (!document.getElementById) { 
           return document.all[strElmtId]; 
      } else { 
           return document.getElementById(strElmtId); 
      } 
 }
 
 function formHandler(URL) {
    if(URL != "")
    {
        var sOptions;
        sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
        sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
        sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
        sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

        popup = window.open(URL,"newWin",sOptions);
        popup.focus(); 
    }
}

function safari() {
var agt=navigator.userAgent.toLowerCase();
try {
	if (agt.indexOf("safari") != -1) { document.write ("<style type=\"text/css\">#globNavOptions span {margin: 0 0 10px 14px;  display: block; white-space: nowrap; float: left;} #globNavOptionsInside span {margin: 0 0 10px 14px;  display: block; white-space: nowrap; float: left;}</style>"); } 
	else if (agt.indexOf("camino") != -1) { document.write ("<style type=\"text/css\">#globNavOptions span {margin: 0 0 10px 0px;  display: block; white-space: nowrap; float: left;} #globNavOptionsInside span {margin: 0 0 10px 0px;  display: block; white-space: nowrap; float: left;}</style>"); } 
	else { document.write ("<style type=\"text/css\">#globNavOptions span {margin: 0 0 10px 14px; } #globNavOptionsInside span {margin: 0 0 10px 14px; }</style>");}
} 
catch (err) {

}}

safari();

//for product F&B pages
function popMe(myURL, title,w,h) {
     var winl = (screen.width - w) / 2;
     var wint = (screen.height - h) / 2;
     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+'resizable=0'
   window.open(myURL, title, winprops);
} 

function popMe2(myURL, title,w,h,scrollbars) {
     var winl = (screen.width - w) / 2;
     var wint = (screen.height - h) / 2;
     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbars;
     window.open(myURL, title, winprops);
}

//sets the form target to newTarget
function setFormTarget(newTarget){
    window.document.forms[0].target = newTarget;
}//resetFormTarget

//traps enter keypress on searchinput textboxes
function clickButton(strID, event) {
	var pButton = document.getElementById(strID);
	if (event && event.which) {
		if (event.which == 13) {
			pButton.click();
			return false;
		}
	} else if (window.event && window.event.keyCode) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancel = true;
			pButton.click();
			return false;
		}
	}
}

//// <summary>
/// Raises the click event of a given button
/// </summary>
/// <param name="buttonObjectId">Id of the Button whose click event is to be raised</param>
function RaiseButtonClickEvent (buttonObjectId)
{
	var buttonObject = document.getElementById(buttonObjectId);
	if (buttonObject != null) { 
	    buttonObject.click();
	} 
}

//// <summary>
/// Populates a TextBox with a given value
/// </summary>
/// <param name="textObjectId">Id of the TextBox to be populated</param>
/// <param name="value">Value to be assigned</param>
function PopulateTextBox (textObjectId, value)
{
	var textObject = document.getElementById(textObjectId);
	if (textObject != null && Trim(value) != '') { 
	    textObject.value = value;
	} 
}

/// <summary>
/// Trims both left & right blank spaces
/// </summary>
/// <param name="value">String to trim</param>
/// <returns>Trimmed string</returns>
function Trim(value)
{
	return RightTrim(LeftTrim(value));
}

/// <summary>
/// Trims left blank spaces
/// </summary>
/// <param name="value">String to trim</param>
/// <returns>Left trimmed string</returns> 
function LeftTrim(value)
{
	var whiteSpace = new String(" \t\n\r");
	var string = new String(value);
	if (whiteSpace.indexOf(string.charAt(0)) != -1) 
    {
		var characterIndex=0, stringLength = string.length;
		while (characterIndex < stringLength && whiteSpace.indexOf(string.charAt(characterIndex)) != -1)
		{
			characterIndex++;
		}	
		string = string.substring(characterIndex, stringLength);
    }
   return string;
}

/// <summary>
/// Trims right blank spaces
/// </summary>
/// <param name="value">String to trim</param>
/// <returns>Right trimmed string</returns>
function RightTrim(value)
{
	var whiteSpace = new String(" \t\n\r");
    var string = new String(value);
    if (whiteSpace.indexOf(string.charAt(string.length-1)) != -1) 
    {
		var stringLength = string.length - 1;       
		while (stringLength >= 0 && whiteSpace.indexOf(string.charAt(stringLength)) != -1)
		{
			stringLength--;
		}	
		string = string.substring(0, stringLength+1);
	}
	return string;
}


/// <summary>
/// Swaps out the main hero image on the overview template of the product pages
/// </summary>
/// <param name="someImageID">the image id of the hero image to be swapped</param>
/// <param name="newSource">the new image source</param>
/// <returns></returns> 
function SwapNewProductHeroImage(someImageID, newSource) {
    var theHeroImage = document.getElementById(someImageID);
    if (theHeroImage != null) {
        theHeroImage.src = newSource;
    }
}


/// <summary>
/// Swaps out the main hero image on the product page image galleries and changes the low/high res link URLs
/// </summary>
/// <param name="someImageID">the image id of the hero image to be swapped</param>
/// <param name="newSource">the new image source</param>
/// <param name="lowResLink">the link id for the user to download low res version</param>
/// <param name="lowResNewSrc">the new image source for the low res image</param>
/// <param name="highResLink">the link id for the user to download high res version</param>
/// <param name="highResSrc">the new image source for the high res image</param>
/// <returns></returns> 
function SwapNewProductHeroImageAndLowHighResLinks(someImageID, newSource, lowResLink, lowResNewSrc, highResLink, highResSrc) {
    var theHeroImage = document.getElementById(someImageID);
    var theLowResLink = document.getElementById(lowResLink);
    var theHighResLink = document.getElementById(highResLink);

    if (theHeroImage != null) {
        theHeroImage.src = newSource;
    }

    if (theLowResLink != null) {
        theLowResLink.href = lowResNewSrc;
    } 

    if (theHighResLink != null) {
        theHighResLink.href = highResSrc;
    } 
}
  		
