var Uprefix
Uprefix = '/';
function DE_init(){
		//MM_preloadImages(Uprefix+'images/home/menu_btn_01_over.gif',Uprefix+'images/home/menu_btn_02_over.gif',Uprefix+'images/home/menu_btn_03_over.gif',Uprefix+'images/home/menu_btn_04_over.gif',Uprefix+'images/home/Btn_Lrg_04_over.jpg',Uprefix+'images/home/Btn_Lrg_03_over.jpg',Uprefix+'images/home/Btn_Lrg_02_over.jpg',Uprefix+'images/home/Btn_Lrg_01_over.jpg',Uprefix+'images/home/btn-Contact-over.gif',Uprefix+'images/home/menu_btn_06_over.gif',Uprefix+'images/home/menu_btn_07_over.gif')
}

function gXP(iE){
	xPos=eval(iE).offsetLeft;
	tempEl=eval(iE).offsetParent;
	while (tempEl!=null){
		xPos+=tempEl.offsetLeft;
		tempEl=tempEl.offsetParent;
	}
	return xPos;
}
function gYP(iE){
	yPos=eval(iE).offsetTop;
	tempEl=eval(iE).offsetParent;
	while (tempEl!=null){
		yPos+=tempEl.offsetTop;
		tempEl=tempEl.offsetParent;
	}
	return yPos;
}
var outtimer=[], intimer=[]	
var IEver=7
if (navigator.userAgent.match(/MSIE (\d+)/)) IEver = eval(RegExp.$1);
var isSafari = navigator.userAgent.indexOf('AppleWebKit')!=-1;
var isFF3 = false
if (navigator.userAgent.indexOf('Firefox') != -1) {
    isFF3 = navigator.userAgent.indexOf('Firefox/2') == -1;
    if (!isFF3) {
	    var mat = navigator.userAgent.match(/rv:(\d+\.\d+)/);
	    if (mat) isFF3 = parseFloat(mat[1]) >= 1.9
	}
}

