var GfsReq;
var GfsAjax;
var mouseY;
function CreateXMLHttp(CreateFlag) {
    if(CreateFlag){
        GfsReq = null;
        if (window.XMLHttpRequest)
        {
            GfsReq = new XMLHttpRequest();
            if (GfsReq.overrideMimeType) {
                GfsReq.overrideMimeType("text/xml");
            }
        }
        else if (window.ActiveXObject)
        {
            GfsReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
}
function CreateGFSAjaxXMLHttp(CreateFlag) {
    if(CreateFlag){
        GfsAjax = null;
        if (window.XMLHttpRequest)
        {
            GfsAjax = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            GfsAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
}
var StartFlag = false;
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay, GFSContextPath, itemNumber) {
    if(typeof fRef == 'function'){
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return _st(f, mDelay);
    }
    return _st(fRef, mDelay);
}
window.setTimeout = function(fRef, mDelay, GFSContextPath, itemNumber, skuNumber, skuMinimum) {
    if(typeof fRef == 'function'){
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return _st(f, mDelay);
    }
    return _st(fRef, mDelay);
}

// start flag
function addItemsToCart(GFSContextPath, itemNumber) {
    if(!IsAcceptCookie()) {
        ShowGray(GFSContextPath);
        GetMessage(GFSContextPath, true, "alert/no_cookies.aspx");
        return false;
    }
    ShowGray(GFSContextPath);
    var locdiv = window.parent.document.getElementById("GFSShutter");
    var timeId = window.setTimeout(addItemsToCart, 1000, GFSContextPath, itemNumber);
    if(locdiv != null) {
        window.clearTimeout(timeId);
        M_AddItemsToCart(GFSContextPath, itemNumber);
    }
}

function addToCart(GFSContextPath, itemNumber, skuNumber, skuMinimum) {
    if(!IsAcceptCookie()) {
        //alert("Please Enable Cookies in your Web Browser to Continue.");
        ShowGray(GFSContextPath);
        GetMessage(GFSContextPath, true, "alert/no_cookies.aspx");
        return false;
    }
    ShowGray(GFSContextPath);
    var locdiv = window.parent.document.getElementById("GFSShutter");
    var timeId = window.setTimeout(addToCart, 1000, GFSContextPath, itemNumber, skuNumber, skuMinimum);
    if(locdiv != null) {
        window.clearTimeout(timeId);
        M_AddToCart(GFSContextPath, itemNumber, skuNumber, skuMinimum);
    }
}

//function AdvanceSearch(host) {
//    var querys = "acid";
//    com.gfs.webservice.CustomerWebService.getResultAdvanceSearch(host, querys, function(result) 
//    {
//        document.getElementById("ResultAdvanceSearch").innerHTML = "$" + result;
//    });
//}

function SetMouseY(){
    if(typeof(event.clientY) == "undefined"){
        mouseY = 300;
    } else {
        mouseY = event.clientY;
    }
}
// which browse?
function getOs()
{
    if(navigator.userAgent.indexOf("MSIE") > 0) return 1;
    if(isFirefox=navigator.userAgent.indexOf("Firefox") > 0) return 2;
    if(isSafari=navigator.userAgent.indexOf("Safari") > 0) return 3;
    if(isCamino=navigator.userAgent.indexOf("Camino")> 0) return 4;
    if(isMozilla=navigator.userAgent.indexOf("Gecko/") > 0) return 5;
    return 0;
}
// is accept cookie
function IsAcceptCookie() {
    var BrowseVersion = getOs();
    if(BrowseVersion == 1) {
		var TempCookieValue = document.cookie;
		if(document.cookie == "") {
			document.cookie = "gfs_cookie_test";
			if(document.cookie == "gfs_cookie_test") {
				document.cookie = "";
				return true;
			} else {
				return false;
			}
        } else {
			document.cookie = "gfs_cookie_test";
			if(document.cookie.indexOf("gfs_cookie_test") > -1) {
				document.cookie = "";
				return true;
			} else {
				return false;
			}
		}
    } else {
        var cookieEnabled = navigator.cookieEnabled;
        if(!cookieEnabled) {
            return false;
        }
    }
    
    return true;
}
function $(link)
{
    location.href = link;
}
// The function is controlling layout of All Categories
function LayoutShowAndHidden(PageName) {
    if(document.getElementById("layout").style.display == "none") {
	    document.getElementById("layout").style.display = "block";
	    document.getElementById("WhichSearch").style.display = "none";
	    ShowAndHiddenSelect("none");
    } else {
	    document.getElementById("layout").style.display = "none";
	    document.getElementById("WhichSearch").style.display = "block";
        ShowAndHiddenSelect("block");
    }
}
// display shppping item
function ShippingItemShow(Url, DivName) {
    CreateXMLHttp(true);
    GfsReq.onreadystatechange = function() {
        if (GfsReq.readyState == 4) {
          if (GfsReq.status == 200) {
            var returnString = GfsReq.responseText;
            document.getElementById(DivName).innerHTML = returnString;
          } else {
            alert("Gfs:" + GfsReq.statusText);
          }
        }
    };
    GfsReq.open("GET", Url + "?id=" + (new Date()).getTime(), true);
    GfsReq.send(null);
    CatalogShow(DivName);
}

function CatalogShow(DivName) {
	document.getElementById(DivName).style.display = "block";
}

function CatalogHidden(DivName) {
	document.getElementById(DivName).style.display = "none";
}

// Gfs Chemicals's Search function
function GfsSearch(tabs, name, SearchCondition, contextPath, evt) {
    var version = getOs();
    if(version == 1 || version == 3) {
        if(window.event.keyCode == 13 || window.event.keyCode == 0)
        {
            show_window_loading();
            GoSearchResultPage(name, SearchCondition, contextPath);
        }
    } 
    else if(version == 2)
    {
        if(evt.which == 13 || evt.which == 1)
        {
            show_window_loading();
            GoSearchResultPage(name, SearchCondition, contextPath);
        }
    }
}
// Go to page of Gfs Chemicals's Search result
function GoSearchResultPage(name, SearchCondition, contextPath) 
{
    if(null != document.getElementById(SearchCondition) && document.getElementById(SearchCondition).value.replace(/(^\s+)|\s+$/g,"") != "")
    {
        var WhichSearch = document.getElementById(name).value;
        if(WhichSearch == "EntireSite") {
            window.location.href = contextPath + "/search_prm_p.aspx?whichsearch=" + WhichSearch + "&searchcontent=" + encodeURIComponent(document.getElementById(SearchCondition).value);
        } else if(WhichSearch == "Catalog" || WhichSearch == "ProductNum" || WhichSearch == "CasNum" || WhichSearch == "ProductName") {
            window.location.href = contextPath + "/search_p.aspx?whichsearch=" + WhichSearch + "&searchcontent=" + encodeURIComponent(document.getElementById(SearchCondition).value);
        } else if(WhichSearch == "MSDS") {
            window.location.href = contextPath + "/search_m.aspx?whichsearch=" + WhichSearch + "&searchcontent=" + encodeURIComponent(document.getElementById(SearchCondition).value);
        } else {
            window.location.href = contextPath + "/search_prm_p.aspx?whichsearch=" + WhichSearch + "&searchcontent=" + encodeURIComponent(document.getElementById(SearchCondition).value);
        }
    }
    else
    {
        if(null != document.getElementById(SearchCondition))
            document.getElementById(SearchCondition).focus();
        hidden_window_loading();
        alert("Please enter search conditions.");
    }
}
function PeriodicGoSearchResultPage(SearchCondition, form)
{
    window.location.href = "../../../search_periodic.aspx?periodic=" + SearchCondition;
}
function PeriodicMouseOver(form) {
    form.style.color = "#ff33ff";
    form.style.background = "#ffffff";
}
function PeriodicMouseOut(form, backcolor) {
    form.style.color = "#003366";
    form.style.background = backcolor;
}
// Gfs' control tabs on product's detail page
var whichDisplay = "gfs-tabs-column1";
function GfsDisplayHomeTabs(form, title1,url1,title2,url2,title3,url3) {
    if(null == form || form.id == "gfs-tabs-column1") {
		if(whichDisplay != "gfs-tabs-column1") {
			document.getElementById("gfs-tabs-row").style.background = "url(../images/index_mid_bj0.gif)";
			document.getElementById('gfs-tab-content-column1').style.display = "block";
			document.getElementById('gfs-tab-content-column2').style.display = "none";
			document.getElementById('gfs-tab-content-column3').style.display = "none";
			whichDisplay = "gfs-tabs-column1";
		}
    } else if(form.id == "gfs-tabs-column2") {
		if(whichDisplay != "gfs-tabs-column2") {
			document.getElementById("gfs-tabs-row").style.background = "url(../images/index_mid_bj01.gif)";
			document.getElementById("gfs-tab-content-column1").style.display = "none";
			document.getElementById("gfs-tab-content-column2").style.display = "block";
			document.getElementById('gfs-tab-content-column3').style.display = "none";
			whichDisplay = "gfs-tabs-column2";
		}
    } else if(form.id == "gfs-tabs-column3") {
		if(whichDisplay != "gfs-tabs-column3") {
			document.getElementById("gfs-tabs-row").style.background = "url(../images/index_mid_bj02.gif)";
			document.getElementById('gfs-tab-content-column1').style.display = "none";
			document.getElementById('gfs-tab-content-column2').style.display = "none";
			document.getElementById('gfs-tab-content-column3').style.display = "block";
			whichDisplay = "gfs-tabs-column3";
		}
	}
}
// add products to shopping cart
function M_AddToCart(GFSContextPath, itemNumber, skuNumber, skuMinimum) {
    var QuantityObj = document.getElementById("Quantity" + skuNumber);
    if(null == QuantityObj || QuantityObj.value == "") {
        hideShutter();
        alert("Please enter quantity.");
    } else if(QuantityObj.value.match(/\D/)) {
        hideShutter();
        alert("Invalid quantity.");
    } else if(QuantityObj.value == 0) {
        hideShutter();
        alert("Quantity can not be zero.");
    } else if(skuMinimum != "" && parseInt(skuMinimum) > parseInt(QuantityObj.value)){
        hideShutter();
        alert("Minimum purchase quantity is " + skuMinimum + ".");
    } else {
        CreateXMLHttp(true);
        var url = GFSContextPath + "/addproductcart.aspx?ItemNumber=" + itemNumber + "&SkuNumber=" + skuNumber 
            + "&SkuMinimum=" + skuMinimum + "&Quantity=" + document.getElementById("Quantity" + skuNumber).value;
        GfsReq.open("GET", url + "&id=" + (new Date()).getTime(), true);
        GfsReq.onreadystatechange = function() {
            if (GfsReq.readyState == 4) {
                if (GfsReq.status == 200) {
                    var returnString = GfsReq.responseText;
                    GetMessage(GFSContextPath, returnString, "alert/shopping_alert.aspx?status=" + returnString);
                } else {
                    alert("Error:" + GfsReq.statusText);
                    hideShutter();
                }
            }
        };
        GfsReq.send(null);
    }
}
// add products to shopping cart
function M_AddItemsToCart(GFSContextPath, ItemNumber) {
    var arr = document.getElementsByTagName("input");
    var SkuNumber = "";
    var SkuMinimum = "";
    var IsEmpty = false;
    var IsSuccess = true;
    var Quantities = "";
    var Message = "";
    for(i = 0; i < arr.length; i++) {
        var QuantityObj = document.getElementById("Quantity" + arr[i].value);
        if((arr[i].name == "Sku" + ItemNumber) && null != QuantityObj && QuantityObj.value != ""){
            SkuNumber += arr[i].value + ";";
            IsEmpty = true;
            if(QuantityObj.value.match(/\D/)) {
                IsSuccess = false;
                hideShutter();
                alert("Invalid quantity.");
                break;
            } else if(QuantityObj.value == 0) {
                IsSuccess = false;
                hideShutter();
                alert("Quantity can not be zero.");
                break;
            }
            var _SkuQuantity = document.getElementById("Quantity" + arr[i].value).value;
            var _SkuMinimum = document.getElementById("SkuMinimum" + arr[i].value).value;
            
            Quantities += _SkuQuantity + ";";
            SkuMinimum += _SkuMinimum + ";";
            if(parseInt(_SkuMinimum) > parseInt(_SkuQuantity)){
                IsSuccess = false;
                hideShutter();
                alert("Minimum purchase quantity of Sku# " + arr[i].value + " is " + _SkuMinimum + ".");
                break;
            }
        }
    }
    if(!IsEmpty){
        hideShutter();
        alert("Please enter quantity.");
    } else {
        if(IsSuccess){
            CreateXMLHttp(true);
            GfsReq.onreadystatechange = function() {
                if (GfsReq.readyState == 4) {
                    if (GfsReq.status == 200) {
                        var returnString = GfsReq.responseText;
                        //hidden_window_loading();
                        GetMessage(GFSContextPath, returnString, "alert/shopping_alert.aspx?status=" + returnString);
                        //hidden_window_loading();
                    } else {
                        alert("Error:" + GfsReq.statusText);
                        hideShutter();
                    }
                }
            };
            SkuNumber = SkuNumber.substring(0, SkuNumber.length - 1);
            Quantities = Quantities.substring(0, Quantities.length - 1);
            SkuMinimum = SkuMinimum.substring(0, SkuMinimum.length - 1);
            var url = GFSContextPath + "/addproductcart.aspx?ItemNumber=" + ItemNumber + "&SkuNumber=" + SkuNumber + "&SkuMinimum=" + SkuMinimum + "&Quantity=" + Quantities;
            GfsReq.open("GET", url + "&id=" + (new Date()).getTime(), true);
            GfsReq.send(null);
        } 
    }
}
// add products to favorite
function addToFavoriteProduct(GFSContextPath, itemNumber, skuNumber) {
    show_window_loading();
    CreateXMLHttp(true);
    GfsReq.onreadystatechange = function() {
        hidden_window_loading();
        if (GfsReq.readyState == 4) {
            if (GfsReq.status == 200) {
                var returnString = GfsReq.responseText;
                if(returnString.indexOf("success") > -1)
                    alert("Added this product into Favorite successfully.");
                else if(returnString.indexOf("fail") > -1)
                    alert("Failed to add this product into Favorite.");
                else if(returnString.indexOf("not") > -1) {
                    var Index = returnString.indexOf("|");
                    var Temp = returnString.substring(Index + 1);
                    var Url = GFSContextPath + "/login.aspx?return_url=" + GFSContextPath + "/mygfs_favoriteproduct.aspx?id=" + Temp;
                    window.open(Url, '_parent');
                }
                else if(returnString.indexOf("exist") > -1)
                    alert("You have collected this item.");
                    
            } else {
                alert("Error:" + GfsReq.statusText);
            }
        }
    };
    var url = GFSContextPath + "/addfavoriteproduct.aspx?ItemNumber=" + itemNumber + "&SkuNumber=" + skuNumber;
    GfsReq.open("GET", url + "&id=" + (new Date()).getTime(), true);
    GfsReq.send(null);  
}

// addToBulk
function addToBulk(GFSContextPath, itemNumber, skuNumber) {
    var QuantityObj = document.getElementById("Quantity" + skuNumber);
    var IsSuccess = true;
    if(null != QuantityObj && QuantityObj.value != "") {
        if(QuantityObj.value.match(/\D/)){
            alert("Invalid quantity.");
            IsSuccess = false;
        }
    }
    if(IsSuccess){
        var Url = GFSContextPath + "/bulk.aspx?ItemNumber=" + itemNumber + "&SkuNumber=" + skuNumber + "&Quantity=" + QuantityObj.value;
        window.open(Url + "&id=" + (new Date()).getTime(), "");
    }
}

//addToQuotes
function addToQuotes(GFSContextPath, itemNumber) {
    document.forms[0].elements["ItemNumber"].value = itemNumber;
    document.forms[0].action = GFSContextPath + "/" + "quotes.aspx";
    document.forms[0].target = "_blank";
    document.forms[0].submit();  
    document.forms[0].target = "_self";
    document.forms[0].action = ""; 
}
//
function TrackOrder(GFSContextPath, TrackingNumber, TrackingType) {
    ShowGray(GFSContextPath);
    GetMessage(GFSContextPath, true, "alert/trackorder_alert.aspx?trackingno=" + TrackingNumber + "&trackingtype=" + TrackingType);
}
// get customer' price of every product
function getYourPrice(cL, sku) {
    com.gfs.webservice.CustomerWebService.getYourPrice(cL, sku, function(result) 
    {
        document.getElementById("YourPrice" + sku).innerHTML = "$" + result;
    });
}

// get total price
function getYourTotalPrice(cL) {
    com.gfs.webservice.CustomerWebService.getYourTotalPrice(cL, function(result)
    {
        if(result != 0){
            document.getElementById("TotalYourPrice").innerHTML = "Subtotal : $" + result
        } else {
            document.getElementById("TotalYourPrice").style.display = "none";
        }
    });
}

function getYourTotalPriceInStock(cL, skus) {
    com.gfs.webservice.CustomerWebService.getYourTotalPriceInStock(cL, skus, function(result)
    {
        if(result != 0){
            document.getElementById("TotalYourPrice").innerHTML = "Subtotal : $" + result
        } else {
            document.getElementById("TotalYourPrice").style.display = "none";
        }
    });
}

//FCKeditor Validate
 var oEditer;     
 
function CustomValidate(source,args)
{
     var value = oEditer.GetXHTML(true);
     if(value == '')
     {
        args.IsValid = false;
     }
     else
     {
        args.IsValid = true;
     }
}

function FCKeditor_OnComplete( editorInstance )
{  
    oEditer = editorInstance;
}

var is_first_leave = false;

function UpdateShoppingCartNumber(txt_product_count, cL, skuNumber, skuMinimum) 
{
    var s_product_count = txt_product_count.value.trim();
    var txt_o_product_count = txt_product_count.nextSibling;//document.getElementById("QuantityHidden" + skuNumber);
    var o_product_count = txt_o_product_count.value.trim();
    var is_success = true;
    var txt_quantity = document.getElementById("Quantity" + skuNumber);
    if(null != txt_quantity && txt_quantity.value != "") {
        if(txt_quantity.value == 0){
            txt_product_count.value = o_product_count;
            is_success = false;
        } else if(txt_quantity.value.match(/\D/)){
            txt_product_count.value = o_product_count;
            is_success = false;
        } else if(parseInt(s_product_count) < parseInt(skuMinimum)) {
            alert("Minimum purchase quantity of Sku# " + skuNumber + " is " + skuMinimum + ".");
            txt_product_count.value = o_product_count;
            is_success = false;
        }
    } else {
        txt_product_count.value = o_product_count;
        is_success = false;
    }
    var row_index = txt_product_count.parentNode.parentNode.rowIndex;
    if(is_success){
        if(s_product_count != o_product_count) {
            // load window
            show_window_loading();
            // update product number
            var result = com.gfs.webservice.CustomerWebService.UpdateSkuNumber(cL, skuNumber, s_product_count, function(result)
            {
                if(result) {
                    // change total price
                    com.gfs.webservice.CustomerWebService.getYourTotalPrice(cL, function(result)
                    {
                        document.getElementById("TotalYourPrice").innerHTML = "Subtotal : $" + result;                     
                        show_update_number_div(txt_product_count, null, null, document_click, 86, 73);
                        document.getElementById("update_result_div").innerHTML = "<div class='content_3'><p class='t_c'>Modify Successful.<br>Total Price:<strong><em style=\"color:#ff7100;font-style:normal;\">$" + result + "</em></strong><br><a onmouseover='link_hover(this)' onmouseout='link_out(this)' onclick='javascript:hidden_update_number_div();'>Close</a></p></div><div class='c_b_3'></div>";
                        document.getElementById("update_result_div").className = "box_window_3";
                        
                        txt_o_product_count.value = s_product_count;
                        is_first_leave = true;
                    });
                } else {
                    txt_product_count.value = txt_o_product_count.value;
                }
            });

            
            //hidden load window
            hidden_window_loading();
        }
    }
}

// display window loading
function show_window_loading() {
    var locdiv = document.getElementById("window_loading");
    locdiv.style.top = getScrollTop() + 3 + "px";
	locdiv.style.left = (window.screen.width - 240) + "px";
	locdiv.style.display = "block";
}
// hidden window loading
function hidden_window_loading() {
    var locdiv = document.getElementById("window_loading");
    locdiv.style.display = "none";
}
// display the div of update number result
function show_update_number_div(sender, cfm_func, cancel_func, document_func, offsetX, offsetY) {
    var locdiv = document.getElementById("update_result_div");
    locdiv.style.top = (getposOffset(sender,"top")-offsetX)+"px";
	locdiv.style.left = (getposOffset(sender,"left")-offsetY)+"px";
	locdiv.style.display = "block";
	
	document.onclick = document_func;
}
// 
var document_click = function(e)
{

    var locdiv = document.getElementById("update_result_div");
    
    if(locdiv.style.display == "block")
    {
        var sender=null;

	    if(typeof(event)!='undefined')
	    {
		    sender=event.srcElement;
	    }
	    else if(e)
	    {
		    sender=e.target;
	    }
	    
        if(contains(locdiv, sender)) {
	        if(!is_first_leave) {
		        locdiv.style.display = "none";
	        }
	    }
	    is_first_leave = false;
    }
}

function contains(locdiv, sender)
{
	if(locdiv == sender) {
	    return false;
	}
	if(null == sender)
	    return true;
	
	return contains(locdiv, sender.parentNode);
}
	    
// hidden the div of update number result
function hidden_update_number_div() {
    var locdiv = document.getElementById("update_result_div");
    locdiv.style.display = "none";
}

// the style is focus.
function link_hover(link_obj) {
    link_obj.className = 'remove_hover';
}
// the style is out
function link_out(link_obj) {
    link_obj.className = '';
}
//
function getposOffset(what, offsettype) { 
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; 
    var parentEl=what.offsetParent; 
    while (parentEl!=null) { 
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; 
         parentEl=parentEl.offsetParent; 
    } 
    return totaloffset; 
} 
//
function getScrollTop() {
    if (typeof(window.pageYOffset) != 'undefined') 
    { 
       return window.pageYOffset; 
    } 
    else if (typeof(window.parent.document.compatMode)!= 'undefined' && window.parent.document.compatMode != 'BackCompat') 
    { 
       return window.parent.document.documentElement.scrollTop; 
    } 
    else if (typeof(window.parent.document.body)!= 'undefined') 
    { 
       return window.parent.document.body.scrollTop; 
    }
}
//
function amz_js_PopWin(url,name,options){
    var ContextWindow = window.open(url,name,options);
    ContextWindow.focus();
    return false;
}
// the focus event of Tell Friend
function TellFriend_YourFriend_OnFocus(txt){
    if(txt.value == "Type in e-mail addresses separating them with a ';'.")
        txt.value = '';
}
// the blur event of Tell Friend
function TellFriend_YourFriend_OnBlur(txt) {
    if(txt.value == '')
        txt.value = "Type in e-mail addresses separating them with a ';'.";
}

// the focus event of Tell Friend
function TellFriend_My_OnFocus(txt){
    if(txt.value == "Your email address.")
        txt.value = '';
}
// the blur event of Tell Friend
function TellFriend_My_OnBlur(txt) {
    if(txt.value == '')
        txt.value = "Your email address.";
}
function GetMessage(GFSContextPath, ReturnString, FileName) {
    CreateGFSAjaxXMLHttp(true);
    GfsAjax.open("GET", GFSContextPath + "/" + FileName, true);
    GfsAjax.onreadystatechange = function () {
        if (GfsAjax.readyState == 4) {
            ShowMessage(GfsAjax.responseText);
        }
    }
    GfsAjax.send(null);
}
// show add to shopping cart result
function ShowMessage(ResultMessage){
    var Shutter = window.parent.document.getElementById("GFSShutter");
    if(Shutter != null) {
        info.innerHTML = ResultMessage;
    } else {
        var shutter = window.parent.document.createElement("div");
        shutter.style.height = window.parent.document.body.scrollHeight;
        shutter.setAttribute('id','GFSShutter');
        shutter.style.zIndex = '1000';
        window.parent.document.body.appendChild(shutter);
        info = window.parent.document.createElement('div');
        info.setAttribute('id','GFSInfo');
        var Result = "<table width=\"360\" height=\"135\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"150\">&nbsp;</td></tr></table>";
        var Height = 0;
        if(getOs() == 1) {
            Result = ResultMessage;
            Height = 200;
            info.innerHTML = Result;
            info.style.top = getScrollTop() + Height;
            info.style.zIndex = '1001';
        } else {
            Result = ResultMessage;
            info.innerHTML = Result;
            info.style.top = 150;
            info.style.zIndex = '1001';
        }
        window.parent.document.body.appendChild(info);
    }
    ShowAndHiddenSelect("none");
}
function ShowGray(GFSContextPath) {
    var shutter = window.parent.document.createElement("div");
    shutter.style.height = window.parent.document.body.scrollHeight;
    shutter.setAttribute('id','GFSShutter');
    shutter.style.zIndex = '1000';
    window.parent.document.body.appendChild(shutter);

    info = window.parent.document.createElement('div');
    info.setAttribute('id','GFSInfo');
    var Result = "<table width=\"360\" height=\"135\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=\"150\">&nbsp;</td></tr></table>";
    var Height = 0;
    if(getOs() == 1) {
        Height = 200;
        info.innerHTML = "<img src='" + GFSContextPath + "/images/progress_bar.gif'/>";
        info.style.top = getScrollTop() + Height;
        info.style.zIndex = '1001';
    } else {
        info.innerHTML = "<img src='" + GFSContextPath + "/images/progress_bar.gif'/>";
        info.style.top = 150;
        info.style.zIndex = '1001';
    }
    window.parent.document.body.appendChild(info);
    
    //ShowAndHiddenSelect("none");
}
// remove the shutter and the info box
function hideShutter() {
    shutter = parent.document.getElementById('GFSShutter');
    shutter.parentNode.removeChild(shutter);
    info = parent.document.getElementById('GFSInfo');
    info.parentNode.removeChild(info);
    ShowAndHiddenSelect("block");
}
// show and hidden select
function ShowAndHiddenSelect(value) {
    var SelectCount = document.getElementsByTagName('select').length;
    for(var i = 0; i < SelectCount; i++){
        document.getElementsByTagName('select')[i].style.display = value;
    }
}
// msds search
function MsdsSearch(SearchCondition){
    if(null != document.getElementById(SearchCondition) && document.getElementById(SearchCondition).value.replace(/(^\s+)|\s+$/g,"") != "")
    {
        document.forms[0].submit();
    } else {
        alert("Please enter msds content.");
    }
}

// cofa search
function COfASearch(SearchCondition,FormName){
    if(null != document.getElementById(SearchCondition) 
        && document.getElementById(SearchCondition).value.replace(/(^\s+)|\s+$/g,"") != ""  
        && "Lot#" != document.getElementById(SearchCondition).value)
    {
        document.forms[FormName].submit();
    } else {
        alert("Please enter Lot#.");
    }
}
// product specification search
function ProductSpecificationSearch(SearchCondition,FormName) {
    if(null != document.getElementById(SearchCondition) 
        && document.getElementById(SearchCondition).value.replace(/(^\s+)|\s+$/g,"") != ""
        && "Item#" != document.getElementById(SearchCondition).value)
    {
        document.forms[FormName].submit();
    } else {
        alert("Please enter Item#.");
    }
}
// cofa event
function COfAEvent(txt) {
    if(txt.value == '')
        txt.value = "Lot#";
    else if(txt.value == 'Lot#')
        txt.value = "";
}
// product specification event
function ProductSpecificationEvent(txt) {
    if(txt.value == '')
        txt.value = "Item#";
    else if(txt.value == 'Item#')
        txt.value = "";
}
//confim delete
function deleteConfirm()
{  
	var array = document.forms[0].elements;
	if(array == null || typeof(array) == "undefined")
	{
	    return false;
	}

	var isSelected = false;

	for(i=0;i<array.length;i++)
	{
		if(array[i].checked)
		{
			isSelected = true;
			break;
		}
	}

	if (isSelected)
	{
		return confirm("Confirm to delete?");
	}
	else
	{
		alert("Please choose one item");		
		return false;
	}
}

function SetPosition(EleId) {
    document.getElementById(EleId).style.left = ((window.screen.width - 850)/2 + (850 - 780) /2);
}
// Open a new window
function OpenForm(N_Url, N_Width, N_Height) {
    var left_space = ((window.screen.width - 850)/2 + (850 - N_Width) /2);
    var statusp = "height="+N_Height+", width="+N_Width+", top=0, left=" + left_space + ", toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no";
    window.open(N_Url, 'newwindow', statusp);
}
function click() {
    if(event.button == 2)
    {
        
    }
}