	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) {
//		alert(field);
        fVal=document.getElementById(field).value;
        fSel=field+'Sel';
        fOther=field+'Other';
        if(fVal==match) {
            document.getElementById(fOther).className='show';
//	           document.getElementById(fSel).className='hide';  
        }
        else {
            document.getElementById(fOther).className='hide';
//	        document.getElementById(fSel).className='show'; 
        }
//	 	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);

//		alert('set ' + field + ' to ' + fVal);		
}

function updateMethod() {
	document.form.Method.value=document.getElementById('shipSelect').contentWindow.document.getElementById('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;
}

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.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.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);
}

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;


function getFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
//		alert(field.options[i].value);
    
        if (i == -1)   return "";
		else   return field.options[i].value;        
//	 ? field.options[i].text : field.options[i].value;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
            alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
         break;
   }
   
   return "";
}

function validateOptions(thisForm) {

	var vReq=document.options.required.value.split(",");	// put required fields into array
	var vError=document.options.reqErrors.value.split(",");  // error messages
	var thisField;
	var alertOut="";

	for(j=0;j<vReq.length-1;j++) {
	
		thisField = eval("document.options." + vReq[j]);
// 		alert(thisField.name+"="+thisField.type);

		theVal=getFieldValue(thisField);
//		alert(theVal);

		if(!theVal) 
			alertOut+=vError[j] + " is required!\n";
	
	}		
	
	if(alertOut!="") {	
		alert(alertOut);
		return false;  
	}
	else 
	{
		document.forms[0].submit();
		return true;
	}
		
}

  function getRadioValue(frm,radio_name) {

	var oRadio = eval("document." + frm + "." + radio_name );

	for(var i = 0; i < oRadio.length; i++) { 
		if(oRadio[i].checked) 
			return oRadio[i].value;
	}

	return '';
}

