function WriteReview(pid){
  day = new Date();
  id = day.getTime();
  
  eval("page" + id + " = window.open('write-review.php?id='+pid, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=400');");
  //var el = window.open('/write-review.php?id='+pid, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=450,left = 615,top = 300');
}

function openEFWindow(id){
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('emailfriend.php?id='+id, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=400');");
  //var el = window.open('emailfriend.php?id='+id, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=450,left = 615,top = 300');
}
// Provides some ajax for the custom display.
var BasePrice;
$(document).ready(function() {
	// Hide modal box when it is clicked
	$('#Mask').click(function () {  
		
		$(this).hide();  
		$("#OutOfStock").hide();
	});	
	
	$('a.OutofStock').click(function(){
		var pos = $(this).offset();
		pos.top = pos.top + 20;
		$("#OutOfStock").css(pos);
		$("#OptID").val($(this).attr("rel"));
		$("#Mask").show();		
		$("#OutOfStock").show();		
	});
});

function ShowOutOfStock(opt,prod){
	
	var obj = $("#OutOfStock");
	//obj.css('top', ($(window).height()-obj.height())/2);
  //obj.css('left', ($(window).width()-obj.width())/2);
  var pos = $("#"+opt).offset();  
  obj.css('top', pos.top-obj.height()-$("#"+opt).height()*2);
  obj.css('left', pos.left);
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
		
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	$('#mask').show();	
	$('#mask').fadeTo(0,0.8);	
	$.ajax({
		type: "POST",
		url: "/customdisplay/outofstock.php",
		data: "option="+$("#"+opt).val()+"&prod="+prod,
		success: function(msg){
			$("#OutOfStock").html(msg);
		}
	});
  obj.show();
} 	

function UpdatePrice(optid){
	var val = parseFloat(($("#BasePrice").val()));	
	var val2
	var valend=val;
	$(".optclass").each(function(){				
		if ($(this).attr('type')=='radio'){
  		if (this.checked){
	      val2 = $(this).attr( 'rel' );
	    } else {
	    	val2 = 0;
	    }
	  } else {	    
	  	val2 = $("#"+this.id + " option:selected").attr('rel');
	  }
	  if (val2==''||val2=='undefined'){
	  	val2=0;
	  }
	    valend = valend + parseFloat(val2);
	});
	$("#Price").html('$'+valend.toFixed(2));
}

function HandleRequired(CheckStock,pid){
	bOK=true;
	var Missed = '';
	$(".optclass").each(function(){	
		alert($this).attr('name');
		if ($(this).attr('ref') == '1'){
			if ($(this).attr('type')=='radio'){
				if ($(this).attr('checked') == true){
					if (Missed == ''){
						Missed = $(this);
					}
					bOK=false;
				} 
			} else {
				if ($(this).val() == ''){
					if (Missed == ''){
						Missed = $(this);
					}					
    		  bOK=false;
		   	}
		  }
		}
	});
	if (!bOK){
		alert("You must select the necessary options.");
		Missed.focus();
	} else {		
		if (CheckStock){
			// Verify that the inventory is available to handle this order.
    	$.ajax({
	    	type: "POST",
		    url: "customdisplay/check-stock.php",
   		  data: "prod="+pid,		
    		success: function(msg){
    			if (msg <= 0){
		  		  bOK=false;
			  	}
  			}
	  	});
  	}
	}	
	return bOK;
}

	

function CheckOptionStock(optid,prodid){
	// AJAX
	if ($("#"+optid).val()!=""){
  	$.ajax({
	  	type: "POST",
		  url: "customdisplay/check-stock.php",
  		data: "option="+$("#"+optid).val(),
	  	success: function(msg){
		  	if (msg==0){
  			  ShowOutOfStock(optid, prodid);
	  		}
		  }	
  	});
  }
}// Provides some ajax for the custom display.
var BasePrice;
$(document).ready(function() {
	// Hide modal box when it is clicked
	$('#mask').click(function () {  
		
		$(this).hide();  
		$("#OutOfStock").hide();
	});	
});

function ShowOutOfStock(opt,prod){
	
	var obj = $("#OutOfStock");
	//obj.css('top', ($(window).height()-obj.height())/2);
  //obj.css('left', ($(window).width()-obj.width())/2);
  var pos = $("#"+opt).offset();  
  obj.css('top', pos.top-obj.height()-$("#"+opt).height()*2);
  obj.css('left', pos.left);
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
		
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	$('#mask').show();	
	$('#mask').fadeTo(0,0.8);	
	$.ajax({
		type: "POST",
		url: "/customdisplay/outofstock.php",
		data: "option="+$("#"+opt).val()+"&prod="+prod,
		success: function(msg){
			$("#OutOfStock").html(msg);
		}
	});
  obj.show();
} 	

function UpdatePrice(optid){
	var val = parseFloat(($("#BasePrice").val()));	
	var val2
	var valend=val;
	$(".optclass").each(function(){				
		if ($(this).attr('type')=='radio'){
  		if (this.checked){
	      val2 = $(this).attr( 'rel' );
	    } else {
	    	val2 = 0;
	    }
	  } else {	    
	  	val2 = $("#"+this.id + " option:selected").attr('rel');
	  }
	  if (val2==''||val2=='undefined'){
	  	val2=0;
	  }
	    valend = valend + parseFloat(val2);
	});
	$("#Price").html('$'+valend.toFixed(2));
}

function HandleRequired(CheckStock,pid){
	bOK=true;
	var Missed = '';
	$(".optclass").each(function(){	
		if ($(this).attr('ref') == '1'){
			if ($(this).attr('type')=='radio'){
				if ($(this).attr('checked') == true){
					if (Missed == ''){
						Missed = $(this);
					}
					bOK=false;
				} 
			} else {
				if ($(this).val() == ''){
					if (Missed == ''){
						Missed = $(this);
					}					
    		  bOK=false;
		   	}
		  }
		}
	});
	if (!bOK){
		alert("You must select the necessary options.");
		Missed.focus();
	} else {		
		if (CheckStock){
			// Verify that the inventory is available to handle this order.
    	$.ajax({
	    	type: "POST",
		    url: "customdisplay/check-stock.php",
   		  data: "prod="+pid,		
    		success: function(msg){
    			if (msg <= 0){
		  		  bOK=false;
			  	}  				
  			}
	  	});
  	}
	}	
	return bOK;
}

	

function CheckOptionStock(optid,prodid){
	// AJAX
	if ($("#"+optid).val()!=""){
  	$.ajax({
	  	type: "POST",
		  url: "customdisplay/check-stock.php",
  		data: "option="+$("#"+optid).val(),
	  	success: function(msg){
		  	if (msg==0){
  			  ShowOutOfStock(optid, prodid);
	  		}
		  }	
  	});
  }
}                                                                                                                      



function dispvote(){
	if ($("#dispvote").html() == '+'){
		$("#dispvote").html("-");
	} else {
		$("#dispvote").html("+");
	}	
	$("#votebox").slideToggle("fast");		
}