var secSet = null;
var activeTimer = null;
var bHover = '';
var img = '';

var agt=navigator.userAgent.toLowerCase();
var is_safari = agt.indexOf("safari")!=-1;
var is_ie = agt.indexOf("msie")!=-1;
var is_ie6under = false;
if (is_ie) is_ie6under = (agt.indexOf("msie 6")!=-1 || agt.indexOf("msie 5")!=-1 || agt.indexOf("msie 4")!=-1);

var pchj_idpredirect = '';
function pchj_setIdpRedirect(idpredirect) {
  pchj_idpredirect = idpredirect;
}
function pchj_hov(idval){
	if(document.getElementById(idval+'a')){document.getElementById(idval+'a').style.visibility = 'hidden';}
	else if(idval=='pch_pwx'){document.getElementById('pch_pw_dd').className = 'pchb pch_ov_ugo';}
	else if(idval=='pch_shx'){document.getElementById('pch_sh_dd').className = 'pchb pch_ov_ugo';}
}
function pchj_off(idval){
	if(document.getElementById(idval+'a')){document.getElementById(idval+'a').style.visibility = '';}
  else if(idval=='pch_pwx'){document.getElementById('pch_pw_dd').className = 'pchb pch_ov_dgo';}
  else if(idval=='pch_shx'){document.getElementById('pch_sh_dd').className = 'pchb pch_ov_dgo';}
}

function pch_blurlogin(state) {
	if (state=='load'){
		if (document.getElementById('loginname').value!=''){
			document.getElementById('pch_undiv').style.display='none';}
	}
	else if (state=='over'){
		if(document.getElementById('pch_undiv').style.display==''){
			document.getElementById('pch_undiv').style.display='none';}
	}
	else
	{
		if (document.getElementById('loginname').value==''){
			if (document.getElementById('login_focus').value!='true'){
				document.getElementById('pch_undiv').style.display='';
				if (!pch_loginnameDone){document.onmousemove = '';}
			}
		}
	}
}
function pch_blurpass(state) {
	if (state=='load'){
		if (document.getElementById('password').value!=''){
			document.getElementById('pch_pwdiv').style.display='none'; return true;}	
	}
	else if (state=='over'){
		if(document.getElementById('pch_pwdiv').style.display==''){
			document.getElementById('pch_pwdiv').style.display='none';}	
	}
	else{
    if (document.getElementById('password').value==''){
			if (document.getElementById('pass_focus').value!='true'){
      document.getElementById('pch_pwdiv').style.display='';
      pch_loginnameDone = false;
			}
		}
	}
}
function pch_checkpass() {
	if (!pch_loginnameDone){
		if (pch_blurpass('load')) {pch_loginnameDone = true; document.onmousemove = '';}
	}
}
function pchj_passwatch(){if ((pch_loginnameField.onfocus)&&(!pch_loginnameDone)) {document.onmousemove = pch_checkpass;}}

function pchj_loginex(login, password, target, ci, ev)
{
  var loginBox = document.getElementById('loginname');
  var passwordBox = document.getElementById('password');
  loginBox.value = login;
  passwordBox.value = password;
  var idp = 'https://idp.securepaynet.net/login.aspx?ci=' + ci + '&prog_id=275048&spkey=SPSWNET-CORPWEB159&target='+target;
  var frm;
  if (document.pchFL){frm = document.pchFL;}
  else {frm = document.forms[0];}
  if (frm.__VIEWSTATE){frm.__VIEWSTATE.name = 'NOVIEWSTATE';}
  if (frm.__EVENTTARGET){frm.__EVENTTARGET.name = 'NOEVENTTARGET';}
  frm.action = idp; frm.method = 'POST';
  pchj_mout('pch_pw'); frm.submit();
  return pchj_cancelEvent(ev);
}
function pchj_login_action(frm)
{
	var idp = ('https://idp.securepaynet.net/login.aspx?ci=9106&prog_id=275048&spkey=SPSWNET-CORPWEB159');
	
	var mya = ('https://mya.securepaynet.net/login_redirect.aspx');
	idp += '&signalnonorig=' + encodeURIComponent(mya);
	if (pchj_idpredirect != '') {idp += '&target=' + pchj_idpredirect;}
	
	frm.action = idp; return true;
}
	
