function isNumFunction(Val){
	var i;

	if (Val != ""){
		for (i=0;i<Val.length;i++){
			if (Val.charAt(i)>="0" && Val.charAt(i)<="9")
				continue;
			switch (Val.charAt(i))
			{
				case " " :
				case "(" :
				case ")" :
				case "+" :
				case "-" :
				case "." :
				case "," :
				case ":" :
				case "/" :
				case "$" :
					continue;
			}
			return false;
		}
	}
	return true;
}

var MsgArray = new Array(
	"Warning: changing the status of an order to CANCELED is irreversible.If you are not sure, we suggest placing the order ON HOLD.\n Are you sure you want to proceed?")

var idxMsg;
var sWidth = "";
var sHeight = "";
var popupReturnValue = "";

var Nav4 = (document.all) ? false : true;
var dialogWin = new Object()

function mdOpen(idx,paramwidth,paramheight,b1Label,b2Label,b3,b3Label,b3Action,Title,Img,ctrl,a1,a2){
		idxMsg = idx;
		sWidth = paramwidth;
		sHeight = paramheight;
		if (typeof(a1)=='undefined' && typeof(ctrl)=='undefined') a1=true;
		if (typeof(a2)=='undefined') a2=false;
		oArguments = new _ArgumentsArray(b1Label,b2Label,b3,b3Label,b3Action,Title,Img,ctrl,a1,a2)
		if(Nav4){
			openDialog(sWidth,sWidth,oArguments);
		}
		else{
			p= window.showModalDialog("ModalContent.htm",oArguments,_MDSetFeatures())
			popupReturnValue=p;
			if(popupReturnValue=="button")eval(b3Action);
			if (popupReturnValue==true || popupReturnValue==false || typeof(a1)=='undefined') return popupReturnValue;
			else rtn(popupReturnValue);
		}
}
function openDialog(width, height, args) {
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
		// Initialize properties of the modal dialog object.
		dialogWin.returnFunc = retFunc;
		dialogWin.returnedValue = "";
		dialogWin.args = args;
		dialogWin.url = "ModalContent1.htm"
		dialogWin.width = width;
		dialogWin.height = height;
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		dialogWin.name = (new Date()).getSeconds().toString()
		// Assemble window attributes and try to center the dialog.
		// Generate the dialog and make sure it has focus.
		dialogWin.left = window.screenX +
			   ((window.outerWidth - dialogWin.width) / 2)
			dialogWin.top = window.screenY +
			   ((window.outerHeight - dialogWin.height) / 2)
			var attr = "screenX=" + dialogWin.left +
			   ",screenY=" + dialogWin.top + ",resizable=no,width=" +
			   dialogWin.width + ",height=" + dialogWin.height
		dialogWin.win=window.open(dialogWin.url, dialogWin.name,attr)
		dialogWin.win.focus()
	} else {
		dialogWin.win.focus()
	}
}

function retFunc(){
	rtn(dialogWin.returnedValue);
}

function rtn(val){
	if(typeof(val)=='string' && (val.indexOf('main.asp')==0 || val.indexOf('admin.asp')==0)){
		document.location=val;
	}
	else eval(val); //execute Action
}

function blockEvents() {
	window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
	window.onclick = deadend
	window.onfocus = checkModal
}

//Nav4 As dialog closes, restore the main window's original event mechanisms.
function unblockEvents() {
	window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
	window.onclick = null
	window.onfocus = null
}

function deadend() {
	if (dialogWin.win && !dialogWin.win.closed) {
		dialogWin.win.focus()
		return false
	}
}

// Invoked by onFocus event handler of EVERY frame, return focus to dialog window if it's open.
function checkModal() {
	if (dialogWin.win && !dialogWin.win.closed) dialogWin.win.focus()
}

function _MDSetFeatures(){
	var sContent = MsgArray[idxMsg]
	sHeight = (sHeight!="" || isNaN(parseInt(sHeight)))?sHeight:"150" //Math.floor(sContent.length/2)
	sWidth = (sWidth!="" || isNaN(parseInt(sWidth)))?sWidth:"250"
	if(navigator.appVersion.indexOf("Windows NT 5.1")>-1 || window.screen.height>=1024){sHeight= parseInt(sHeight) + 40; sWidth=parseInt(sWidth) + 40;}

    var sFeatures="dialogHeight: " + sHeight + "px;";
	sFeatures +="dialogWidth: " + sWidth + "px;";

	sFeatures +=" resizable:yes;"
	sFeatures +=" status:no;"
	sFeatures +=" scroll:no;"
	sFeatures +=" menubar=no,"
	sFeatures +=" modal=yes"
	return sFeatures;
}

