function parse_bio_location()
    {
       var s = document.location.hash.substr(1);
        if(s){
           var links=new Array();
            links[0]="profile";
            links[1]="snaps";
            links[2]="videos";
            links[3]="schedule"; 
           
            if(links.inArray(s)){
              eval('showBio'+stCap(s)+'("'+currentModelId +'");');
            }else{
               showBioProfile(currentModelId);
               document.location.href='#profile';
            }
    }else{
          showBioProfile(currentModelId);
          document.location.href='#profile'; 
         }
	showModelRating(0);
     }

    
Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array. Returns false if it is not.
{
var i;
for (i=0; i < this.length; i++) {
// Matches identical (===), not just similar (==).
if (this[i] === value) {
return true;
}
}
return false;
};
    

function stCap(strObj){
return(strObj.charAt(0).toUpperCase()+strObj.substr(1).toLowerCase());
}

function activateBioTab(tabId){
    document.getElementById('tabProfile').className=''; 
    document.getElementById('tabSnaps').className=''; 
    document.getElementById('tabVideos').className=''; 
    document.getElementById('tabSchedule').className=''; 
    if (document.getElementById('tabRequest')) document.getElementById('tabRequest').className='';
    document.getElementById(tabId).className='active';
}
function whenCompletedBioProfile(){
    activateBioTab(currentTab);
    var bio_holder = document.getElementById('bio_holder'); 
    bio_holder.innerHTML = ajax.response; 
    if(currentTab == 'tabSchedule'){
    	new Calendar({ date: 'Y-m-d' }, { classes: ['dashboard'], direction: 1, tweak: {x: 3, y: -3} });
    	addEmbedSchedule(currentModelId,gmtHours);
    //showCalendar();  
    }
   
}
function whenLoadingBioProfile(){
    var bio_holder = document.getElementById('bio_holder'); 
    bio_holder.innerHTML = '<div id="bio_holder_preloader"></div>'; 
}
function showBioProfile(modelId){
       currentTab = 'tabProfile';
       ajax.requestFile = "index.php";
       ajax.setVar("_o","Bio");
       ajax.setVar("_m","modelBioProfilePage");
       ajax.setVar("model_id",modelId);
       ajax.method = "GET";
       ajax.onLoading = whenLoadingBioProfile; 
       ajax.onCompletion = whenCompletedBioProfile;
       ajax.runAJAX();
}

function showBioSnaps(modelId){
       currentTab = 'tabSnaps';
       ajax.requestFile = "index.php";
       ajax.setVar("_o","Bio");
       ajax.setVar("_m","modelBioSnapsPage");
       ajax.setVar("model_id",modelId);
       ajax.method = "GET";
       ajax.onLoading = whenLoadingBioProfile;
       ajax.onCompletion = whenCompletedBioProfile; 
       ajax.runAJAX();  
}

function showBioVideos(modelId){
       currentTab = 'tabVideos';
       ajax.requestFile = "index.php";
       ajax.setVar("_o","Bio");
       ajax.setVar("_m","modelBioVideosPage");
       ajax.setVar("model_id",modelId);
       ajax.method = "GET";
       ajax.onLoading = whenLoadingBioProfile;
       ajax.onCompletion = whenCompletedBioProfile; 
       ajax.runAJAX();
}
function showBioSchedule(modelId){
	  //var now = new Date();
       //var gmtHours = - now.getTimezoneOffset()/60;
       currentTab = 'tabSchedule';
       ajax.requestFile = "index.php";
       ajax.setVar("_o","Bio");
       ajax.setVar("_m","modelBioSchedulePage");
       ajax.setVar("model_id",modelId);
	   ajax.setVar("user_tz",gmtHours);
       ajax.method = "GET";
       ajax.onLoading = whenLoadingBioProfile;
       ajax.onCompletion = whenCompletedBioProfile; 
       ajax.runAJAX();
       //addEmbedSchedule(modelId,gmtHours);
}
function showBioRequest(modelId){
       currentTab = 'tabRequest';
       ajax.requestFile = "index.php";
       ajax.setVar("_o","Bio");
       ajax.setVar("_m","modelBioRequestPage");
       ajax.setVar("model_id",modelId);
       ajax.method = "GET";
       ajax.onLoading = whenLoadingBioProfile;
       ajax.onCompletion = whenCompletedBioProfile;
       ajax.runAJAX();
}