var isNewSite = function() {
	if (typeof this.result=='undefined') {
		this.result = document.getElementById('PC_subnav_substation')!=null;
	} 
	return this.result;
}
var lyrrefTbl=[], IE6fhack=new RegExp()
IE6fhack.compile("viewprod|HomepageEdit|arresterconfig|webconfig|contact.asp|orderstatus\\.|itilookup|cart\\.asp|/order\\.asp|apply\\.asp","i");
function showDly(ref,lyr)
{
    show(ref,lyr)
}
function show(ref,lyr,bHide)
{
	var loc;
	var obj=document.getElementById(lyr);
	var offset = isNewSite() ? (document.all?6:7) : (document.all||isSafari||isFF3) ? 30 : 0
	var Yoffset = 28; 
	var subOff = isFF3||isSafari ? 9 : 7
	var subOffLeft = IEver<=6||isSafari||isFF3 ? subOff+53 : subOff+54
	var isSubMenu=false
	if(typeof ref=='object') {
	    loc = ref.parentElement || ref.parentNode
	    isSubMenu = true
	} else
	    loc =document.getElementById(ref)
	if (!loc && ref && window.jQuery) {
		loc = $(ref)[0];
		isSubMenu=true;
	} else if (loc)
	    lyrrefTbl[lyr] = ref;
	    
	if (loc && loc.tagName=='A') {
	    if (isSubMenu) return;    
	    else Yoffset = 66-22;
	}
	
	if (bHide && typeof(ref)=='string' && !outtimer[ref]) {
  		outtimer[ref] = setTimeout("show('"+ref+"','"+lyr+"',true)", 25);
		return;
	} else if (typeof(ref)=='string' && outtimer[ref])  {
		clearTimeout(outtimer[ref]);
		outtimer[ref]=null;
	}
	var tbl = document.getElementById('tblHeader')
	var X = -1, Y=-1;
	if (window.jQuery)  $('DIV.CLpersonalLinks').css('display','none')
	if (isSubMenu) {
	    if (lyr.match(/^prodpopoutdiv(75|76|77)$/)) {
	        X = gXP(loc.offsetParent)- (window.jQuery?$(obj).width()+subOffLeft:200)
	    }else
    		X = gXP(loc.offsetParent)+loc.offsetParent.offsetWidth-subOff
		Y = gYP(loc)-40 //(IEver<7?30:40)
		if (window.jQuery) {
    		var max = IEver<=6? 493: 508   //gYP(loc.offsetParent)+loc.offsetParent.offsetHeight
	    	var H = $(obj).height() + 58
		    if (Y + H > max) {
		        Y = max - H
		        if (Y < gYP(loc.offsetParent)+15) Y = gYP(loc.offsetParent)+15
		    }
		}
	}
	else if (loc) {
		Y = gYP(loc)
		X = gXP(loc)-(isNewSite()? 0 : gXP(tbl))
	}
	
	var objSt = obj.style
	if (X!=-1) objSt.left = (X+offset) + 'px';
	if (Y!=-1) objSt.top= (Y+Yoffset)+'px';
	if (bHide || !window.jQuery || !isSubMenu)
		objSt.display=bHide?'none':''
	else {
		hidesubs(lyr);
		if(!$(obj).is(':visible')) {
			if(jQuery.browser.msie) $(obj).show(); else $(obj).fadeIn(100);	// avoid anti-alias issue in IE
		}
	}
	objSt.zIndex = 10
	
	// yet another hack for IE 6 !! Put a blank iframe object behind menus so it will overlap select tags
	if (window.jQuery && IEver <= 6 && IE6fhack.test( document.location.href) ) {
	    if (bHide){
	        //alert(ref)
	        $('iframe.iframebackgroundCL,#iframebg'+lyr).hide().remove()
	    }else if (X!=-1) {
	        if (!document.getElementById('iframebg'+lyr) ) {
		    var iframe = $('<iframe class="iframebackground'+(lyr.substr(0,7)=='prodpop'?'PO':'')+'" id="iframebg'+lyr+'" src="javascript:\'&lt;html&gt;&lt;/html&gt;\';" scrolling="no" frameborder="0" style="position:absolute;border:none;display:block;z-index:9"></iframe>')
	        if (isSubMenu)
	            iframe.css('margin', '-10px 0px 18px 10px')
	        iframe.css({left:(X+offset-8-(lyr=='PC_subnav_ps'?100:0)) + 'px', top:(Y+Yoffset+8)+'px', width:(obj.offsetWidth+1)+'px', height:(obj.offsetHeight+(isSubMenu?3: 16))+'px'})
	        obj.parentNode.appendChild(iframe[0])
	        }
	    }
	}

	if (typeof(ref)=='string' && ref != '' && !isSubMenu) {
		var N=''
		if (ref.match(/(\d+)$/)) N = RegExp.$1;
		obj = document.getElementById('subnav_chapeau'+N);
		if (obj) {
		    objSt = obj.style
			objSt.left = (X+offset) + 'px';
			objSt.top = (Y-1)+'px';
   		    objSt.display = bHide?'none':''
		    objSt.zIndex = 11		
		}
	}
	if (bHide) hidesubs();
}
function hidesubs(keep)
{
	if (window.jQuery) {
	    $('div.prodPopout' + (keep?':not(#'+keep+')':'') ).hide()
	    $('li.popOutLock' + (keep?':not(#'+keep+'roll)':'') ).removeClass('popOutLock')
	    $('iframe.iframebackgroundPO'+ (keep?':not(#iframebg'+keep+')':'') ).hide().remove()
	}
}
var pomenu=0
function prodPopout(which, evt)
{
    evt = evt || window.event
    if (!window.jQuery) return;
    var ele = evt.srcElement || evt.target
    
	hidesubs();
	if(which == -98){ // Arrester popup
		pomenu=which;
		popProdPopout(["/SurgeArresters/arresters.asp","Overview","/SurgeArresters/ArresterConfig.asp?tran_type=Station","Station", "/SurgeArresters/ArresterConfig.asp?tran_type=Intermediate", "Intermediate", "/SurgeArresters/ArresterConfig.asp?tran_type=Distribution", "Distribution", "/SurgeArresters/ArresterConfig.asp?tran_type=Riser%20Pole", "RiserPole"], ele, which,ele.offsetParent)
	}
	if(which == -99){ // Prolec Transformers popup
		pomenu=which;
		popProdPopout(["/PowerEquipment/transformers.asp","Overview","/PowerEquipment/ProlecLookup.asp?type=PAD","Pad-Mount Transformers", "/PowerEquipment/ProlecLookup.asp?type=POL", "Pole-Type Transformers"], ele, which,ele.offsetParent)
	}
	
    //hidesubs();
    if (which < 1) {
        return
    //} else if (document.getElementById('prodpopoutdiv'+which)) {
    //    show(ele, 'prodpopoutdiv'+which)
    } else if (typeof aryProdPop!='undefined' && aryProdPop[which] && aryProdPop[which].length) {
        pomenu=which
        popProdPopout(aryProdPop[which], ele, which,ele.offsetParent)
    } /*else {
        $.ajaxSetup({async:true})
        pomenu=which
        $.getJSON('/scripts/prodPopout.asp', {subcat:which, pr:getprnd()}, function(data) {popProdPopout(data,ele,which,ele.offsetParent); if(window.sessionStorage)window.sessionStorage["prodpopout"+which+getprnd()]=data.join('\\\\')})
    }*/
}
function popProdPopout(data, ref, which, par)
{
    var div = document.getElementById('prodpopoutdiv'+which)
    var isNew=false;
    if (pomenu!=which) return;      // another menu queued while one still loading 
    if (!div) {
        div = document.createElement("DIV")
        div.id = 'prodpopoutdiv'+which
        div.style.display = 'none';
        div.className = "prodPopout" + (which==75||which==76||which==77?' prodPopleft':'')
        if (par) {
            while (!par.id && par.tagName!='DIV' && par.offsetParent) par = par.offsetParent;
            if (div.attachEvent) {
                div.attachEvent('onmouseover', function(){show('', 'prodpopoutdiv'+which); show(lyrrefTbl[par.id], par.id);} )
                div.attachEvent('onmouseout', function(){show('', 'prodpopoutdiv'+which,true); show(lyrrefTbl[par.id], par.id, true);} )
            } else if (div.addEventListener) {
                div.addEventListener('mouseover', function(){show('', 'prodpopoutdiv'+which); show(lyrrefTbl[par.id], par.id)}, false)
                div.addEventListener('mouseout', function(){show('', 'prodpopoutdiv'+which,true); show(lyrrefTbl[par.id], par.id, false)} , false)
            }
        }
        isNew=true
        
        var html = '<UL>', len=data.length
        for (var i=0; i<len; i+=2)
            html += '<LI><NOBR><a href="'+(data[i].charAt(0)=='/'?data[i]:'/viewprod.asp?model='+escape(data[i]))+'" target=_top class=normalLink onmouseover="" onmouseout="">' + data[i+1] + '</a></NOBR>'
        html += '</ul>'
        div.innerHTML = html;
    }
    if (data.length == 0) {
        if (window.jQuery) $(ref.parentNode).removeClass('popOutLock')
        return
    } else {
        if(isNew)document.body.appendChild(div)
        if (window.jQuery) $(ref.parentNode).addClass('popOutLock').attr('id', 'prodpopoutdiv'+which+'roll')
        show(ref, 'prodpopoutdiv'+which)
    }
            
}

