﻿// JScript File
function ConfirmAction(strMessage)
{
if(strMessage=='') 
{
  var a = confirm('Are you sure You wish to do this action?');
}
else
{
  var a = confirm(strMessage);
}

  if(!a)
  {
    return false;
  }
}

function redirect() 
{
	window.location.href="index.aspx";
}
function confRemove(strName)
{
	var strConf = confirm('Are you sure you wish to remove ' + strName + ' from your cart ?')
	return strConf
}
function confDelete(strName)
{
	var strConf = confirm('Are you sure you wish to delete ' + strName + '?')
	return strConf
}
function validateProdQtyBox(txtQty)
{
	if(IsNumeric(txtQty.value))
	{
		if(txtQty.value.length > 6)
		{
			alert('You Can Not Select A Quantity Higher Then 999,999');
			txtQty.value = 1;
			txtQty.focus();
			return false;
		}
	}
	else
	{
		alert('Please Insert A Numeric Value For Qty!');
		txtQty.value = 1;		
		txtQty.focus();
		return false;
	}
}

var strValidChars = '0123456789.,';
var returnbol = false;
function IsNumeric(strString){
	var strChar;
	var blnResult = true;
	var i;
	if (strString.length == 0) return returnbol;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
		{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			{
			blnResult = false;
			}
		}
	return blnResult;
}



function ProdViewincrease(txtQty)
{
	if(txtQty.value < 0)
	{
		txtQty.value = 1;
		return;
	}
	txtQty.value = ++txtQty.value;
}

function ProdViewdecrease(txtQty)
{	
	if(txtQty.value <= 0)
	{
		txtQty.value = 1;
		return;
	}
	txtQty.value = --txtQty.value;
}


var DeptID;

function SetDeptID(DptID){
	DeptID=DptID;
}

function SetDeptImage(){
	if (DeptID==1)
		document.getElementById("TitTD1").setAttribute("background","RoyalImages/navbg1.gif");
	else if(DeptID==2)
		document.getElementById("TitTD2").setAttribute("background","RoyalImages/navbg1.gif");
	else if(DeptID==3)
		document.getElementById("TitTD3").setAttribute("background","RoyalImages/navbg1.gif");
	else if(DeptID==4)
		document.getElementById("TitTD4").setAttribute("background","RoyalImages/navbg1.gif");
	else if(DeptID==5)
		document.getElementById("TitTD5").setAttribute("background","RoyalImages/navbg1.gif");
	else
		document.getElementById("TitTD0").setAttribute("background","RoyalImages/navbg1.gif");
}

//Preload function

	var iPath = '';
	var iExt = 'jpg';
	var prefix = '';
	var strFrontImage = '';
	var strBackImage = '';
	var suffix = new Array('on', 'off');
	var isPreLoad=true;
	var OldDivText = '';
	function preLoad()
	{
	  if(document.images)
	  {
	    var argLen = arguments.length;
	    var sufLen = suffix.length;
	    var suf;
	    if(argLen>0)
	    {
				for(var i = 0; i < argLen; i++)
				{
				  var arg = arguments[i];
				  //var sufLen = suffix.length;
				  for(var j = 0; j < sufLen; j++)
				  {
				    suf = suffix[j]; //var suf = suffix[j];
				    self[arg + suf] = new Image();
				    if(suf=='lf')
				    {
							self[arg + suf].src = strFrontImage; //iPath + prefix + arg + suf + '.' + iExt;
						}
						else
						{
							self[arg + suf].src = strBackImage;
						}
				  }
				}
			}
			else
			{
				isPreLoad=false; 
			}
	  }
	}

