var quick_quote={
		'branch':'',
		'branch_id':'0',
		'category':'',
		'category_id':'',
		'country':'',
		'country_id':'',
		'category_option_value_id':'',
		'selected_hospital':0,
		'selected_treatment':0
		}
var nextfield='';		
		
function IsNumeric(strString)
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
function select_this(obj){
	var req = new Ajax('/query/getTreatments',{ 
		method: 'post',
		data:{'op':'getTreatments','id_branch':obj.value},
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			quick_quote.branch_id=obj.value;
			quick_quote.branch=obj.options[obj.selectedIndex].text;
			$('category_holder').innerHTML='';
			$('category_holder').innerHTML=html;
			$('categories').disabled='';
			//Inject the new DOM elements into the results div.
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			alert('The request is failed.');
		}
	});
		$('quote_button').style.display='none';
		$('countries').disabled='disabled';
		$('categories').disabled='disabled';
	if(obj.value>0){
	$('category_holder').innerHTML='<span class="ajax-loading"></span>'+$('category_holder').innerHTML;
	req.request();	
	}
	


	}
	
	
	
	
	function select_this2(obj){
	
	var req = new Ajax('/query/getCountries',{ 
		method: 'post',
		data:{'op':'getCountries','id_cat':obj.value,'option_value_id':obj.options[obj.selectedIndex].title},
		onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('country_holder').innerHTML='';
			$('country_holder').innerHTML=html;
			$('countries').disabled='';
			$('quote_button').style.display='none';
			if(obj.value==0)quick_quote.selected_hospital=0;
			else
			quick_quote.selected_hospital=100;
			quick_quote.category_id=obj.value;
			quick_quote.category=obj.options[obj.selectedIndex].text;
			quick_quote.category_option_value_id=obj.options[obj.selectedIndex].title;

			//Inject the new DOM elements into the results div.
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			alert('The request is failed.');
		}
	});
			$('countries').disabled='disabled';
			if(obj.value!=''){	
			$('country_holder').innerHTML='<span class="ajax-loading"></span>'+$('country_holder').innerHTML;

	req.request();	
	}
	
	}

	function select_this3(obj){
	
	var req = new Ajax('/query/setCountry',{ 
		method: 'post',
		data:{'op':'setCountry','country_id':obj.value},
		onSuccess: function(html) {
			$('quote_button').style.display='';
			//Clear the text currently inside the results div.
			quick_quote.country_id=obj.value;
			quick_quote.country=obj.options[obj.selectedIndex].text;

			//Inject the new DOM elements into the results div.
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			alert('The request is failed.');
		}
	});
			if(obj.value!=''){	

	req.request();	
	}
	
	}

 
 
	var error=0;
function check(obj,type){
	obj.className='';	
	if((obj.id=='area' || obj.id=='area2') && obj.value.length>2)$(nextfield).focus();

	
	if(type=='tel')
	$('phone_number_header').className='label';
	
	if(type=='empty' && obj.value.length<2){
	obj.className='error';				
	error++;
	}else if(type=='email' && isEmail(obj.value)==false){
	obj.className='error';				

	}else if(type=='emailval' && obj.value!=$('email').value){

				var cityhc = new Element('span', {'class':'Kirmizi8Bold','text':'Email addresses do not match','id':obj.id+'val' }).inject(obj, 'after');
				error++;
	}else if(type=='tel' && (($('tel').value.length<5 && $('mobile').value.length<5) || (IsNumeric($("mobile").value)==false && IsNumeric($("tel").value)==false))){

		$('phone_number_header').className='error';
		error++;
				
	}	
		}
		
function isEmail(str) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = str;
   if(reg.test(address) == false) {
      return false;
   }
        
}