function CheckLogin(){
	var e;
	var f=document.LoginForm;
  e = ""
  f.UserName.value = f.UserName.value.replace(/^ */,'').replace(/\b *$/,'');
  f.Password.value = f.Password.value.replace(/^ */,'').replace(/\b *$/,'');  

  if (f.UserName.value == "") e+="Username blank\n"
  if (f.Password.value == "") 
    e+="Password blank\n"
  if (e!="") {
    alert("Unable to submit this form because of the following error(s):\n\n"+e)
    return false
  } else {
  	return true;
  }
}

function displayRow(){       
var passShow = document.getElementById("passShow");	

if (passShow.style.display == '')  
	passShow.style.display = 'none';	
else passShow.style.display = '';

var passHide = document.getElementById("passHide");
if (passHide.style.display == 'none')
	passHide.style.display = 'block';
	document.getElementById("PasswordHide").focus();
}

function show_it(which){
	var obj
	if (which) obj = document.getElementById(which)
	else obj = document.getElementById('box1')
	if (obj) {
		if (which=='SignupPopUp' && window.jQuery) {
			var pos = $('#LoginButton').offset()
			if (pos.top < 0) pos.top = 0;
			pos.top += $('#LoginButton').height()
			$(obj).css({left:(pos.left-95+33)+'px', top:(pos.top+20)+'px'})
			var mask = $('#simask');
		    var maskHeight = $(document).height();
		    var maskWidth = $(window).width();
		    if (IEver <= 6) $('SELECT').hide()
		    mask.css({'left':0, 'width':maskWidth,'height':maskHeight, 'opacity':0.3}).show();
		   
		}
		obj.style.visibility = "visible";
		obj.style.display = '';
	}
	if (which=='SignupPopUp' ) {
		setTimeout('document.getElementById("LoginX").offsetParent.focus()',0)
		changeCol(document.forms.LoginForm.UserName,1)
		changeCol(document.forms.LoginForm.Password,1)
		if (window.jQuery) {
		     $(document).keydown( function(event) {
			    if ((event.which||event.keyCode) == 27) {
				    hide_it('SignupPopUp')
				    $(document).unbind(event)
				    //event.preventDefault()
			    } 
		    } );
		}
	}
}
function hide_it(which){
	var obj;
	if (which) obj = document.getElementById(which)
	else obj = document.getElementById('box1')
	if (obj) {
		obj.style.visibility = "hidden";
		obj.style.display = 'none';
	}
	if (which=='SignupPopUp') with(document.forms.LoginForm) {
	    if (window.jQuery) {$('#simask').hide(); if (IEver <= 6) $('SELECT').show() }
		//UserName.value = ''
		//Password.value = ''
	}

}
function togglePL(which)
{
	var menu = document.getElementById('CL'+which+'Links')
	if (!menu) return
	if (menu.style.display == 'none') {
		if (window.jQuery) {
		    var menuref = $('#CL'+which)
			var pos = menuref.offset()
			if (pos.top < 0) pos.top = 0;
			pos.top += menuref.height()
			$(menu).css({left:pos.left+'px', top:pos.top+'px'})
			$(document).bind('mousedown', function(event) {CLPLclose(event,which)} );
			$(document).keydown( function(event) {CLPLclose(event,which)} );
			if (window.jQuery && IEver <= 6 && IE6fhack.test(document.location.href) ) {
                var iframe = $('<iframe class="iframebackgroundCL" src="javascript:\'&lt;html&gt;&lt;/html&gt;\';" scrolling="no" frameborder="0" style="position:absolute;border:none;display:block;z-index:900"></iframe>')
                iframe.css({left:pos.left + 'px', top:pos.top+'px', width:$(menu).width()+'px', height:$(menu).height()+'px'})
                menu.parentNode.insertBefore(iframe[0], menu)
	        }
		}
		menu.style.display = '';
	} else {
		menu.style.display = 'none';
        $('iframe.iframebackgroundCL').hide().remove()
	}
}
function CLPLclose(event, which) {
	var target = event.srcElement || event.target
	var key = event.which || event.keyCode
	if (key && key!=1) {if(key!=27) return}
	else if (target.id.substr(0,which.length+2)=='CL'+which) return
	//if (target.tagName!='A') {
		var par = target
		while (par = par.offsetParent) if (par.id.substr(0,which.length+2)=='CL'+which) return
	//}
	document.getElementById('CL'+which+'Links').style.display = 'none'
	$('iframe.iframebackgroundCL').hide().remove()
	$(document).unbind(event)
} 
 