//Rollover function
function RollOver(a, ImgNo, LFAlt, LBAlt, CustID, ProdID)
{
	if (parseFloat(CustID)<=0)
		{
				window.location.href = 'index.asp?PageAction=LOGIN&CALLER=DISPLAYPRODUCT&ProdID=' + ProdID;
			return;
		}
	
	if (document.getElementById("Div_LargeImage").innerHTML=='')
		{
		document.getElementById("Div_LargeImage").innerHTML=OldDivText;
		}
	if(a.title=='Front')
		{
		if(isPreLoad==true)
			document.getElementById("RollOverImage").setAttribute("src",self[ImgNo + 'lf'].src);
		else
			document.getElementById("RollOverImage").setAttribute("src",strFrontImage);
		document.getElementById("RollOverImage").setAttribute("alt",LFAlt);
		document.getElementById("RollOverImage").setAttribute("title",LFAlt);
		document.getElementById("FBImageTop").setAttribute("title","Back");
		document.getElementById("FBImageTop").setAttribute("src","RoyalImages/back.gif");
		document.getElementById("FBImageBottom").setAttribute("title","Back")
		document.getElementById("FBImageBottom").setAttribute("src","RoyalImages/back.gif")
		}
	else if(a.title=='Back')
		{
		if(isPreLoad==true)
			document.getElementById("RollOverImage").setAttribute("src",self[ImgNo + 'lb'].src);
		else
			document.getElementById("RollOverImage").setAttribute("src",strBackImage);
		document.getElementById("RollOverImage").setAttribute("alt",LBAlt);
		document.getElementById("RollOverImage").setAttribute("title",LBAlt);
		document.getElementById("FBImageTop").setAttribute("title","Front");
		document.getElementById("FBImageTop").setAttribute("src","RoyalImages/front.gif");
		document.getElementById("FBImageBottom").setAttribute("title","Front")
		document.getElementById("FBImageBottom").setAttribute("src","RoyalImages/front.gif")
		}
	else
		{
		if(isPreLoad==true)
			document.getElementById("RollOverImage").setAttribute("src",self[ImgNo + 'lf'].src);
		else
			document.getElementById("RollOverImage").setAttribute("src",strFrontImage);
		document.getElementById("RollOverImage").setAttribute("alt",LFAlt);
		document.getElementById("RollOverImage").setAttribute("title",LFAlt);
		document.getElementById("FBImageTop").setAttribute("title","Back");
		document.getElementById("FBImageTop").setAttribute("src","RoyalImages/back.gif");
		document.getElementById("FBImageBottom").setAttribute("title","Back");
		document.getElementById("FBImageBottom").setAttribute("src","RoyalImages/back.gif");
		}
}

function Img_onerror(objImg, strPath)
{
	objImg.src=strPath;
}

//For TAb Handling
var OldTab;
var strGeneral;
OldTab=1;
function TabHandle(TabNo)
{
	var objTD;
	if (OldTab==1)
		{
	  objTD = document.getElementById("TD1");
	  }
	else if (OldTab==2)
		{
		objTD = document.getElementById("TD2");
		}
	else if (OldTab==3)
		{
		objTD = document.getElementById("TD3");
		}
	objTD.bgColor="#E6E6E6";
	objTD.className='NormalTD';
	
	if (TabNo==1)
		{
		objTD = document.getElementById("TD1");
		document.getElementById("Det").innerHTML=strGeneral;
		}
	else if (TabNo==2)
		{
		objTD = document.getElementById("TD2");
		document.getElementById("Det").innerHTML="";
		}
	else if (TabNo==3)
		{
		objTD = document.getElementById("TD3");
		document.getElementById("Det").innerHTML="";
		}
	objTD.bgColor="#B3B3B3";
	objTD.className='CurrentTD';
	OldTab=TabNo;
}

