﻿// JScript File

var disableSearchValidation = false;
var showOneCountry='true';
var myWidth = 0, myHeight = 0;

// JSFile: AddedToOrder.js
// JSMethod: findPosition
var themeScreenOffset = new Array();
themeScreenOffset['default'] = 775;
themeScreenOffset['prorepair'] = 775;
themeScreenOffset['redleftnav'] = getWindowWidth() - 75;

// *******************************************
String.prototype.trim = function () {
return this.replace(/\s*$/, "");
}

function getWindowWidth()
{
SetWindowSize();
return myWidth;
}

function getWindowHeight()
{
SetWindowSize();
return myHeight;
}

function SetWindowSize() {
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
}

function IsTextBoxEmpty(ctlId)
{
var value = document.getElementById(ctlId).value;
if (Trim(value) == "")
{
return true;
}
return false;
}

function RightTrim(sString) 
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function LeftTrim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}

function Trim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function SearchFormSubmitNoFilter(url, searchFieldName)
{
url = url.replace('{0}',searchFieldName);
location.href=url;
}

function SearchFormSubmit(url, searchFieldName, fieldId)
{
var currentValue = document.getElementById(fieldId).value;
currentValue = searchFieldName + '|' + escape(currentValue);
url = url.replace('{0}',currentValue);
location.href=url;
}

function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
var i;

for (i = 0; i < sText.length && IsNumber == true; i++) 
{ 
Char = sText.charAt(i); 
if (ValidChars.indexOf(Char) == -1) 
{
IsNumber = false;
}
}
return IsNumber;
}

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

function GetDivContent(divId)
{
var div = document.getElementById(divId);    
return div.innerHTML;
}

function checkMsgStr(msgStr, msgShowStr) 
{
var returnMsgStr = msgStr;
if (returnMsgStr != "") {
returnMsgStr += "\r\n";
returnMsgStr += msgShowStr;
} else {
returnMsgStr += msgShowStr;
}
return returnMsgStr;
}

function IsValidItemCode(itemCode, minItemCodeL, maxItemCodeL, isCheckOnlyNum) 
{
//always trim the value
var iCode = Trim(itemCode.value);
var IsValidIC=true;
if (isCheckOnlyNum == "true") {
if ((!IsNumeric(iCode)) || (iCode.length == 0) || (iCode.length > maxItemCodeL) || (iCode.length < minItemCodeL)) {
IsValidIC = false;  
} 
} else  {
if ((iCode.length == 0) || (iCode.length > maxItemCodeL) || (iCode.length < minItemCodeL)) {
IsValidIC = false;  
} 
}
return IsValidIC;
}

function checkItem(itemCode, itemQty, cultureFolder, minItemCodeL, maxItemCodeL, invalidQtyMsg, invalidItemCodeMsg ,invalidItemCodeQtyMsg, isCheckOnlyNum)
{    
var iCode = itemCode.value;
var iQty = itemQty.value;  
var errMsgStr = "";

if (!IsNumeric(iQty) || (iQty <= 0)) {
if (!IsValidItemCode(itemCode, minItemCodeL, maxItemCodeL, isCheckOnlyNum)) {
errMsgStr = checkMsgStr(errMsgStr, invalidItemCodeQtyMsg);
} else {
errMsgStr = checkMsgStr(errMsgStr, invalidQtyMsg);
}
} else {
if (!IsValidItemCode(itemCode, minItemCodeL, maxItemCodeL, isCheckOnlyNum)) {
errMsgStr = checkMsgStr(errMsgStr, invalidItemCodeMsg);
}         
}
if (errMsgStr != "") {
alert(errMsgStr);
return false;
} 
return true;
}

function checkCatalogItem(inCatalog, itemCode)
{    
if (itemCode == null || itemCode == "undefined")
return true;

if (inCatalog != "undefined") 
{
var itemFound = inCatalog;
var iCode = itemCode.value;
//var iQty = itemQty.value;  
var errMsgStr = "";        

if (itemFound == "0")
errMsgStr = gMsgItemNotInCatalog.replace("{0}",iCode); 

if (errMsgStr != "") 
{
alert(errMsgStr);
return false;
} 
return true;
}
return true;
}