function changeCol(which, check) {
which.style.background = check && which.value=='' ? 'transparent' : '#FFFFFF';
which.style.color = '#707070';
which.style.border = 'none';
which.style.width = '145px';
which.style.height = '15px';
 
}
function clearSrch(which)
{ if (which.style.color!='#666666') {which.value=''; which.style.color='#666666';} }

function chkLKey(evt) 
{
	evt =evt || Event 
	var code = evt.keyCode||evt.which;
	if (code==13||code==3) {
		if (CheckLogin()) document.forms.LoginForm.submit()
		//if (evt.preventDefault) evt.preventDefault()
		return true
	} else
		return false
}

function getCookie(Name) {   
    var search = Name + "=";
    if (document.cookie.length > 0) {
      offset = document.cookie.indexOf(search);
      if (offset != -1) {
	 offset += search.length
         end = document.cookie.indexOf(";", offset)
	 if (end == -1) end = document.cookie.length;
	 return unescape(document.cookie.substring(offset, end))
     } else 
		return "";
   } else
	return "";
}

function hsignin()
{
	var loc=document.location.pathname+document.location.search
	if (loc.toLowerCase().indexOf('viewprodmain')!=-1)loc=parent.location.pathname+parent.location.search
	if (loc.indexOf('off.asp')!=-1) loc='/front.asp';
	openPage('/resignin.asp?lip='+escape(loc));
}
function hsignout()
{
	openPage('/off.asp')
}

