<!--
function createRequest(){
	try{
			request=new XMLHttpRequest();
	}catch (trymicrosoft){
		try{
				request=new ActiveXObject("Msxm12.XMLHTTP");
		}catch(othermicrosoft){
			try{
					request = new ActiveXObject("Microsoft.XMLHTTP");
		 	}catch(failed){
					request=null;
			}
		}
	}
	if (request==null){
		alert("Error creating request Object!");
	}else{
		return request;
	}
}
var requestItemDetail = createRequest();
function displayItemDetail(itemId) {
	var url="item-detail.php?Item_Id="+itemId;
	url = url + "&dummy=" + new Date().getTime();
	requestItemDetail.open("GET",url,true);
	requestItemDetail.onreadystatechange=displayItemDetail_callback;
	requestItemDetail.send(null);
}
function displayItemDetail_callback(){
	if (requestItemDetail.readyState==4){
		if (requestItemDetail.status==200){
			document.getElementById("divItemDetail").innerHTML = requestItemDetail.responseText;
		}
	}
}

var requestImageNewProduct = createRequest();
function LoadImageNewProduct(itemId){
	var url="imageNewProduct.php?Item_Id="+itemId;
	url = url + "&dummy=" + new Date().getTime();
	requestImageNewProduct.open("GET",url,true);
	requestImageNewProduct.onreadystatechange=LoadImageNewProduct_callback;
	requestImageNewProduct.send(null);
}
function LoadImageNewProduct_callback(){
	if (requestImageNewProduct.readyState==4){
		if (requestImageNewProduct.status==200){
			document.getElementById("divImageNewProduct").innerHTML = requestImageNewProduct.responseText;
		}
	}
}

function insertParam(key, value) 
{ 
    key = escape(key); value = escape(value); 
    var kvp = document.location.search.substr(1).split('&'); 
    var i=kvp.length; var x; while(i--)  
    { 
        x = kvp[i].split('='); 
        if (x[0]==key) 
        { 
                x[1] = value; 
                kvp[i] = x.join('='); 
                break; 
        } 
    } 
 
    if(i<0) {kvp[kvp.length] = [key,value].join('=');} 

    //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');  
} 

function getInsertParam(url, key, value){ 
    key = escape(key); value = escape(value); 
	//var kvp = document.location.search.substr(1).split('&'); 
	var kvp = url.substr(0).split('&'); 
    var i=kvp.length; var x; while(i--)  
    { 
        x = kvp[i].split('='); 
        if (x[0]==key) 
        { 
                x[1] = value; 
                kvp[i] = x.join('='); 
                break; 
        } 
    } 
 
    if(i<0) {kvp[kvp.length] = [key,value].join('=');} 
	
	return kvp.join('&');
    
	//this will reload the page, it's likely better to store this until finished 
    //document.location.search = kvp.join('&');  
}

function insertParam_Modified(url, key, value) 
{ 
    key = escape(key); value = escape(value); 
    var kvp = url.substr(1).split('&'); 
    var i=kvp.length; var x; while(i--)  
    { 
        x = kvp[i].split('='); 
        if (x[0]==key) 
        { 
                x[1] = value; 
                kvp[i] = x.join('='); 
                break; 
        } 
    } 
 
    if(i<0) {kvp[kvp.length] = [key,value].join('=');} 

    //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');  
} 