function _ArgumentsArray(b1Label,b2Label,b3,b3Label,b3Action,Title,Img,ctrl,a1,a2){
	this.msg=(isNumFunction(idxMsg))?MsgArray[idxMsg]:idxMsg;
	this.button1 = b1Label
	this.button2 = b2Label
	this.button3 = b3
	this.label = b3Label
	this.action = b3Action
	this.Title = Title
	this.Img = Img
	this.ctrl = ctrl
	this.action1 = a1;
	this.action2 = a2
}

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_showHideLayers() { //v3.0

 var i,p,v,obj,args=MM_showHideLayers.arguments;
 try{oVal= eval("document.all.hdn" + args[0]); oVal.value=args[2];} //store Layer condition(show/hide)
  catch(e){}
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
	v=args[i+2];
		if (obj.style.visibility){
			obj.style.visibility=(v=='show')?'visible':'hidden';
		}
		else obj.style.display=(v=='show')?'':'none';
	}
}

function RequiredFlds(){
	var sRtn="";
	for(i=1; i<300; i++){
		try{
			ctrl=eval("document.getElementById('Verify" + i + "')")
			if(ctrl.value==''){
				var ctrName=ctrl.className!=''?ctrl.className:ctrl.name;
				alert("Please, enter " + ctrName + "!")
				ctrl.focus();
				sRtn="stop";
				break;
			}
		}
		catch(e){}
	}
	return sRtn;
}

function newwin(sHREF,width){
win2=window.open(sHREF,'lbl','width=' + width + ',height=350,toolbar=no,location=no,directories=no,menubar=no,resizable=no,scrollbars=yes,status=no, left=125, top=175');
win2.creator=self;
}

var keyActions = new Array ();

keyActions [0] = {character:  "m",
                  actionType: "link",
                  param:      "admin.asp?uri=2400"}; //main menu

keyActions [1] = {character:  "h",
                  actionType: "link",
                  param:      "home.asp?uri=1000"}; //home

var serverName="";
var pressedChr="";

// End of user defined array
function hotKeys (event,code) {

  // Get details of the event dependent upon browser
  event = event ? event : window.event ? window.event : null;

  // We have found the event.
  if (event) {
    // Hotkeys require that either the control key or the alt key is being held down

    if (event.ctrlKey && event.altKey) {
      // Pick up the Unicode value of the character of the depressed key.
      var charCode = (event.charCode) ? event.charCode : ((event.which) ? event.which : event.keyCode);
      // Convert Unicode character to its lowercase ASCII equivalent

      var myChar = String.fromCharCode (charCode).toLowerCase();
	  if (myChar=='t')delay(50,myChar);
	  if(myChar!='t' && pressedChr!=''){myChar=pressedChr + '' + myChar; pressedChr='';}

      // Convert it back into uppercase if the shift key is being held down
      if (event.shiftKey) {myChar = myChar.toUpperCase();}

      // Now scan through the user-defined array to see if character has been defined.
      for (var i = 0; i < keyActions.length; i++) {

        // See if the next array element contains the Hotkey character
        if ((keyActions[i].character == myChar || keyActions[i].character =='ch' + charCode) && keyActions[i].param!='') {

          // Yes - pick up the action from the table
          var action;

          // If the action is a hyperlink, create JavaScript instruction in an anonymous function
          if (keyActions[i].actionType.toLowerCase() == "link") {
            action = new Function ('location.href  ="' + serverName + keyActions[i].param + '"');
          }

          // If the action is JavaScript, embed it in an anonymous function
          else if (keyActions[i].actionType.toLowerCase()  == "code") {
			var param=keyActions[i].param;
			if (param.indexOf('javascript:')>-1) param = param.substr(11); //take away javascript: from action and fix xslt smbs
			var regex = new RegExp('&amp;', "g"); param = param.replace(regex,'&');

			if (typeof(code)!='undefined') action = new Function(code);
			else  action = new Function (param);
          }

          // Error - unrecognised action.
          else {
            alert ('Hotkey Function Error: Action should be "link" or "code"');
            break;
          }

          // At last perform the required action from within an anonymous function.
          action ();

          // Hotkey actioned - exit from the for loop.
          break;
        }
      }
    }
	else if (!event.ctrlKey && !event.altKey){ //other key pressed
		var targ;
		if (event.target) targ = event.target; //netscape
		else if (event.srcElement) targ = event.srcElement; //IE
		if (typeof(targ.type)!='undefined'){ g_bIsDirty=true;}
	}
  }
}

function delay(gap,myChar){ /* gap is in millisecs */
var then,now; then=new Date().getTime();
now=then;
pressedChr=myChar;
while((now-then)<gap)
{now=new Date().getTime();}
}

keyActions [0] = {character:  "m",
                  actionType: "link",
                  param:      "admin.asp?uri=2400"}; //main menu

function keyAct(chr,act, actionType){
	if (typeof(actionType)=='undefined') actionType="code";
	var found = false;
	for (var i = 0; i < keyActions.length; i++){
		if (keyActions[i].character==chr){
			found=true;
			keyActions[i].param = act;
			keyActions[i].actionType = actionType;
		}
	}
	if (!found){
		i= keyActions.length ;
		keyActions [i] = {character:  chr,
	                  actionType: actionType,
		              param:      act};
	}
}

//Swap functions

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //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_preloadImages() { //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_preloadImages.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_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];}
}