function StoreSearch(){
	if (chkSearch())
		document.frmSearch.submit()
}
function chkSearch(){
	var f=document.frmSearch;
	if (f.txtSearch.value==''||f.txtSearch.value=='Search the store') {
		alert('Please enter search criteria');
		return false
	} else {
	    with (f) 
	        txtSearch.value = accentTidy(txtSearch.value)
		return true
	}
}
function accentTidy(s){
    var r=s                       
    r = r.replace(/[\xe0\xe1\xe2\xe3\xe4\xe5]/g,"a");                        
    r = r.replace(/[\xc0\xc1\xc2\xc3\xc4\xc5]/g,"A");                        
    r = r.replace(/\xe6/g,"ae");                        
    r = r.replace(/\xc6/g,"AE");   
    r = r.replace(/\xe7/g,"c");                        
    r = r.replace(/\xc7/g,"C");                        
    r = r.replace(/[\xe8\xe9\xea\xeb]/g,"e");                        
    r = r.replace(/[\xc8\xc9\xca\xcb]/g,"E");                        
    r = r.replace(/[\xec\xed\xee\xef]/g,"i");                        
    r = r.replace(/[\xcc\xcd\xce\xcf]/g,"I");                        
    r = r.replace(/\xf1/g,"n");                                                    
    r = r.replace(/\xd1/g,"N");  
    r = r.replace(/[\xf2\xf3\xf4\xf5\xf6]/g,"o");                        
    r = r.replace(/[\xd2\xd3\xd4\xd5\xd6]/g,"O");                        
    r = r.replace(/[\xf9\xfa\xfb\xfc]/g,"u");                        
    r = r.replace(/[\xd9\xda\xdb\xdc]/g,"U");                        
    r = r.replace(/[\xfd\xff]/g,"y");                        
    r = r.replace(/\xdd/g,"Y");
    // remove any remaining "special" characters
    r = r.replace(/[^\x20-\x7F]/g, '');
    return r;                
}


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_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_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];}
}