var embed_schedule_ajax = new sack();
function addEmbedSchedule(modelId,gmtHours){
	   embed_schedule_ajax.requestFile = "index.php";
       embed_schedule_ajax.setVar("_o","Bio");
       embed_schedule_ajax.setVar("_m","renderBioScheduleSWF");
       embed_schedule_ajax.setVar("model_id",modelId);
       embed_schedule_ajax.setVar("user_tz",gmtHours);
       embed_schedule_ajax.method = "GET";
       //embed_schedule_ajax.onLoading = whenLoadingBioProfile;
       embed_schedule_ajax.onCompletion = whenCompletedEmbedSchedule; 
       embed_schedule_ajax.runAJAX();
}
function whenCompletedEmbedSchedule(){
	eval(embed_schedule_ajax.response);
}


function whenCompletedChangeFavorite(src){
   document.getElementById('bio_favorites').innerHTML = fav_ajax.response;

}
function changeFavorite(flag){
       fav_ajax.requestFile = "index.php";
       fav_ajax.setVar("_o","Bio");
       fav_ajax.setVar("_m","modelBioAddToFavoritesPage");
       fav_ajax.setVar("flag",flag);
       fav_ajax.setVar("model_id",currentModelId);
       fav_ajax.method = "GET";
       fav_ajax.onCompletion = whenCompletedChangeFavorite;
       fav_ajax.runAJAX();
}

function whenCompletedNotifyMe(){
	document.getElementById('notifyMe').innerHTML = email_ajax.response;
}
function notifyMe(flag){
   	email_ajax.requestFile = "index.php";
       email_ajax.setVar("_o","Bio");
       email_ajax.setVar("_m","modelBioOnlineModelPage");
       email_ajax.setVar("model_id",currentModelId);
       email_ajax.setVar("flag",flag);
       email_ajax.method = "GET";
	email_ajax.onCompletion = whenCompletedNotifyMe;
       email_ajax.runAJAX();
}





function whenCompletedModelRating(){
    document.getElementById('bio_rating').innerHTML=rating_ajax.response;;
}

function showModelRating(rating){
	rating_ajax.requestFile = "index.php";
       rating_ajax.setVar("_o","Bio");
       rating_ajax.setVar("_m","modelBioRatingPage");
       rating_ajax.setVar("model_id",currentModelId );
       rating_ajax.setVar("rating",rating);
       rating_ajax.method = "GET";
       rating_ajax.onCompletion = whenCompletedModelRating;
       rating_ajax.runAJAX();
}





function setFlashSize(flag){
var newHeight;
switch(flag){
	case '1':
		newHeight = 307;
	break;    
	case '2':
       	newHeight = 695;
	break;
	case '0':
	default:
		newHeight = 275
	}
	//alert(newHeight);
	document.getElementById('member_console').style.height = newHeight+'px';
}

function whenCompletedOnlineHosts(){
document.getElementById('bio_online_hosts').innerHTML = online_ajax.response;
	
}
function showOnlineHosts(){
	online_ajax.requestFile = "index.php";
       online_ajax.setVar("_o","Bio");
       online_ajax.setVar("_m","modelBioOnlineHostsPage");
       online_ajax.setVar("only_online",1);
       online_ajax.method = "GET";
       online_ajax.onCompletion = whenCompletedOnlineHosts; 
       online_ajax.runAJAX();
}

function showGalleryPicture(src){
document.getElementById('bio_model_main_thumb').src = src;
}

function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if ((!isDigit(c)) && (c!='.') && (c!=',') ){ return false;}
      }

      return true;
   }

function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }




