// sniff out browsers
var isNN4 = document.layers ? true : false;
var isIE4 = document.all && !document.getElementById ? true : false;
// all DOM complient browsers, IE5 and up, NN6 and up, etc.
var isDOM = document.getElementById ? true : false;

//global array to place function "pointers" for execution at page load time
var onLoadFunctions=[];

window.onload = OnLoad;

function OnLoad()
{
	if (onLoadFunctions.length >= 0) eval(onLoadFunctions.join(";"));
}

function checkInput()
{
    if (document.LOGINFORM.EmailGlobal.value.length == 0)
    {
		if (document.LOGINFORM.PasswordGlobal.value.length == 0)
		{
			alert("Please enter your E-mail and Password")
			document.LOGINFORM.EmailGlobal.focus();
			return false;
		}
		else
		{
			alert("Please enter your E-mail.");
			document.LOGINFORM.EmailGlobal.focus();
			return false;
		}
	}

    if (document.LOGINFORM.EmailGlobal.value == " ")
    {
       alert("E-mail should not be blank. Please enter your Username.");
       document.LOGINFORM.EmailGlobal.focus();
       return false;
    }

    if (document.LOGINFORM.PasswordGlobal.value.length == 0)
    {
       alert("Please enter your Password.");
       document.LOGINFORM.PasswordGlobal.focus();
       return false;
    }

    if (document.LOGINFORM.PasswordGlobal.value == " ")
    {
       alert("Password should not be blank. Please enter your Password.");
       document.LOGINFORM.PasswordGlobal.focus();
       return false;
    }

    document.LOGINFORM.action += "?ReturnUrl=" + escape(location.href);
    document.LOGINFORM.submit();
	return true;
}

function getCookie (CookieName)
{
    var prefix = CookieName + "=";
    var cookieStartIndex = document.cookie.indexOf(prefix);
    if (cookieStartIndex == -1)
    {
       return;
    }

    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);

    if (cookieEndIndex == -1)
	{
		cookieEndIndex = document.cookie.length;
    }
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function redirect()
{
   var Username = getCookie("username");
   var Password = getCookie("password");
   if (!Username == "" && !Password == "")
   {
	   document.LOGINFORM.username.value = Username;
	   document.LOGINFORM.password.value = Password;
	   document.LOGINFORM.fromcookie.value = "19101963";
	   document.LOGINFORM.submit();
       return true;
   }
   else
   {
    document.login.username.focus();
   }
}

function ViewProfile(profileID)
{
	var theForm = document.forms["listProfilesForm"];
	var queryString = "?id=" + profileID + "&formState=" + GetFormStateString("listProfilesForm");
	location.href = "ViewProfile.aspx" + queryString;
}

function ListProfiles()
{
	var theForm = document.forms["viewProfileForm"];
	var queryString = "?";
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	location.href = "ListProfiles.aspx" + queryString;
}

function EditProfile()
{
	var theForm = document.forms["viewProfileForm"];
	var queryString = "?";
	var hasProfileID = false;
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value) + "&";
		}
		
		if (theForm["profileID"])
		{
			hasProfileID = true;
			queryString += "id=" + theForm["profileID"].value;
		}
	}
	location.href = "EditProfile.aspx" + queryString;
}

function EditProfileFromList(profileID)
{
	var theForm = document.forms["listProfilesForm"];
	var queryString = "?id=" + profileID + "&formState=" + GetFormStateString("listProfilesForm");
	location.href = "EditProfile.aspx" + queryString;
}

function ViewOrder(orderNumber, customerNumber)
{
	var theForm = document.forms["listOrdersForm"];
	var queryString = "?cid=" + customerNumber + 
		"&oid=" + orderNumber + 
		"&formState=" + GetFormStateString("listOrdersForm");
	
	location.href = "/distributor/orders/Load.aspx" + queryString;
}
function ViewAXOrder(orderNumber, customerNumber)
{
	var theForm = document.forms["listOrdersForm"];
	var queryString = "?cid=" + customerNumber + 
		"&oid=" + orderNumber + 
		"&formState=" + GetFormStateString("listOrdersForm");
	
	location.href = "/AXPage/distributor/orders/Detail.aspx" + queryString;
}


function ViewQuickOrder(orderNumber, customerNumber)
{
	var theForm = document.forms["listOrdersForm"];
	var queryString = "?cid=" + customerNumber + 
		"&oid=" + orderNumber + 
		"&formState=" + GetFormStateString("listOrdersForm");
	
	location.href = "/distributor/orders/QuickDetail.aspx" + queryString;
}

function ViewAXQuickOrder(orderNumber, customerNumber)
{
	var theForm = document.forms["listOrdersForm"];
	var queryString = "?cid=" + customerNumber + 
		"&oid=" + orderNumber + 
		"&formState=" + GetFormStateString("listOrdersForm");
	
	location.href = "/AXPage/distributor/orders/QuickDetail.aspx" + queryString;
}

function ListOrders()
{
	var theForm = document.forms["orderDetailForm"];
	var queryString = "?";
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	location.href = "/Distributor/Orders/Status.aspx" + queryString;
}

