function check_save(){
var validEmail = document.getElementById('email').value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.name)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
function isNum(inputString)
{
  var searchForChars = /\D+/;
  if (searchForChars.test(inputString)) return false;
  else return true;
}
function isNric(string){
	var leng=string.length;
	var j=0; var i=0;
	while (i<leng){
		var char=string.charAt(i);
		if (isNum(char) ) j++;
		i++;
	}
	if (isNum(string.charAt(0)) ) return false;
	else if(j<7) return false;
	else return true;
}

if(document.getElementById('nric').value==""){alert("Please provide your NRIC / Passport.");document.getElementById('nric').focus(); return false;}
if(!isNric(document.getElementById('nric').value)){alert("Please provide valid NRIC / Passport.");document.getElementById('nric').focus(); return false;}
if(document.getElementById('name').value==""){alert("Please provide your Name.");document.getElementById('name').focus(); return false;}
if(document.getElementById('email').value==""){alert("Please provide your Email.");document.getElementById('email').focus(); return false; }
if(!validEmail){alert("Please provide valid Email.");document.getElementById('email').focus(); return false;}
if(document.getElementById('mobile').value==""){alert("Please provide your Mobile No.");document.getElementById('mobile').focus(); return false;}
if(!isNum(document.getElementById('mobile').value)){alert("Please provide your valid Mobile No.");document.getElementById('mobile').focus(); return false;}
if(document.getElementById('room_rating').value==0){alert("Please rate resort Room.");document.getElementById('room').focus(); return false;}
if(document.getElementById('service_rating').value==0){alert("Please rate resort Service.");document.getElementById('service').focus(); return false;}
if(document.getElementById('amentities_rating').value==0){alert("Please rate resort Amentities.");document.getElementById('amentities').focus(); return false;}
if(document.getElementById('location_rating').value==0){alert("Please rate resort Location.");document.getElementById('location').focus(); return false;}
if(document.getElementById('value_rating').value==0){alert("Please rate resort Value.");document.getElementById('value').focus(); return false;}
if(document.getElementById('stayMth').value==""){alert("Please provide Month of Stay.");document.getElementById('stayMth').focus(); return false;}
if(document.getElementById('stayYr').value==""){alert("Please provide Year of Stay.");document.getElementById('stayYr').focus(); return false;}
var date =new Date();
var serverDt=new Date(date.getFullYear(),date.getMonth());
var stayMth=document.getElementById('stayMth').value;
var stayYr=new Number(document.getElementById('stayYr').value);
var mthName= new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
for (var i=0; i<=11; i++){
	if (stayMth==mthName[i]) stayMth=i;	
}
/*if (stayMth=="Jan") stayMth=0;
if (stayMth=="Feb") stayMth=1;
if (stayMth=="Mar") stayMth=2;
if (stayMth=="Apr") stayMth=3;
if (stayMth=="May") stayMth=4;
if (stayMth=="Jun") stayMth=5;
if (stayMth=="Jul") stayMth=6;
if (stayMth=="Aug") stayMth=7;
if (stayMth=="Sep") stayMth=8;
if (stayMth=="Oct") stayMth=9;
if (stayMth=="Nov") stayMth=10;
if (stayMth=="Dec") stayMth=11;*/
var selectDt=new Date(stayYr,stayMth);
if(selectDt>serverDt){alert("Please provide valid stay date.");document.getElementById('stayYr').focus();return false;}


var name=document.getElementById('name').value;
var nric=document.getElementById('nric').value;
var mobile=document.getElementById('mobile').value;
var email=document.getElementById('email').value;
var uid=document.getElementById('uid').value;
var pic=document.getElementById('pic').value;
var resort=document.getElementById('slide_resort').value;
var room_rating=document.getElementById('room_rating').value;
var service_rating=document.getElementById('service_rating').value;
var amentities_rating=document.getElementById('amentities_rating').value;
var location_rating=document.getElementById('location_rating').value;
var value_rating=document.getElementById('value_rating').value;
var feedback=document.getElementById('feedback').value;
var mth=document.getElementById('stayMth').value;
var year=document.getElementById('stayYr').value;

if (document.getElementById('form').recommend[0].checked) var commend="Yes";
if (document.getElementById('form').recommend[1].checked) var commend="No";

$.ajax({
		  type: 'POST',
		  url: "/wp-content/themes/costasands/save_review.php",
		  data: "name="+name+"&nric="+nric+"&mobile="+mobile+"&email="+email+"&uid="+uid+"&pic="+pic+"&resort="+resort+"&room_rating="+room_rating+"&service_rating="+service_rating+"&amentities_rating="+amentities_rating+"&location_rating="+location_rating+"&value_rating="+value_rating+"&feedback="+feedback+"&stayMth="+mth+"&stayYr="+year+"&recommend="+commend
});//ajax

alert("Thank you for submitting your review!");
return true;
}
