// Form Validator
var supportcenter_login_box="";
var toggle_menu_html;
function $(id){	
    var obj = null;
	if(document.getElementById){obj = document.getElementById(id);}
	else if(document.all){obj = document.all[id];}
    return obj;
}
function regCheckItem(itemType) {
	var fullname	= $('news_name').value;// myForm.fullname.value;
	var	email		= $('news_email').value; // myForm.email.value.toLowerCase();
	var	country		= $('news_country').value; // myForm.email.value.toLowerCase();
	if(itemType.indexOf('name')>-1){
		checkFullname(fullname);
	}
	else if(itemType.indexOf("mail")>-1){
		checkEmail(email);
	}
	else if(itemType.indexOf("country")>-1){
		checkcountry(country);
	}
}

function checkForm() {
	var fullname	= $("news_name").value;
	var country	= $("news_country").value;
	var	email		= $("news_email").value.toLowerCase();
	if(checkFullname(fullname) && checkEmail(email) && checkcountry(country)){
		//$("result_uptodate_user").style.display="block";
		//sR("/beta/uptodate_user.php","name="+fullname+"&email="+email,"POST","result_uptodate_user");
		return true;
	}
	else return false;
}

function checkFullname(fullname){
	if(notEmpty(fullname)) {
		var msg = 'OK';
		changeDiv('news_name_chk','reg_white',msg);
		return true;	
	}
	else {
		var msg = 'Error';
		changeDiv('news_name_chk','reg_red',msg);
		return false;
	}
}
function checkcountry(country){
	if(notEmpty(country)) {
		var msg = 'OK';
		changeDiv('news_country_chk','reg_white',msg);
		return true;	
	}
	else {
		var msg = 'Error';
		changeDiv('news_country_chk','reg_red',msg);
		return false;
	}
}

function checkEmail(email){
	if(isMail(email)) {
		var msg = 'OK';
		changeDiv('news_email_chk','reg_white',msg);
		return true;
	}
	else {
		var msg = 'Error';
		changeDiv('news_email_chk','reg_red',msg);
		return false;
	}
}


/////////////////////////////////////////////////////////////////
function notEmpty(elem){
	var filter=(/^[a-zA-Z0-9 ]+$/);
	if (filter.test(elem) && elem.length >= 3) return true;
	else return false;
}
function isMail(elem) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(elem))return true;
	else return false;
}


function changeDiv(divId,class_name,msg) {
	document.getElementById(divId).className=class_name;
	document.getElementById(divId).innerHTML=msg;
}


function set(type1,ITEMHERE){
	if(type1=="good"){
			$(ITEMHERE).style.backgroundColor="#EEFFEE";
			$(ITEMHERE).style.borderLeft="#33BB66 5px solid";			
	}else{
			$(ITEMHERE).style.backgroundColor="#FFEEEE";		
			$(ITEMHERE).style.borderLeft="#FF9999 5px solid";											
	}
}
function matchit(item1,in_item2) {
  var re = new RegExp(item1);
  var m = re.exec(in_item2);
  if (m == null) return false;
  else return (m.index+1);
}
function isNumber(elem){
	var filter=(/^[0-9]+$/);
	if (filter.test(elem) && elem.length >= 7) return true;
	else return false;
}
var check_name=false , check_email=false , check_project=false ,check_no=false;
var bad="<img src='images/invalid.gif' border='0' alt='Error' align='absmiddle' /> ";
var good="<img src='images/validate.gif' border='0' alt='Valid' align='absmiddle' /> ";	
function $(id){  
	var obj = null;
	if(document.getElementById){   
		obj = document.getElementById(id);
    }
	else if(document.all)
	{ obj = document.all[id]; }; 
	return obj; 
}

function alertSize() {
    if (self.innerWidth) {   // FirFox
      myWidth = self.innerWidth;
      myHeight = self.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // IE
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
	  myWidth=myWidth+21;
    } else if (document.body) {
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
	return myWidth;
}

var z=new Array();
var thespeed=10;
var intervalID;
var obj_here;
var total_details=1;
var old_cutter;
function add_detail(object_id,str_cutter){
	if(old_cutter!=str_cutter)total_details=1;
	var dt_tbl=$(object_id).tBodies[0];
	var copy_cell=dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[0].innerHTML;	
	var copy_cell2=dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML;
	//alert(copy_cell2);
	while(copy_cell.indexOf(str_cutter+total_details)>-1)
	copy_cell=copy_cell.replace(str_cutter+total_details,str_cutter+parseInt(total_details+1));
	total_details++;
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML="";
	dt_tbl.insertRow(dt_tbl.rows.length);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].insertCell(0);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].insertCell(1);
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[0].innerHTML=copy_cell;
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].style.verticalAlign="bottom";
	dt_tbl.rows[parseInt(dt_tbl.rows.length)-1].cells[1].innerHTML=copy_cell2;
	old_cutter=str_cutter;
}

