/*********************************************************************************************************************************/
/************************************************** START: GLOBAL VARIABLES ******************************************************/
/*********************************************************************************************************************************/
	var http 		= getHTTPObject();			// creating the HTTP Object
	var isWorking 	= false;					// flag - present status on whether any process is in progress or not.
	var counter 	= 0;
	var arrTestimonialDetails = new Array(); 
/*********************************************************************************************************************************/
/**************************************************** END: GLOBAL VARIABLES ******************************************************/
/*********************************************************************************************************************************/

/*********************************************************************************************************************************/
/************************************************** START: FORM LEVEL CHECKS *****************************************************/
/*********************************************************************************************************************************/
	function toggleText(e,div_val)
	{
		new Effect.toggle(div_val,'slide');
		if(e.innerHTML == "more...")
			e.innerHTML = "close...";
		else
			e.innerHTML = "more...";
	}
/*********************************************************************************************************************************/
/**************************************************** END: FORM LEVEL CHECKS *****************************************************/
/*********************************************************************************************************************************/


/*********************************************************************************************************************************/
/************************************************ START: FADE IN - APPEAR TESTIMONIALS (AJAX BASED) ******************************/
/*********************************************************************************************************************************/
	// depending upon the browser type, it creates an HTTP object...
	function getHTTPObject()
	{
		var xmlhttp;
		/*@cc_on
		@if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
		@else
		xmlhttp = false;
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
		{
			try{
			  xmlhttp = new XMLHttpRequest();
			} catch (e) {
			  xmlhttp = false;
			}
		}
		return xmlhttp;
	}


	function testimonials()
	{
		if (!isWorking && http) 
		{
			http.open("GET", "complaintcenter_testimonials_fetchall.php", true);
			http.onreadystatechange = httpResponse_testimonials;
			isWorking = true;
			http.send(null);
		}
	}

	// returns the response or results from the source file.
	function httpResponse_testimonials()
	{
		if (http.readyState == 4)					// if HTTP has completed retreiving the data
		{
			if (http.status == 200 || http.status == 0) 			// If the data was retrieved successfully (OK)
			{ 														// Use the XML DOM to unpack the data 
				var xmlResponse = http.responseXML.getElementsByTagName("xmlResponse")[0];
				if(xmlResponse.childNodes.length > 0)				// if RECORD EXISTS then loop till the End of Records for the
				{													// selected date.
					for(i=0; i<xmlResponse.childNodes.length; i++)
					{
						ID					= xmlResponse.childNodes[i].getAttribute("id");			// ID
						UserDetails			= xmlResponse.childNodes[i].getAttribute("userDetails");// userDetails
						ShortDescription	= xmlResponse.childNodes[i].firstChild.data;			// ShortDescription
						ImagePath			= xmlResponse.childNodes[i].getAttribute("imagePath");	// userDetails
//						alert("i: " + i + "\nID: " + ID + "\nUser Details: " + UserDetails);// + "\nShortDescription: " + ShortDescription);
						
						arrTestimonialDetails[i]	= new Array(ID, UserDetails, ShortDescription, ImagePath);
						nTestimonialDetails = arrTestimonialDetails[i];
					}
				}
				// Start test loop
				loopTestimonials();		
			}
			else if (http.status != 0) 				// IE returns a status code of 0 on some occasions, so ignore this case
				 alert("Error while retrieving the URL: " + http.statusText); 

			isWorking = false;
		}
	}
	
	function loopTestimonials() 
	{
		// Code to show the testimonial
		var Id				= arrTestimonialDetails[counter][0];
		var UserDetails		= arrTestimonialDetails[counter][1];
		var ShortDescription= arrTestimonialDetails[counter][2];
		var ImagePath		= arrTestimonialDetails[counter][3];
		//alert("i: " + i + "\nID: " + ID + "\nUser Details: " + UserDetails + "\nShortDescription: " + ShortDescription);
		//new Effect.Fade("testimonials");
		var html			= " <table width=\"95%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\" style=\"line-height:18px;\">"
							+ "		<tr>"
							+ "			<td width=\"20%\" align=\"center\" valign=\"top\"><img src=\"./admin/"+ImagePath+"\" alt=\"Tenant Landord Disputes\" /></td>"
							+ "			<td width=\"80%\" align=\"left\">"+ShortDescription+" &nbsp; &nbsp; --- <em>"+UserDetails+"</em>"
							+ "				<div style=\"float:right;padding-right:25px;\"><a href=\"./complaint_center_testimonials.php#anc_"+Id+"\" class=\"skyblue\">more...</a></div>"
							+ "			</td>"
							+ "		</tr>"
							+ "	</table>";
		document.getElementById("testimonials").innerHTML = html;
		//new Effect.Appear("testimonials");
		
		// increment counter
		counter++;
		// when at the end, start again
		if (counter == arrTestimonialDetails.length)
			counter = 0;

		setTimeout(loopTestimonials, 7000);
	}

	
	window.onload = testimonials;

/*********************************************************************************************************************************/
/************************************************** END: FADE IN - APPEAR TESTIMONIALS (AJAX BASED) ******************************/
/*********************************************************************************************************************************/