function PopupWindow(url, width , height){
	var leftVal = (screen.width - width) / 2;
	var topVal = (screen.height - height) / 2;
	var sFeature = "top=" + topVal + ",left=" + leftVal + ",width=" + width + ",height=" + height + ",toolbar=yes,resizable=yes,scrollbars=yes,status=yes"
	window.open(url, 'popup', sFeature); 
}
function EnlargeImage(url,w,h){
	window.open (url,'Image','location=0,status=0,scrollbars=1,resizable=1,width='+w+',height='+h);
}
function checkNull(txtBox,msg){
	var txtBox;
	if (txtBox.value == ''){
		alert(msg);
		txtBox.focus();
		return false;
	}else{
		return true;
	}
}
function addToCart(catalog_id, category_id, start, no, prd_id, qty, unit_price, phpsess_id){
	if (phpsess_id != ''){
		if (qty == '' || qty == 0 || qty < 0){
			alert('Please enter at least 1 of Qty Needed.');
			return false;
		}
		//window.location = 'add_to_cart_action.php?catalog_id='+catalog_id+'&category_id='+category_id+'&start='+start+'&no='+no+'&prd_id='+prd_id+'&qty='+qty+'&unit_price='+unit_price+'&PHPSESSID='+phpsess_id;
		document.forms[0].action = 'add_to_cart_action.php?catalog_id='+catalog_id+'&category_id='+category_id+'&start='+start+'&no='+no+'&prd_id='+prd_id+'&qty='+qty+'&unit_price='+unit_price+'&PHPSESSID='+phpsess_id;
		document.forms[0].method = 'post';
		document.forms[0].submit();
		return true;
	}else{
		alert('Please sign in to add items to the cart.');
		return false;
	}
}
function UpdateQtyToCart(catalog_id, category_id, start, no, prd_id, qty, unit_price, phpsess_id){
	if (phpsess_id != ''){
		if (qty == '' || qty < 0){
			alert('Please enter at least 1 of Qty Needed.');
			return false;
		}
		window.location = 'update_to_cart_action.php?catalog_id='+catalog_id+'&category_id='+category_id+'&start='+start+'&no='+no+'&prd_id='+prd_id+'&qty='+qty+'&unit_price='+unit_price+'&PHPSESSID='+phpsess_id;
		//document.forms[0].action = 'update_to_cart_action.php?catalog_id='+catalog_id+'&category_id='+category_id+'&start='+start+'&no='+no+'&prd_id='+prd_id+'&qty='+qty+'&unit_price='+unit_price+'&PHPSESSID='+phpsess_id;
		//document.forms[0].method = 'post';
		//document.forms[0].submit();
		return true;
	}else{
		alert('Please sign in to add items to the cart.');
		return false;
	}
}
function qty_changed(i){
	if (document.getElementById('chk'+i)){
		document.getElementById('chk'+i).checked = true;
	}
	findSelectedItem();
}
function add_qty(txtbox,i){	
	if (document.getElementById(txtbox).value == ''){
		document.getElementById(txtbox).value = 0;
	}
	document.getElementById(txtbox).value = parseInt(document.getElementById(txtbox).value) + 1;
	if (document.getElementById('chk'+i) && document.getElementById(txtbox).value > 0){
		document.getElementById('chk'+i).checked = true;
	}
	findSelectedItem();
}

function less_qty(txtbox,i){
	if (document.getElementById(txtbox).value == ''){
		document.getElementById(txtbox).value = 0;
	}
	var qty = parseInt(document.getElementById(txtbox).value) - 1;
	if (qty == 0){
		if (document.getElementById('chk'+i)){
			document.getElementById('chk'+i).checked = false;
		}
	}
	if (qty < 0){
		alert('The Qty can not be less than 0.');
		document.getElementById(txtbox).value = 0;
	}else{
		document.getElementById(txtbox).value = qty;
	}
	findSelectedItem();
}
function findSelectedItem(){
	if (document.getElementById('hidCount')){
		var noOfChk = document.getElementById('hidCount').value;		
		var selectedCheckbox = 0;
		var str_list;
		if (document.getElementById("txtList")){
			document.getElementById("txtList").value = '';
			for(var i = 0; i <= noOfChk; i++){
				if (document.getElementById('chk'+i).checked == true){
					str_list = document.getElementById('chk'+i).value;
					document.getElementById("txtList").value = document.getElementById("txtList").value + '||' + str_list;
					selectedCheckbox++;
				}
			}
		}
	}
}

function defaultQty(i){
	if (document.getElementById('chk'+i).checked == true){
		document.getElementById('txtQty'+i).value = 1;
	}else{
		document.getElementById('txtQty'+i).value = 0;
	}
}

function addItem(chkbox, txtbox, j){
	findSelectedItem();
	if (chkbox.checked == true){
		txtbox.value = 1;
	}else{
		txtbox.value = 0;
	}
}