function checkItemByClientID(itemCode, itemQty, cultureFolder, minItemCodeL, maxItemCodeL, invalidQtyMsg, invalidItemCodeMsg ,invalidItemCodeQtyMsg, isCheckOnlyNum)
{
var iCode = document.getElementById(itemCodeCtlid);
var iQty = document.getElementById(itemQtyCtlId);
return checkItem(iCode, iQty, cultureFolder, minItemCodeL, maxItemCodeL, invalidQtyMsg, invalidItemCodeMsg ,invalidItemCodeQtyMsg, isCheckOnlyNum)
}

var _processingQuickAddItem = false;

function QuickAddItem(itemCodeCtlid, itemQtyCtlId, cultureFolder, minItemCodeL, maxItemCodeL, invalidQtyMsg, invalidItemCodeMsg ,invalidItemCodeQtyMsg, isCheckOnlyNum)
{
if (_processingQuickAddItem)
{
return;
}

var iCode = document.getElementById(itemCodeCtlid);
var iQty = document.getElementById(itemQtyCtlId);
var itemCode = document.getElementById(itemCodeCtlid).value;
var itemQty = document.getElementById(itemQtyCtlId).value;   
if (checkItem(iCode, iQty, cultureFolder, minItemCodeL, maxItemCodeL, invalidQtyMsg, invalidItemCodeMsg ,invalidItemCodeQtyMsg, isCheckOnlyNum))
{
_processingQuickAddItem = true;

var newLocation;
newLocation = location.href;

//add it.
if (newLocation.indexOf ("addproductid")==-1)
{
index = newLocation.indexOf("?");
if (index != -1) {
location.href = newLocation + '&addproductid=' + itemCode + '&addproductqty=' + itemQty;		            
}
else
{
location.href = newLocation + '?addproductid=' + itemCode + '&addproductqty=' + itemQty;            
}
}
else 
{
// if already exists, update the querystring values;
location.href = UpdateQueryStringkeys(itemCode,itemQty);
}
}
}

function EnterKeyPressed(evt)
{
if ((evt.which == 13) || (evt.keyCode == 13))
{        
disableSearchValidation = true;
return true;   
} 
return false;
}

function UpdateQueryStringkeys(itemCode,itemQty)
{    
var rootUrl = "";
var queryStringCollection = "";    
var url = location.href;

if (url.indexOf("?") == -1)
rootUrl = url;
else
{
var urlWithoutQueries = url.split("?");
rootUrl = urlWithoutQueries[0];
queryStringCollection = urlWithoutQueries[1];
}

var queryStringPairsCollection = queryStringCollection.split("&");
var newQueryString = rootUrl + "?";

for (var i=0;i<queryStringPairsCollection.length;i++) 
{
var pair = queryStringPairsCollection[i].split("=");
if (pair[0] == "addproductid") 
{
pair[1] = itemCode;
}
else  if (pair[0] == "addproductqty") 
{
pair[1] = itemQty;
}
newQueryString += pair[0] + "=" + pair[1];
if (i!=queryStringPairsCollection.length-1)
newQueryString += "&";
}

return newQueryString;    
}

function LaunchAd(target, url, AdId, Division, PromoCode, LinkedPromotionCode, CM, height, width)
{

var strHref = url +"?adId=" + AdId + "&amp;division=" + Division 
+ "&amp;PromoCode=" + PromoCode + "&amp;PromoCode2=" + LinkedPromotionCode + "&amp;cm_sp=" + CM;

if (target == "_self")
{
self.location = strHref;
}            
else if (target == "_popup")
{
BrowseWindow(strHref,1,target,height,width);
}else
{
BrowseResizableDetailedWindow(strHref,1,target,height,width);
}
}

function BrowseWindow(URL, win_number, win_name, height, width)
{
var popup = window.open(URL, win_name, "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes");
if ((popup!=null) && (typeof(popup)=='object') && popup.focus != null) popup.focus();
}

function BrowseResizableWindow(URL, win_number, win_name, height, width)
{
var popup = window.open(URL, win_name, "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes");
if ((popup!=null) && (typeof(popup)=='object')) popup.focus();
}

