                                                                   
function $() 	{ return document.getElementById(arguments[0]); }

/* global variables */
var itemCount = 0;           
var braceletordered = false;
		


function changePrice(ckBox, price){
	$(ckBox).value =price;
}



 function dont()
 {
 alert("inside dont");
		
 }

function Format$() 					{ return CurrencyFormatted(arguments[0]); }  

/** string textbox_id,int o, optional arg[2] == cboList */


/** Show Member Number */
function showMN(show) {setExisting(show);}  /** THE CB() call is so the membership details follow through */
function setExisting(is_existing) {

   if(is_existing) {  ShowDIV('mem_no_div'); ShowDIV('MemberNumber'); $('MemberNumber').value = "";  }
   else {  HideDIV('mem_no_div'); HideDIV('MemberNumber'); $('MemberNumber').value = "N/A - New member !!"; }       

}




function SetDisplay(i,o) { document.getElementById(i).style.display=o; }
function HideDIV(id) { SetDisplay(id,"none");  }
function ShowDIV(id) { SetDisplay(id,"block"); }      

function hide(id) { SetDisplay(id,"none");  }
function show(id) { SetDisplay(id,"block"); }
  
function ShowHideDiv_CheckBox(c,id) { if(c.checked) { SetDisplay(id,"block"); } else SetDisplay(id,"none"); }