function pchj_key_name(frm,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if (keycode == 13){pch_blurpass('load');}
}

function pchj_search(ev){	
	var frm; var okSubmit = true;
  if(document.pchFS){frm = document.pchFS;} else {frm = document.forms[0];}
  var pc_opt = frm.pch_active_search.value;
  var pc_action = frm.elements[pc_opt+'_action'].value;
  var pc_field = frm.elements[pc_opt+'_field'].value;
  var pc_value = frm.searchField.value;
  if(frm.elements[pc_field]){frm.elements[pc_field].value=pc_value;}
  else{frm.searchField.name = pc_field;}
  if(pc_opt=='pch_sdomain') {if (!pchj_domain(pc_value)){okSubmit = false; frm.searchField.value='';}}
  if(pc_opt=='pch_swhois') {if (!pchj_domain(pc_value)){okSubmit = false; frm.searchField.value='';}}
  if(pc_opt=='pch_ssite') {if (!pchj_site(pc_value)){okSubmit = false; frm.searchField.value='';}}
  if(pc_opt=='pch_shelp') {
  	var win=window.open(pc_action+'&'+pc_field+'='+pc_value, '_pch_help', 'left=10,bottom=10,resizable=yes,scrollbars=yes,width=800,height=500');
		if (win){win.focus();}
		document.getElementById('pch_active_text').value='Help Center Search'; frm.searchField.value=document.getElementById('pch_active_text').value; frm.searchField.className='pch_t11 pch_ti pch_i_ss';
		okSubmit = false;
  } else {frm.target='_self'; frm.method = 'POST';}
  if (okSubmit){
		if (frm.__VIEWSTATE){frm.__VIEWSTATE.name = 'NOVIEWSTATE';}
		frm.action = pc_action; frm.submit();
  }
  return pchj_cancelEvent(ev);
}
function pchj_cancelEvent(ev) {
  if (!ev) return false;
  ev.returnValue = false;
  ev.cancelBubble = true;
  if (ev.stopPropagation) ev.stopPropagation();
  if (ev.preventDefault) ev.preventDefault();
  return false;
}
function pchj_inApp_hideDDs(sect){
	pchjNav('pch_dn',sect,'hide','ov');pchjNav('pch_ho',sect,'hide','ov');pchjNav('pch_ws',sect,'hide','ov');pchjNav('pch_em',sect,'hide','ov');pchjNav('pch_sc',sect,'hide','ov');pchjNav('pch_bs',sect,'hide','ov');
}
function pchj_notaDD(idval){return false;}

