var popUp; 
var valid = true;
var tempX=0;
var tempY=0;
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);

function addedOnLoad()
	{
		//document.onmousemove = getMouseXY;
		document.onmousedown = getMouseXY;
	}
document.onLoad = addedOnLoad()


function OpenCalendar(idname, postBack,formid,referto)
{

	if(typeof(referto)=="undefined")
	referto = "";
	else
	referto = document.getElementById(referto).value;
	popUp = window.open('/popcalendar.aspx?formname=' + formid + 
		'&id=' + idname + '&selected=' + document.getElementById(idname).value + '&postBack=' + postBack+'&refferer='+referto, 
		'popupcal', 
		'titlebar=0,width=185,height=185,left='+tempX+',top='+tempY);
	//alert(tempX+" "+tempY);
	popUp.focus();
}
function getMouseXY(e) {
  if (IE)
 	{ // grab the x-y pos.s if browser is IE
	if (document.body){    
		    //tempX = event.clientX + document.body.scrollLeft
		    //tempY = event.clientY + document.body.scrollTop
		    tempX = event.screenX;
		    tempY = event.screenY;
		}
	}
	 else 
	{  // grab the x-y pos.s if browser is NS
	    //tempX = e.pageX
	    //tempY = e.pageY
	    tempX = e.screenX;
	    tempY = e.screenY;
	}  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  if (tempX > 200){tempX = tempX-150}
    
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
}
function SetDate(formId, id, newDate, postBack)
{
	eval('var theform = document.getElementById(formId);');
	popUp.close();
	document.getElementById(id).value = newDate;
	if (postBack)
		__doPostBack(id,'');
}

function IsEmpty(field)
{
	if(field.value=="")
	{
	alert("Number of people can not be empty!");
	field.focus();
	return false;
	}
	
	return true;
}

function IsEmptyDate(field)
{
	if(field.value=="")
	{
	alert("Date can not be empty!");
	field.focus();
	return false;
	}
	
	return true;
}

function ValidateDates(df, dt,filed)	
{
	if(!IsEmpty(filed))
	return false;
	
	if(!IsEmptyDate(df))
	return false;
	
	if(!IsEmptyDate(dt))
	return false;
	
	//return date.getFullYear()+'-'+parseInt(date.getMonth()+1)+'-'+date.getDate();
	var dateFrom = new Date(df.value.substring(6,10),parseInt(df.value.substring(3,5)-1),df.value.substring(0,2));
	var dateTo = new Date(dt.value.substring(6,10),parseInt(dt.value.substring(3,5)-1),dt.value.substring(0,2));
	
	check_date(df);
	if(!valid)
	return false;
	
	check_date(dt);
	if(!valid)
	return false;
	
	//isDate(dateFrom);
	//isDate(dateTo);
	
	if(Date.parse(dateFrom)>=Date.parse(dateTo))
	{
		valid = false;
		alert("Date is incorrect!");
	}
	return valid;
}

function check_date(field)
{
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
       valid = true;
   }
   /* Error-message if err != 0 */
   else {
      alert("Date is incorrect!");
      DateField.select();
	  DateField.focus();
	  valid = false;
   }
}
function isDate(dtStr){
     var daysInMonth = DaysArray(12)
     var pos1=dtStr.indexOf(dtCh)
     var pos2=dtStr.indexOf(dtCh,pos1+1)
     var strDay=dtStr.substring(0,pos1)
     var strMonth=dtStr.substring(pos1+1,pos2)
     var strYear=dtStr.substring(pos2+1)
     strYr=strYear
     if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
     if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
     for (var i = 1; i <= 3; i++) {
          if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
     }
     month=parseInt(strMonth)
     day=parseInt(strDay)
     year=parseInt(strYr)
     if (pos1==-1 || pos2==-1){
          alert("The date format should be : dd/mm/yyyy")
          return false
     }
     if (strMonth.length<1 || month<1 || month>12){
          alert("Please enter a valid month")
          return false
     }
     if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
          alert("Please enter a valid day")
          return false
     }
     if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
          alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
          return false
     }
     if (year==2004 && month==1 && day<4){
          alert("Please enter a valid date greater than 03/01/2004 ; date - "+day+"/"+month+"/"+year+" no good")
          return false
     }
     if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
          alert("Please enter a valid date")
          return false
     }
return true
}