function BrowseResizableDetailedWindow(URL, win_number, win_name, height, width)
{
var popup = window.open(URL, win_name, "height=" + height + ",width=" + width + ",location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
if ((popup!=null) && (typeof(popup)=='object')) popup.focus();
}

function PopupDatePicker(ctl, cultureFolder, y, m, d, datePickerMode)
{
var currentValue = "";

var currentValue = document.getElementById(ctl).value
if(currentValue.length > 0)
{
currentValue = "&m=" + m + "&y=" + y;
}
var PopupWindow=null;
settings = 'width=300,height=200,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';
PopupWindow=window.open('/' + cultureFolder + '/DatePicker.aspx?mode=' + datePickerMode + '&dateField=' + ctl + currentValue, 'DatePicker',settings);
if ((PopupWindow!=null) && (typeof(PopupWindow)=='object')) PopupWindow.focus();
return false;
}

// ***********************************************
// Shows/hides the the div.
// ***********************************************
function toggleDivVisibility(divid) {
alert(divid);
var temp = document.getElementById(divid).style.display;
if(temp=="") {
document.getElementById(divid).style.display="none";
} else if(temp=="block") {
document.getElementById(divid).style.display="none";
} else {
document.getElementById(divid).style.display="block";
}
}

// Shows/hides the expandable/collapsable menu nodes.
function toggleMenusVisibility(menuid, nbMenu) 
{
var i;
for( i = 1001; i <= nbMenu; ++i )
{
var menuName = ("menu" + i);
if( menuid == menuName )
{            
expandMenuVisibility(menuid);
}
else
{           
collapseMenuVisibility(menuid);
}
}
}

function expandMenuVisibility(menuid) 
{
if( document.getElementById(menuid) != null )
{
document.getElementById(menuid).style.display="block";
}
}

function collapseMenuVisibility(menuid)
{
if( document.getElementById(menuid) != null )
{
document.getElementById(menuid).style.display="none";
}
}

function toggleOtherVisibility(dropdown, value) {
if (dropdown != null) {
id = dropdown.id
if (id != null) {
index = id.indexOf("_ddlSiteTerms")
if (index != -1) {
divId = id.substring(0, index) + "_divOther"
div = document.getElementById(divId)
if (div != null) {
if(dropdown.value == value) {
	div.style.display="block";
} else {
	div.style.display="none";
}
}
}
}
}
}

function passwordChanged(id)
{
document.getElementById(id).value = "true";
}

function answerChanged(id)
{
document.getElementById(id).value = "true";
}

function validateUserId(a, e)
{
var str = e.Value;
e.IsValid = (str.length >= 4 && str.length <= 50);
}

function validatePassword(a, e)
{
var str = e.Value;
e.IsValid = (str.length >= 6 && str.length <= 12);
}

function validateFirstName(a, e)
{
var str = e.Value;
e.IsValid = (str.length >= 2 && str.length <= 25);
}

function validateLastName(a, e)
{
var str = e.Value;
e.IsValid = (str.length >= 2 && str.length <= 25);
}

function validateTelNumber(a, e)
{
var str = e.Value;
e.IsValid = (str.length >= 10);
}
function SetTextBoxQtyFocus(controlId)
{
var controlsId = controlId.split("$");
//Get the last 2 digit of the iteration control.
var lastTwoDigits = controlsId[controlsId.length-3].substring(3);
var intLastTwoDigits = parseInt(lastTwoDigits, 10);

var productDetailsRowLastDigit = controlsId[controlsId.length-2].substring(17);
if(productDetailsRowLastDigit == "1")
{
productDetailsRowLastDigit = "2";
}
else
{
productDetailsRowLastDigit = "1";
}

if ((event.which == 40) || (event.keyCode == 40))
{
intLastTwoDigits += 1;
var nextTextBoxControl="";
//bring the focus at the next quantity textbox.
for(var i=0;i<=controlsId.length-1;i++)
{
if(i == (controlsId.length-3))
{
if(intLastTwoDigits.toString().length == 2)
{
nextTextBoxControl += "ctl" + intLastTwoDigits.toString() + "$"
}
else
{
nextTextBoxControl += "ctl0" + intLastTwoDigits.toString() + "$"
}
}
else if(i == (controlsId.length-2))
{
nextTextBoxControl += "ProductDetailsRow" + productDetailsRowLastDigit + "$"
}
else if(i == (controlsId.length-1))
{
nextTextBoxControl += controlsId[i]
}
else
{
nextTextBoxControl += controlsId[i] + "$";
}
}
var txtControl = document.getElementById(nextTextBoxControl)
if(txtControl != null)
{
txtControl.focus();   
}
else
{
//bring it to the top.
var firstTextBoxControl="";
for(var i=0;i<=controlsId.length-1;i++)
{
if(i == (controlsId.length-3))
{
firstTextBoxControl += "ctl01$"
}
else if(i == (controlsId.length-2))
{
firstTextBoxControl += "ProductDetailsRow1$"
}
else if(i == (controlsId.length-1))
{
firstTextBoxControl += controlsId[i]
}
else
{
firstTextBoxControl += controlsId[i] + "$";
}
}
document.getElementById(firstTextBoxControl).focus();
}
}
else if((event.which == 38) || (event.keyCode == 38))
{
intLastTwoDigits -= 1;

//bring the focus at the previous quantity textbox.
var previousTextBoxControl="";
for(var i=0;i<=controlsId.length-1;i++)
{
if(i == (controlsId.length-3))
{
previousTextBoxControl += "ctl0" + intLastTwoDigits.toString() + "$"
}
else if(i == (controlsId.length-2))
{
previousTextBoxControl += "ProductDetailsRow" + productDetailsRowLastDigit + "$"
}
else if(i == (controlsId.length-1))
{
previousTextBoxControl += controlsId[i]
}
else
{
previousTextBoxControl += controlsId[i] + "$";
}
}
var txtControl = document.getElementById(previousTextBoxControl)
if(txtControl != null)
{
txtControl.focus();   
}
}
}

// DatePopup format validator
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
var i;
for (i = 0; i < s.length; i++){   
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){   
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
} 
return this
}

