function preview(myimage) {
	if(myimage!="") {
		html = "<html><body style='margin: 0; padding: 0;'><img src='" + myimage + "' name='image' onClick='window.close();'";
		html+="onload='window.resizeTo(document.image.width+10,document.image.height+60)'>"; 
		html+="</body></html>";
		popup=window.open('','image','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
		popup.document.open();
		popup.document.write(html);
		popup.document.close();
	} else {
		alert('No image available!');
	}
};
function open_list(d,m,f) {
	window.open("images_list.php?dir="+d+"&max="+m+"&form="+f,"images_list","height=600,width=600,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1");
}
function change_color(i) {
// change_availability2();
	document.getElementById("product_image_big").src=img[i];
	document.getElementById("play_color_id").options[i].selected=true;
	for(j=0;j<img.length;j++) {
		if(i==j) {
			document.getElementById("color"+j).className="product_color_selected";
		} else {
			document.getElementById("color"+j).className="product_color_normal";
		}

		var color_url=document.getElementById("img_color"+j).src;
		color_img=color_url.substr(color_url.lastIndexOf('/')+1);
		color_path=color_url.substr(0,color_url.lastIndexOf('/')+1);
		if(i==j) {
			if(color_img.charAt(0)!='x')
				document.getElementById("img_color"+j).src=color_path+'x-'+color_img;
		} else {
			if(color_img.charAt(0)=='x')
				color_img=color_img.substr(color_img.indexOf('-')+1);

			document.getElementById("img_color"+j).src=color_path+color_img;
		}
	}
}
function update_price(quantity,price) {
	if(quantity==0 || quantity=="") {
		p=price
	} else {
		p=quantity*price;
	}
	document.getElementById("price_value").innerHTML=p;
}

function $(id) {
	return document.getElementById(id);
}
function $s(id) {
	return $(id).style;
}
function toggle(obj) {
	var el = $s(obj);
	el.display = (el.display != 'none' ? 'none' : '' );
}

// function change_availability(color_id,size_id){
// alert(color_id+" - "+size_id);
// }
function change_availability(color_id,size_id){
// alert(color_id+" - "+size_id);
var ava_list=new Array("good", "poor", "upcoming");
var ava_desc=ava[color_id][size_id];
document.getElementById(ava_desc).style.display="block";
for(n=0;n<ava_list.length;n++){
	if(ava_list[n]!=ava_desc)
		document.getElementById(ava_list[n]).style.display="none";
}
}

function change_availability2(color,size){
// alert(color_id+" - "+size_id);
// var ava_list=new Array("good", "poor", "upcoming");
// var ava_desc=ava[color_id][size_id];

var ava_list=new Array("good", "poor", "upcoming");

var color_id=document.getElementById('play_color_id')[document.getElementById('play_color_id').selectedIndex].value;
if(size){
var size_id=document.getElementById('play_size_id')[document.getElementById('play_size_id').selectedIndex].value;
}else{
size_id="";
}
// change_availability(color_id,size_id);
var ava_desc=ava[color_id][size_id];

document.getElementById(ava_desc).style.display="block";
for(n=0;n<ava_list.length;n++){
	if(ava_list[n]!=ava_desc)
		document.getElementById(ava_list[n]).style.display="none";
}
}

function check_availability(color,size,text){
var color_id=document.getElementById('play_color_id')[document.getElementById('play_color_id').selectedIndex].value;
if(size){
var size_id=document.getElementById('play_size_id')[document.getElementById('play_size_id').selectedIndex].value;
}else{
size_id="";
}
var ava_desc=ava[color_id][size_id];
if(ava_desc=="upcoming"){
	alert(text);
	return false;
}
else
	return true;
}

function check_limit(form,unit_price,total,total_prod,max_limit,txt){
// 	var quantity=document.getElementById(quantity_input).value;

var quantity=form.play_product_quantity.value;
// alert(unit_price);
// alert(form.play_product_quantity.value);
// alert(total+" - "+quantity+" - "+price);

	var total_tot = total-total_prod+(unit_price*quantity);
// alert(total_tot+' - '+max_limit);
if(total_tot>max_limit){
alert(txt);
	return false;
}else{
	return true;
}
}

function check_limit_tot(total,max_limit,txt){
if(total>max_limit){
alert(txt);
	return false;
}else{
	return true;
}
}