function QuickListOrders()
{
	var theForm = document.forms["orderDetailForm"];
	var queryString = "?";
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	location.href = "QuickOrderList.aspx" + queryString;
}
function ViewShipDetails(shipmentNumber, orderNumber, customerNumber)
{
	var theForm = document.forms["orderDetailForm"];
	var queryString = "?sid=" + URLEncode(shipmentNumber) + 
		"&oid=" + orderNumber + "&cid=" + customerNumber;
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "&formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	
	location.href="/Distributor/Orders/ShipDetail.aspx" + queryString;
}
function ViewAXShipDetails(shipmentNumber, orderNumber, customerNumber)
{
	var theForm = document.forms["orderDetailForm"];
	var queryString = "?sid=" + URLEncode(shipmentNumber) + 
		"&oid=" + orderNumber + "&cid=" + customerNumber;
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "&formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	
	location.href="/AXPage/Distributor/Orders/ShipDetail.aspx" + queryString;
}


function EditRejectBillingAddressUpdateRequest(requestID)
{
	location.href = "/Distributor/Admin/BillingUpdateRequestStatus.aspx?rid=" + requestID;
}

function ViewMessage(messageID)
{
	var queryString = "?mid=" + messageID + 
		"&formState=" + GetFormStateString("MyMessagesForm");
	
	location.href = "/distributor/Profile/MessageDetail.aspx" + queryString;
}

function ViewMessages()
{
	var theForm = document.forms["MessageDetailForm"];
	var queryString = "?";
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	location.href = "/Distributor/Profile/MyMessages.aspx" + queryString;
}

function AdminViewMessage(messageID)
{
	var queryString = "?mid=" + messageID + 
		"&formState=" + GetFormStateString("AdminMessagesForm");
	
	location.href = "/distributor/Admin/MessageDetail.aspx" + queryString;
}

function AdminViewMessages()
{
	var theForm = document.forms["AdminMessageDetailForm"];
	var queryString = "?";
	
	if (theForm)
	{
		if (theForm["__FORMSTATE"])
		{
			queryString += "formState=" + URLEncode(theForm["__FORMSTATE"].value);
		}
	}
	location.href = "/Distributor/Admin/Messages.aspx" + queryString;
}


function ToggleShipmentDetail(detailCellID)
{
	ToggleMenu(detailCellID);
}

function ToggleMenu(menuID)
{
	var menu;
	
	if (isDOM)
	{
		menu = document.getElementById(menuID)
		
		if (menu != null)
		{
			if (menu.style.display == "none")
			{
				menu.style.display = "";
			}
			else
			{
				menu.style.display = "none";
			}
		}
	}
	if (isIE4)
	{
		menu = document.all[menuID];
		if (menu != null)
		{
			if (menu.style.display == "none")
			{
				menu.style.display = "";
			}
			else
			{
				menu.style.display = "none";
			}
		}
	}
	if (isNN4)
	{
		menu = document.layers[menuID];
		
		if (menu != null)
		{
			if (menu.display == "none")
			{
				menu.display = "";
			}
			else
			{
				menu.display = "none";
			}
		}
	}
}

function ToggleRows(id)
{
	if (isNN4 || isIE4) return;
	
	var selectList = document.getElementById("ArtSent" + id);
	
	if (!selectList) return;
	
	switch (selectList[selectList.selectedIndex].value.toLowerCase())
	{
		case "mail":
			SetDisplay("DateArtSentRow" + id, "");
			SetDisplay("SelectNewArtRow" + id, "none");
			break;
		case "artrelay":
			SetDisplay("DateArtSentRow" + id, "");
			SetDisplay("SelectNewArtRow" + id, "none");
			break;
		case "attached":
			SetDisplay("DateArtSentRow" + id, "none");
			SetDisplay("SelectNewArtRow" + id, "");
			break;
		default:
			SetDisplay("DateArtSentRow" + id, "none");
			SetDisplay("SelectNewArtRow" + id, "none");
			break;
	}
}

function SetDisplay(id, value)
{
	if (isNN4 || isIE4) return;
	
	var el = document.getElementById(id);
	
	if (el)
	{
		el.style.display = value;
	}
}