function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
}
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1){
alert(gMsgDateFormat);
return false
}
if (strMonth.length<1 || month<1 || month>12){
alert(gMsgValidMonth);
return false
}
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert(gMsgValidDay);
return false
}
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
gMsgValidYear = gMsgValidYear.replace("{0}",minYear);
gMsgValidYear = gMsgValidYear.replace("{1}",maxYear);
alert(gMsgValidYear);
return false
}
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert(gMsgValidDate);
return false
}
return true
}

function ValidateDate(control){
if (isDate(control.value)==false){
control.focus()
return false
}
return true
}

function confirmLogoff()
{
if (confirm(gMsgConfirmLogoff))
{
Delete_Cookie('MSCSAuth', '/', '');
return true;
}
else
{
return false;
}
}

function Get_Cookie( check_name ) {
var a_all_cookies = document.cookie.split( ';' );
var a_temp_cookie = '';
var cookie_name = '';
var cookie_value = '';
var b_cookie_found = false;
for ( i = 0; i < a_all_cookies.length; i++ )
{
a_temp_cookie = a_all_cookies[i].split( '=' );
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
if ( cookie_name == check_name )
{
b_cookie_found = true;
if ( a_temp_cookie.length > 1 )
{
cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
}
return cookie_value;
break;
}
a_temp_cookie = null;
cookie_name = '';
}
if ( !b_cookie_found )
{
return null;
}
}

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";
}

var cnn;
var lastInvoice;
function checkInvoice(invoiceNum)
{
// Need to throw a CoreMetrics Pageview tag to show 
// that a user has attempted to view an invoice
cmCreatePageviewTag("View Invoice_" + gCoreMetricCountryCode + "_" + gCoreMetricLanguageCode,"OLP_ow_" + gCoreMetricCountryCode + "_" + gCoreMetricLanguageCode,null,null);
window.open("/" + gFolderNameForCulture + "/olp/invoiceloading.aspx?type=inv&invoice_num=" + invoiceNum, 'loading', 'menubar=no,statusbar=no,toolbar=no,resizable=yes,height=340,width=620');
}

function stateChanged()
{
if(cnn.readyState == 4)
{
window.open("/" + gFolderNameForCulture + "/olp/invoiceloading.aspx?type=inv&invoice_num=" + lastInvoice, 'loading', 'menubar=no,statusbar=no,toolbar=no,resizable=yes,height=340,width=620')
}
}

