
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Ajax function
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/********************************************************************************************************************************
* Function Name: ajaxLink
* Description: 
********************************************************************************************************************************/
function ajaxLink(strUrl, waitingMessage, websiteUrl, responseObjectName, waitingObjectName)
{
	var actionUrl = strUrl;
	$.ajax(
	{
		type: "GET",
		url: actionUrl,
		timeout: 75000, beforeSend: function(x) 
		{
			var waitingIdicator = "<img src=\"" + websiteUrl + "images/ajax-loader.gif\" align=\"left\" hspace=\"6\" />" + waitingMessage;
			$("#" + waitingObjectName).html(waitingIdicator);
		},
		dataType: "html",
		success: function(data)
		{
			//Remove the waiting Idicator
			$("#" + waitingObjectName).html("");
			$("#" + responseObjectName).html(data);
			
			//alert(data.PageMessage);
		},
		error: displayError 
	});
	return false;
}
/********************************************************************************************************************************
* Function Name: displayError
* Description: handle ajax error
********************************************************************************************************************************/
function displayError(XMLHttpRequest, textStatus, errorThrown) 
{
	try 
	{
		alert(XMLHttpRequest.responseText);
		alert("AJAX error: error Type: " + textStatus + " \nError Description: " + errorThrown);
		if (textStatus == "timeout") 
		{
			alert("Time out");
		}
	}
	catch (e) 
	{
	}
} 

/********************************************************************************************************************************
* 
********************************************************************************************************************************/
function displayVideoDialog()
{
	$("a[name='show_video_dialog']").click
	(
	 	
		function()
		{
			var loadLink = $(this).attr("title");
			
			var loadControl = $(this).attr("href");
			var title = $(loadControl).attr("title");
			$(loadControl).load(loadLink).dialog({
				modal: true,
				bgiframe: true,
				autoOpen: false,
				height: 350,
				width: 500,
				draggable: true,
				resizeable: true
		 	}); 
			$(loadControl).dialog("open");
			return false;
		}
	);
}

/********************************************************************************************************************************
* Function Name: openDivWindow
* Description: display div window 
********************************************************************************************************************************/
function openDivWindow(strUrl, width, height)
{
	//Remove the currentWindow
	$("#divWindow").show().remove();
	var actionUrl = strUrl;
	
	
	
	if(width == null)
	{
		width = 400;
	}
	if(height == null)
	{
		width = 550;
	}
	$.ajax(
	{
		type: "GET",
		url: actionUrl,
		timeout: 65000, 
		beforeSend: function(x) 
		{


		},
		dataType: "html",
		success: function(data)
		{
			//Remove the waiting Idicator
			 
    
	
		
			var divWindow = "<div id=\"divWindow\" style=\"display:none;position:absolute; z-index:1000; top:0px; width:" + width + "px;  height:" + height + "px; \">" + data + "</div>";
			$("#main_wrapper").prepend(divWindow);
			//Position window
			
			var topPos = ($(window).height() - $("#divWindow").height() )/2 + $(window).scrollTop();
    		var leftPos = ($(window).width() - $("#divWindow").width() )/2 + $(window).scrollLeft();
			
			$("#divWindow").css("position","absolute");
			$("#divWindow").css("left",leftPos + "px");
			if(topPos <= 0)
			{
				topPos = 10;
			}
			//End of Position window
			$("#divWindow").show();
			
			$("#divWindow").animate({top:"+=" + topPos + "px"}, 1000);
			//alert(data.PageMessage);
		} 
	});
	return false;
}

/********************************************************************************************************************************
* Function Name: closedivWindow
* Description: close the current chat window 
********************************************************************************************************************************/
function closeDivWindow()
{
		$("#divWindow").animate({top:"0px"}, 1000);
		$("#divWindow").hide(500, function()
			{
				$("#divWindow").show().remove();
			}
		);
		

}
/********************************************************************************************************************************
* 
********************************************************************************************************************************/
function selectSpotImage(TestimonialVideoID)
{
	$("img[class=img_selected]").attr("class","img");;
	
	$("#spot_image_" + TestimonialVideoID).attr("class","img_selected");
	if(document.getElementById("hCurrentTestimonialVideoID") != null)
	{
		document.getElementById("hCurrentTestimonialVideoID") = TestimonialVideoID;
	}
}
/********************************************************************************************************************************
* Function Name: ajaxSubmit
* Description: Perform a submit form using ajax
********************************************************************************************************************************/

function ajaxSubmitDiv(divName, buttonName, responseObjectName, waitingObjectName, actionUrl, waitingMessage, websiteUrl)
{
	//Do ajax submit
	var postData = $("#" + divName + " *").serialize();
	//alert(postData);
	postData = postData + "&" + buttonName + "=submit"

	$.ajax(
	{
		type: "POST",
		url: actionUrl,
		data: postData,
		timeout: 65000, 
		beforeSend: function(x) 
		{
			var waitingIdicator = "<div class=\"waitingmessage\" name=\"waitingMessage\"><img src=\"" + websiteUrl + "images/ajax-loader.gif\" align=\"left\" hspace=\"6\" />" + waitingMessage + "</div>";
			$("#" + waitingObjectName).prepend(waitingIdicator);
		},
		dataType: "html",
		success: function(data)
		{
			//return false;
			//Remove the waiting Idicator
			$("#" + waitingObjectName).html("");
			
			$("#" + responseObjectName).html(data);
			loadPage();
			//alert(data.PageMessage);
		},
		error: displayError 
	});
	return false;
}

