// JavaScript Document
function check_enquiry(){
if(document.frm_enquiry.txt_fname.value=='First Name' || document.frm_enquiry.txt_fname.value=='')
{
alert("Enter First Name");
document.frm_enquiry.txt_fname.focus();
return false;
	
}

if(document.frm_enquiry.txt_lname.value=='Last Name' || document.frm_enquiry.txt_lname.value=='')
{
alert("Enter Last Name");
document.frm_enquiry.txt_lname.focus();

return false;
	
}
if(document.frm_enquiry.txt_city.value=='City' || document.frm_enquiry.txt_city.value=='')
{
alert("Enter City");
document.frm_enquiry.txt_city.focus();

return false;
	
}
if(document.frm_enquiry.txt_country.value=='Country' || document.frm_enquiry.txt_country.value=='')
{
alert("Enter Country");
document.frm_enquiry.txt_country.focus();

return false;
	
}
if(document.frm_enquiry.txt_phone.value=='Phone' || document.frm_enquiry.txt_phone.value=='')
{
alert("Enter Phone");
document.frm_enquiry.txt_phone.focus();

return false;
	
}
//adde

/*var lines;
var TA=document.frm_enquiry.txt_phone.value;
if(document.all) { // IE
lines=TA.split("\r\n");
}
else { //Mozilla
lines=TA.split("\n");
}
for(var i=0; i<lines.length; i++) {
	if(isNaN(lines[i])){
		alert("enter valid phone number");
		document.frm_enquiry.txt_phone.focus();
		return false;
	}
}


*/






//

if(document.frm_enquiry.txt_email.value=='Email' || document.frm_enquiry.txt_email.value=='')
{
alert("Enter Email");
document.frm_enquiry.txt_email.focus();

return false;
	
}

if(document.frm_enquiry.txt_message.value=='Message' || document.frm_enquiry.txt_message.value=='')
{
alert("Enter Message");
document.frm_enquiry.txt_message.focus();

return false;
	
}

	document.frm_enquiry.submit();
	
	
	
	
	
}
function checkemail(){
var str=document.frm_enquiry.txt_email.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
document.frm_enquiry.txt_email.focus();
testresults=false
}
return (testresults)
}

function checnum(as)
{
	var dd = as.value;
	
	if(isNaN(dd))
	{
		dd = dd.substring(0,(dd.length-1));
		as.value = dd;
	}		
}

function loan()
{
	var a = document.frm_emi_calculator.txt_amt.value;
	var b = document.frm_emi_calculator.txt_intrst.value;
	var c = document.frm_emi_calculator.txt_period.value;
	alert(a);
	var n = c * 12;
	var r = b/(12*100);
	var p = (a * r *Math.pow((1+r),n))/(Math.pow((1+r),n)-1);
	var prin = Math.round(p*100)/100;
	var ann	=	prin*n;
	document.getElementById('ann_loan_pay').innerHTML = ann;
	document.getElementById('mon_pay').innerHTML = prin;

	var mon = Math.round(((n * prin) - a)*100)/100;
	var tot = Math.round((mon/n)*100)/100;
		var monint	=	tot*n;
	document.getElementById('mon_int').innerHTML = monint;

	document.first.r3.value = tot;
	for(var i=0;i<n;i++)
	{
		var z = a * r * 1;
		var q = Math.round(z*100)/100;
		var t = p - z;
		var w = Math.round(t*100)/100;
		var e = a-t;
		var l = Math.round(e*100)/100;
		a=e;
		
	}
}
//*******************Reservation Form Validation********************

function reservation(){
if(document.frm_reservation.txt_name.value=="")	{
	alert("Enter Name");
	document.frm_reservation.txt_name.focus();
	return false;
}
 if(document.frm_reservation.txt_age.value=="")
{
	alert("Enter Age");
	document.frm_reservation.txt_age.focus();
	return false;
}
 if(document.frm_reservation.txt_dob.value=="")
{
	alert("Enter Date Of Birth");
	document.frm_reservation.txt_dob.focus();
	return false;
}
 if(document.frm_reservation.txt_occup.value=="")
{
	alert("Enter Occupation");
	document.frm_reservation.txt_occup.focus();
	return false;
}
 if(document.frm_reservation.txt_comm_add.value=="")
{
	alert("Enter Communication Address");
	document.frm_reservation.txt_comm_add.focus();
	return false;
}

 if(document.frm_reservation.txt_perm_add.value=="")
{
	alert("Enter Permanent Address");
	document.frm_reservation.txt_perm_add.focus();
	return false;
}

document.frm_reservation.submit.click();
}