//*** for quick order page only
//tested on IE and FireFox
function tabOnEnterForQuickOrder (field, evt) {
var keyCode = document.layers ? evt.which : document.all ?
evt.keyCode : evt.keyCode;
if (keyCode != 13 && keyCode !=9)
return true;
else {
var el=getNextElement(field);

if(el.type=='select-one')
{
var butAddBottom=document.getElementById('ctl00_cphMainContent_butAddTop');
butAddBottom.focus();
butAddBottom.click();
}
else if (el.type!='hidden')
el.focus(); 
else{
while (el.type=='hidden')
el=getNextElement(el); 
el.focus();
} 
return false;
}
}

function getNextElement (field) {
var form=field.form;

for (var e = 0; e < form.elements.length; e++) { 
if (field == form.elements[e])
break;
}
return form.elements[++e];
}

function CheckList(source, arguments)
{
arguments.IsValid = (arguments.Value != "SelectOne");
}

function fnCheckAllInSameContainerAndGroup(Container,oSender,sGroup){
if(oSender.type.toLowerCase() != "checkbox") return;
var sSenderId = oSender.id;
var isChecked = oSender.checked;
var sParentGroupName = sGroup + "_Parent";
var sChildGroupName = sGroup + "_Child";
var isParent = (sSenderId.match("Parent") != null);
var isChild = (sSenderId.match("Child") != null);
var aAllInputs = document.getElementById(Container).getElementsByTagName("input");
if((aAllInputs != null) && (aAllInputs.length != null) && (aAllInputs.length > 0))
{
if(isParent)
{
for(var i = 0; i < aAllInputs.length; i++)
{
if(aAllInputs[i].type.toLowerCase() == "checkbox")
{
sInputId = aAllInputs[i].id.toString();
if(sInputId.match(sParentGroupName) != null || sInputId.match(sChildGroupName) != null)
{
if (!aAllInputs[i].disabled)
{
aAllInputs[i].checked = isChecked;
}
}
}
}
}
if(isChild)
{
if(!isChecked)
{
for(var j = 0; j < aAllInputs.length; j++)
{
if(aAllInputs[j].type.toLowerCase() == "checkbox")
{
sInputId = aAllInputs[j].id.toString();
if(sInputId.match(sParentGroupName) != null || sInputId.match(sParentGroupName) != null)
{
if (!aAllInputs[j].disabled)
{
aAllInputs[j].checked = isChecked;
}
}
}
}
}
else
{
var bAllChecked = true;
for(var k = 0; k < aAllInputs.length; k++)
{
if(aAllInputs[k].type.toLowerCase() == "checkbox")
{
sInputId = aAllInputs[k].id.toString();
if(sInputId.match(sChildGroupName) != null)
{
if((!aAllInputs[k].checked) && (!aAllInputs[k].disabled))
{
bAllChecked = false;
break;
}
}
}
}
if(bAllChecked)
{
for(var m = 0; m < aAllInputs.length; m++)
{
if(aAllInputs[m].type.toLowerCase() == "checkbox")
{
sInputId = aAllInputs[m].id.toString();
if(sInputId.match(sParentGroupName) != null)
{
if (!aAllInputs[m].disabled)
{
aAllInputs[m].checked = true;
}
}
}
}
}
}
}
}
}

function fnContinueReturn(){
if(confirm(gMsgContinueReturn))
{
location.href = 'FinalizeReturn.aspx';
}
else
{
location.href = 'RequestReturn.aspx';
}
}

function fnDisplaySubItems(){
    
    var ContainerDiv = document.getElementById("Container");
    // for IE
    ContainerDiv.style.filter = "alpha(opacity=25)";    
    // for Mozilla/Firefox
    ContainerDiv.style.MozOpacity = "0.25";    
    // for Opera
    ContainerDiv.style.opacity = "0.25";    
           
    var MainContentDiv = document.getElementById("MainContentSection");
    // for IE
    MainContentDiv.style.filter = "alpha(opacity=25)";        
    // for Mozilla/Firefox
    MainContentDiv.style.MozOpacity = "0.25";
    // for Opera
    MainContentDiv.style.opacity = "0.25";
 
    var SubstituteItemsDiv = document.getElementById("SubstituteItems");
    SubstituteItemsDiv.style.visibility = "visible";
}