function toggle_onfocus(id){
	$(id).style.color='#DDDDDD';
	$(id).style.borderColor='#FFFFFF';
	$(id).style.background='#999999';
}
function toggle_onblur(id){
	$(id).style.color='#666666';
	$(id).style.borderColor='#999999';
}
function toggle_onfocus_r(id){
	$(id).style.color='#DDDDDD';
	$(id).style.borderColor='#FFFFFF';
	$(id).style.background='#999999';
}
function toggle_onblur_r(id){
	$(id).style.color='#666666';
	$(id).style.borderColor='#999999';
	$(id).style.background='#DDDDDD';
}
var name;
var email;
var phone;
var adult_number;
var rooms_number;
var arrival_date;
var dep_date;
var comments;
var destination;
var room_type;
var url;
function save_reservation()
{	
	if(validate_all("reservation_form"))
	{
		$("ajax_img").style.display="block";
		name=$("your_name").value;
		email=$("your_email").value;
		phone=$("your_phone").value;
		rooms_number=$("rooms_number").value;
		adult_number=$("adult_number").value;
		arrival_date=$("arrivaldate").value;
		dep_date=$("depdate").value;
		destination=$("destination").value;
		room_type=$("room_type").value;
		comments=$("comments").value;
		url=$("url").value;
		child_number=$("child_number").value;
		
		if($("child_item_1"))ci1=$("child_text_1").value;
		if($("child_item_2"))ci2=$("child_text_2").value;
		if($("child_item_3"))ci3=$("child_text_3").value;
		if($("child_item_4"))ci4=$("child_text_4").value;
		if($("child_item_5"))ci5=$("child_text_5").value;
		
		if(arrival_date>dep_date){
			alert("Arrival Date Can't be before Dept date.");
			return false;
		}
		else{
			sR(url+"ajax_functions.php","type=save_reservation&name="+name+"&email="+email+"&phone="+phone+"&rooms_number="+rooms_number+"&arrival_date="+arrival_date+"&dep_date="+dep_date+"&comments="+comments+"&room_type="+room_type+"&adult_number="+adult_number+"&destination="+destination+"&ci1="+ci1+"&ci2="+ci2+"&ci3="+ci3+"&ci4="+ci4+"&ci5="+ci5+"&child_number="+child_number,"POST","inner_content_div");
					}
	}
}

function reset_toggle_objects()
{
	reset_item("toggle_name");
	reset_item("toggle_email");
	reset_item("toggle_phone");
	reset_item("toggle_company");
	reset_item("toggle_project");
	reset_item("CODE");
	reset_item("toggle_contacted");	
}
function applied_cv(){
	$("link_egypt_int_body_padding").innerHTML="<div class='added_cv'>You are applied successfully ...</div>";
}
function reset_item(item_id)
{
	$(item_id).value="";
	$(item_id).style.color="#444444";
	$(item_id).style.background="#999999";
	$(item_id).style.border="solid ";
	$(item_id).style.borderWidth="1px";
	$(item_id).style.borderColor="#CCCCCC";
	if($(item_id+'_validation'))$(item_id+'_validation').style.display="none";
}
function showdiv(id)
{
	var div_tocopy=$(id+'_con');
	var targetdiv=$('target');
	targetdiv.innerHTML=div_tocopy.innerHTML;
}
function hide_submenu(){
	$("topsection_page").style.display="none";
}
var location1=null;
var contact_flag=false;
var ctrlPressed=0;
var altPressed=0;
var shiftPressed=0;

function IsNumeric(sText){
   var ValidChars = "0123456789.+";
   var IsNumber=true;
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      if (ValidChars.indexOf(sText.charAt(i)) == -1){IsNumber = false;}
   }
   return IsNumber;
}
function display_room(id){
	var url=$("url").value;
	sR(url+"ajax_functions.php","type=display_room&id="+id,"POST","page_full_img");
}
function room_selected(){
	document.forms['rooms_title_form'].submit();
}

function show_more_description(){
	if($("show_more_description").innerHTML=="More"){
		$("more_description").style.display="block";
		$("show_more_description").innerHTML="Hide";
	}
	else{
		$("more_description").style.display="none";
		$("show_more_description").innerHTML="More";
	}

}
function child_number_changed(){
	number=$("child_number").value;
	for(i=1;i<6;i++){
		$("child_item_"+i).style.display="none";
	}
	if(number>0){
		for(i=1;i<=number;i++){
			$("child_item_"+i).style.display="block";
		}
	}
}
function room_types_changed(){
	type=$("room_type").value;
	type=type.split(' ').join('');
	$('adult_number').disabled=false;
	if(type=='SingleRoom'){
		$('adult_number').value=1;	
		$('adult_number').disabled='disabled';
	}
	if(type=='DoubleRoom'){
		$('adult_number').value=2;	
		$('adult_number').disabled='disabled';
	}
	if(type=='TripleRoom'){
		$('adult_number').value=3;	
		$('adult_number').disabled='disabled';
	}
	
	
}
function show_our_formula(id){
	var url=$("url").value;
	sR(url+"ajax_functions.php","id="+id+"&type=our_formula","POST","our_formula_container");
}
function change_rooms_title(){
	var val=$("rooms_title").value;
	document.forms['rooms_title_form'].action=val;
	document.forms['rooms_title_form'].submit();
}
var name,email;
function submit_news(){
	if(checkForm()){
		var url=$("url").value;
		name=$("news_name").value;
		email=$("news_email").value;
		country=$("news_country").value;
		sR(url+"ajax_functions.php","country="+country+"&name="+name+"&email="+email+"&type=news_form","POST","news_form");
	}
}