function pchj_lnk(link)
{if(link.match('http://help.securepaynet.net/')){
window.open(link,'_pch', 'left=20,top=20,resizable=yes,scrollbars=yes,width=800,height=620');
}else{window.open(link,'_self');}
function pchj_myalnk(link)
{if(window.MYAFilterLinks){MYAFilterLinks(link);}
	window.open(link,'_self');}

}
function pchj_blurBox(){
	if(document.RegisterDomainForm)
	{
		if(document.RegisterDomainForm.domainToCheck){document.RegisterDomainForm.domainToCheck.blur();}	
		if(document.RegisterDomainForm.fblur){document.RegisterDomainForm.fblur.value=1;}
	}
	if(document.LookupForm)
	{
		if(document.LookupForm.domainToCheck){document.LookupForm.domainToCheck.blur();}
		if(document.LookupForm.fblur){document.LookupForm.fblur.value=1;}
	}
}
function pchj_cartclose() {
  atlChiClose();  
}
function pchj_internationalclose() {
  atlIsiClose();
}
function pchj_mout(div){bHover='';window.status='';pchj_setDDTimeout(div);}
function pchj_movr(div,status){
	if(div=='pch_dn'){
		pchj_blurBox();}
	if(is_safari){
		bHover=status;window.status=status;pchj_setDD(div,status,false);}
	else{
		bHover=status;window.status=status;setTimeout('pchj_setDD(\'' + div + '\', \'' + status + '\', false)',400);}
}
function pchj_uout(div){pchj_setDDTimeout(div);}
function pchj_uovr(div){pchj_setDD(div,'',true);}
function pchj_pout(div, item){window.status='';pchj_setDDTimeout(div);}
function pchj_povr(div, link, item){window.status=link;document.getElementById(div).style.display='';pchj_setDD(div,'',true);}
function pchj_sout(sline, div, bkgem){
	var bkg = document.getElementById(sline).style.backgroundColor.toString();
	if((bkg!='#bbb')&&(bkg!='rgb(187, 187, 187)')){document.getElementById(sline).style.backgroundColor='#fff';}
	window.status='';pchj_setDDTimeout(div);
}
function pchj_sovr(sline, div, link, item){
	var bkg = document.getElementById(sline).style.backgroundColor.toString();
	if((bkg!='#bbb')&&(bkg!='rgb(187, 187, 187)')){document.getElementById(sline).style.backgroundColor='#eee';}
	window.status=link;pchj_setDD(div,'',true);
}
function pchj_findDiv(n, d) { 
	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=pchj_findDiv(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function pchjNav() { 	
	var p,v,obj,args=pchjNav.arguments,i=0;
  if (!((args[i]==args[i+1])&&(args[i+2]=='hide')&&(args[i+3]=='ov')))
		if ((obj=pchj_findDiv(args[i]))!=null) { v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
			obj.visibility=v; if(v=='hidden'){pchj_off(args[i]+'x');}    
		if (args[i]=='pch_sh'){v=(v=='visible')?'':(v='hidden')?'none':v; obj.display=v;}}
}

function pchj_hideDDs(sect) {pchjNav('pch_pw',sect,'hide','ov');pchjNav('pch_sh',sect,'hide','ov');
	pchj_inApp_hideDDs(sect);pchj_showElement('SELECT');pchj_showElement('OBJECT');pchj_showElement('EMBED');
}
  
function pchj_hideDD(sect) {
	pchj_off(sect+'x'); pchjNav(sect,'','hide'); pchj_hideDDs('');
}
function pchj_setDD(sect, windowStatusVal, bshow) {
	pchj_hideDDs(sect);
	if ((bHover==windowStatusVal)||(bshow)){
		pchjNav(sect,'','show');pchj_hov(sect+'x');
		if (secSet != null) window.clearTimeout(secSet);		
		if	(document.getElementById(sect)){if(is_ie6under) pchj_hideElement('SELECT', document.getElementById(sect));}
	}
}
function pchj_setDDTimeout(sect){
	if (secSet != null) window.clearTimeout(secSet);
	secSet = window.setTimeout('pchj_hideDD("' + sect + '")',400);
}
function pchj_hideElement( elmID, overDiv ) {
  for(i = 0; i < document.getElementsByTagName( elmID ).length; i++) {
    obj = document.getElementsByTagName( elmID )[i];
    if(!obj || !obj.offsetParent) continue;
    // Find the element's offsetTop and offsetLeft relative to the BODY tag.
    objLeft   = obj.offsetLeft - overDiv.offsetParent.offsetLeft;
    objTop    = obj.offsetTop;
    objParent = obj.offsetParent;
    while((objParent.tagName.toUpperCase() != 'BODY')&&(objParent.tagName.toUpperCase() != 'HTML')){
      objLeft  += objParent.offsetLeft;
      objTop   += objParent.offsetTop;
      objParent = objParent.offsetParent;}
    objHeight = obj.offsetHeight;
    objWidth  = obj.offsetWidth;
    if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
    else if((overDiv.offsetParent.offsetTop + overDiv.offsetHeight + 20) <= objTop);
    else if(overDiv.offsetParent.offsetTop >= eval(objTop + objHeight));
    else if(overDiv.offsetLeft >= eval(objLeft + objWidth));
    else {
      obj.style.visibility = 'hidden';
    }
  }	    
}
function pchj_showElement(elmID) {
  for(i = 0; i < document.getElementsByTagName( elmID ).length; i++) {
    obj = document.getElementsByTagName(elmID)[i];
    if(!obj || !obj.offsetParent) continue;
		if (is_ie&&(obj.readyState==4)&&(obj.tagName.toUpperCase()=='OBJECT')) continue;
    obj.style.visibility = '';
  }
}
function pchj_key(frm,e,fnc){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if (keycode == 13){pchj_search(e);}
}
function pchj_domain(searchValue)
{
	var canSubmit = false;
	if (searchValue != '')
	{
		var regExInvalidChars = /[^a-zA-Z0-9-\s.]+/;
		if (regExInvalidChars.test(searchValue))
		{
			alert('Invalid character in domain.\n\nOnly letters, numbers or hyphens are allowed.')
		}
		else
		{
		canSubmit = true;
		}
	}
	else
	{
		alert('Please enter a domain name.')
	}
	if (canSubmit) 
	{
		return true;
	}
	else
	{
		return false;
	}
}
function pchj_site(searchValue)
{
	var canSubmit = false;
	if ((searchValue != '')&&(searchValue.replace(' ', '') != 'Search'))
	{
		var regExInvalidChars = /[^a-zA-Z0-9-\s."']+/;
		if (regExInvalidChars.test(searchValue))
		{
			alert('Invalid characters in search.')
		}
		else
		{
		canSubmit = true;
		}
	}
	else
	{
		alert('Please enter a search term.')
	}
	if (canSubmit) 
	{
		return true;
	}
	else
	{
		return false;
	}
}
function pchj_state(isnow)
{
var was = document.getElementById('pch_active_search').value;
document.getElementById('pch_active_search').value = isnow;
if((isnow!='pch_sdomain')&&(document.getElementById('pch_sdomain'))){document.getElementById('pch_sdomain').style.backgroundColor='#fff';}
document.getElementById(was).style.backgroundColor='#fff';
document.getElementById(isnow).style.backgroundColor='#bbb';
var txt = document.getElementById('searchField');
txt.focus(); txt.value = txt.value;
}



function pcSetLogIn(val, sn)
{ 
	if((val.toLowerCase()=='true')||(val.toString()=='1')){
    document.getElementById('pch_login').style.display='none';
    document.getElementById('pch_logout').style.display='';
  } 
	else{
    document.getElementById('pch_login').style.display='';
    document.getElementById('pch_logout').style.display='none';
  }
	if(sn.length!=0){
		if(sn.length<30){document.getElementById('pch_sn').innerHTML = ('&#xa0;' + sn);}
		else{sn=sn.substring(0,30);document.getElementById('pch_sn').innerHTML = ('&#xa0;' + sn.concat('...'));}	
	}
}
function pcSetLogInEx(val, sn, taname, taphone, taemail)
{
  pcSetLogIn(val, sn);
}

function pcSetCart(itemcount)
{
 
  atlChiClearCache();
  var cartButton = document.getElementById('pch_ctx');
  var cartCountDiv = document.getElementById('pch_ct_count');
  var cartCountTip = document.getElementById('pch_ct_count_tip');
  if (itemcount > 0) {
    var counttext = itemcount;
    if (itemcount > 99) {
      counttext = '**';
    }
    cartButton.className = 'pchb pch_ct_but_full';
    cartCountDiv.innerHTML = counttext;
    cartCountTip.title = itemcount + ' items in your cart.';
  }
  else {
    cartButton.className = 'pchb pch_ct_but_empty';
    cartCountDiv.innerHTML = '';
    cartCountTip.title = 'Cart is empty.';
  }
	
}
function pch_checkfields() {('pch_blurpass(\'load\')',250); setTimeout('pch_blurlogin(\'load\')',250);}
		
function pchj_setup(){
	
  if(document.getElementById('searchField').value!='Search'){document.getElementById('searchField').className='pch_i_ss';}
  document.getElementById(document.getElementById('pch_active_search').value).style.backgroundColor='#bbb';
  document.getElementById('searchField').value=document.getElementById('pch_active_text').value;
  
	if (res_getCookie(pchj_tempCookie)!=null){
		document.getElementById('res_id_table').className='pch_res_table';
		document.getElementById('res_id_td1').className='pch_t1 pch_res_td1';
		document.getElementById('res_id_td2').className='pch_t1 pch_res_td2';
		if (document.getElementById('res_id_icn')){document.images['res_id_icn'].src = 'https://imagesak.securepaynet.net/fos/icn/icn_viewnarrow.png';}
		document.getElementById('res_option').style.display='';
		document.getElementById('res_option_sb').style.display='';
	}
	
} 