function checkThemAll2(){
	error=0;
check($('name'),'empty');
check($('lastname'),'empty');
check($('email'),'email');
check($('tel'),'tel');
check($('whentreatment'),'empty');
if(quick_quote.category_id>0)
{
	$('hospital_header').className='';
	var len=$('h_c').value;
	if(quick_quote.selected_hospital>=len)
	{
			$('hospital_header').className='error';
			error+=quick_quote.selected_hospital;
	}
}

//check($('tel'),'tel');
//check($('message'),'empty');
if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{
	$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
	}

		}
 function check_hospital(obj){
	 if(obj.checked)quick_quote.selected_hospital=0;else quick_quote.selected_hospital++;
	 
	 
	 if(quick_quote.category_id>0)
{
	$('hospital_header').className='';
	var len=$('h_c').value;
	if(quick_quote.selected_hospital>=len)
	{
			$('hospital_header').className='error';
			error+=quick_quote.selected_hospital;
	}
}

 }
 
 function checkThemAll3(){
	error=0;
check($('your_name'),'empty');
check($('your_email'),'email');
check($('recipients_name'),'empty');
check($('recipients_email'),'email');
check($('message'),'empty');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
}

 }
 function checkThemAllReview(){
	error=0;
check($('name'),'empty');
check($('email'),'email');
check($('country'),'empty');
check($('city'),'empty');
check($('message'),'empty');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
}

 }

 function check_treatment(obj){
	 if(obj.checked)quick_quote.selected_treatment++;else quick_quote.selected_treatment--;
	 
	 
		$('hospital_header').className='';
		var len=$('treatment_count').value-quick_quote.selected_treatment;
		if(len==$('treatment_count').value)
		{
				$('hospital_header').className='error';
				error+=quick_quote.selected_treatment;
		}

 }
 function checkThemAll4(){
	error=0;
	var len=$('treatment_count').value-quick_quote.selected_treatment;
	if(len==$('treatment_count').value)
	{
			$('hospital_header').className='error';
			error=1;
	}
check($('name'),'empty');
check($('lastname'),'empty');
check($('email'),'email');
check($('confirmdate'),'empty');
check($('tel'),'tel');
check($('hv'),'empty');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	
	if($('q_f_p'))$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
	
	
	}

 }
 
  function checkThemAll4_2(){
	error=0;
	check($('name'),'empty');
	check($('lastname'),'empty');
	check($('email'),'email');
	check($('confirmdate'),'empty');
	check($('tel'),'tel');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	
	if($('q_f_p'))$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
}

 }
  function checkThemAll4_3(){
	error=0;
		var len=$('treatment_count').value-quick_quote.selected_treatment;
	if(len==$('treatment_count').value)
	{
			$('hospital_header').className='error';
			error=1;
	}

	check($('name'),'empty');
	check($('lastname'),'empty');
	check($('email'),'email');
	check($('tel'),'tel');
check($('hv'),'empty');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	
	if($('q_f_p'))$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
}

 }
 function checkThemAll5(){
	error=0;
	var len=$('treatment_count').value-quick_quote.selected_treatment;
	if(len==$('treatment_count').value)
	{
			$('hospital_header').className='error';
			error=1;
	}
check($('name'),'empty');
check($('lastname'),'empty');
check($('email'),'email');
check($('tel'),'tel');
check($('message'),'empty');
check($('hv'),'empty');
if(uplds.length !=0)alert("Please wait till the attachement finishes uploading");
else if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	
	if($('q_f_p'))$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
}

 }
 function checkThemAll5_2(){
	error=0;
check($('name'),'empty');
check($('lastname'),'empty');
check($('email'),'email');
check($('tel'),'tel');
check($('message'),'empty');

if(error>0){alert('Please fill in all mendatory fields!');
return 0;}else{	
	if($('q_f_p'))$('q_f_p').style.display='none';
	$('processing_quote').style.display='';
	$('quick_quote_form').submit();
}

 }

 function checkThemAllQuote(){
	error=0;
	check($('name'),'empty');
	check($('lastname'),'empty');
	check($('email'),'email');
	check($('tel'),'tel');
	check($('whentreatment'),'empty');
	if(error>0){alert('Please fill in all mendatory fields!');
	return 0;}else{	
	}

 }

//------------------------------------------------free quote part ---------------------------------------------------
		var images_path='http://www.visitandcare.com/';
