<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}
//-->

<!-- Hide JS source from HTML validators
function Dollar (val) {  // force to valid dollar amount
	var str,pos,rnd=0;
    if (val < .995) rnd = 1;  // for old Netscape browsers
		str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
        pos = str.indexOf (".");
        if (pos > 0) str = str.substring (rnd, pos + 3);
	        return str;
}

function ReadForm (obj1) { // process un-named selects
	var i,amt,des,obj,pos,val;
    amt = obj1.baseamt.value*1.0;       // base amount
    des = obj1.basedes.value;           // base description
    for (i=0; i<obj1.length; i++) {     // run entire form
	    obj = obj1.elements[i];           // a form element
        if (obj.type == "select-one" &&   // just get selects
	        obj.name == "") {             // must be un-named
             pos = obj.selectedIndex;        // which option selected
             val = obj.options[pos].value;   // selected value
             pos  = val.indexOf ("@");       // price set?
             if (pos >= 0) amt = val.substring (pos + 1)*1.0;
             pos  = val.indexOf ("+");       // price increment?
             if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
             pos  = val.indexOf ("%");       // percent change?
             if (pos >= 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
             if (des.length == 0) des = val;
             else des = des + ", " + val;    // accumulate value
        }

   	}
   obj1.item_name.value = des;
   obj1.amount.value = Dollar (amt);
   if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}

function MouseEvent(e){
	if(e){
		this.e = e;
	}else{
		this.e = window.event;
	}
	
	if(e.pageX){
		this.x = e.pageX;
	}else{
		this.x = e.clientX;
	}
	
	if(e.pageY){
		this.y = e.pageY;
	}else{
		this.y = e.clientY;
	}
	
	if(e.target){
		this.target = e.target;
	}else{
		this.target = e.srcElement;
	}
}

function select_menu(sel){
	ajaxEngine.sendRequest("request1", "selection=" + sel, "t=" + new Date().getTime());
	ajaxEngine.sendRequest("request1", "menu=" + sel, "t=" + new Date().getTime());
}

function select_item(sel, num){
	ajaxEngine.sendRequest("request1", "item=" + sel, "num=" + num, "t=" + new Date().getTime());
}

/*function show_shipping(sel, e){
	var e = new MouseEvent(e);
	var div_target = document.getElementById("shipDiv");
	var y = e.y + 10;
	div_target.style.top = y + "px";
	ajaxEngine.sendRequest("request1", "ship=" + sel, "t=" + new Date().getTime());
}*/

function init(){
	ajaxEngine.registerRequest("request1", "display_body.php");
	ajaxEngine.registerRequest("request_save", "save_data.php");
	ajaxEngine.registerAjaxElement("targetDiv");
	ajaxEngine.registerAjaxElement("menuDiv");
}

function open_shipping(type){
	var h;
	var w;
	var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;
    
	if(type == "admin"){
		h = 300;
		w = 600;
	}else{
		screen_height = (window.screen.height) - 200;
		h = 125;
		w = 400;
	}
    shipping_window = window.open('shipping.php','shipping_window','height='+ h +',width='+ w +',status=no,toolbar=no,menubar=no,location=no');
    shipping_window.moveTo(screen_width - 200, screen_height);
}

function select_admin_menu(sel){
	window.location.href="index.php?selection=" + sel;
}

function save_item(prod_id, field){
	var field_val = document.getElementById(field).value;
	if(field == "image_files"){
		var image_selection = document.getElementById("sel_images").value;
		if(image_selection == ""){
			alert("Please Select an Image first!");
			return;
		}
		if(field_val == ""){
			field_val = image_selection;
		}else{
			field_val += "|" + image_selection;
		}
	}
	if(field == "remove_image"){
		var agree = confirm("Are you sure you want to remove this image? " + field_val);
		if(!agree){
			return;
		}
	}
	
	ajaxEngine.sendRequest("request_save", "mode=item", "prod_id=" + prod_id, "field=" + field, "field_val=" + field_val, "t=" + new Date().getTime());
	if(field == "image_files" || field == "remove_image"){
		pausecomp(1250);
		window.location.href="index.php?selection=item|" + prod_id;
	}
}

function save_format(format_id, field, field_num){
	var field_val;
	
	if(field == "price"){
		field_val = document.getElementById(field_num).value * 1.0;
	}else{
		field_val = document.getElementById(field_num).value;
	}
	
	ajaxEngine.sendRequest("request_save", "mode=format", "format_id=" + format_id, "field=" + field, "field_val=" + field_val, "t=" + new Date().getTime());
}

function set_focus(field_name) {
	document.getElementById(field_name).focus();
}

function open_upload(cat, catid, mode){
    upload_window = window.open('upload_cat_titles.php?category=' + cat + "&cat_id=" + catid + "&mode=" + mode,'upload_window','height=125,width=600,status=no,toolbar=no,menubar=no,location=no');
    
    var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;

    upload_window.moveTo(screen_width - 200, screen_height);
}

function category(mode, type){
    cat_window = window.open('add_remove_cat.php?mode=' + mode + "&type=" + type,'cat_window','height=200,width=600,status=no,toolbar=no,menubar=no,location=no');
    
    var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;

    cat_window.moveTo(screen_width - 200, screen_height);
}

function formats(mode, type){
	var h;
	var w;
	var sw;
	if(type == "retail" && mode == "add"){
		h = "250";
		w = "750";
		sw = "350";
	}else{
		h = "200";
		w = "600";
		sw = "200";
	}
    format_window = window.open('add_remove_formats.php?mode=' + mode + "&type=" + type,'format_window','height=' + h +',width='+ w +',status=no,toolbar=no,menubar=no,location=no');
    
    var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;

    format_window.moveTo(screen_width - sw, screen_height);
}

function confirm_response(type){
	
	var agree = confirm("Are you sure you want to delete this "+ type +"?");
	if(agree){
		document.frmUpload.submit();
	}else{
		return;
	}
}

function edit_description(prod_id){
    desc_window = window.open('edit_description.php?prod_id=' + prod_id,'desc_window','height=350,width=600,status=no,toolbar=no,menubar=no,location=no');
    
    var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;

    desc_window.moveTo(screen_width - 200, screen_height);
}

function select_formats(prod_id, mode){
    formats_window = window.open('format_selection.php?prod_id=' + prod_id + "&mode=" + mode, 'formats_window','height=300,width=700,status=no,toolbar=no,menubar=no,location=no');
    
    var screen_height = window.screen.height / 2;
    var screen_width = window.screen.width / 2;

    formats_window.moveTo(screen_width - 200, screen_height);
}

function pausecomp(millis)
{
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); }
	while(curDate-date < millis);
} 

function validate_input(type){
	switch(type){
		case "formats":
			var format_name = document.getElementById("the_name").value;
			var format_type = document.getElementById("sel_type").value;
			var price = document.getElementById("price").value;
			if(format_name == ""){
				alert("FORMAT can NOT be blank!");
				return;
			}
			if(format_type == ""){
				alert("TYPE can NOT be blank!");
				return;
			}
			if(price == ""){
				alert("PRICE can NOT be blank!");
				return;
			}
			document.frmUpload.submit();
			break;
		case "retail":
			break;
		default:
			break;
	}
}
-->
