var emailregexp = /^[\w\-\.]+@([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)*[a-zA-Z0-9]+-{0,1}[a-zA-Z0-9]+(-{0,1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,4}$/;
var daysInMonth = new Array();
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;   // must programmatically check this
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;


function chkForm(frmname,lang) {
	return checkForm(frmname);
}

function checkForm(){
	var frm = document.forms['tx_mpcontactform_pi1'];
	if(frm["tx_mpcontactform_pi1[message]"]){
		if (frm["tx_mpcontactform_pi1[message]"].value == "") {
			alert(messages[0]);
			frm["tx_mpcontactform_pi1[message]"].focus();
			return false;
		}
	}
	if(frm["tx_mpcontactform_pi1[firstname]"]){
		if (frm["tx_mpcontactform_pi1[firstname]"].value == "") {
			alert(messages[1]);
			frm["tx_mpcontactform_pi1[firstname]"].focus();
			return false;
		}
	}
	if(frm["tx_mpcontactform_pi1[lastname]"]){
		if (frm["tx_mpcontactform_pi1[lastname]"].value == "") {
			alert(messages[2]);
			frm["tx_mpcontactform_pi1[lastname]"].focus();
			return false;
		}
	}
	if(frm["tx_mpcontactform_pi1[email]"]){
		if(frm["tx_mpcontactform_pi1[email]"].value=="" || !frm["tx_mpcontactform_pi1[email]"].value.match(emailregexp)){
			alert(messages[3]);
			frm["tx_mpcontactform_pi1[email]"].focus();
			return false;
		}
	}
	if(frm["tx_mpcontactform_pi1[country]"]){
		if (frm["tx_mpcontactform_pi1[country]"].value == "") {
			alert(messages[4]);
			frm["tx_mpcontactform_pi1[country]"].focus();
			return false;
		}
	}
	if(frm["tx_mpcontactform_pi1[termsofuse]"]){
		if (!frm["tx_mpcontactform_pi1[termsofuse]"].checked) {
			alert(messages[5]);
			frm["tx_mpcontactform_pi1[termsofuse]"].focus();
			return false;
		}
	}


	return true;

}
 
function removeHighlight(el){
	el.style.background = '#ffffff';
	if(isIE) el.style.border = '1px solid #7F9DB9';
	if(document.getElementById('p'+el.name))
	document.getElementById('p'+el.name).style.color = '#000000';
}
function highlight(el){
	el.focus();
	el.style.background = '#EC641F';
	if(document.getElementById('p'+el.name))
	document.getElementById('p'+el.name).style.color = '#EC641F';
}


//##########################################
// Additional validation functions
//##########################################
function isNumber(val){
if (val == "") return false;
  for (var i = 0; i< val.length; i++) {
    if (val.charAt(i) < "0" || val.charAt(i) > "9")
      return false;
  }    
  return true;
}

//##########################################
function isIntegerInRange (intVar, intLow, intHigh){
    return ((intVar >= intLow) && (intVar <= intHigh));
}
//##########################################
function isDay (intDay){
	return isIntegerInRange (intDay, 1, 31);
}

function isMonth (intMonth){
	return isIntegerInRange (intMonth, 1, 12);
}

function isYear (intYear){
    return isIntegerInRange (intYear, 1900, 2009);
}

function daysInFebruary (intYear){		// February has 29 days in any year evenly divisible by four,
    								// EXCEPT for centurial years which are not also divisible by 400.
    return (  ((intYear % 4 == 0) && ( (!(intYear % 100 == 0)) || (intYear % 400 == 0) ) ) ? 29 : 28 );
}


//##########################################
function isDate (intYear, intMonth, intDay){
    if (! (isYear(intYear) && isMonth(intMonth) && isDay(intDay))) return false;

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}
//##########################################
function IsValidDate(strDate){
	var blnIsDate = false;
	
	var objRegExp = /^(\d{2})\.(\d{2})\.(\d{4})$/;
	blnIsDateFormat = objRegExp.test(strDate);
	if (blnIsDateFormat){
		objRegExp.exec(strDate);
		intDay 		= parseInt(RegExp.$1, 10);
		intMonth 	= parseInt(RegExp.$2, 10);
		
		if (RegExp.$3.length == 2){
			intYear = parseInt("19"+ RegExp.$3, 10);
		}
		else if(RegExp.$3.length == 4){
			intYear		= parseInt(RegExp.$3, 10);
		}
		else {
			return false;
		}
		blnIsDate = isDate(intYear,intMonth,intDay);
	}
	return blnIsDate;
}




function isValidString(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123 || h==32))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

