//Write out the standard JavaScript used for opening Windows and auto-selecting combo boxes.
function AutoCombo( myselect )
	{
    if(myselect.selectedIndex != 0)
        	{
            document.frmCombo.submit();
        	}
	}

function AutoComboAll( myselect )
   	{
       document.frmCombo.submit();
   	}

function AutoCurrency( myselect )
   	{
       document.frmCurrency.submit();
   	}

function OpenItemPopUp(ItemCode, ImageWidth, ImageHeight)
	{
	var popupURL = "itempopup.asp?item=" + ItemCode + "&style=0";

	var popup = window.open(popupURL,"ItemDetail",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=' + (ImageWidth + 40) + ',height=' + (ImageHeight + 40));
	}

function OpenHelpPopUp(PageId)
	{
	var popupURL = "help.asp?pageid=" + PageId;
	var popup = window.open(popupURL,"OnlineHelp",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=300,height=400,z-lock=yes');
	}

function OpenPopUp(PopupURL, PopUpWidth, PopUpHeight)
	{
	var screenLeft = (screen.width / 2) - (PopUpWidth / 2);
	var screenTop = screen.height / 2 - (PopUpHeight / 2);
	
	var popup = window.open(PopupURL,"PopUp",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,width=' + PopUpWidth + ',height=' + PopUpHeight + ',z-lock=yes,left=' + screenLeft + ',top=' + screenTop);
	popup.focus();
	}

function OpenScrollingPopUp(PopupURL, PopUpWidth, PopUpHeight)
	{
	var screenLeft = (screen.width / 2) - (PopUpWidth / 2);
	var screenTop = screen.height / 2 - (PopUpHeight / 2);
	
	var popup = window.open(PopupURL,"PopUp",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=' + PopUpWidth + ',height=' + PopUpHeight + ',z-lock=yes,left=' + screenLeft + ',top=' + screenTop);
	popup.focus();
	}

function OpenModalPopUp(PopupURL, PopUpWidth, PopUpHeight)
	{
	var screenLeft = (screen.width / 2) - (PopUpWidth / 2);
	var screenTop = screen.height / 2 - (PopUpHeight / 2);
	
	var popup = window.open(PopupURL, 'PopUp','titlebar=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,width=' + PopUpWidth + ',height=' + PopUpHeight + ',z-lock=yes,left=' + screenLeft + ',top=' + screenTop);
//	var popup = window.showModalDialog(PopupURL, '','unadorned: yes; status: no; resizable: no; dialogWidth: ' + PopUpWidth + '; dialogHeight: ' + PopUpHeight);
	popup.focus();
	}

function OpenCheckout(SiteId)
	{
	var popupURL = "checkout1.asp?siteid=" + SiteId;
	var popup = window.open(popupURL,"Checkout",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,left=100,top=100,width=550,height=400,z-lock=yes');
	}

function ClosePopUp()
{
	close();
}

function ImageRestore()
{
  var i;
  var x;
  var a=document.MM_sr;

  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
  	x.src=x.oSrc;
}

function ImagePreload()
{
	var d=document;
	
	if(d.images)
		{
		if(!d.MM_p) d.MM_p=new Array();
	
			var i;
			var j=d.MM_p.length;
			var a=ImagePreload.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 ImageFindObject(n, d)
{
  var p;
  var i;
  var 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=ImageFindObject(n,d.layers[i].document); return x;
}

function ImageSwap()
{
	var i;
	var j=0;
	var x;
	var a=ImageSwap.arguments;

	document.MM_sr=new Array;
	for (i=0;i<(a.length-2);i+=3)
		if ((x=ImageFindObject(a[i]))!=null)
			{
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
			}
}
// Function to generate an alert and refresh the parent page
function alertTimeOut()
{
    var date = new Date();
    var hours = "";
    var minutes = "";
    
    if (date.getHours() > 12 ) {
        hours = date.getHours() - 12;
    }
    else {
        hours = date.getHours();
    }
    
    if (date.getMinutes() < 10) {
        minutes = "0" + date.getMinutes();
    }
    else {
        minutes = date.getMinutes();
    }
    
    if (confirm("Time: " + hours + ":" + minutes + "\n\n" + 
                "Your Session will expire in two minutes. \n\n" + 
                "Click OK to refresh the current page and renew your session.\n" +
                "Clicking Cancel will allow you to continue your work on the current page,\n" +
                "but your session may expire.")) {
        window.location.reload();
    }
}

function WindowResize(parNewWidth, parNewHeight)
{
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		document.body.clientWidth = parNewWidth;
		document.body.clientHeight = parNewHeight;
	}
	else return;
}

//by Malachy Magennis: mal_bmx@hotmail.com
//submitted and presented on A1 javaScripts: www.a1javascripts.com
function TB_animateWindow(windowWidth, windowHeight, targetWidth, targetHeight, widthMod, heightMod, fullScreen)
{
	if (fullScreen)
		{
		targetWidth = screen.availWidth;
		targetHeight = screen.availHeight;
		}
	if (windowWidth < targetWidth) windowWidth += widthMod;
	if (windowHeight < targetHeight) windowHeight += heightMod;
	windowLeft = (screen.availWidth / 2) - (windowWidth / 2);
	windowTop = (screen.availHeight / 2) - (windowHeight / 2);
	top.window.resizeTo(windowWidth, windowHeight);
	top.window.moveTo(windowLeft, windowTop);
	if (windowWidth < targetWidth || windowHeight < targetHeight)
	setTimeout('TB_animateWindow(' + windowWidth + ', ' + windowHeight + ', ' + targetWidth + ', ' + targetHeight + ', ' + widthMod + ', ' + heightMod + ', ' + fullScreen + ');', 10);
}

function submitonce(theform, act, par_GridFormName)
{

	// Display the loading message once we've submit the form
	ShowLoadingPage();

	//if IE 4+ or NS 6+
	if (document.all||document.getElementById)
	{
		//screen thru every element in the form, and hunt down 'submit' and 'reset'
		theform.act.value=act;
		theform.submit();
		for (i=0;i<theform.length;i++)
			{
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="button")
			//disable em
			tempobj.disabled=true
			}
	}
}

function confirmdelete(theform, par_GridFormName)
	{
	if (confirm("Are you sure you wish to delete this record?"))
		{
		submitonce(theform, 'delete', par_GridFormName);
		return true;
		}
	}

function confirmmutipledelete(theform, par_GridFormName)
	{
	if (confirm("Are you sure you wish to delete all the selected records?"))
		{
		submitonce(theform, 'delsel', document.par_GridFormName);
		return true;
		}
	}

function datePlus (dateYear, dateMonth, dateDay)
{
	var currentDate = new Date();
	
	// Load the date operator with the current date
	currentDate.setYear(dateYear.value);
	currentDate.setMonth(dateMonth.value);

	// Increment the current date by one day
	currentDate.setDate(Math.abs(dateDay.value) + 1);

	// Now set the field values to the new date values
	dateYear.value = currentDate.getYear();
	dateMonth.value = currentDate.getMonth();
	dateDay.value = currentDate.getDate();
}

function dateMinus (dateYear, dateMonth, dateDay)
{
	var currentDate = new Date();
	
	// Load the date operator with the current date
	currentDate.setYear(dateYear.value);
	currentDate.setMonth(dateMonth.value);

	// Increment the current date by one day
	currentDate.setDate(Math.abs(dateDay.value) - 1);

	// Now set the field values to the new date values
	dateYear.value = currentDate.getYear();
	dateMonth.value = currentDate.getMonth();
	dateDay.value = currentDate.getDate();
}

function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function isNumberString (InString)
{
	if(InString.length == 0) return (false);

	var RefString="1234567890";

	for (Count = 0; Count < InString.length; Count++)
		{
		TempChar = InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
		return (false);
		}
	return (true);
}

function HideLoadingPage()
	{
	this.document.getElementById("loaderContainer").style.display = "none";
	}
function ShowLoadingPage()
	{
	this.document.getElementById("loaderContainer").style.display = "";
	}
function goto_url(url)
	{
	ShowLoadingPage();
	this.location.href = url;
	}