function addTreatment(id,op){   
		var gallery = $('cart');
		var error='';
		
		
		var addimages = function(images) {
			
			if(images.length!=0){
			gallery.empty();
			$('loading_place').empty();
			
			
			images.each(function(image) {
				if(image.error!='')error=image.error;
				var el = new Element('div', {'id':'cart'+image.id,'class':'preview'});
				$('tick'+image.id).empty();
				 var tick = new Element('img', {'src':images_path+'images/tick3.gif', 'title':'This treatment is in your basket.','alt':'This treatment is in your basket','border':'0','align':'absmiddle'}).inject($('tick'+image.id));
				 var ch = new Element('div', {'class':'cancel'}).inject(el);	
				var name = new Element('div', {'class': 'Arial12Black','html': image.name,'style':'width:500px; float:left;'}).setHTML(image.name).inject(ch, 'after');
				
				
							var ch2 = new Element('a', {'href': 'javascript:removeTreatment("'+image.id+'");'}).inject(ch);
	
				var cancel = new Element('img', {'src': images_path+'images/del.gif','align':'absmiddle', 'border':'0'}).inject(ch2);
				//var footer = new Element('hr',{'width': "100%"}).inject(ch, 'after');
				
				el.inject(gallery);
				$('nex').empty();
			var nl = new Element('a', {'href': 'get-a-free-quote/select-hospital','style':'cursor:pointer;text-align:right;float:right; padding-top:5px;'});
	
			 var next = new Element('img', {'src': images_path+'images/quote_next.gif', 'class':'nextbutton','border':'0','align':'absmiddle'}).inject(nl);
			 nl.inject($('nex'));
			 $('next-bottom').empty();
				var nl = new Element('a', {'href': 'get-a-free-quote/select-hospital','style':'cursor:pointer;text-align:right;float:right;'}).inject($('next-bottom'));
	
			 var next = new Element('img', {'src': images_path+'images/next-bottom.gif', 'class':'nextbutton','border':'0','align':'absmiddle'}).inject(nl);
	if(id==image.id)$('cart'+image.id).effect('background-color', {duration: 500}).start('#f00', 'fff');

			});
			
			
			 
			 
			}else{$('loading_place').empty();}
			if(error) alert(error);
		};
	if(op=='get')var url = '/query/addTreatment/'+id;
	else
				var url = '/query/addTreatment/'+id+'/'+$('count'+id).value+'/'+$('tra'+id).value;
				var request = new Json.Remote(url,{	
						method: 'post',
						onComplete: function(jsonObj) {
							addimages(jsonObj.previews);
						}
				}).send();

			
			
/*			var request = new Request.JSON({
				url:'query.php',
				onSuccess: function(jsonObj) {
					addimages(jsonObj.previews);
				},
				onFailure: function() {
				$('cart').set('text', 'The request failed.');
				$('loading_place').empty();
			}
			});
*/			
			
			
			
		if(op=='get')val="op=get&id="+id;
			else val="op="+op+"&id="+id+"&amount="+$('count'+id).value+"&tra="+$('tra'+id).value;
		request.send(val);
		loading2()
		}
		function check_gallery(gallery){
		$('cart').empty();
		var name = new Element('h5', {'class': 'Arial12Red','style':'text-align:center;'}).setHTML('Your treatment cart is empty.<br>Please select treatment.<br>');			
		var cancel = new Element('img', {'src': images_path+'images/empty.png', 'align':'absmiddle'}).inject(name);
		name.inject($('cart'));
		}		
		function loading2(){
		$('loading_place').empty();
		var cancel = new Element('img', {'src': images_path+'images/loading.gif', 'align':'absmiddle'}).inject($('loading_place'));		
		var cancel = new Element('span', {'text': 'Updating your cart', 'class':'Arial12Gray'}).inject($('loading_place'));		
		//var name = new Element('div', {'class': 'Arial12Red','html': 'Loading...','style':'text-align:center;'}).inject($('loading_place'));
		}
		
		
function removeTreatment(id){   
		log=$('cart'+id);
/*		var highlight = new Fx.Morph(log, {
		duration: 800,
		link: 'cancel',
		transition: 'Fx.Transitions.Quint.easeOut'
	});

*/	
	
	var gallery = $('cart');

	var addimages = function(images) {
		$('loading_place').empty();
		
/*				highlight.start({
				backgroundColor: ['#fff36f', '#fff'],
				opacity: [1, 0]
			});

*/	$('tick'+id).empty();
	log.remove();
	if(images.length==0){
		check_gallery();
	$('next-bottom').empty();
	$('nex').empty();}

				
	};

	
				var url = '/query/removeTreatment/'+id+'/'+$('tra'+id).value;
				var request = new Json.Remote(url,{	
						method: 'post',
						onComplete: function(jsonObj) {
							addimages(jsonObj.previews);
						}
				}).send();
				
				
				
				
				
				
				
	val="op=remove&id="+id;
	request.send(val);
	loading2();
	
	}
	
	
	
