function printView(dist, height, width) {
	offsetX = (screen.width - width) / 2;
	offsetY = (screen.height - height) / 4;
	strFeatures = "scrollbars,resizable,status,height=" + height +", width=" + width;	
	window.open(dist,'printPreview', strFeatures);
}
function productJumper(thisObjct) {
	if (thisObjct.value != "") {
		document.productForm.cpid.value = thisObjct.value;
		document.productForm.submit();
	}
}
function categoryJumper(thisObjct) {
	if (thisObjct.value != "") {
		document.categoryForm.ID.value = thisObjct.value;
		document.categoryForm.submit();
	}
}
function healthJumper(thisObjct) {
	if (thisObjct.value != "") {
		document.healthForm.ID.value = thisObjct.value;
		document.healthForm.submit();
	}
}

function goTo(new_page) {
	parent.location=new_page;
}

function removeRecord(record_id, fieldName, row_count) {
	rowToDelete= document.getElementById(row_count);
	currentClassName = 	rowToDelete.className;
	rowToDelete.className = "listDelete";
	del_confirm = confirm("Are you sure you want to deactivate/delete this record?");
	if (del_confirm == true){
		myHiddenField = document.getElementById(fieldName);
		myHiddenField.value = record_id;
		document.record_del_form.submit();
	} else {
		rowToDelete.className = currentClassName;
	}
}

function getFilePath(myfield) {
	myValue = myfield.value;
	fieldName = myfield.name;
	fieldName += "_hidden";
	myHiddenField = document.getElementById(fieldName);
	myHiddenField.value = myValue;
}

function sortBy(sortBy, sortDirection) {
	myHiddenField = document.getElementById('order_by_record');
	myHiddenField.value = sortBy;
	myHiddenField = document.getElementById('acdc_record');
	myHiddenField.value = sortDirection;
	document.sort_by_form.submit();
}

function pagelpp(lpp) {
	lpp_hidden_1 = document.getElementById(lpp);
	lpp_value = lpp_hidden_1.value;
	lpp_hidden_2 = document.getElementById('lpp_record');
	lpp_hidden_2.value = lpp_value;
	document.record_lpp_form.submit();
}

function productSizeCheck(pcheck) {
	pro = document.getElementById(pcheck);
	if (arguments.length > 1) {
		if (pro.checked == false) {
			var i = 1;
			while (i < arguments.length) {
				if (arguments[i] = 'D') {
					document.getElementById(arguments[i+1]).disabled = true;
				} else if (arguments[i] = 'C') {
					document.getElementById(arguments[i+1]).checked = false;
				}
				i++;
				i++;
			}
		} else {
			var i = 1;
			while (i < arguments.length) {
				if (arguments[i] = 'D') {
					document.getElementById(arguments[i+1]).disabled = false;
				} else if (arguments[i] = 'C') {
					document.getElementById(arguments[i+1]).checked = true;
				}
				i++;
				i++;
			}
		}
	}
}

function addProductSubmit(product_pos) {
	document.getElementById("item_cpid").value = document.getElementById("cpid_"+product_pos).value;
	document.getElementById("item_id").value = document.getElementById("pid_"+product_pos).value;
	document.getElementById("item_name").value = document.getElementById("name_"+product_pos).value;
	document.getElementById("item_price").value = document.getElementById("price_"+product_pos).value;
	document.getElementById("item_discount").value = document.getElementById("discount_"+product_pos).value;
	document.getElementById("item_size").value = document.getElementById("size_"+product_pos).value;
	document.getElementById("item_tax").value = document.getElementById("tax_"+product_pos).value;
	document.getElementById("item_qty").value = document.getElementById("qty_"+product_pos).value;
	document.add_product_form.submit();
}

function rfc(t_itemID) {
	document.getElementById("itemID").value = t_itemID;
	document.remove_item_form.submit();
}

function atc(t_itemID) {
	document.getElementById("pid").value = t_itemID;
	document.getElementById("qty").value = document.getElementById("qty_" + t_itemID).value;
	document.add_to_cart_form.submit();
}

function changeState() {
	document.getElementById("change_state").value = "1";
	document.update_cart_form.submit();
}

function setSubmitValue(formId, fieldId, fieldValue) {
	document.getElementById(fieldId).value = fieldValue;
	var myForm = document.getElementById(formId);
	//document.fromName.submit();
	myForm.submit();
}

