
// CMS JavaScripts
// global vars
	var iClicked = false; 
// other shipping option id value
	var match = 4;
	
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function PopIt(filename, orgname, h, w) {
    popup = window.open(filename,"popDialog","height="+h+",width="+w+",scrollbars=yes")
    popup.opener.name = orgname;
    if ( popup.document.close() ) {
        popup.document.close();
    }
}

function ClosePopUp() {
        self.document.close();
}

function glossary(term) {

    popup = window.open("/glossary.src?T="+term,"popGlossary","height=400,width=400,scrollbars=yes");
    popup.opener.name = "main";
    if ( popup.document.close() ) {
        popup.document.close()
	}
}

function delay_ms(millisecs) {
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); } 
	while(curDate-date < millisecs);
} 

function moduleSet(uMod,p) {
	if(uMod>0) {
		popup = window.open('/lib/modset.src?UM='+uMod+'\&p='+p,'modSet','height=400,width=400,scrollbars=yes');
		popup.opener.name = "main";
		if ( popup.document.close() ) {
		        popup.document.close()
		}
	}
}	

function handleCountry(field,match) {
        fVal=document.getElementById(field).value;
        fSel=field+'Sel';
        fOther=field+'Other';
        if(fVal==match) {
            document.getElementById(fOther).className='show';
        }
        else {
            document.getElementById(fOther).className='hide';
        }
//		if the ship country changes then update shipping selector
		f=document.getElementById('form');
        if(document.getElementById('form').Same[1].checked)  
	        f.SCountry.value=f.Country.value;
		if(fVal)
			loadIframe('shipSelect','/cart/shipselect.src?C='+f.SCountry.value+'&M='+f.Method.value);

}


function enableElementDisplay(id) {
// stupid IE 7 doesn't support table-row so set block for it
    try {
        document.getElementById(id).style.display = "table-row";
    }
    catch (e) {
        document.getElementById(id).style.display = "block";
    }

}
 
function enableShipping(match) {
        enableElementDisplay('s1');
        enableElementDisplay('s2');
        enableElementDisplay('s3');
        enableElementDisplay('s4');
        enableElementDisplay('s5');
        enableElementDisplay('s6');

        f=document.getElementById('form');

        if(f.SCountry.value==match ) {
            fSel='SCountryOther';
            document.getElementById(fSel).className='show';
        }
        else {
            fSel='SCountryOther';
//          f.SCountry.value=''; 
            document.getElementById(fSel).className='hide';
        }
//      alert(f.OtherSCountry.value);
//      f.OtherSCountry.value=f.OtherCountry.value;
//		updateMethod(); 
}

function disableShipping(match) {

        document.getElementById('s1').style.display='none';
        document.getElementById('s2').style.display='none';
        document.getElementById('s3').style.display='none';
        document.getElementById('s4').style.display='none';
        document.getElementById('s5').style.display='none';
        document.getElementById('s6').style.display='none';

        f=document.getElementById('form');


        f.SName.value=f.First.value + ' ' + f.Last.value;
        f.SAddress.value=f.Address.value;
        f.SAddress2.value=f.Address2.value;
        f.SCity.value=f.City.value;
        f.SState.value=f.State.value;
        f.SZip.value=f.Zip.value;
//      f.SPhone.value=f.Phone.value;
        if(f.Country.value==match) { 
            f.SCountry.value=f.Country.value;
//          if(f.OtherCountry.value) {
                f.OtherSCountry.value=f.OtherCountry.value;
//          }
        }
        else {
            f.SCountry.value=f.Country.value;
            if(f.OtherCountry.value) 
                f.OtherSCountry.value=f.OtherCountry.value;
        }
  
        if(f.SCountry.value==match ) {
            fSel='SCountryOther';
            document.getElementById(fSel).className='show';
        }
        else {
            fSel='SCountryOther';
//          f.SCountry.value=''; 
            document.getElementById(fSel).className='hide';
        }
//      alert('d:'+f.OtherSCountry.value);
  
        loadIframe('shipSelect','/cart/shipselect.src?C='+f.SCountry.value+'&M='+f.Method.value);
//        updateMethod();
}

function loadIframe(iframeName, url) {
    if ( window.frames[iframeName] ) {
        window.frames[iframeName].location = url;   
        return false;
    }
    return true;
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 

window.onload = externalLinks;