function getHospitals(id,op){   
			var gallery = $('hospitals');
			$('hospitals').empty();
			var addimages = function(images) {
				if(images.length!=0){
				gallery.empty();
				
				$('loading_place').empty();
				$('hospitalhc').empty();
			var el = new Element('option', {'value':'0','selected':'selected'}).setHTML('Choose a Hospital');
	el.inject(gallery);				
	var s;var s2;var ig=0;
				images.each(function(image) {
					
					var city = new Element('option', {'value':image.id}).setHTML(image.hospital);
					
					
					city.inject(gallery);
			
		
				});								if(images.length>1){s='s';s2=''; }else{ s='';s2='s';}				 
					 if(images.length>0)ig=images.length;			
				//$('hospitalsrow').highlight('#f00').focus();
	
				var cityhc = new Element('span', {'class':'Kirmizi8Bold'}).setHTML('&laquo; '+ig+' Hospital'+s+' offer'+s2+' your treatment.').inject($('hospitalhc'));
	
				}else{$('loading_place').empty();}
			};
		
				var url = '/query/getHospitals/'+id;
				var request = new Json.Remote(url,{	
						method: 'post',
						onComplete: function(jsonObj) {
							addimages(jsonObj.previews);
						}
				}).send();

			loading2()
			}
			
function addHospitals(id,op){   
		var gallery = $('hospitals');
		
		var addimages = function(images) {
			if(images.length==0)
				$('step3holder').style.display='none'; 
				else 
				$('step3holder').style.display='';
			var browserName=navigator.appName; 
			
			$('loading_place').empty();

			for(var i=1;i<5;i++){
								var def='<table align="center" border="0" cellpadding="0" cellspacing="0" width="127">    <tbody><tr>        <td class="grey20Bold" height="40" width="140">['+i+']</td>    </tr>    <tr>        <td align="left"><div style="text-align: left;" align="center">    <span>        <a id="ctl00_ContentPlaceHolder1_lnkAdd3" class="orange12" href="" style="color: rgb(255, 102, 0); font-size: medium;"></a></span></div>        </td>    </tr>    <tr>        <td><span id="ctl00_ContentPlaceHolder1_lblLocationAdd3" class="grey11Bold"></span></td>    </tr>    <tr>        <td align="center" valign="top"><span id="ctl00_ContentPlaceHolder1_lblyoumayAdd3" class="grey1Bold">you may</span></td>    </tr>    <tr>        <td class="red16Bold" align="center"><span id="ctl00_ContentPlaceHolder1_lblSelectonemoreAdd3" class="red16Bold">select one more<br>hospital above</span></td>    </tr>    <tr>        <td align="center" valign="bottom"></td>    </tr></tbody></table>';

				$('hh'+i).innerHTML=def;;
				
				}
				
			if(images.length!=0){
			i=0;
			var error=0;
			$('buttonholder').empty();
			var another = new Element('img', {'src': images_path+'images/add_another_hospital.gif','align':'absmiddle', 'border':'0'}).inject($('buttonholder'));

			images.each(function(image) {
				if(image.error!='')error=image.error;			 
				i++;
				gallery=$('hh'+i);
				$('hh'+i).empty();
				var holder = new Element('div', {'id':'hhh'+i});
				var table = new Element('table', {'class':'hcart'});
				var row1 = new Element('tr');
				var row2 = new Element('td', {'class':'Arial14GrayBold','style':'padding-bottom:7px;' }).setHTML('['+i+']').inject(row1);
				row1.inject(table);
				if(image.logo!=''){
					var row3 = new Element('tr');
					var row4 = new Element('td', {'class':'orange12'}).inject(row3);
					var img = new Element('img', {'src':images_path+'images/logos/'+image.logo,'class':'hospital_logo' }).inject(row4);
					row3.inject(table);
				}
				var row3 = new Element('tr');
				var row4 = new Element('td', {'class':'Arial12BlueBold' }).setHTML(image.name).inject(row3);
				row3.inject(table);
				var row5 = new Element('tr');
				var row6 = new Element('td', {'class':'grey11Bold' }).setHTML(image.city+' / '+image.country).inject(row5);
				row5.inject(table);
				var row7 = new Element('tr');
				var row8 = new Element('td').inject(row7);
				var ch2 = new Element('a', {'href': 'javascript:addHospitals("'+image.id+'","removeHospital");'}).inject(row8);
				var cancel = new Element('img', {'src': images_path+'images/del.gif','align':'absmiddle', 'border':'0'}).inject(ch2);

				row7.inject(table);
				
				
				table.inject(holder);
				holder.inject(gallery);
				if (browserName=="Microsoft Internet Explorer")
				$('hh'+i).innerHTML=holder.outerHTML;
				
		//if(id==image.id)$('hh'+i).effect('background-color', {duration: 500}).start('#f00', 'fff');

	
			});		

			if(error!='')alert(error);		 



			}else{$('loading_place').empty();}
		};
	
			if(op=='removeHospital')var url = '/query/removeHospital/'+id;
			else var url = '/query/addHospital/'+id;
				var request = new Json.Remote(url,{	
						method: 'post',
						onComplete: function(jsonObj) {
							addimages(jsonObj.previews);
						}
				}).send();

				loading2()
		}



