$(document).ready(function() {

	//if submit button is clicked
	$('#submit').click(function () {

		//Get the data from all the fields
        var spam = $('input[name=spam]');
       	var country= $('input[name=country]');
		var name = $('input[name=name]');
        var phone = $('input[name=phone]');
       	var Mphone = $('input[name=Mphone]');
        var r_s = $('input[name=r_s]');
        var r_t = $('input[name=r_t]');
        var r_d = $('input[name=r_d]');
        var r_f = $('input[name=r_f]');
        var start = $('select[name=start]');
        var Month = $('select[name=Month]');
        var year = $('select[name=year]');
        var end = $('select[name=end]');
         var tomonth = $('select[name=tomonth]');
        var toyear = $('select[name=toyear]');
        var email = $('input[name=email]');
	  	var comment = $('textarea[name=comment]');


		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
        	if (spam.val()!=='') {
			spam.addClass('hightlight');
			return false;
		} else spam.removeClass('hightlight');
          if (country.val()=='') {
			country.addClass('hightlight');
			return false;
		} else country.removeClass('hightlight');
		if (name.val()=='') {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');
          if (phone.val()=='') {
			phone.addClass('hightlight');
			return false;
		} else country.removeClass('hightlight');
		if (email.val()=='') {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');



           var x=email.val()
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  	email.addClass('hightlight');
			return false;
  }  else email.removeClass('hightlight');


		//organize the data properly
	   var data = 'country=' + country.val() + '&name=' + name.val() + '&phone=' + phone.val() + '&Mphone=' + Mphone.val() + '&r_s=' + r_s.val() + '&r_t=' + r_t.val() + '&r_d=' + r_d.val()  + '&r_f=' + r_f.val() + '&start=' + start.val() + '&Month=' + Month.val() + '&year=' + year.val() + '&end=' + end.val() + '&tomonth=' + tomonth.val() + '&toyear=' + toyear.val() + '&email=' + email.val()  + '&comment='  + encodeURIComponent(comment.val());

		//disabled all the text fields
		$('.text').attr('disabled','true');

		//show the loading sign
		$('.loading').show();

		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "process_frm.php",

			//GET method is used
			type: "GET",

			//pass the data
			data: data,

			//Do not cache the page
			cache: false,

			//success
			success: function (html) {
				//if process.php returned 1/true (send mail success)
				if (html==1) {
					//hide the form
					$('.form').fadeOut('slow');

					//show the success message
					$('.done').fadeIn('slow');

				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');
			}
		});

		//cancel the submit button default behaviours
		return false;
	});
});

function setColor (control, color) {
if (control.style) {
if (control.value != control.defaultValue) {
control.style.backgroundColor = color;
}
else {
control.style.backgroundColor = '';
}
}
}

  function setValue1(set) {
        var field = document.getElementById("r_s"); false;
        field.value = set;



  }

 function Disable(obj,state){
    clds=obj.parentNode.childNodes;
    if (!obj.ary){
    obj.ary=new Array();
        for (i1=0;i1<clds.length;i1++){
            if (clds[i1].tagName=='INPUT'){
                obj.ary[obj.ary.length]=clds[i1];
                }
        }
    }
    for (i=0;i<obj.ary.length;i++){
        obj.ary[i].removeAttribute('disabled');
    }
    if (obj.checked==state){
        for (i1=0;i1<obj.ary.length;i1++){
            obj.ary[i1].setAttribute('disabled','disabled');
        }
    }
    obj.removeAttribute('disabled');

}






 function selectCheckBox()
{
  var e= document.myform.elements.length;
  var cnt=0;

  for(cnt=0;cnt<e;cnt++)
  {
    if(document.myform.elements[cnt].name=="r_s"){
     alert(document.myform.elements[cnt].value)
    }
  }
}
function newwindow()
{window.open('bed_charges.php','jav','width=401,height=400,resizable=no,screenX=200,screenY=300,left=200,top=300,');}
