// Brand global2.js - no jquery today
// ISITE Design

var ISITE = function() {
	
	var buttons = document.getElementsByTagName("INPUT");
	for(var i=0; i<buttons.length; i++) {
	    if(buttons[i].type == 'submit')
	    {
		    buttons[i].onmouseover = addHover;
		    buttons[i].onmouseout = removeHover;
		}
	}
};



//*************************************Master page*********************************************************
function tbQueryEnter()
{    
    var ev = window.event;
	ev.cancelBubble = true;
	if(ev.keyCode == 13)
	{	    
		var bn = document.getElementById('ctl00_bnSearch');
		if(bn != null)
		{		    
		    bn.focus();
		}
	}
}

function feedbackDDChanged()
{
    var lb = document.getElementById('ctl00_ContentPH_Central_lbSectionid');
    if(lb.selectedIndex == 0)
    {
        for(var i=0; i<lb.options.length; i++)
        {
           lb.options[i].selected=true;
        }
    }
    if(lb.selectedIndex == 1)
    {
        for(var i=0; i<lb.options.length; i++)
        {
           lb.options[i].selected=false;
        }
    }
}

function ForgotPassLogic1()
{
    var lb = document.getElementById('ctl00_ContentPH_Central_tbEmail');
    if(lb)
    {
        lb.value='';
    }
}

function ForgotPassLogic2()
{
    var lb = document.getElementById('ctl00_ContentPH_Central_tbUserName');
    if(lb)
    {
        lb.value='';
    }
}

//*************************************^^^^^^^^^^^^********************************************************

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//*************************************Advanced Search Entries*********************************************
function ClearAdvancedSearch()
{
    var textboxes = document.getElementsByTagName("INPUT");
    for(var i=0; i<textboxes.length; i++) {
        if(textboxes[i].type == 'text')
        {
            if(textboxes[i].id.indexOf('_as_') != -1)
                textboxes[i].value = '';
        }
    }
    
    var selects = document.getElementsByTagName("select");
    for(var i=0; i<selects.length; i++) {
        if(selects[i].id.indexOf('_as_') != -1)
            selects[i].selectedIndex = 0;
        if(selects[i].id.indexOf('_tax_') != -1)
            selects[i].selectedIndex = -1;
    }
}


//*************************************^^^^^^^^^^^^^^^^^^^^^^^*********************************************

//*************************************Add products to list************************************************
function valListNameFunc(source, arguments)
{
    var lb = document.getElementById('ctl00_ContentPH_Central_lbListName');
    
    if(lb != null)
    {
        if(lb.value == '' || lb.selectedIndex == -1)
        {            
            var rb = document.getElementById('ctl00_ContentPH_Central_rbExist');
            if(rb != null)
            {                
                if(rb.checked == true)                                    
                    arguments.IsValid = false;                
                else
                {                    
                    var ln = document.getElementById('ctl00_ContentPH_Central_tbNewListName');
                    if(ln != null)
                    {                        
                        if(ln.value == '')
                            arguments.IsValid = false;                        
                        else                       
                            arguments.IsValid = true;                        
                    }
                    else
                        arguments.IsValid = false;                                            
                }                
            }
            else            
                {
                    arguments.IsValid = false; 
                }         
        }
        else       
            arguments.IsValid = true;
        
    }
    else
    {    
        var ln = document.getElementById('ctl00_ContentPH_Central_tbNewListName');
        if(ln != null)
        {                        
            if(ln.value == '')
                arguments.IsValid = false;                        
            else                       
                arguments.IsValid = true;                        
        }
        else
            arguments.IsValid = false;
    }
}
//*************************************^^^^^^^^^^^^^^^^^^^^************************************************