function getCities(id,op){   
		var gallery = $('cities');
			$('hospitals').empty();
			$('hospitalhc').empty();
			$('cities').empty();
			$('cityhc').empty();
			
		var addimages = function(images) {
			if(images.length!=0){
			gallery.empty();
			
			$('loading_place').empty();
			$('cityhc').empty();
			var el = new Element('option', {'value':'0','selected':'selected'}).setHTML('Choose a City');
el.inject(gallery);				
var s;var s2;var ig=0;
			images.each(function(image) {
				if(image.count>1){s='s';s2=''; }else{ s='';s2='s';}				 
				 if(image.count>0)ig=image.count;
				var city = new Element('option', {'value':image.id}).setHTML(image.city) ;
				
				
				city.inject(gallery);
				
			//	$('cityrow').highlight('#f00').focus();
			});				
			var cityhc = new Element('span', {'class':'Kirmizi8Bold' }).setHTML('&laquo; '+ig+' Hospital'+s+' offer'+s2+' your treatment.').inject($('cityhc'));

			cityhc.inject($('cityhc'));
			}else{$('loading_place').empty();}
		};
				var url = '/query/getCities/'+id;
				var request = new Json.Remote(url,{	
						method: 'post',
						onComplete: function(jsonObj) {
							addimages(jsonObj.previews);
						}
				}).send();


			/*var request = new Request.JSON({
				url:'query.php',
				onSuccess: function(jsonObj) {
					addImages(jsonObj.previews);
				},
				onFailure: function() {
				$('cart').set('text', 'The request failed.');
				$('loading_place').empty();
			}
			});
			val="op="+op+"&country="+id;
		request.send(val);*/
		loading2()
		}
		function showButton(){
			var addbut='<input id="ctl00_ContentPlaceHolder1_btnAdd" src="/images/add_hospital.gif" style="border-width: 0px;" type="image" onclick="addHospitals($(\'hospitals\').value, \'addHospitals\');">';
			$('buttonholder').innerHTML=addbut;
			}
			



function getDialingCode(cc){

	

	var req = new Ajax('/query/getCC',{ 
		method: 'post',
		data:{'op':'getDialingCode','cc':cc},
		onSuccess: function(html) {
			$('dialing').value='+'+html;
			//Inject the new DOM elements into the results div.
			$('dialing2').value='+'+html;

			//Inject the new DOM elements into the results div.
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			alert('The request is failed.');
		}
	});
			if(cc!=''){	

	req.request();	
	}
	


	
	var val="op=getDialingCode&cc="+cc;
	
		req.send(val);
	
	
}
		

function FN_mv() {
	this.className="hover";
}
function FN_mt() {
	this.className="";
}
function FN_initMnC(m) {
	var menu,lis=[];
	menu= document.getElementById("center");
	if (menu) lis = menu.getElementsByTagName("li");
	for (var x=0;x<lis.length;x++) {
		lis[x].onmouseover=FN_mv;
		lis[x].onmouseout=FN_mt;
	}

}