// CMS JavaScripts
// global vars
	var iClicked = false; 
	
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 updateMethod() {
	document.form.Method.value=document.getElementById('shipSelect').contentWindow.document.getElementById('Method').value;
}
 
function enableShipping() {
	document.getElementById('s1').style.display='table-row';
        document.getElementById('s2').style.display='table-row';
        document.getElementById('s3').style.display='table-row';
        document.getElementById('s4').style.display='table-row';
        document.getElementById('s5').style.display='table-row';
        document.getElementById('s6').style.display='table-row';
}

function disableShipping() {
		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.Name.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.OtherCountry.value=''; 
		f.SCountry.value=f.Country.value;
        f.OtherSCountry.value=f.OtherCountry.value;
        if(f.SCountry.value==match ) {
        	fSel='SCountryOther';
		document.getElementById(fSel).className='show';
		}
 		loadIframe('shipSelect','/cart/shipselect.src?C='+f.SCountry.value+'&M='+f.Method.value);
}

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;