function selectAll(){
	var el = document.getElementsByName("chk");
	var qty = document.getElementsByName("txtQty");
	for(var i = 0; i < el.length; i++){
		if (el[i].checked == true){
			el[i].checked = false;
			qty[i].value = 0;
			document.frmAddToCart.txtList.value = '';
		}else{
			el[i].checked = true;
			qty[i].value = 1;
			var selectedCheckbox = 0;
			var str_list;
			document.frmAddToCart.txtList.value = '';
			for(var j = 0; j < el.length; j++){
				if (el[j].checked == true){
					str_list = el[j].value;
					document.frmAddToCart.txtList.value = document.frmAddToCart.txtList.value + '||' + str_list;
					selectedCheckbox++;
				}
			}
		}
	}
}
function checkout(url){
	if (confirm("Do you to check out the selected item?")){
		window.location = url;
		return true;
	}else{
		return false;
	}
}
function isSignIn(phpsessid){
	var noOfChk;
	var isFound = false;
	if (phpsessid == ''){
		alert('Please sign in to add items to the cart.');
		return false;
	}else{
		noOfChk = document.getElementById('hidCount').value;
		for(var i = 0; i <= noOfChk; i++){
			if (document.getElementById('chk'+i).checked == true){
				isFound = true;
				break;
			}
		}
	}
	if (isFound == false){
		alert('Please select at least 1 item.');
		return false;
	}else{
		return true;
	}
}

function clearSelectedCheckbox(){
	noOfChk = document.getElementById('hidCount').value;
	for(var i = 0; i <= noOfChk; i++){
		document.getElementById('chk'+i).checked = false;
	}
}

