
function options_price($product,$n,$currency_code) {
    $options=new Array();
    for($i=1;$i<=$n;$i++) {
       $opt_str="option-"+$i;
		   $this_opt=document.getElementById($opt_str);
		   if(!$this_opt) { continue; }
		   $options[$i-1]=$this_opt.value;
		}
		if(!$options.length){$options[0]=0;}
		if($options.length) {
		   $opts=$options.sort();
       $url=ROOTURL+'inc/ajax/options_price.php?product='+$product+'&option='+$opts.join(",")+'&code='+$currency_code;
       ajax_do(ajax_init(),$url,change_price,'GET');
    }
}

//change the price on page
function change_price($xh_obj) {
   $response=$xh_obj.responseXML.documentElement;
   price=$response.getElementsByTagName('price')[0].firstChild.data;
   stock=$response.getElementsByTagName('stock')[0].firstChild.data;
   document.getElementById('totalprice').firstChild.nodeValue=price;
   $btn=document.getElementById('basket_button');
   $status=document.getElementById('availability');
	 if(stock==0){
	    $btn.style.display='none';
			$status.className='invalid';
			$status.firstChild.nodeValue='Item out of stock';
   }else{
	    $btn.style.display='block';
			$status.className='valid';
			$status.firstChild.nodeValue='Item in stock';
	 }
   document.getElementById("quantity").value=1;
}