//*************************************Add saved search************************************************
function valSearchNameFunc(source, arguments)
{
    var lb = document.getElementById('ctl00_ContentPH_Central_lbExistingSearch');
    
    if(lb != null)
    {
        if(lb.value == '' || lb.selectedIndex == -1)
        {            
            var rb = document.getElementById('ctl00_ContentPH_Central_rbChooseExisting');
            if(rb != null)
            {                
                if(rb.checked == true)                                    
                    arguments.IsValid = false;                
                else
                {                    
                    var ln = document.getElementById('ctl00_ContentPH_Central_tbSearchName');
                    if(ln != null)
                    {                        
                        if(ln.value == '')
                            arguments.IsValid = false;                        
                        else                       
                            arguments.IsValid = true;                        
                    }
                    else
                        arguments.IsValid = false;                                            
                }                
            }
            else            
                {
                    arguments.IsValid = false; 
                }         
        }
        else       
            arguments.IsValid = true;
        
    }
    else
    {    
        var ln = document.getElementById('ctl00_ContentPH_Central_tbSearchName');
        if(ln != null)
        {                        
            if(ln.value == '')
                arguments.IsValid = false;                        
            else                       
                arguments.IsValid = true;                        
        }
        else
            arguments.IsValid = false;
    }
}
//*************************************^^^^^^^^^^^^^^^^^^^^************************************************

//****************************************CheckProducts****************************************************
function getProductsCheckboxes()
{
	var result = new Array();
	var arr = document.getElementsByTagName("INPUT");
	var j = 0;
	for (var i=0; i <= arr.length-1; i++)
	{
		if ((arr[i].type != "checkbox") || (arr[i].name.indexOf("chbSel_") == -1))
			continue;
				
		result[j] = arr[i];
		j++;
	}
	return result;
}
	
function ClearSelHid()
{
	document.forms[0].checkedItems.value = "";
}

function onSetChecked(value)
{
	var arr = getProductsCheckboxes();
	var result = "";
	var hasChecked = false;	
	for (var i=0; i <= arr.length-1; i++)
	{
		if (value != null)
			arr[i].checked = value;

		if (arr[i].checked)
		  hasChecked = true;

		if (result != "") result += ",";
		result += arr[i].name+"="+(arr[i].checked ? "1" : "0");
	}
	document.forms[0].checkedItems.value = result;	
	return hasChecked;
}

//****************************************^^^^^^^^^^^^^****************************************************

function SetDivLongCiteVisibility()
{   
   var contr = document.getElementById('ctl00_ContentPH_Central_lbDetail1');
   
   if(contr != null)
   {
    
    var trr = true;
    if(contr.value == '2')
    {
        trr = false;        
    }
    
    
    
    var arr = getProductsLongCiteDivs();
    
    
    
    for (var i=0; i <= arr.length-1; i++)
	{
	    if(trr)
	    {
	        arr[i].style.display = 'block';
	    }
	    else
	    {
	        arr[i].style.display = 'none';
	    }	    
	}
   }
}

function getProductsLongCiteDivs()
{
    var result = new Array();
	var arr = document.getElementsByTagName("DIV");
	var j = 0;
	for (var i=0; i <= arr.length-1; i++)
	{
		if (arr[i].id.indexOf("longCite_div") == -1)
			continue;
				
		result[j] = arr[i];
		j++;
	}
	return result;
}

//****************************************^^^^^^^^^^^^^****************************************************

function addHover(e) {
	if (!e) var e = window.event;
	if (e.target) var tg = e.target;
	else if (e.srcElement) var tg = e.srcElement;
	if(tg.type == 'submit')
	    tg.className+=' over';
}
// will fail in a situation with other classes that begin with 'over';
// should be re-written to use regex to account for that.
function removeHover(e) {
	if (!e) var e = window.event;
	if (e.target) var tg = e.target;
	else if (e.srcElement) var tg = e.srcElement;
	if(tg.type != 'submit')
	    return;
	start = tg.className.indexOf('over');
	if (start == 0 && tg.className.length < 4)
	{	// over is only class in className
		tg.className = '';
	}
	else if (tg.className.length == start + 4)
	{  // over is last class in className
		tg.className = tg.className.substr(0, start - 1);
	}
	else if(start >= 0)
	{ // over is in the middle of a list of classes
		
		classBegin = tg.className.substr(0, start - 1);
		classEnd = tg.className.substr(start + 3);
		tg.className = classBegin + classEnd;
	}
}

// keep the rest or else no onload will fire
// the big init()
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) clearInterval(_timer);
	ISITE();
};

/* Dean Edwards window.onload */
/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", init, false);
}

// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<scr" + "ipt id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
	if (this.readyState == "complete") {
		init(); // call the onload handler
	}
};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;