function fnCloseSubItems(){

    var SubstituteItemsDiv = document.getElementById("SubstituteItems");
    SubstituteItemsDiv.style.visibility = "hidden";
    
    var ContainerDiv = document.getElementById("Container");
    // for IE
    ContainerDiv.style.filter = "alpha(opacity=100)";
    // for Mozilla/Firefox
    ContainerDiv.style.MozOpacity = "1.00";
    // for Opera
    ContainerDiv.style.opacity = "1.00";
    
    var MainContentDiv = document.getElementById("MainContentSection");
    // for IE
    MainContentDiv.style.filter = "alpha(opacity=100)";
    // for Mozilla/Firefox
    MainContentDiv.style.MozOpacity = "1.00";
    // for Opera
    MainContentDiv.style.opacity = "1.00";
    
    return false;
}

function checkSSTIQtybyJavaScript(){

var isFound = "false";

for (j=0;j<mySSTIQTYA.length;j++)
{
var txtQty = document.getElementById(mySSTIQTYA[j]);
var txtQtyV = txtQty.value;

if (!IsNumeric(txtQtyV)) {
alert(qtySSTIErrMsg);
return false;
}

if (txtQtyV > 0 && txtQtyV <= 99999) {
isFound = "true";
}
}

if (isFound == "false"){
alert(qtySSTIErrMsg);
return false;
}

return true;
}
function checkAreaCodePhone(sender,args)
{
args.IsValid=true;
cvPhone.style.display="none";
cvAreaCodePhone.style.display="none";
if ((rexPhone.style.display=="none") && (rexAreaCodePhone.style.display=="none")) 
{
if ((txtAreaCodePhone.value.length>0) && (txtPhone.value.length==0))
{
args.IsValid=false;
}
else if ((txtAreaCodePhone.value.length==0) && (txtPhone.value.length>0))
{
args.IsValid=false;
}
}
}
function checkAreaCodeMobile(sender,args)
{
args.IsValid=true;
cvMobile.style.display="none";
cvAreaCodeMobile.style.display="none";
if ((rexMobile.style.display=="none") && (rexAreaCodeMobile.style.display=="none")) 
{
if ((txtAreaCodeMobile.value.length>0) && (txtMobile.value.length==0))
{
args.IsValid=false;
}
else if ((txtAreaCodeMobile.value.length==0) && (txtMobile.value.length>0))
{
args.IsValid=false;
}
}
}
function checkAreaCodeFax(sender,args)
{
args.IsValid=true;
cvFax.style.display="none";
cvAreaCodeFax.style.display="none";
if ((rexFax.style.display=="none") && (rexAreaCodeFax.style.display=="none")) 
{
if ((txtAreaCodeFax.value.length>0) && (txtFax.value.length==0))
{
args.IsValid=false;
}
else if ((txtAreaCodeFax.value.length==0) && (txtFax.value.length>0))
{
args.IsValid=false;
}
}
}

function ShowProgressBarIfValid()
{
if(Page_ClientValidate())
{
ShowProgressBar();
}
}

function ModifyCardLink()
{   
var ddlPaymentMethod = document.getElementById(ddl);
var hiddenModifyLink = document.getElementById(hid);
var lnkModifyCreditCard = document.getElementById(lnk);
var trAutoPayNote = document.getElementById(autoNote);
if (ddlPaymentMethod != null)
{
var selIndex = ddlPaymentMethod.selectedIndex;
var selValue = ddlPaymentMethod.options[selIndex].value;

if (selValue == li)
{
lnkModifyCreditCard.style.display = 'none';
}
else
{
var arrValues = selValue.split("|");
var sEdit = arrValues[0];
var sCreditCardId = arrValues[1];
if (sEdit == "0")
{
lnkModifyCreditCard.style.display = 'none';
}
else
{
lnkModifyCreditCard.style.display = "";
lnkModifyCreditCard.href = hiddenModifyLink.value.replace('{0}',sCreditCardId);
}
}
if (selValue == li && autoCheck == 'True')
{
trAutoPayNote.style.visibility = 'visible';
}
else
{
trAutoPayNote.style.visibility = 'collapse';
}
}
}

var objURL = new Object();
window.location.search.replace(
new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
function( $0, $1, $2, $3 ){
objURL[ $1 ] = $3;
}
);

for (var strKey in objURL){
if(strKey == "hsi_domain")
{
setCookie(strKey, unescape(objURL[ strKey ]), 30);
}
if(strKey == "hsi_locale")
{
setCookie(strKey, unescape(objURL[ strKey ]), 30);
}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}