function convertEncodesToSymbols(strHTML)
{
  var strFixedHTML = strHTML;
  strFixedHTML = strFixedHTML.replace("&#153;", "\u2122");
  strFixedHTML = strFixedHTML.replace("&trade;", "\u2122");
  strFixedHTML = strFixedHTML.replace("&nbsp;", "\u00A0");
  strFixedHTML = strFixedHTML.replace("&iexcl;", "\u00A1");
  strFixedHTML = strFixedHTML.replace("&cent;", "\u00A2");
  strFixedHTML = strFixedHTML.replace("&pound;", "\u00A3");
  strFixedHTML = strFixedHTML.replace("&curren;", "\u00A4");
  strFixedHTML = strFixedHTML.replace("&yen;", "\u00A5");
  strFixedHTML = strFixedHTML.replace("&brvbar;", "\u00A6");
  strFixedHTML = strFixedHTML.replace("&sect;", "\u00A7");
  strFixedHTML = strFixedHTML.replace("&uml;", "\u00A8");
  strFixedHTML = strFixedHTML.replace("&copy;", "\u00A9");
  strFixedHTML = strFixedHTML.replace("&ordf;", "\u00AA");
  strFixedHTML = strFixedHTML.replace("&laquo;", "\u00AB");
  strFixedHTML = strFixedHTML.replace("&not;", "\u00AC");
  strFixedHTML = strFixedHTML.replace("&shy;", "\u00AD");
  strFixedHTML = strFixedHTML.replace("&reg;", "\u00AE");
  strFixedHTML = strFixedHTML.replace("&macr;", "\u00AF");
  strFixedHTML = strFixedHTML.replace("&deg;", "\u00B0");
  strFixedHTML = strFixedHTML.replace("&plusmn;", "\u00B1");
  strFixedHTML = strFixedHTML.replace("&sup2;", "\u00B2");
  strFixedHTML = strFixedHTML.replace("&sup3;", "\u00B3");
  strFixedHTML = strFixedHTML.replace("&acute;", "\u00B4");
  strFixedHTML = strFixedHTML.replace("&micro;", "\u00B5");
  strFixedHTML = strFixedHTML.replace("&para;", "\u00B6");
  strFixedHTML = strFixedHTML.replace("&middot;", "\u00B7");
  strFixedHTML = strFixedHTML.replace("&cedil;", "\u00B8");
  strFixedHTML = strFixedHTML.replace("&sup1;", "\u00B9");
  strFixedHTML = strFixedHTML.replace("&ordm;", "\u00BA");
  strFixedHTML = strFixedHTML.replace("&raquo;", "\u00BB");
  strFixedHTML = strFixedHTML.replace("&frac14;", "\u00BC");
  strFixedHTML = strFixedHTML.replace("&frac12;", "\u00BD");
  strFixedHTML = strFixedHTML.replace("&frac34;", "\u00BE");
  strFixedHTML = strFixedHTML.replace("&iquest;", "\u00BF");
  strFixedHTML = strFixedHTML.replace("&Agrave;", "\u00C0");
  strFixedHTML = strFixedHTML.replace("&Aacute;", "\u00C1");
  strFixedHTML = strFixedHTML.replace("&Acirc;", "\u00C2");
  strFixedHTML = strFixedHTML.replace("&Atilde;", "\u00C3");
  strFixedHTML = strFixedHTML.replace("&Auml;", "\u00C4");
  strFixedHTML = strFixedHTML.replace("&Aring;", "\u00C5");
  strFixedHTML = strFixedHTML.replace("&AElig;", "\u00C6");
  strFixedHTML = strFixedHTML.replace("&Ccedil;", "\u00C7");
  strFixedHTML = strFixedHTML.replace("&Egrave;", "\u00C8");
  strFixedHTML = strFixedHTML.replace("&Eacute;", "\u00C9");
  strFixedHTML = strFixedHTML.replace("&Ecirc;", "\u00CA");
  strFixedHTML = strFixedHTML.replace("&Euml;", "\u00CB");
  strFixedHTML = strFixedHTML.replace("&Igrave;", "\u00CC");
  strFixedHTML = strFixedHTML.replace("&Iacute;", "\u00CD");
  strFixedHTML = strFixedHTML.replace("&Icirc;", "\u00CE");
  strFixedHTML = strFixedHTML.replace("&Iuml;", "\u00CF");
  strFixedHTML = strFixedHTML.replace("&ETH;", "\u00D0");
  strFixedHTML = strFixedHTML.replace("&Ntilde;", "\u00D1");
  strFixedHTML = strFixedHTML.replace("&Ograve;", "\u00D2");
  strFixedHTML = strFixedHTML.replace("&Oacute;", "\u00D3");
  strFixedHTML = strFixedHTML.replace("&Ocirc;", "\u00D4");
  strFixedHTML = strFixedHTML.replace("&Otilde;", "\u00D5");
  strFixedHTML = strFixedHTML.replace("&Ouml;", "\u00D6");
  strFixedHTML = strFixedHTML.replace("&times;", "\u00D7");
  strFixedHTML = strFixedHTML.replace("&Oslash;", "\u00D8");
  strFixedHTML = strFixedHTML.replace("&Ugrave;", "\u00D9");
  strFixedHTML = strFixedHTML.replace("&Uacute;", "\u00DA");
  strFixedHTML = strFixedHTML.replace("&Ucirc;", "\u00DB");
  strFixedHTML = strFixedHTML.replace("&Uuml;", "\u00DC");
  strFixedHTML = strFixedHTML.replace("&Yacute;", "\u00DD");
  strFixedHTML = strFixedHTML.replace("&THORN;", "\u00DE");
  strFixedHTML = strFixedHTML.replace("&szlig;", "\u00DF");
  strFixedHTML = strFixedHTML.replace("&agrave;", "\u00E0");
  strFixedHTML = strFixedHTML.replace("&aacute;", "\u00E1");
  strFixedHTML = strFixedHTML.replace("&acirc;", "\u00E2");
  strFixedHTML = strFixedHTML.replace("&atilde;", "\u00E3");
  strFixedHTML = strFixedHTML.replace("&auml;", "\u00E4");
  strFixedHTML = strFixedHTML.replace("&aring;", "\u00E5");
  strFixedHTML = strFixedHTML.replace("&aelig;", "\u00E6");
  strFixedHTML = strFixedHTML.replace("&ccedil;", "\u00E7");
  strFixedHTML = strFixedHTML.replace("&egrave;", "\u00E8");
  strFixedHTML = strFixedHTML.replace("&eacute;", "\u00E9");
  strFixedHTML = strFixedHTML.replace("&ecirc;", "\u00EA");
  strFixedHTML = strFixedHTML.replace("&euml;", "\u00EB");
  strFixedHTML = strFixedHTML.replace("&igrave;", "\u00EC");
  strFixedHTML = strFixedHTML.replace("&iacute;", "\u00ED");
  strFixedHTML = strFixedHTML.replace("&icirc;", "\u00EE");
  strFixedHTML = strFixedHTML.replace("&iuml;", "\u00EF");
  strFixedHTML = strFixedHTML.replace("&eth;", "\u00F0");
  strFixedHTML = strFixedHTML.replace("&ntilde;", "\u00F1");
  strFixedHTML = strFixedHTML.replace("&ograve;", "\u00F2");
  strFixedHTML = strFixedHTML.replace("&oacute;", "\u00F3");
  strFixedHTML = strFixedHTML.replace("&ocirc;", "\u00F4");
  strFixedHTML = strFixedHTML.replace("&otilde;", "\u00F5");
  strFixedHTML = strFixedHTML.replace("&ouml;", "\u00F6");
  strFixedHTML = strFixedHTML.replace("&divide;", "\u00F7");
  strFixedHTML = strFixedHTML.replace("&oslash;", "\u00F8");
  strFixedHTML = strFixedHTML.replace("&ugrave;", "\u00F9");
  strFixedHTML = strFixedHTML.replace("&uacute;", "\u00FA");
  strFixedHTML = strFixedHTML.replace("&ucirc;", "\u00FB");
  strFixedHTML = strFixedHTML.replace("&uuml;", "\u00FC");
  strFixedHTML = strFixedHTML.replace("&yacute;", "\u00FD");
  strFixedHTML = strFixedHTML.replace("&thorn;", "\u00FE");
  strFixedHTML = strFixedHTML.replace("&yuml;", "\u00FF");
  strFixedHTML = strFixedHTML.replace("&euro;", "\u20AC");
  strFixedHTML = strFixedHTML.replace("&reg;", "\u00AE");
  strFixedHTML = strFixedHTML.replace("&reg", "\u00AE");
	return strFixedHTML;
}
function globalpopup(strURL,xWidth, yHeight)
{
	var windowSizeSettings = "top=5,width=" + xWidth + ",height=" + yHeight + ",resizable=no";
  window.open(strURL,"",windowSizeSettings);
}
function GoToLink(strLink, IsNewWindow)
{
  if(IsNewWindow==true)
  {
    window.open(strLink);
    return false;
  }
  else
  {
    window.location.href=strLink;
    return false;
  }
}

