/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getPage(index){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will 		
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	/*
	http.open('get', 'internal_request.php?action=get_products&id=' 
			+ document.form_category_select.select_category_select.selectedIndex);*/
	http.open('get', 'internal_request.php?id='+ index);	
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
	
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
			info =  http.responseText.split("::");
			image = info[6].split(',');
			if (info[9]==1){
				document.getElementById('name').innerHTML = "Featured Therapist - "+info[1];
			} else {
				document.getElementById('name').innerHTML = info[1];
			}
			document.getElementById('age').innerHTML = '<b>Age:</b> '+info[2];
			document.getElementById('weight').innerHTML = '<b>Weight:</b> '+info[3];
			document.getElementById('height').innerHTML = '<b>Height:</b> '+info[4];
			document.getElementById('vital').innerHTML = '<b>Vital Statistics:</b> '+info[5];
			document.getElementById('descr').innerHTML = '<b>Description:</b> '+info[7];
			viewThumbs();
			viewPhoto(0);
			viewVideo(info[8]);			
	}
}
function viewThumbs(){
	tempArray = new Array();
	var count = 0;
	
	for (i=0;i<image.length;i++){			
		if(image[i]!=""){
			tempArray[count] = image[i];
			count++;
		}
	}
	var img = "";
	for (i=0;i<tempArray.length;i++){
		img += '<a href="javascript:viewPhoto('+i+')"><img src="images/therapist/S/'+tempArray[i]+'" alt='+info[1]+' border="0"></a>&nbsp;&nbsp;';
	}
	document.getElementById('Image').innerHTML = img;	  
}
function therapist(id){
	pageDown();
	window.open ("therapist_info.php?id="+id,"mywindow");	
}
function viewPhoto(id){
	document.getElementById('galleryimage').innerHTML = '<a href="images/therapist/L/'+tempArray[id]+'" rel="lightbox" title="'+info[1]+'"><img src="images/therapist/M/'+tempArray[id]+'" alt='+info[1]+' border="0"></a>';
	initLightbox();
}
function viewVideo(src){
	document.getElementById('video').innerHTML = '<iframe src="video.php?src='+src+'" frameborder="0" width="230" height="249" allowtransparency="1"></iframe>';
}
function viewFacility(src){
	document.getElementById('facility').innerHTML = '<a href="images/lodging/L/'+src+'" rel="lightbox[lodging]"><img src="images/lodging/M/'+src+'" border="0"></a>';
	initLightbox();
}
function viewMassage(src){
	document.getElementById('facility').innerHTML = '<a href="images/massage/L/'+src+'" rel="lightbox[lodging]"><img src="images/massage/M/'+src+'" border="0"></a>';
	initLightbox();
}
function pageDown() {
  if (window.scrollBy)
    window.scrollBy(0, window.innerHeight ? window.innerHeight : 
document.body.clientHeight);
}
function pageUp() {
  if (window.scrollBy)
    window.scrollBy(0, window.innerHeight ? -window.innerHeight : -
document.body.clientHeight);
}