var setA_ajax = new sack();
function whenCompletedAppointment(){
	   resetAppointment();
       document.getElementById('success').style.display='block';
}
function whenCompletedRequest(){
	   resetRequest();
       document.getElementById('success').style.display='block';
}
function validateAppointment(date,duration,time_hour,time_min,ampm){
	document.getElementById('success').style.display='none';	
	document.getElementById('error_empty_fields').style.display='none';
	document.getElementById('error_duration_not_number').style.display='none';
	document.getElementById('error_duration_minimum').style.display='none';
	var result = true;
	
	if(date==''){
		result = false;
		document.getElementById('error_empty_fields').style.display='block';
	} 
	if(time_hour==''){
		result = false;
		document.getElementById('error_empty_fields').style.display='block';
	} 
	if(time_min==''){
		result = false;
		document.getElementById('error_empty_fields').style.display='block';
	} 
	
	if(ampm==''){
		result = false;
		document.getElementById('error_empty_fields').style.display='block';
	} 
	
	
	if(duration==''){
		result = false;
		document.getElementById('error_empty_fields').style.display='block';
	} 
	if(duration!='' && !isInteger(duration)){
		result = false;
		document.getElementById('error_duration_not_number').style.display='block';
	}
	if((duration!='') && (isInteger(duration)) && (duration<5)){
		result = false;
		document.getElementById('error_duration_minimum').style.display='block';
	}
	return result;
}
function sendAppointment(){
	if(user_logged == 'true'){

	   var date = document.getElementById('date').value;
       var  time_hour = document.getElementById('time_hour').value; 
       var  time_min = document.getElementById('time_min').value; 
	   
       var time = time_hour + ':' + time_min + ':00';
       
       var ampm = document.getElementById('ampm').value;
       var duration = document.getElementById('duration').value;
       var comment = document.getElementById('comment').value;

       if(validateAppointment(date,duration,time_hour,time_min,ampm)){
       setA_ajax.requestFile = "index.php";
       setA_ajax.setVar("_o","Bio");
       setA_ajax.setVar("_m","setAppointment");
       setA_ajax.setVar("model_id",currentModelId );
       setA_ajax.setVar("date",date);
       setA_ajax.setVar("time",time);
       setA_ajax.setVar("ampm",ampm);
       setA_ajax.setVar("duration",duration);
       setA_ajax.setVar("comment",comment);
       setA_ajax.method = "POST";
       setA_ajax.onCompletion = whenCompletedAppointment;
       setA_ajax.runAJAX();
       }
	}
}

function validateRequest(comment){
	document.getElementById('success').style.display='none';
	document.getElementById('error_empty_fields').style.display='none';
	document.getElementById('error_empty_comment').style.display='none';
	var result = true;

	if(comment==''){
		result = false;
		document.getElementById('error_empty_comment').style.display='block';
	}
	return result;
}

function sendRequest(){
	if(user_logged == 'true'){

       var comment = document.getElementById('comment').value;

       if(validateRequest(comment)){
       setA_ajax.requestFile = "index.php";
       setA_ajax.setVar("_o","Bio");
       setA_ajax.setVar("_m","sendRequest");
       setA_ajax.setVar("model_id",currentModelId );
       setA_ajax.setVar("comment",comment);
       setA_ajax.method = "POST";
       setA_ajax.onCompletion = whenCompletedRequest;
       setA_ajax.runAJAX();
       }
	}
}

function setAppointment(day,hour,min,duration){
    if(hour>12){
      document.getElementById('ampm').value = 'PM';
      hour = hour - 12;
    }else{
      document.getElementById('ampm').value = 'AM';
    }
     document.getElementById('time_hour').value = hour;
     document.getElementById('time_min').value = min;
     document.getElementById('duration').value = duration;
     document.getElementById('date').value = days[day];
}

function resetRequest(){
       document.getElementById('comment').value='';
}

function resetRequest(){
       document.getElementById('comment').value='';
}

function resetAppointment(){
	   document.getElementById('date').value='';
       document.getElementById('time_hour').value='';
       document.getElementById('time_min').value='';
       document.getElementById('ampm').value='';
       document.getElementById('duration').value='';
       document.getElementById('comment').value='';
}
