  function silentErrorHandler() {return true;}
  window.onerror=silentErrorHandler;  

  function new_review(){     
    get_tab('new_review',escort_id,0);
  }

  function show_big_image(image_id,member){		  
	 var call = '/escort/image/' + escort_id   + '/' + image_id;
	 if (member==1){
	   call = call + '/1';
	 }  
	 new Effect.Fade("large_pic",{ duration: 0.1 });
	 setTimeout("new Ajax.Updater('large_pic',   '" + call + "' , { method: 'get', onComplete:function(){ new Effect.Appear('large_pic',{ duration: 0.15 });},asynchronous:true });",120);	
  }

  function show_image(ctl,pos){		
	var pause = pos * .5;		
	Effect.Appear(ctl,{ duration: pause });		
  }
	
  function urlencode(s) {
    s = encodeURIComponent(s);
    s = s.replace(/\'/g,"%27");
    return s;   
  }
  
  var last_div = "profile";
  function get_tab(tab,escort_id,currency)
  {	  	  
	  
	// Set the active class in the selected tab
	  
	// Switch off the active class on the other tabs
	set_active_tab('tab_members','');
	set_active_tab('tab_profile','');
	set_active_tab('tab_reviews','');
	set_active_tab('tab_diary','');
	set_active_tab('tab_book_members','');	
	
	var tab_container = 'tab_' + tab;
	set_active_tab(tab_container,'active');
	
	
	// Change the tab itself  
	var currency = (currency == null) ? "0" : currency;
	new Effect.Fade(last_div,{ duration: 0.25 });
	
		
	switch (tab) 
	{
	case 'profile' :		
      setTimeout("new Effect.Appear('profile',{ duration: 0.25 });",600);
      last_div="profile";
      var call = '/escort/rates/' + escort_id + '/' + currency;
      new Ajax.Updater('rates', call , { method: 'get'});
      break;
	case 'reviews' :	      
	  setTimeout("new Effect.Appear('review',{ duration: 0.25 });",600);
	  last_div="review";
	  break;
	case 'book' :
	  setTimeout("new Effect.Appear('book',{ duration: 0.25 });",600);
	  last_div="book";
	  init_dhtmlxCalendar();
	  break;
	case 'book_members' :		
	  setTimeout("new Effect.Appear('book_members',{ duration: 0.25 });",600);
	  last_div="book_members";
	  init_dhtmlxCalendar();
	  break;  
	default :         
	  var call = '/escort/' + tab + '/' + escort_id + '/' + currency;	  
	  setTimeout("new Ajax.Updater('ajax', '" + call + "', { method: 'get', onComplete:function(){ new Effect.Appear('ajax',{ duration: 0.25 });},asynchronous:true });",600);
	  last_div="ajax";
	}		  
	
	
	
	
  }   
 
    
  function submit_review(){	  	 	 
  
	  var call = '/escort/new_review/' + escort_id ;	
	  new Effect.Fade('ajax',{ duration: 0.5 });	 

	  params = serialize("new_review");
	  
	  params = params + '&rate_looks=' + current['looks'];
	  params = params + '&rate_personality=' + current['personality'];
	  params = params + '&rate_performance=' + current['performance']; 
	  params = params + '&rate_agency=' + current['agency'];   	  
	  setTimeout("new Ajax.Updater('ajax', '" + call + "', {  parameters: '" + params + "', method: 'post', onComplete:function(){ new Effect.Appear('ajax'); set_current_start()},asynchronous:true });",600);	  	 
  }

  function serialize(form){	  
	  params = "";	  
	  var flds=document.getElementById(form);
	  for (var i=0;i<flds.length;i++)
	  {
		  params = params +  "&" + flds.elements[i].name +"=" + urlencode(flds.elements[i].value); 	    	   
	  }
	  return params;
  }
    
  function submit_booking(){	  	 	   	
	 	 	  
	  
	  var call = '/escort/new_booking/' + escort_id ;	
	  new Effect.Fade('book',{ duration: 0.5 });	 

	  params = serialize("new_booking");	
	  // setTimeout("new Effect.Appear('book',{ duration: 0.25 });",600);	  
	  setTimeout("new Ajax.Updater('book', '" + call + "', {  parameters: '" + params + "', method: 'post', onComplete:function(){ new Effect.Appear('book');init_dhtmlxCalendar()},asynchronous:true });",600);
	  
	  
  }
  
  function init_dhtmlxCalendar(){	  	 

	  
    var cal1,
		cal2,
		mCal,
		mDCal,
		newStyleSheet;
    
	var dateFrom = null;
	var dateTo = null;	
	cal1 = new dhtmlxCalendarObject('apt_date');
	cal1.setDateFormat('%W %e% %M %Y');
  }

 
  function set_current_start(){
	  show_stars('looks',current['looks'] );
	  show_stars('personality',current['personality'] );
	  show_stars('performance',current['performance'] );
	  show_stars('agency',current['agency'] );
  }  
  
	var current =[] ;	
	
	function loadStars()
	{	   
	   
	   star1 = new Image();
	   star1.src = path + "star-off.gif";
	   star2 = new Image();
	   star2.src= path + "star-on.gif";
	}
	
	function highlight_star(ctrl)
	{				 		 
		 params = ctrl.split('_',2);
		 q = params[0];
		 id = params[1];

	   if(typeof (current[q]) == "undefined"){
		   current[q] = 0;
	   }
	      
		 if (current[q]> id){
			 for (i=1;i<=5;i++){
				 var star = q + "_" + i;
				 document.getElementById(star).src= star1.src;
			 }	 
		 }	 

		 current[q] = id;

		 show_stars(q,id);
	}

	function show_stars(q,value){
			 
		 var vote_text_control =  q + "_vote";
		 for (i=1;i<=value;i++){
			 var star = q + "_" + i;
			 switch(i)
			 {
			 case 1:
			   var vote_text = "Poor";
			   break;
			 case 2:
			   var vote_text = "OK";
			   break;
			 case 3:
			   var vote_text = "Good";
			   break;
			 case 4:
			   var vote_text = "Very Good";
			   break;
			 case 5:
			   var vote_text = "Superb";
			   break;
			 }
			 document.getElementById(star).src= star2.src;
			 document.getElementById(vote_text_control).innerHTML=vote_text;
		 }	     
	}	

	function set_active_tab(tab,class_name){
	  //alert(document.getElementById(tab));
	  //document.getElementById(tab).className=active;		
	  var tab_id = document.getElementById(tab);
	  if (tab_id !== null){		
	    tab_id.setAttribute("class", class_name);
	    tab_id.setAttribute("className", class_name);
	  }
    }