function Point(strImage)
{
	//--- Make the cursor a hand for the item passed in.
	window.document.all(strImage).className = "Point";
}

function DontPoint(strImage)
{
	//--- Make the cursor normal for the item passed in.
	window.document.all(strImage).className = "DontPoint";
}

function DisplayItem(strImage, strDiv)
{
	var strDisplay;
	if (document.getElementById)	{
		//--- Check if the DIV is already displayed
		if (window.document.getElementById(strDiv).style.display == "none")	{
			//--- We need to display the DIV
			strDisplay = "";
			//--- And we need to change the image to the MINUS
			window.document.getElementById(strImage).src = "/images/minus.gif";
		} else	{
			//--- We need to hide the DIV
			strDisplay = "none";
			//--- And we need to change the image to the PLUS
			window.document.getElementById(strImage).src = "/images/plus.gif" ;
		}
		window.document.getElementById(strDiv).style.display = strDisplay;
	} else {
		//--- Check if the DIV is already displayed
		if (window.document.all.strDiv.style.display == "none")	{
			//--- We need to display the DIV
			strDisplay = "";
			//--- And we need to change the image to the MINUS
			window.document.all.strImage.src = "/images/minus.gif";
		} else	{
			//--- We need to hide the DIV
			strDisplay = "none";
			//--- And we need to change the image to the PLUS
			window.document.all.strImage.src = "/images/plus.gif" ;
		}
		window.document.all.strDiv.style.display = strDisplay;
	}
}
var alpha = new RegExp("[a-zA-Z]");
var digit = new RegExp("/^([ +-])*\d*(\.|,)*\d*$/");
var truecount=0;
var PatternsDict = new Object();

PatternsDict.timePat = /^\d{2}:\d{2}$/;  // matches 12:34 but also 75:83
PatternsDict.timePat2=/^([1-9]|1[0-2]):[0-5]\d$/;  // matches 5:04 or 12:34 but not 75:83
PatternsDict.numeric=/^[ +-]*\d*(\.|,)*\d*$/;  //

PatternsDict.DatePat1=/\d{1,2}[-\/. ]\d{1,2}[-\/. ]\d{2}$/; 			// matches 01-12-99 using -\/.or space as separators
PatternsDict.DatePat2=/\d{1,2}[-\/. ]\d{1,2}[-\/. ]\d{4}$/;			// matches 01-12-1999
PatternsDict.DatePat3=/\d{1,2}[-\/. ][A-Za-z0-9_äÄ]{3}[-\/. ]\d{2}$/;	// matches 01-jan-99
PatternsDict.DatePat4=/\d{1,2}[-\/. ][A-Za-z0-9_äÄ]{3}[-\/. ]\d{4}$/;	// matches 01-jan-1999
PatternsDict.DatePat5=/\w{3}[-\/. ]\d{1,2}[-\/. ]\d{2}$/;				// matches jan-01-99
PatternsDict.DatePat6=/\w{3}[-\/. ]\d{1,2}[-\/. ]\d{4}$/;				    // matches jan-01-1999
PatternsDict.DatePat7=/\d{1,2}[-\/. ][A-Za-z0-9_äÄ]{3,}[-\/. ]\d{4}$/;	// matches 01-january-1999
PatternsDict.DatePat8=/\d{1,2}[-\/. ][A-Za-z0-9_äÄ]{3,}[-\/. ]\d{2}$/;	// matches 01-january-99

function matchPattern(value,Pattern)
{
	var thePat = PatternsDict[Pattern];     // select the validating regular expr
	var gotIt = thePat.exec(value);   // run it on value of elArr[i]
	return gotIt
}

var monVal=new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

var emonth="JAN.FEB.MAR.APR.MAY.JUN.JUL.AUG.SEP.OCT.NOV.DEC.";
var dmonth="JAN.FEB.MÄR.APR.MAI.JUN.JUL.AUG.SEP.OKT.NOV.DEZ.";