function validateEmail(obj)
  {
    var src=obj.value;
		//emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[a-zA-Z]$"
		emailReg = "^\\w+([-+.\']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"
		var regex = new RegExp(emailReg);
		if(regex.test(src) == false){
			alert('Please enter a valid email address and try again!');
			obj.focus();
      return false;			
		}
		return true;
	}

function CheckKey()
  {
    if(window.event.keyCode==13)
    {
    window.event.keyCode=0;
    SetEmail();
    }
  }
  function SetEmail()
  {
      var stremail;
      stremail=document.forms[0].txtEmail.value;
      if(stremail=='')
      {
        alert('Please enter email address');
        return false;
      }
      else
      {
        if(validateEmail(document.forms[0].txtEmail)==true)
        {
          UseCallback(stremail,"");
          document.forms[0].txtEmail.value="";
          return false;
        }
      } 
      return false;
  }
  
  function GetMessageFromServer(txtEmail, context){
      alert(txtEmail);
      return false;
    }
  function GoToCategory(intValue)
    {
    if(intValue>0)
      {
      window.location.href='index.aspx?PageAction=VIEWCATG&CatgID=' + intValue;  //args.Value;
      }
    }
  function GoToManufacturer(intValue)
    {
      if(intValue>0)
      {
      window.location.href='index.aspx?PageAction=MFGMAIN&ManfID=' + intValue;  //args.Value;
      }
    }
