var BV=parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
var BN=navigator.appName;
var IsWin=(navigator.userAgent.indexOf('Win')!=-1);
var IsMac=(navigator.userAgent.indexOf('Mac')!=-1);
var OP=(navigator.userAgent.indexOf('Opera')!=-1&&BV>=4)?true:false;
var NS=(BN.indexOf('Netscape')!=-1&&(BV>=4&&BV<5)&&!OP)?true:false;
var SM=(BN.indexOf('Netscape')!=-1&&(BV>=5)||OP)?true:false;
var IE=(BN.indexOf('Explorer')!=-1&&(BV>=4)||SM)?true:false;


function MM_RestoreImage() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_LoadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_LoadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function MM_SwapImage() { //v3.0
  var i,j=0,x,a=MM_SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function SpawnWindow(sURL,sheight,swidth) {
	var sOptionStr;

	sOptionStr = "width="+ swidth + ",height="+ sheight +",toolbar=yes,status=yes,resizable=yes,scrollbars=yes";
	var objPopupWindow = window.open(sURL,'NewWindow',sOptionStr);

	if(!objPopupWindow)
		{
		alert("MWS Image Viewer\n\n The popup to display the larger image has been blocked. \n\n Please disable this to view the larger image.");
		}

}

function ValidateLoginFields() { 
	// login id
	if (document.LoginForm.txtlogin.value.length < 1) {
		alert("Please enter your login ID.");
		document.LoginForm.txtlogin.focus();
		return false;
	}		

	// password
	if (document.LoginForm.txtpassword.value.length < 1) {
		alert("Please enter your login password.");
		document.LoginForm.txtpassword.focus();
		return false;
	}		
}

function ListProducts(oSource, sL1Code, sL2Code) {
	if (oSource.options[oSource.selectedIndex].value != ''){
		//window.open('https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code + oSource.options[oSource.selectedIndex].value);
		document.CategoryForm2.txtURLState.value = 'https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code + oSource.options[oSource.selectedIndex].value; 
		window.frames['iframeProductList'].location = 'https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code + oSource.options[oSource.selectedIndex].value; 
	}
}

function ListProducts2(sPageName, oSource) {
	if (oSource.options[oSource.selectedIndex].value != ''){
		
		document.location.href = sPageName + '?l1code=' + oSource.options[oSource.selectedIndex].value;
	}
	document.CategoryForm2.txtURLState.value = '';
}

function ListProducts3(sPageName, oSource, sL1Code) {
	var sValue = oSource.options[oSource.selectedIndex].value;

	if (sValue != ''){
		//check the first character to see if we have any further categories
		var sL3 = sValue.substring(0,1);
		var sL2Code = sValue.substring(1);
		if (sL3 == 'Y'){
			// we would need to retrieve data here to populate the drop down list
			document.location.href = sPageName + '?l1code=' + sL1Code + '&l2code=' + sValue;
			document.CategoryForm2.txtURLState.value = '';
		}
		else{
			//window.open('https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code);
			document.CategoryForm2.txtURLState.value = 'https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code; 
			window.frames['iframeProductList'].location = 'https://mwsltd.secure-op.com/HierarchySearch.aspx?BOSSFCode=' + sL1Code + sL2Code; 
		}
	}
}

// resizes Iframe according to content
function resizeMe(obj){ 
	if (document.CategoryForm2.txtURLState.value != '' || document.getElementById("SearchText").value != '') {
		obj.style.height = 800;
		
	}
	else{
		obj.style.height = 0;
	}
}

function blinkIt() {
      s=document.getElementById('tabExisting');
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
}

function checkWindowSizeForTabs()
	{
	var winW = 800, winH = 600;
	
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }
	}
	
	if(winW > 1000)
		{
		document.getElementById("existingTabHolder").innerHTML = "<a href='https://mwsltd.secure-op.com/index.aspx?FirstPage=Logon.aspx'><img src='img/tabs/existingTab.gif' border='0' id='tabExisting' name='tabExisting'></a>";
		}
	else
		{
		document.getElementById("existingTabHolder").innerHTML = "";
		}
	}