function getDateString(value)
{
	var theDay,theMonth,theYear
	if (matchPattern(value,"DatePat2") || matchPattern(value,"DatePat1")) { // dates dd.mm.yy or dd.mm.yyyy
		var re = /[-\/. ]/;
		var ss = value.split(re);
		theDay=parseInt(ss[0]);
		theMonth=parseInt(ss[1]);
		theYear=parseInt(ss[2]);
		validDateNumeric(theDay,theMonth,theYear);
		return theDay+"-"+theMonth+"-"+theYear;
	} else if (matchPattern(value,"DatePat4") ||matchPattern(value,"DatePat3")||
	matchPattern(value,"DatePat7")||matchPattern(value,"DatePat8")) {
		var re = /[-\/. ]/;
		var ss = value.split(re);
		theDay=parseInt(ss[0]);
		var month=ss[1].substring(0,3);
		theYear=parseInt(ss[2]);
		theMonth = ConvMonthString(month);
		validDateNumeric(theDay,theMonth,theYear);
		return theDay+"-"+theMonth+"-"+theYear;
	}
	return''; // blank string
}



function validDateNumeric(day,month,year)
{
	var monthdays;

	if (isNaN(year)) {
		return false;
	}

	if (isNaN(month) || month < 1 || month > 12) {
		return false;
	}
	switch (month) {
		case 2:
		if (year%4 != 0)
		monthdays=28;
		else if  (year%400 == 0)
		monthdays=29;
		else if (year%100 == 0)
		monthdays=28;
		else
		monthdays=29;
		break;
		case 4:
		case 6:
		case 9:
		case 11:
		monthdays=30;
		break;
		default:
		monthdays=31;
	}
	if (isNaN(day) || day < 1 || day > monthdays) {
		return false;
	}
	return true;
}

function validDateString(day,month,year)
{
	var theMonth= emonth.indexOf(month.toUpperCase( )+".");
	if (theMonth== -1) {
		theMonth= dmonth.indexOf(month.toUpperCase( )+".");
		if (theMonth== -1) {
			return false;
		}
	}
	theMonth=theMonth/4 + 1;
	return validDateNumeric(day,theMonth,year);
}

function IsDate(value)
{
	if (matchPattern(value,"DatePat2") || matchPattern(value,"DatePat1")) { // dates dd.mm.yy or dd.mm.yyyy
		var re = /[-\/. ]/;
		var ss = value.split(re);
		var day=parseInt(ss[0]);
		var month=parseInt(ss[1]);
		var year=parseInt(ss[2]);
		return validDateNumeric(day,month,year);
	} else if (matchPattern(value,"DatePat4") ||matchPattern(value,"DatePat3")||
	matchPattern(value,"DatePat7")||matchPattern(value,"DatePat8")) {
		var re = /[-\/. ]/;
		var ss = value.split(re);
		var day=parseInt(ss[0]);
		var month=ss[1].substring(0,3);
		var year=parseInt(ss[2]);
		return validDateString(day,month,year);
	}
	return false;
}
function valid(){
	if (document.layers||document.all) {
//		var truthBeTold = window.confirm("Do you wish to send the survey?");
//		if (!truthBeTold) {
//			return false;
//		}
		form=document.forms['phpesp_response'];
		for (i=0; i<form.elements.length; i++ ) {
			if ("validator" in form.elements[i]) {
				fieldname=form.elements[i].valfname;
				switch(form.elements[i].validator) {
					case "Date":
					ddate=form.elements[i].value;
					if (ddate=='') continue;
					if(!IsDate(ddate)){
						alert(fieldname+" is not a valid date format");
						form.elements[i].focus();
						return false;
					} else {
						form.elements[i].value=getDateString(ddate);
					}
					break;
					case "Numeric":
					nums=form.elements[i].value ;
					if (nums=='') continue;
					if(!matchPattern(nums,"numeric")){
						alert(fieldname+" is a number only field, e.g. 1000.00 -3.4 no thousands separator");
						form.elements[i].focus();
						return false;
					}
					break;
				}
			}
		}
	}
	return true;
}