/** Formats a number into decimal 2 dec places for currency */
function CurrencyFormatted(amount) {  var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = '';  if(i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100;  s = new String(i); if(s.indexOf('.') < 0) { s += '.00'; }  if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s;  return s; }

    
 
/**  Function Wrapper.*/
function MenuSection_CheckBox(_C,id,label_id) {  if(_C.checked) { SetDisplay(id,"block");  if(HIDE_CHECKBOX_ON_SELECT ==true){ SetDisplay(_C.id,"none");  $(label_id).innerHTML=""; } }else {  SetDisplay(id,"none"); }}

function pF(o){return parseFloat(o);}    
function FloatTryParse(id) { return (isNaN(pF($(id).innerHTML)))?0:pF($(id).innerHTML);}       

/** Returns True if object can be parsed. */
function Float_TryParse(object) { if (isNaN(pF(object))) return false; else { if(arguments.length==2) arguments[1] = pF(object);; return true; }}

/** Pop up window for Terms and Conditions*/ 
function popupWindow(url) {   name = "Terms"; w = POPUP_WIDTH; h = POPUP_HEIGHT; w += 32;  h += 96; wleft = (screen.width - w) / 2; wtop = (screen.height - h) / 2; if (wleft < 0) {  w = screen.width;  wleft = 0;  }  if (wtop < 0) {  h = screen.height; wtop = 0; } var win = window.open(url, name, 'width=' + w + ', height=' + h + ', left=' + wleft + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');   win.resizeTo(w, h); win.moveTo(wleft, wtop); win.focus();  }       

/**check that the terms and contditions are met in the page */
function termsValidator(){

//checkTitle is selected
		  var radioSelected = false;
		  for (i = 0;  i < document.OrderForm.chkTerms.length;  i++)
		  {
		    if (document.OrderForm.chkTerms[i].checked)
		        return true;
		  }
		  if (!radioSelected)
		  {
		    alert("Please Accept the Terms and Conditions");
			 document.OrderForm.chkTerms[0].focus();
		    return (false);
		  }
 
 
 }


	// checks that the input is all characters and that it is the length of constraint c
function checkInput(itemNum, l, min, max){
	
 var maxlen = parseInt(max);
 var minlen = parseInt(min);	
var len = parseInt(l);

 	if(len > maxlen ){	 		
 		alert("Your Length Chosen is too long ("+min+"-"+max+"cm). Please try again");
 		$('custLen'+itemNum).value = max;
 		 	return false;
 		}
 	if(len < minlen ){
 		alert("Your Length Chosen is too short ("+min+"-"+max+"cm). Please try again");
 		$('custLen'+itemNum).value = min;
 		return false;
 		}else{ 		
 	return len ;
 	}
}//end check Input



function updateCustomLen(itemNum, length, min, max){
	if(val = checkInput(itemNum, length,min, max)){
		//fill in the custom length radio button
		$('cust-'+itemNum).value = val;
		//alert($('cust-'+itemNum).value);
		$('cust-'+itemNum).checked = true;
// hide('opt3-'+itemNum+'-div');
 //showselected('3',itemNum,length + 'cm');
 }
}


/** This function is used to validate before the postback validate. */
function submitit() { if(termsValidator() && User_Data_Validator('OrderForm') ){ return true;}else return false;
}
/**  This function is used to determin is JS is enabled  */
function validate_js() {
      	
              
    $('JavascriptEnabled').value = "Y";
 }
 
/** ticks off all any checkbos associated with a quantity if the qty is filled and the checkbox is not
	also checks the qty value entered for validity and changes it to a 
**/

 function tickCheck(q, m){
	  var _q = parseFloat($(q).value);; //turn the quantity into a number
		
	//data validation on quantity _q 
	if((_q=='undefined')|| (_q==undefined)) 
	{ 
        alert('Not a valid input'); 
		$(q).value = '0'; //set the real value to 0
		
		
    };
    if(isNaN(_q)) { 
        alert('The Quantity You enetered is not Numeric..\r\nPlease Try again');  
        $(q).value = '0';
	};
		if(_q == 0){	$(m).checked = false;}		
		else { 		$(m).checked = true;}
	 
 }
 


 

/** Updates Membership cost details on order form */
function updateMembershipSelection() { 
	if ( $('isExisting').checked )  
		if ( $('isRenewing').checked) { 
			return ANUAL_MEMBERSHIP_FEE;
		}
		else return 0;
	else{
 		return 0; //usually = ANUAL_MEMBERSHIP_FEE; changed due to onlineSPECIAL
		}
 }	  

/**  Shows Hides a Layer by request of the PHP settings  */  
function ShowOnLoad(id,_b,_c) { if(_b==true) { $(id).style.display="block";  }  else { 	$(id).style.display="none"; }$(_c).checked = _b; }  
 
/** This is a simple function that is called at the end of render of order.php page */
/*
    Does not get called for OrderN.php as the call has been removed
*/
function init(val) {
  if(val==1) {
  
     	
			if(!ALLOW_CHECKBOX_GROUPS){  
        	
        		HideDIV('spacer5'); 
        		HideDIV('chkOrderBracelets'); 
        		HideDIV('chkOrderNecklace');   
        		HideDIV('chkOrderWALLCard');  
        		HideDIV('chkOrderKEYRing'); 
        		HideDIV('chkOrderDT');   
        		HideDIV('lblBraceletes');   
        		HideDIV('lblNecklaces');   
        		HideDIV('lblWalletCardText'); 
        		HideDIV('lblKeyRingText');  
        		HideDIV('lblDogTags'); 
        	}
        

        
        	ShowOnLoad("WALLCardOrder",SHOW_ORDER_WALLCard_ON_LOAD,'chkOrderWALLCard');
        	ShowOnLoad("DogTagsOrder",SHOW_ORDER_DOGTAG_ON_LOAD,'chkOrderDT');
        	ShowOnLoad("KEYRingOrder",SHOW_ORDER_KEYRing_ON_LOAD,'chkOrderKEYRing');
        	ShowOnLoad("NecklaceOrder",SHOW_ORDER_NECKLACE_ON_LOAD,'chkOrderNecklace');
        	ShowOnLoad("BraceleteOrder",SHOW_ORDER_BRACELET_ON_LOAD,'chkOrderBracelets');
        	
        	
	
	}
	else if (val==2) { }
	
	CB();
}  
/** Page & Document Events */
function onload() {
	validate_js(); 
	
}   




