function newWindow(nome, pagina, w, h, t, l, scrollAllowed){
 var winW = w
 var winH = h
 var winT = t
 var winL = l

 if (scrollAllowed)
 	s = "scrolling=yes,scrollbars=yes"
 else 
 	s = "scrolling=no,scrollbars=no"
 	
 var properties="statusbar=yes,toolbar=no," + s + ",directories=no,menubar=no,top="+winT+",left="+winL+",width="+winW+",height="+winH+",resizable=no"
 
 var win=window.open(pagina,nome,properties)
//if (win.opener==null)
 win.opener=this
 win.focus()
 return true
 }
 
function email_check(input) {
 pattern = /^[^@ ]+@[^@ ]+\.[^@ \.]+$/ 
 
 return pattern.test(input)
 }
 
function trim(input) {
 while (input.substring(input.length-1,input.length) == ' ')
 	input = input.substring(0, input.length-1)

 while (input.charAt(0) == ' ')
 	input = input.substring(1)

 return input
 }

function checkNum(campo, len) {
 minLen = len.substring(0, len.indexOf("-"))
 maxLen = len.substring(len.indexOf("-")+1)

 if (minLen==maxLen) {
	var pattern = "^[0-9]{" + maxLen + "}$"
	var msgErr = maxLen + " digits long"
	}
 else {
	var pattern = "^[0-9]{" + minLen + "," + maxLen + "}$"
	var msgErr = minLen + " to " + maxLen + " digits"	
	}

 re = new RegExp(pattern)
 
 if (re.test(campo))
	return true 
 else {
 	alert("This field should be numeric (" + msgErr + ")")
 	return false 
 	}
 }

function y2k(number) { 
 return (number < 1000) ? number + 1900 : number; 
 }

function checkDate (day,month,year) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
 }

function isAfterToday(dd, mm, yy) {
 var now = new Date();
 var today = new Date(y2k(now.getYear()), now.getMonth(), now.getDate());
 
 var test = new Date(y2k(yy), parseInt(mm, 10) - 1, dd);
 
 return (test > today)
 }

 
function toPDF(page, tourId) {
	w = newWindow("printwin", "pdfprint.php?page=" + page + "&id=" + tourId, 784, 450, 80, 20, true);
}

function printPage() {
	w = newWindow("printwin", "printable.html", 784, 450, 80, 20, true);
}