function returnProduct(t_itemID, t_max_qty, t_type) {
	if (t_type == 1) {
		var t_qty = -1;
		while(t_qty < 0) {
			t_qty = prompt("Quantity to Return (between  1 and " + t_max_qty + ")", t_max_qty);
			if (!t_qty) {
				alert("Action Canceled");
			} else {
				t_qty = parseInt(t_qty);
				if (!t_qty) {
					alert("Invalid Value");
					t_qty = -1;
				} else if (t_qty > t_max_qty) {
					alert("Invalid Value");
					t_qty = -1;
				} else {
					document.getElementById("item_id").value = t_itemID;
					document.getElementById("return_qty").value = t_qty;
					document.getElementById("return_type").value = t_type;
					
					var myForm = document.getElementById("return_product_form");
					myForm.submit();
				}
			}
		}
	} else {
		document.getElementById("item_id").value = t_itemID;
		document.getElementById("return_type").value = t_type;
		
		var myForm = document.getElementById("return_product_form");
		myForm.submit();
	}
}

function googleCheckout() {
	$.ajax({
		type: "POST",
		url: "submit_order.php",
		data: "submit_order=1",
		beforeSend: function(){
			var vObjectOn = document.getElementById("GButtonOn");
			vObjectOn.className = "hideDiv";
			
			var vObjectOff = document.getElementById("GButtonOff");
			vObjectOff.className = "showDiv";
		}, //show loading just when link is clicked
		complete: function(){}, //stop showing loading when the process is complete
		success: function(){
		  document.google_checkout_form.submit();
		}//so, if data is retrieved, store it in html and show loading just when link is clicked
	}); //close $.ajax(	
}

function checkOut() {
	document.getElementById("checkout_flag").value = "1";
	document.update_cart_form.submit();
}

function setShippingAddress() {
	document.getElementById("address_change").value = "1";
	document.checkout_form.submit();
}

function change_color(curStar) {
	if (curStar == 0) {
		selectedStar = "../images/pill_green.gif";
		curStar = document.getElementById("t_rate").value;
		if (curStar == "")
			curStar = 0;
	} else {
		selectedStar = "../images/pill_green.gif";
	}
	for (var i = 1; i <= curStar; i++) {
		MM_swapImage("star_" + i,'',selectedStar,1);
	}
	if (curStar < 5) {
		for (var i = 5; i > curStar; i--) {
			MM_swapImage("star_" + i,'','../images/pill_gray.gif',1);
		}
	}
}

function set_color(curStar) {
	document.getElementById("t_rate").value = curStar;
}

function reset_color() {
	document.getElementById("t_rate").value = '';
	change_color(0);
}

function resetSearchText(v, o) {
	if (v == 1) {
		if (o.value == 'Search Website') {
			o.value = '';
		}
	} else {
		if (o.value == '') {
			o.value = 'Search Website';
		}
	}
}

// object symptom-category
function oSC(sId, sName, cId, cName) {
	this.symptomId = sId;
	this.symptomName = sName;
	this.categoryId = cId;
	this.categoryName = cName;
}
// function to add oSC to an array
function oS(sId, sName, cId, cName) {
	allSymptoms[allSymptoms.length] = new oSC(sId, sName, cId, cName);
}

function reload_sym(catObj, symObj) {
	removeAllOptions(symObj);
	for(var i = 0; i < allSymptoms.length; i++) {
		if (allSymptoms[i].categoryId == catObj.value) {
			addOption(symObj,allSymptoms[i].symptomName,allSymptoms[i].symptomId,false);
		}
	}
}

function multiselectFormSubmit() {
	if (arguments.length > 0) {
		var argLen = arguments.length;
		for (var i = 0; i < argLen; i++) {
			selectAllOptions(arguments[i]);
		}
		return true;
	}
}

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		if (!hasOptions(obj)) { return; }
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
			to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}


// -------------------------------------------------------------------
// mySleep(naptime)
//  javascript sleep function
// -------------------------------------------------------------------
function mySleep(naptime) {
	naptime = naptime * 1000;
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();
	//alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
	while(sleeping){
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > naptime){ 
			sleeping = false; 
		}
	}      
	//alert("Wakeup!");
}


 //------------------------------------------------------------------------------------------------//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
  
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){
   	document.MM_sr[j++]=x; 
   	if(!x.oSrc) 
   		x.oSrc=x.src; x.src=a[i+2];
   	}
}
