function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function check_email(address) {
	//var emailPat = /^((\w|\.|\_)+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var emailPat = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	var matchArray = address.match(emailPat);
	if (matchArray == null)
		return false;
	else
		return true;
}

function isDigit() {
	if ((event.keyCode < 48)||(event.keyCode > 57 )) {
	  if (event.keyCode != 46)
		{event.returnValue=false;}
	}
}

function trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ")
	{ // Check for space at the start of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length-1, retValue.length);

	while (ch == " ")
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	return retValue;
}
 
function getfileextension(inputId) 
{ 
 var fileinput = document.getElementById("foo"); 
 if(!fileinput ) return ""; 
 var filename = fileinput.value; 
 if( filename.length == 0 ) return ""; 
 var dot = filename.lastIndexOf("."); 
 if( dot == -1 ) return ""; 
 var extension = filename.substr(dot,filename.length); 
 return extension; 
}

function check_ext(file) {
	var getext=getfileextension(file);
	var ext = /^(jpg|png|jpeg|gif)$/;
	var matchArray = getext.match(ext);
	if (matchArray == null)
		return false;
	else
		return true;
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 * modified by OT
 */
//format is dd/mm/yyyy
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1974;
var maxYear=2010;

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }

   return this
}

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(isNaN(day)){
		return false
	}
	if(month > 12 || isNaN(month)){
		return false
	}
	if(year > maxYear || year < minYear || isNaN(year)){
		return false	
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}

return true
}

function validate_whatsyourstory(){
	if(trim(document.f_story.tMembershipNo.value) == "")
	{
		alert("Please fill your membership mumber.");
		document.f_story.tMembershipNo.focus();
		return;
	}
	if(trim(document.f_story.tName.value) == "")
	{
		alert("Please fill your name.");
		document.f_story.tName.focus();
		return;
	}
	if(trim(document.f_story.tEmail.value) == "")
	{
		alert("Please fill your email correctly.");
		document.f_story.tEmail.focus();
		return;
	}
	if(trim(document.f_story.tEmail.value) != "" && !check_email(trim(document.f_story.tEmail.value)))
	{
		alert("Please fill your email correctly.");
		document.f_story.tEmail.focus();
		return;
	}
	if(trim(document.f_story.tContact.value) == "")
	{
		alert("Please fill your contact number correctly.");
		document.f_story.tContact.focus();
		return;
	}
	
	 var reg = new RegExp('^[-]?[0-9-+]+[\.]?[0-9-+]$');
	if (!reg.test(document.f_story.tContact.value))
	{
		alert("Please fill your contact number correctly.");
		document.f_story.tContact.focus();
		return;
	}
	
	if(trim(document.f_story.tRCI_Me.value) == "")
	{
		alert("Please fill your RCI and Me.");
		document.f_story.tRCI_Me.focus();
		return;
	}
	if(trim(document.f_story.tStory.value) == "")
	{
		alert("Please fill your story.");
		document.f_story.tStory.focus();
		return;
	}
	if(document.f_story.file1.value != "" && document.f_story.file1.value.indexOf('gif') == -1 && document.f_story.file1.value.indexOf('jpg') == -1 && document.f_story.file1.value.indexOf('jpeg') == -1 && document.f_story.file1.value.indexOf('JPG') == -1)
	{
		alert("Please upload file with extension jpg/gif.");
		document.f_story.file1.focus();
		return;
	}
	if(document.f_story.file2.value != "" && document.f_story.file2.value.indexOf('gif') == -1 && document.f_story.file2.value.indexOf('jpg') == -1 && document.f_story.file2.value.indexOf('jpeg') == -1 && document.f_story.file2.value.indexOf('JPG') == -1)
	{
		alert("Please upload file with extension jpg/gif.");
		document.f_story.file2.focus();
		return;
	}
	if(document.f_story.file3.value != "" && document.f_story.file3.value.indexOf('gif') == -1 && document.f_story.file3.value.indexOf('jpg') == -1 && document.f_story.file3.value.indexOf('jpeg') == -1 && document.f_story.file3.value.indexOf('JPG') == -1)
	{
		alert("Please upload file with extension jpg/gif.");
		document.f_story.file3.focus();
		return;
	}
	if(document.f_story.file4.value != "" && document.f_story.file4.value.indexOf('gif') == -1 && document.f_story.file4.value.indexOf('jpg') == -1 && document.f_story.file4.value.indexOf('jpeg') == -1 && document.f_story.file4.value.indexOf('JPG') == -1)
	{
		alert("Please upload file with extension jpg/gif.");
		document.f_story.file4.focus();
		return;
	}
	if(document.f_story.file5.value != "" && document.f_story.file5.value.indexOf('gif') == -1 && document.f_story.file5.value.indexOf('jpg') == -1 && document.f_story.file5.value.indexOf('jpeg') == -1 && document.f_story.file5.value.indexOf('JPG') == -1)
	{
		alert("Please upload file with extension jpg/gif.");
		document.f_story.file5.focus();
		return;
	}
	document.f_story.submit();
	
}

