function winPop(pageToLoad, winName, width, height, center, scroll, control)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + ","
    + "height=" + height + ","
    + "location=0,"
    + "menubar=0,"
    + "resizable=" + control + ","
    + "resizable=0,"
    + "scrollbars="+scroll+", "
    + "status=0,"
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    newwindow = window.open(pageToLoad,winName,args );
    if (window.focus) {newwindow.focus()}
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
		myfield.form.submit();
		return false;
	}
	else
		return true;
}

function changeLocationInfo(pLocID)
{
	var iID = 99;

	for(var ii = 0; ii < arrLocations.length; ii++)
	{
		if (arrLocations[ii][0] == pLocID)
		{
			iID = ii;
		}
	}
	
	document.forms['propertyform'].Address.value = arrLocations[iID][1].replace('<?>','\r\n');
	document.forms['propertyform'].City.value = arrLocations[iID][2];
	document.forms['propertyform'].County.value = arrLocations[iID][3];
	document.forms['propertyform'].Postcode.value = arrLocations[iID][4];
	document.forms['propertyform'].Country.value = arrLocations[iID][5];
	document.forms['propertyform'].PhoneNumber.value = arrLocations[iID][6];
}

function isNumeric(pValue)
{
	var reNumericExpression = /^[0-9]+$/;
	
	if (pValue.match(reNumericExpression))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function ValidateForm(pForm)
{
	var bValid = true;
	var sTemp = '';
	var dobRegxp;
	
	for (var ii=0; ii < pForm.elements.length; ii++)
   	{   		
   		if ((bValid) && 
   			(pForm.elements[ii].name != "Notes") && 
   			(pForm.elements[ii].name != "DateCompleted") && 
   			(pForm.elements[ii].name != "Image") && 
   			(pForm.elements[ii].name != "Account") && 
   			(pForm.elements[ii].name != "ContainerCode") && 
   			(pForm.elements[ii].name != "Manufacturer") && 
   			(pForm.elements[ii].name != "Width") && 
   			(pForm.elements[ii].name != "Height") && 
   			(pForm.elements[ii].name != "Depth") && 
   			(pForm.elements[ii].name != "Location") && 
   			(pForm.elements[ii].value == ''))
   		{
   			if (pForm.elements[ii].name.indexOf('NewQuantity') == -1)
   			{
				alert('All fields are mandatory and must be filled in - please enter the missing information and re-submit.');
				pForm.elements[ii].focus();
				bValid = false;
				break;
			}
   		}
   		else if ((bValid) && (pForm.elements[ii].name == "RequiredBy"))
   		{
   			//dobRegxp = new RegExp('^([0-9]){2}(\\/|-){1}([0-9]){2}(\\/|-)([0-9]){4}( ){1}([0-9]){2}(:)([0-9]){2}(:)([0-9]){2}$');
   			dobRegxp = new RegExp('^([0-9]){2}([0-9]){2}([0-9]){4}$');
   			if (dobRegxp.test(pForm.elements[ii].value) != true)
			{
				alert('The Date needs to be entered in the following format ddmmyyyy');
				pForm.elements[ii].focus();
				bValid = false;
				break;
			}
   		}   		
   		else if ((bValid) && (pForm.elements[ii].name == "RequiredByTime"))
   		{
   			//dobRegxp = new RegExp('^([0-9]){2}(\\/|-){1}([0-9]){2}(\\/|-)([0-9]){4}( ){1}([0-9]){2}(:)([0-9]){2}(:)([0-9]){2}$');
   			dobRegxp = new RegExp('^([0-9]){4}$');
   			if (dobRegxp.test(pForm.elements[ii].value) != true)
			{
				alert('The Time needs to be entered in the following format hhmm');
				pForm.elements[ii].focus();
				bValid = false;
				break;
			}
   		}   		   		
   		else if ((bValid) && (!isNumeric(pForm.elements[ii].value)))
   		{
   			if ((pForm.elements[ii].name.indexOf('Quantity') != -1)||(pForm.elements[ii].name == 'NumberOfItemsToImport'))
   			{
				if (pForm.elements[ii].name.indexOf('Quantity') != -1)
				{
					sTemp = 'Quantity';
				}
				else
				{
					sTemp = pForm.elements[ii].name;
				}
				
				alert('The field \'' + sTemp + '\' must be a number - please re-enter.');
				pForm.elements[ii].value = '';
				pForm.elements[ii].focus();
				bValid = false;
				break;
			}
   		}
    }
    
    return bValid;
}

function ValidateQuantity(pForm)
{
	var bValid = true;
	
	if  ((bValid) && (pForm.Quantity.value == ''))
	{
		alert('You must enter a Quantity');
		pForm.Quantity.focus();
		bValid = false;
	}
	
	if  ((bValid) && (parseInt(pForm.Quantity.value) > parseInt(pForm.Available.value)))
	{
		alert('The maximum number of items available is ' + pForm.Available.value);
		pForm.Quantity.value='';
		pForm.Quantity.focus();
		bValid = false;
	}	
    
    return bValid;
}

function setQtyFocus()
{
	setTimeout("document.forms['propertyform'].Quantity.focus();",100);
}

/************* INFO BOX *******************/

// Variables
var xMouse                      = 0;
var yMouse                      = 0;
var MyTimeOut;
var iItemMenuWidth              = 400;
var iMenuItemHeight             = 100;

document.onmousedown 			= handleMouseDown;
document.onmousemove 			= handleMouseMove;

function handleMouseMove(e)
{
	getMousePosition();
}

function handleMouseDown(e)
{

}

function adjustXPositionForScreen(pX,pOffset)
{
    return adjustPosition(pX,pOffset,(document.body.clientWidth + document.documentElement.scrollLeft));
}

function adjustYPositionForScreen(pY,pOffset)
{
    return adjustPosition(pY,pOffset,(document.body.clientHeight + document.documentElement.scrollTop));
}

function adjustPosition(pPosition,pOffset,pMax)
{
    var iDiff = ((pPosition + pOffset) - pMax);
    if (iDiff>0)
    {
        pPosition = (pPosition - iDiff);
    }
    return pPosition;
}

function getMousePosition()
{
    xMouse = (event.clientX + document.documentElement.scrollLeft);
    yMouse = (event.clientY + document.documentElement.scrollTop);
}

function ShowInfoBox(pID)
{
    MyTimeOut = setTimeout('ShowBox(' + pID + ');',1500);
}

function ShowBox(pID)
{
    GetItemDetails(pID);
    var theDivStyle         = document.getElementById('InfoBox').style;
    theDivStyle.top         = adjustYPositionForScreen(yMouse,iMenuItemHeight);
    theDivStyle.left        = adjustXPositionForScreen(xMouse,iItemMenuWidth);
    theDivStyle.display  	= 'block';
}

function HideInfoBox()
{
    clearTimeout(MyTimeOut);
    document.getElementById('InfoBox').innerHTML = '<img class="noborder" src="../images/loader.gif" alt=""/>  Loading...';
    var theDivStyle         = document.getElementById('InfoBox').style;
    theDivStyle.display  	= 'none';
}