function PrintReport(url){
	window.open(url,'mywindow','width=900,height=600,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}
function sortColumn(url, col_name, order_by){
	document.location = url+'&sort_col='+col_name+'&sort_by='+order_by;
}
function showLogin(){
	window.open('wholesales_login.php','ws_login','location=0,status=0,scrollbars=1,resizable=1,width=240,height=160');
	return false;
}
function hidePrice(){
	window.open('wholesales_logout.php','ws_login','location=0,status=0,scrollbars=1,resizable=1,width=240,height=160');
	return false;
}

var requestAddOneLineItem = createRequest();
function addOneLineItem(itemID, Qty, cartNo, notes){
	var url="add_to_cart_one_line.php?itemID="+itemID+"&Qty="+Qty+"&cartNo="+cartNo+"&notes="+escape(notes);
	url = url + "&dummy=" + new Date().getTime();
	requestAddOneLineItem.open("GET",url,true);
	requestAddOneLineItem.onreadystatechange=addOneLineItem_callback;
	requestAddOneLineItem.send(null);
}
function addOneLineItem_callback(){
	if (requestAddOneLineItem.readyState==4){
		if (requestAddOneLineItem.status==200){
			document.getElementById("divAddCartResult").innerHTML = requestAddOneLineItem.responseText;
			window.location.reload()
			//document.getElementById("ifCartShortcut").src = "cart_shortcut.php"
		}
	}
}

// Wish List
var requestAddWishList = createRequest();
function addWishList(itemID, Qty){
	var url="add_to_wish_list.php?itemID="+itemID+"&Qty="+Qty;
	url = url + "&dummy=" + new Date().getTime();
	requestAddWishList.open("GET",url,true);
	requestAddWishList.onreadystatechange=addWishList_callback;
	requestAddWishList.send(null);
}
function addWishList_callback(){
	if (requestAddWishList.readyState==4){
		if (requestAddWishList.status==200){
			document.getElementById("divAddCartResult").innerHTML = requestAddWishList.responseText;
			window.location.reload()
		}
	}
}

// Wish list...
var requestUpdateWishlistQty = createRequest();
function updateWishlistQty(itemID, Qty){
	var url="upd_wishlist_qty.php?type=wishlist-qty&itemID="+itemID+"&Qty="+Qty;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateWishlistQty.open("GET",url,true);
	requestUpdateWishlistQty.onreadystatechange=updateWishlistQty_callback;
	requestUpdateWishlistQty.send(null);
}
function updateWishlistQty_callback(){
	if (requestUpdateWishlistQty.readyState==4){
		if (requestUpdateWishlistQty.status==200){
			document.getElementById("divUpdateCartQtyResult").innerHTML = requestUpdateWishlistQty.responseText;
			window.location.reload()
		}
	}
}

// Quotation...
var requestUpdateQuotationQty = createRequest();
function updateQuotationQty(quoNo, itemID, Qty, rowid){
	var url="upd_quo_qty.php?type=quotation-qty&quoNo="+quoNo+"&itemID="+itemID+"&Qty="+Qty+"&quotationorderdetail_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateQuotationQty.open("GET",url,true);
	requestUpdateQuotationQty.onreadystatechange=updateQuotationQty_callback;
	requestUpdateQuotationQty.send(null);
}
function updateQuotationQty_callback(){
	if (requestUpdateQuotationQty.readyState==4){
		if (requestUpdateQuotationQty.status==200){
			document.getElementById("divUpdateQuoQtyResult").innerHTML = requestUpdateQuotationQty.responseText;
			window.location.reload()
		}
	}
}

var requestDisplayUpdatingQuotationItem = createRequest();
function displayUpdatingQuotationItem(quoNo, itemID, rowid){
	var url="divUpdateItem.php?quoNo="+quoNo+"&itemID="+itemID+"&quotationorderdetail_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestDisplayUpdatingQuotationItem.open("GET",url,true);
	requestDisplayUpdatingQuotationItem.onreadystatechange=displayUpdatingQuotationItem_callback;
	requestDisplayUpdatingQuotationItem.send(null);
}
function displayUpdatingQuotationItem_callback(){
	if (requestDisplayUpdatingQuotationItem.readyState==4){
		if (requestDisplayUpdatingQuotationItem.status==200){
			document.getElementById("divDisplayUpdatingQuotationItem").innerHTML = requestDisplayUpdatingQuotationItem.responseText;			
		}
	}
}

// Used on divUpdateItem.php
function calculateTotalPrice(){
	var totalPrice;
	totalPrice = (document.getElementById('txtAmount').value * document.getElementById('cmbItemPrice').value) - document.getElementById('txtDiscountAmount').value;
	document.getElementById('txtTotal').value = totalPrice;
}

var requestUpdateQuotationItem = createRequest();
function updateQuotationItem(quoNo, itemID, Qty, unitPrice, percent, discount, notes, rowid){
	var url="upd_quo_qty.php?type=quotation-item&quoNo="+quoNo+"&itemID="+itemID+"&Qty="+Qty+"&unitPrice="+unitPrice+"&percent="+percent+"&discount="+discount+"&notes="+escape(notes)+"&quotationorderdetail_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateQuotationItem.open("GET",url,true);
	requestUpdateQuotationItem.onreadystatechange=updateQuotationItem_callback;
	requestUpdateQuotationItem.send(null);
}
function updateQuotationItem_callback(){
	if (requestUpdateQuotationItem.readyState==4){
		if (requestUpdateQuotationItem.status==200){
			document.getElementById("divUpdateQuoItemResult").innerHTML = requestUpdateQuotationItem.responseText;
			window.location.reload()
		}
	}
}
// End of Quotation's functions

// Cart...
var requestUpdateCartQty = createRequest();
function updateCartQty(itemID, Qty, cart_no, rowid){
	var url="upd_cart_qty.php?type=cart-qty&itemID="+itemID+"&Qty="+Qty+"&cart_no="+cart_no+"&mycart_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateCartQty.open("GET",url,true);
	requestUpdateCartQty.onreadystatechange=updateCartQty_callback;
	requestUpdateCartQty.send(null);
}
function updateCartQty_callback(){
	if (requestUpdateCartQty.readyState==4){
		if (requestUpdateCartQty.status==200){
			document.getElementById("divUpdateCartQtyResult").innerHTML = requestUpdateCartQty.responseText;
			window.location.reload()
		}
	}
}

var requestDisplayUpdatingCartItem = createRequest();
function displayUpdatingCartItem(itemID, cartNo, rowid){
	var url="divUpdateCartItem.php?itemID="+itemID+"&cart_no="+cartNo+"&mycart_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestDisplayUpdatingCartItem.open("GET",url,true);
	requestDisplayUpdatingCartItem.onreadystatechange=displayUpdatingCartItem_callback;
	requestDisplayUpdatingCartItem.send(null);
}
function displayUpdatingCartItem_callback(){
	if (requestDisplayUpdatingCartItem.readyState==4){
		if (requestDisplayUpdatingCartItem.status==200){
			document.getElementById("divDisplayUpdatingCartItem").innerHTML = requestDisplayUpdatingCartItem.responseText;
			calculateCartTotalPrice();
		}
	}
}

// Wish list
var requestDisplayUpdatingWishlistItem = createRequest();
function displayUpdatingWishlistItem(itemID){
	var url="divUpdateWishlistItem.php?itemID="+itemID;
	url = url + "&dummy=" + new Date().getTime();
	requestDisplayUpdatingWishlistItem.open("GET",url,true);
	requestDisplayUpdatingWishlistItem.onreadystatechange=displayUpdatingWishlistItem_callback;
	requestDisplayUpdatingWishlistItem.send(null);
}
function displayUpdatingWishlistItem_callback(){
	if (requestDisplayUpdatingWishlistItem.readyState==4){
		if (requestDisplayUpdatingWishlistItem.status==200){
			document.getElementById("divDisplayUpdatingCartItem").innerHTML = requestDisplayUpdatingWishlistItem.responseText;
			calculateCartTotalPrice();
		}
	}
}

// Used on divUpdateCartItem.php
function calculateCartTotalPrice(){
	var totalPrice;
	totalPrice = (document.getElementById('txtAmount').value * document.getElementById('cmbItemPrice').value) - document.getElementById('txtDiscountAmount').value;
	document.getElementById('txtTotal').value = totalPrice;
}

var requestUpdateCartItem = createRequest();
function updateCartItem(itemID, Qty, unitPrice, percent, discount, cartNo, notes, rowid){
	var url="upd_cart_qty.php?type=cart-item&itemID="+itemID+"&Qty="+Qty+"&unitPrice="+unitPrice+"&percent="+percent+"&discount="+discount+"&cart_no="+cartNo+"&notes="+escape(notes)+"&mycart_id="+rowid;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateCartItem.open("GET",url,true);
	requestUpdateCartItem.onreadystatechange=updateCartItem_callback;
	requestUpdateCartItem.send(null);
}
function updateCartItem_callback(){
	if (requestUpdateCartItem.readyState==4){
		if (requestUpdateCartItem.status==200){
			document.getElementById("divUpdateCartItemResult").innerHTML = requestUpdateCartItem.responseText;
			window.location.reload()
		}
	}
}
// End of cart...

// Wish list
var requestUpdateWishlistItem = createRequest();
function updateWishlistItem(itemID, Qty, unitPrice, percent, discount){
	var url="upd_wishlist_qty.php?type=wishlist-item&itemID="+itemID+"&Qty="+Qty+"&unitPrice="+unitPrice+"&percent="+percent+"&discount="+discount;
	url = url + "&dummy=" + new Date().getTime();
	requestUpdateWishlistItem.open("GET",url,true);
	requestUpdateWishlistItem.onreadystatechange=updateWishlistItem_callback;
	requestUpdateWishlistItem.send(null);
}
function updateWishlistItem_callback(){
	if (requestUpdateWishlistItem.readyState==4){
		if (requestUpdateWishlistItem.status==200){
			document.getElementById("divUpdateCartItemResult").innerHTML = requestUpdateWishlistItem.responseText;
			window.location.reload()
		}
	}
}

// This script is used for productgroup_popupmenu.php

function onMouseOverCell(ParentID, GroupID) {
	clearBackgroundColor(ParentID);
	clearPrductGroupPopupMenu(GroupID); 
	loadPrductGroupPopupMenu(GroupID);
	document.getElementById('tr'+GroupID).style.backgroundColor = '#CCCCCC';
	if (document.getElementById('tr'+ParentID)) {
		document.getElementById('tr'+ParentID).style.backgroundColor = '#CCCCCC';
	}
}
function onMouseOutCell(GroupID) {
	document.getElementById('tr'+GroupID).style.backgroundColor = '#FFFFFF';
}

//--------------------------------------TOP MENU----------------------------------------------------------
function onMouseOverCellTop(ParentID, GroupID) {
	clearBackgroundColorTop(ParentID);
	clearPrductGroupTopMenu(GroupID); 
	loadPrductGroupTopMenu(GroupID);
	document.getElementById('trTop'+GroupID).style.backgroundColor = '#CCCCCC';
	if (document.getElementById('trTop'+ParentID)) {
		document.getElementById('trTop'+ParentID).style.backgroundColor = '#CCCCCC';
	}
}
function onMouseOutCellTop(GroupID) {
	document.getElementById('trTop'+GroupID).style.backgroundColor = '#FFFFFF';
}
var requestProductGroupTopMenu;
var groupIDTop;
function loadPrductGroupTopMenu(_groupID){
	requestProductGroupTopMenu = createRequest();
	var url="productgroup_topmenu.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	groupID = _groupID;
	requestProductGroupTopMenu.open("GET",url,true);
	requestProductGroupTopMenu.onreadystatechange=loadPrductGroupTopMenu_callback;
	requestProductGroupTopMenu.send(null);
}
function loadPrductGroupTopMenu_callback(){
	if (requestProductGroupTopMenu.readyState==4){
		if (requestProductGroupTopMenu.status==200){
			if (document.getElementById("divProductGroupTopMenu"+groupID)){
				document.getElementById("divProductGroupTopMenu"+groupID).innerHTML = requestProductGroupTopMenu.responseText;
			}
		}
	}
}

var requestClearProductGroupTopMenu;
function clearPrductGroupTopMenu(_groupID){
	requestClearProductGroupTopMenu = createRequest();
	var url="get_productgroup_popupmenu.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	groupID = _groupID;
	requestClearProductGroupTopMenu.open("GET", url, true);
	requestClearProductGroupTopMenu.onreadystatechange=clearPrductGroupTopMenu_callback;
	requestClearProductGroupTopMenu.send(null);
}
function clearPrductGroupTopMenu_callback(){
	if (requestClearProductGroupTopMenu.readyState==4){
		if (requestClearProductGroupTopMenu.status==200){
			var str = requestClearProductGroupTopMenu.responseText;
			var arrList = str.split('-');
			for(var i=0; i<arrList.length; i++){
				if (arrList[i] != groupID){
					document.getElementById("divProductGroupTopMenu"+arrList[i]).innerHTML = "";
				}
			}		
		}
	}
}
function clearBackgroundColorTop(_groupID){
	requestClearBackgroundColor = createRequest();
	var url="clear_background_color.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	//alert(url);
	requestClearBackgroundColor.open("GET", url, false);
	requestClearBackgroundColor.onreadystatechange=clearBackgroundColorTop_callback;
	requestClearBackgroundColor.send(null);
}
function clearBackgroundColorTop_callback(){
	if (requestClearBackgroundColor.readyState==4){
		if (requestClearBackgroundColor.status==200){
			var str = requestClearBackgroundColor.responseText;
			var arrList = str.split('-');
			for(var i=0; i<arrList.length; i++){
				document.getElementById("trTop"+arrList[i]).style.backgroundColor = "#FFFFFF";
			}		
		}
	}
}
function clearAllPrductGroupTopMenu(_groupID){
	document.getElementById("divProductGroupTopMenu"+_groupID).innerHTML = "";
}
//--------------------------------------END TOP MENU----------------------------------------------------------
var requestProductGroupPopupMenu;
var groupID;
function loadPrductGroupPopupMenu(_groupID){
	requestProductGroupPopupMenu = createRequest();
	var url="productgroup_popupmenu.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	groupID = _groupID;
	requestProductGroupPopupMenu.open("GET",url,true);
	requestProductGroupPopupMenu.onreadystatechange=loadPrductGroupPopupMenu_callback;
	requestProductGroupPopupMenu.send(null);
}
function loadPrductGroupPopupMenu_callback(){
	if (requestProductGroupPopupMenu.readyState==4){
		if (requestProductGroupPopupMenu.status==200){
			if (document.getElementById("divProductGroupPopupMenu"+groupID)){
				document.getElementById("divProductGroupPopupMenu"+groupID).innerHTML = requestProductGroupPopupMenu.responseText;
			}
		}
	}
}

var requestClearProductGroupPopupMenu;
function clearPrductGroupPopupMenu(_groupID){
	requestClearProductGroupPopupMenu = createRequest();
	var url="get_productgroup_popupmenu.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	groupID = _groupID;
	requestClearProductGroupPopupMenu.open("GET", url, true);
	requestClearProductGroupPopupMenu.onreadystatechange=clearPrductGroupPopupMenu_callback;
	requestClearProductGroupPopupMenu.send(null);
}
function clearPrductGroupPopupMenu_callback(){
	if (requestClearProductGroupPopupMenu.readyState==4){
		if (requestClearProductGroupPopupMenu.status==200){
			var str = requestClearProductGroupPopupMenu.responseText;
			var arrList = str.split('-');
			for(var i=0; i<arrList.length; i++){
				if (arrList[i] != groupID){
					document.getElementById("divProductGroupPopupMenu"+arrList[i]).innerHTML = "";
				}
			}		
		}
	}
}

function clearBackgroundColor(_groupID){
	requestClearBackgroundColor = createRequest();
	var url="clear_background_color.php?ParentID="+_groupID;
	url = url + "&dummy=" + new Date().getTime();
	//alert(url);
	requestClearBackgroundColor.open("GET", url, false);
	requestClearBackgroundColor.onreadystatechange=clearBackgroundColor_callback;
	requestClearBackgroundColor.send(null);
}
function clearBackgroundColor_callback(){
	if (requestClearBackgroundColor.readyState==4){
		if (requestClearBackgroundColor.status==200){
			var str = requestClearBackgroundColor.responseText;
			var arrList = str.split('-');
			for(var i=0; i<arrList.length; i++){
				document.getElementById("tr"+arrList[i]).style.backgroundColor = "#FFFFFF";
			}		
		}
	}
}

function clearAllPrductGroupPopupMenu(_groupID){
	document.getElementById("divProductGroupPopupMenu"+_groupID).innerHTML = "";
}

function searchSelectCategory(categoryID, categoryDes, detailGroupID){	
	// Group Id
	document.getElementById('hidSelectedCategory').value = categoryID;
	document.getElementById('divSelectedCategory').innerHTML = categoryDes;
	// Detail Group Id
	document.getElementById('hidDetailGroupID').value = detailGroupID;
	document.getElementById('frmSearch').submit();
}
//-->
// ------------------- search_shortcut.php --------------------
var requestIBNC = createRequest();
function loadItemBrandNameChild(parentId){	
	var url = "load_item_brand_name_child.php?parent_id="+parentId;
	url = url + "&dummy=" + new Date().getTime();
	requestIBNC.open("GET",url,true);
	requestIBNC.onreadystatechange = loadItemBrandNameChild_Callback;
	requestIBNC.send(null);
}
function loadItemBrandNameChild_Callback(){
	if (requestIBNC.readyState==4){
		if (requestIBNC.status==200){
			var item_brand_name_child = requestIBNC.responseText;
			if (requestIBNC.responseText != ""){
				nrec = item_brand_name_child.split("##");
				num_rec=nrec.length;
				document.getElementById('cmbItemBrandNameChild').length=num_rec;
				document.getElementById('cmbItemBrandNameChild').options[0] = new Option("SELECT ONE...");
				document.getElementById('cmbItemBrandNameChild').options[0].value = 0;
				for (i=0;i<num_rec;i++){
					ctype=nrec[i].split("#");
					document.getElementById('cmbItemBrandNameChild').options[i+1] = new Option(ctype[1]);
					document.getElementById('cmbItemBrandNameChild').options[i+1].value=ctype[0];
				}
			}else{
				document.getElementById('cmbItemBrandNameChild').options[0] = new Option("NO DETAIL...");
				document.getElementById('cmbItemBrandNameChild').options[0].value = 0;
			}
		}
	}	
}
// -----------------------------------------------------
function Set_Cookie(name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