function validate_rci_comment(){
	if(trim(document.f_comment.tFirstName.value) == "")
	{
		alert("Please fill your first name.");
		document.f_comment.tFirstName.focus();
		return;
	}
	if(trim(document.f_comment.tLastName.value) == "")
	{
		alert("Please fill your last name.");
		document.f_comment.tLastName.focus();
		return;
	}
	if(trim(document.f_comment.tMemberID.value) == "")
	{
		alert("Please fill your Member ID and Relation Number.");
		document.f_comment.tMemberID.focus();
		return;
	}
	if(trim(document.f_comment.tEmail.value) == "" || !check_email(trim(document.f_comment.tEmail.value)))
	{
		alert("Please fill your email correctly.");
		document.f_comment.tEmail.focus();
		return;
	}
	if(trim(document.f_comment.tResort.value) == "")
	{
		alert("Please fill your Resort Name/ID.");
		document.f_comment.tResort.focus();
		return;
	}
	if(isNaN(trim(document.f_comment.tDate.value)) == true)
	{
		alert ("here!");
		alert("Please fill your Check-In Date correctly.");
		document.f_comment.tDate.focus();
		return;
	}
	if(isNaN(trim(document.f_comment.tMonth.value)) == true)
	{
		alert("Please fill your Check-In Date correctly.");
		document.f_comment.tMonth.focus();
		return;
	}
	if(isNaN(trim(document.f_comment.tYear.value)) == true)
	{
		alert("Please fill your Check-In Date correctly.");
		document.f_comment.tYear.focus();
		return;
	}
	if(isDate(trim(document.f_comment.tDate.value) + '/' + trim(document.f_comment.tMonth.value) + '/' + trim(document.f_comment.tYear.value)) == false)
	{
		alert("Please fill your Check-In Date correctly.");
		document.f_comment.tDate.focus();
		return;
	}
	
	var h,i,flag;
	for(h=1;h<=5;h++){
		for(i=0;i<5;i++){
			flag=false;
			if(document.f_comment.elements['sComment'+h+'[]'][i].checked){
				flag=true;break;
			}
			if(i==4 && flag==false){ 
				alert("Please choose one of 1-5 for Service");
				//document.f_comment.elements['sComment'+h+'[]'][0].focus();
				document.f_comment.elements['sComment'+h+'[]'][0].focus();
				return; 
			}
		}
	}
	/*if(trim(document.f_comment.sAdditionalComment.value) == "")
	{
		alert("Please fill your additional comment.");
		document.f_comment.sAdditionalComment.focus();
		return;
	}*/
	for(h=1;h<=4;h++){
		for(i=0;i<5;i++){
			flag=false;
			if(document.f_comment.elements['aComment'+h+'[]'][i].checked){
				flag=true;break;
			}
			if(i==4 && flag==false){ 
				alert("Please choose one of 1-5 for Accomodations");
				document.f_comment.elements['aComment'+h+'[]'][0].focus();
				return; 
			}
		}
	}
	/*if(trim(document.f_comment.aAdditionalComment.value) == "")
	{
		alert("Please fill your additional comment.");
		document.f_comment.aAdditionalComment.focus();
		return;
	}*/
//alert('test');	
	for(h=1;h<=4;h++){
		for(i=0;i<5;i++){
			flag=false;
			if(document.f_comment.elements['eComment'+h+'[]'][i].checked){
				flag=true;break;
			}
			if(i==4 && flag==false){ 
				alert("Please choose one of 1-5 for Overall Experience");
				document.f_comment.elements['eComment'+h+'[]'][0].focus();
				return; 
			}
		}
	}
	/*if(trim(document.f_comment.eAdditionalComment.value) == "")
	{
		alert("Please fill your additional comment.");
		document.f_comment.eAdditionalComment.focus();
		return;
	}*/
	document.f_comment.submit();
	
}

function validate_holiday_planner(){
	if(trim(document.f_holiday.tMemberID.value) == "")
	{
		alert("Please fill your Member ID.");
		document.f_holiday.tMemberID.focus();
		return;
	}
	if(trim(document.f_holiday.tName.value) == "")
	{
		alert("Please fill your name.");
		document.f_holiday.tName.focus();
		return;
	}
	if(trim(document.f_holiday.tContactNumber.value) != "" && isNaN(trim(document.f_holiday.tContactNumber.value)))
	{
		alert("Please fill your contact number correctly.");
		document.f_holiday.tContactNumber.focus();
		return;
	}
	if(trim(document.f_holiday.tEmail.value) == "" || !check_email(trim(document.f_holiday.tEmail.value)))
	{
		alert("Please fill your email correctly.");
		document.f_holiday.tEmail.focus();
		return;
	}
	/*if(trim(document.f_holiday.tContactTime.value) == "")
	{
		alert("Please fill your Contact Time.");
		document.f_holiday.tContactTime.focus();
		return;
	}*/
	if(trim(document.f_holiday.tTravelGroup.value) != "" && isNaN(trim(document.f_holiday.tTravelGroup.value)))
	{
		alert("Please fill size of your travel group.");
		document.f_holiday.tTravelGroup.focus();
		return;
	}
	if(trim(document.f_holiday.tAdult.value) != "" && isNaN(trim(document.f_holiday.tAdult.value)))
	{
		alert("Please fill number of adult.");
		document.f_holiday.tAdult.focus();
		return;
	}
	if(trim(document.f_holiday.tChild.value) != "" && isNaN(trim(document.f_holiday.tChild.value)))
	{
		alert("Please fill number of child.");
		document.f_holiday.tChild.focus();
		return;
	}
	document.f_holiday.submit();
}