function GetFormStateString(formName)
{
	var theForm = document.forms[formName];

	if (theForm==null || theForm["__FORMSTATEFIELDS"]==null || theForm["__FORMSTATEFIELDS"].value.length==0)
	{
		return "";
	}
	
	var formStateFields = theForm["__FORMSTATEFIELDS"].value.split(",");

	var formField;
	var fieldType;
	var formFieldState=new String();
	
	for (var i=0, len=formStateFields.length;i<len;++i)
	{
		formField = theForm[formStateFields[i]];
		if (!formField) 
		{
			continue;
		}
		
		fieldType = formField.type ? formField.type : "";

		switch (fieldType)
		{
			case "select-one":
				if (formField.selectedIndex >= 0)
					formFieldState+=URLEncode(formField.name + '=') + URLEncode(formField[formField.selectedIndex].value) + '&';
				break;
			case "text":
				if (formField.value.length > 0)
					formFieldState+=URLEncode(formField.name + '=') + URLEncode(formField.value) + '&';
				break;
			case "hidden":
				if (formField.value.length > 0)
					formFieldState+=URLEncode(formField.name + '=') + URLEncode(formField.value) + '&';
				break;
			case "radio":
				if (formField.checked)
					formFieldState+=URLEncode(formField.name + '=') + URLEncode(formField.value) + '&';
				break;
			case "checkbox":
				if (formField.checked)
					formFieldState+=URLEncode(formField.name + '=') + URLEncode(formField.value) + '&';
				break;
			default:
				if (formField.length)
				{
					if (formField[0].type == "radio")
					{
						for (var j = 0, len2 = formField.length; j < len; ++j)
						{
							if (formField[j].checked)
							{
								formFieldState+=URLEncode(formField[j].name + '=') + URLEncode(formField[j].value) + '&';
								break;
							}
						}
					}
					else
					{
						for (var j = 0, len2 = formField.length; j < len; ++j)
						{
							if (formField[j].checked)
							{
								formFieldState+=URLEncode(formField[j].name + '=') + URLEncode(formField[j].value) + '&';
							}
					}
				}
			}
		}
	}
	return URLEncode(formFieldState);
}

function URLEncode(s)
{
	return (s!=null) ? escape(s).replace(/\+/, "%2B") : '';
}

function ToggleSearch()
{
    if (isNN4 || isIE4) return;

    var selectList = document.getElementById("searchoption");

    if (!selectList) return;
 
    switch (selectList[selectList.selectedIndex].value.toLowerCase())
    
    {
            case "product":
           
                    SetDisplay("ProductSearchcolumn", "");
                    //SetDisplay("SiteSearchcolumn","none");
                    SetDisplay("PriceSearch1column", "none");
                    SetDisplay("PriceLabel", "none");
                    SetDisplay("PriceSearch2column", "none");
                    SetDisplay("ProductCatSearchcolumn", "none");
                    break;

            case "sitesearch":
                    SetDisplay("ProductSearchcolumn", "");
                    //SetDisplay("SiteSearchcolumn","none");
                    SetDisplay("PriceSearch1column", "none");
                    SetDisplay("PriceLabel", "none");
                    SetDisplay("PriceSearch2column", "none");
                    SetDisplay("ProductCatSearchcolumn", "none");
                    break;

            case "price":

                    SetDisplay("ProductSearchcolumn", "none");
                    //SetDisplay("SiteSearchcolumn","none");
                    SetDisplay("PriceSearch1column", "");
                    SetDisplay("PriceLabel", "");
                    SetDisplay("PriceSearch2column", "");
                    SetDisplay("ProductCatSearchcolumn", "none");
                    break;

            case "productcat":
        
                    SetDisplay("ProductSearchcolumn", "none");
                    //SetDisplay("SiteSearchcolumn","none");
                    SetDisplay("PriceSearch1column", "none");
                    SetDisplay("PriceLabel", "none");
                    SetDisplay("PriceSearch2column", "none");
                    SetDisplay("ProductCatSearchcolumn", "");
                    break;

            default:

                    SetDisplay("ProductSearchcolumn", "");
                    //SetDisplay("SiteSearchcolumn","none");
                    SetDisplay("PriceSearch1column", "none");
                    SetDisplay("PriceLabel", "none");
                    SetDisplay("PriceSearch2column", "none");
                    SetDisplay("ProductCatSearchcolumn", "none");
                    break;
    }

}
function ValidNumber1()
{
var iChars = "!@#$%^&*()+=-[]\\\',./{}|\":<>?";

  for (var i = 0; i < document.Form1.getElementsByTagName["ctl00$Content$txtPONumber"].value.length; i++)
   {
  	if (iChars.indexOf(document.Form1.getElementsByTagName["ctl00$Content$txtPONumber"].value.charAt(i)) != -1) 
  	{
  	alert ("Your Entered Number has special characters. \nThese are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }
  }

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function SubmitSearch()
{

    //bpp remove var theSearchForm = document.forms["Search"];
    var theSearchForm = document.forms[1];
   if (theSearchForm != null)
        {
        var selectList =  theSearchForm["searchoption"];
        if (selectList)
            {
            switch (selectList[selectList.selectedIndex].value.toLowerCase())
                {
                case "product":
                            theSearchForm.action = "/Search/SiteSearch.aspx";
                             break;
                case "sitesearch":
                            theSearchForm.action = "/Search/SiteSearch.aspx";
                            break;
                case "price":
                            theSearchForm.action = "/search/IdeaSearchp.aspx";
                            break;
                case "productcat":
                 
                            theSearchForm["command"].value="Category";
                            theSearchForm["Goto"].value="Category";
                            theSearchForm.action = "/Products/ProductList.aspx";
                            break;
                default:

                            theSearchForm.action = "/Products/ProductList.aspx";
                            break;
                }
            }
        else
            {
            theSearchForm.action = "/Products/ProductList.aspx";
            }
        theSearchForm.submit();     
        }
}