function jumpToAd(adId) {
var adLink = document.getElementById(adId);
var adLinkTarget = adLink.target;
var adLinkHref = adLink.href;
switch(adLinkTarget)
{
case '_blank':
window.open(adLinkHref);
break;
default:
self.location.href = adLinkHref;
}
}
//to read the querystring value
function getParameterByName( name ) {   
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )     
return "";
else     
return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function _isInteger(val) {
var digits="1234567890";
for (var i=0; i < val.length; i++) {
if (digits.indexOf(val.charAt(i))==-1) { return false; }
}
return true;
}

function _getInt(str,i,minlength,maxlength) {
for (var x=maxlength; x>=minlength; x--) {
var token=str.substring(i,i+x);
if (token.length < minlength) { return null; }
if (_isInteger(token)) { return token; }
}
return null;
}

function getDateFromFormat(val,format) {
val=val+"";
format=format+"";
var i_val=0;
var i_format=0;
var c="";
var token="";
var token2="";
var x,y;
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth()+1;
var date=1;
var hh=now.getHours();
var mm=now.getMinutes();
var ss=now.getSeconds();
var ampm="";

while (i_format < format.length) {
c=format.charAt(i_format);
token="";
while ((format.charAt(i_format)==c) && (i_format < format.length)) {
token += format.charAt(i_format++);
}
if (token=="yyyy" || token=="yy" || token=="y") {
if (token=="yyyy") { x=4;y=4; }
if (token=="yy")   { x=2;y=2; }
if (token=="y")    { x=2;y=4; }
year=_getInt(val,i_val,x,y);
if (year==null) { return 0; }
i_val += year.length;
if (year.length==2) {
if (year > 70) { year=1900+(year-0); }
else { year=2000+(year-0); }
}
}
else if (token=="MMM"||token=="NNN"){
month=0;
for (var i=0; i<MONTH_NAMES.length; i++) {
var month_name=MONTH_NAMES[i];
if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
if (token=="MMM"||(token=="NNN"&&i>11)) {
month=i+1;
if (month>12) { month -= 12; }
i_val += month_name.length;
break;
}
}
}
if ((month < 1)||(month>12)){return 0;}
}
else if (token=="EE"||token=="E"){
for (var i=0; i<DAY_NAMES.length; i++) {
var day_name=DAY_NAMES[i];
if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
i_val += day_name.length;
break;
}
}
}
else if (token=="MM"||token=="M") {
month=_getInt(val,i_val,token.length,2);
if(month==null||(month<1)||(month>12)){return 0;}
i_val+=month.length;}
else if (token=="dd"||token=="d") {
date=_getInt(val,i_val,token.length,2);
if(date==null||(date<1)||(date>31)){return 0;}
i_val+=date.length;}
else if (token=="hh"||token=="h") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<1)||(hh>12)){return 0;}
i_val+=hh.length;}
else if (token=="HH"||token=="H") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<0)||(hh>23)){return 0;}
i_val+=hh.length;}
else if (token=="KK"||token=="K") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<0)||(hh>11)){return 0;}
i_val+=hh.length;}
else if (token=="kk"||token=="k") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<1)||(hh>24)){return 0;}
i_val+=hh.length;hh--;}
else if (token=="mm"||token=="m") {
mm=_getInt(val,i_val,token.length,2);
if(mm==null||(mm<0)||(mm>59)){return 0;}
i_val+=mm.length;}
else if (token=="ss"||token=="s") {
ss=_getInt(val,i_val,token.length,2);
if(ss==null||(ss<0)||(ss>59)){return 0;}
i_val+=ss.length;}
else if (token=="a") {
if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
else {return 0;}
i_val+=2;}
else {
if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
else {i_val+=token.length;}
}
}

if (i_val != val.length) { return 0; }
if (month==2) {
if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
if (date > 29){ return 0; }
}
else { if (date > 28) { return 0; } }
}
if ((month==4)||(month==6)||(month==9)||(month==11)) {
if (date > 30) { return 0; }
}

if (hh<12 && ampm=="PM") { hh=hh-0+12; }
else if (hh>11 && ampm=="AM") { hh-=12; }

var newdate=new Date(year,month-1,date,hh,mm,ss);

return newdate;

}