//*************Payment Validation********************************
function payments()
{
if(document.frm_payments.txt_name.value=="")
{
	alert("Enter Name");
	document.frm_payments.txt_name.focus();
	return false;
}
if(document.frm_payments.txt_addrs.value=="")
{
	alert("Enter Address");
	document.frm_payments.txt_addrs.focus();
	return false;
}
if(document.frm_payments.txt_phone.value=="")
{
	alert("Enter Phone Number");
	document.frm_payments.txt_phone.focus();
	return false;
}
if(document.frm_payments.txt_email.value=="")
{
	alert("Enter Email Id");
	document.frm_payments.txt_email.focus();
	return false;
}
if(document.frm_payments.txt_purpose.value=="")
{
	alert("Enter Purpose of Payment");
	document.frm_payments.txt_purpose.focus();
	return false;
}
if(document.frm_payments.txt_pymt.value=="")
{
	alert("Enter Payment Amount");
	document.frm_payments.txt_pymt.focus();
	return false;
}
if(!slashchk(document.frm_payments.txt_name.value)) {
		alert("Name contains invalid charactes. Please re-enter");
		document.frm_payments.txt_name.focus();
		return false;           
	}
if(!slashchk(document.frm_payments.txt_addrs.value)) {
		alert("Address contains invalid charactes. Please re-enter");
		document.frm_payments.txt_addrs.focus();
		return false;           
	}
if(!slashchk(document.frm_payments.txt_phone.value)) {
		alert("Phone Number contains invalid charactes. Please re-enter");
		document.frm_payments.txt_phone.focus();
		return false;           
	}
if(!slashchk(document.frm_payments.txt_email.value)) {
		alert("Email Id contains invalid charactes. Please re-enter");
		document.frm_payments.txt_email.focus();
		return false;           
	}
if(!slashchk(document.frm_payments.txt_purpose.value)) {
		alert("Purpose contains invalid charactes. Please re-enter");
		document.frm_payments.txt_purpose.focus();
		return false;           
	}
if(!slashchk(document.frm_payments.txt_pymt.value)) {
		alert("Payment Amount contains invalid charactes. Please re-enter");
		document.frm_payments.txt_pymt.focus();
		return false;           
	}
	
document.frm_payments.submit.click();	
}

function slashchk(st) {
	var i;
	for(i=0;i<st.length;++i) {
		if(st.charAt(i)=="/") {
			return false;
		}
	}
	return true;
}
function checkemailpymt(){
var str=document.frm_payments.txt_email.value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
alert("Please input a valid email address!")
document.frm_payments.txt_email.focus();
testresults=false
}
return (testresults)
}
 //-------------------------------------------------------------
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
var maxDigitsInIPhoneNumber=12;
function isInteger(s)
{   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;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber );

}
function checkInternationalPhone1(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length <= maxDigitsInIPhoneNumber );

}

/*function  phoneVal(frm_payments){
	var Phone=document.frm_payments.txt_phone;
	if( Phone.value!=""){
	
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid phone number");
		Phone.value="";
		document.frm_payments.txt_phone.focus();
		return false;
	}
	if (checkInternationalPhone1(Phone.value)==false){
		alert("Please enter a valid phone number");
		Phone.value="";
		document.frm_payments.txt_phone.focus();
		return false;
	}
	return true;
 }}*/
 function  permphoneVal(frm_payments){
	var Phone=document.frm_payments.txt_perm_phone;
	if( Phone.value!=""){
	
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid phone number")
		Phone.value=""
		Phone.focus()
		return false
	}
	if (checkInternationalPhone1(Phone.value)==false){
		alert("Please enter a valid phone number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }}

function  mobVal(frm_reservation){
	var Phone=document.frm_reservation.txt_mob;
	
	
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid mobile number");
		Phone.value="";
		Phone.focus();
		return false;
	}
	if (checkInternationalPhone1(Phone.value)==false){
		alert("Please enter a valid phone number");
		Phone.value="";
		Phone.focus();
		return false;
	}
	return true
 }
function  permmobVal(frm_reservation){
	var Phone=document.frm_reservation.txt_perm_mob
	
	
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid mobile number")
		Phone.value=""
		Phone.focus()
		return false
	}
	if (checkInternationalPhone1(Phone.value)==false){
		alert("Please enter a valid phone number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }


