var PopupWindow = ""

//************************************************************************************************
function OpenPopUp(windowsname,address,width,height,scrollbars,resizable)
{
	var w = 480, h = 340;
		
	if (document.all || document.layers)
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	
	var popW = width, popH = height;
	
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	if(PopupWindow)
	{
		if(!PopupWindow.closed)
		{
			PopupWindow.close();
		}
	}
	PopupWindow = window.open(address, windowsname,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',status=0,toolbar=0,location=0,menubar=0,directories=0');
	PopupWindow.focus();
}

//************************************************************************************************
function funcValidate(strField,strFieldLimitation)
{
	if(!strField) return false;
	var Chars = strFieldLimitation
	
	for (var i = 0; i < strField.length; i++)
	{
		if (Chars.indexOf(strField.charAt(i)) == -1)
		{
			alert("Please enter number field");
			return false;
		}
	}	
}
//************************************************************************************************
function defaultFocus()
{
	if (document.forms[0][0])
			document.forms[0][0].focus();
}

//************************************************************************************************
function funcValidate(strField,strFieldLimitation)
{
	if(!strField) return false;
	var Chars = strFieldLimitation
	
	for (var i = 0; i < strField.length; i++)
	{
		if (Chars.indexOf(strField.charAt(i)) == -1)
		{
			alert("Please enter number field");
			return false;
		}
	}	
}

//**************************************************************************************************************
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var reason = '';

//**************************************************************************************************************
function isValidDate (myDate,sep) {
// checks if date passed is in valid dd/mm/yyyy format

    if (myDate.length == 10) {
        if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
            var date  = myDate.substring(3,5);
            var month = myDate.substring(0,2);
            var year  = myDate.substring(6,10);

            var test = new Date(year,month-1,date);

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
                reason = '';
                return true;
            }
            else {
                reason = 'valid format but an invalid date';
                return false;
            }
        }
        else {
            reason = 'invalid spearators';
            return false;
        }
    }
    else {
        reason = 'invalid length';
        return false;
    }
}

//**************************************************************************************************************
function tellMeIfInvalid(myDate) {
    if (isValidDate(myDate,'/'))
	{
		return true;
	}
    else
	{
        return false;
	}
		
}
