function iframeResize(iframeWindow) {
	var iframeElement = parent.document.getElementById(iframeWindow.name);
	if (iframeWindow.document.height) {
		iframeElement.style.height = iframeWindow.document.height + 35 +'px';
		iframeElement.style.width = window.document.width + 5 + 'px';
	}
	else if (iframeWindow.document.documentElement.scrollHeight) {
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 35 + 'px';
			iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
	}
}

function writeDateTime() {
	var currentDate = new Date();
	var day = currentDate.getDate();
	var month = currentDate.getMonth() + 1;
	var year = currentDate.getFullYear();
	var hours = currentDate.getHours();
	var minutes = currentDate.getMinutes();
	if (minutes < 10)
		minutes = "0" + minutes;
	var suffix = "AM";
	if (hours >= 12) {
		suffix = "PM";
		hours = hours - 12;
	}
	if (hours == 0) {
		hours = 12;
	}
	document.write(day + "/" + month + "/" + year + "  " + hours + ":" + minutes + " " + suffix);
}

function writeDate() {
	var currentDate = new Date();
	var day = currentDate.getDate();
	var month = currentDate.getMonth() + 1;
	var year = currentDate.getFullYear();
	document.write(day + "/" + month + "/" + year);
}

// Date Validation
var cDate = new Date();
var minYr = cDate.getFullYear() - 95;
var maxYr = cDate.getFullYear() + 1;
var dtCh= "/";

function isNum(s) {
    // checks to see all chars are digits
    var i;
    for (i = 0; i < s.length; i++) {   
	// Check that current character is number.
	var c = s.charAt(i);
	if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripSeparators(s, sep) {
    // returns a string containig all chars NOT in sep
    var i;
    var rc = "";
    for (i = 0; i < s.length; i++) {   
	var c = s.charAt(i);
	if (sep.indexOf(c) == -1) rc += c;
    }
    return rc;
}

function daysInFeb (year) {
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function daysArray(year) {
	for (var i = 1; i <= 12; i++) {
		this[i] = 31;
		if (i == 2) {
			this[i] = daysInFeb(year);
		}
		else if (i==4 || i==6 || i==9 || i==11) {
			this[i] = 30;
		}
	}
	return this;
}

function isDate(dtStr, year) {
	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);

	if (dtStr == "")
		return true;
	if (dtStr == "+25" || dtStr == "25+")
		return true;
	if (dtStr == "+40" || dtStr == "40+")
		return true;

	// use MySQL 2 digit year interpretation
	var year = parseInt(strYear);
	if (strYear.length == 2) {
		year = parseInt(strYear);
		if (year < 70) {
			strYear = "20" + strYear;
		} else {
			strYear = "19" + strYear;
		}
	}
	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);

	var daysInMonth = daysArray(year);

	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 for this date");
		return false;
	}
	if (strDay.length < 1 || day > daysInMonth[month]) {
		alert("please enter a valid day for this date");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYr || year>maxYr) {
		alert("please enter a valid 4 digit year between "+minYr+" and "+maxYr);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isNum(stripSeparators(dtStr, dtCh))==false) {
		alert("please enter a valid date");
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg) {
	var numericExpression = /^[0-9]+$/;
	if(elem.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}
}

function isAlphabet(elem, helperMsg) {
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}
}

function isAlphaNumeric(elem, helperMsg) {
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}
}

function isValidEmail(elem, helperMsg) {
	var emailExp = /^[a-zA-Z0-9\-\.\+\_]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,5}$/;
	if(elem.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}
}

function dow1(w1) {
	return document.write(w1);
}

function dow2(w1, w2) {
	return document.write(w1 + w2);
}

function dow3(w1, w2, w3) {
	return document.write(w1 + w2 + w3);
}

function noenter() {
	return !(window.event && window.event.keyCode == 13);
}

