// JavaScript Document
var xmlHttp = false;
form="";
try 
{
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e) 
{
  try 
  {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch (e2) 
  {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
{
  xmlHttp = new XMLHttpRequest();
}

function checkStatus(photoID)
{
	alert("Starting Download...");
	URL=escape('ajax_check_status.php')+'?PhotoID='+escape(photoID);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnStatus;
	xmlHttp.send(null);
}

function returnStatus()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			alert("Hi");
			document.getElementById('status').innerHTML = "Processing";	
			document.getElementById('upload').innerHTML = response;			
		}
	}
	//pausecomp(500);
}
function checkEmailStatus(email)
{
	URL=escape('ajax_check_mail.php')+'?Email='+escape(email);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnEmailStatus;
	xmlHttp.send(null);
}
function returnEmailStatus()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response == "false")
		{
			document.getElementById('chkEmail').style.color = "#006600";
			document.getElementById('chkEmail').innerHTML = "Available";
		}
		else
		{
			document.getElementById('chkEmail').style.color = "#FF0000";
			document.getElementById('chkEmail').innerHTML = "Not Available";
		}
	}
}

function setTheme(CatID)
{
	URL=escape('ajax_get_theme.php')+'?CatID='+escape(CatID);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnTheme;
	xmlHttp.send(null);
}

function returnTheme()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			//get_theme(response);
			document.getElementById('div_ThemeID').innerHTML = response;			
		}
	}
	//pausecomp(500);
}

function ChkEmailAvailability(Email)
{
	URL=escape('ajax_check_email.php')+'?Email='+escape(Email);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnEmailAvailability;
	xmlHttp.send(null);
}

function returnEmailAvailability()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('EmailCheck').innerHTML = response;			
		}
	}
	
}

function ChkUsernameAvailability(Username)
{
	URL=escape('ajax_check_email.php')+'?Username='+escape(Username);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnUsernameAvailability;
	xmlHttp.send(null);
}

function returnUsernameAvailability()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('Usernamecheck').innerHTML = response;			
		}
	}
	
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}


/******************
* Check Product availibility using product id
******************/
function ChkProductAvailability(ProductID)
{
	URL=escape('ajax-request.php')+'?ProductID='+escape(ProductID);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnProductAvailability;
	xmlHttp.send(null);
}

function returnProductAvailability()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('ProductAvailabilityArea').innerHTML = response;			
		}
	}
}


// check user id availability
function ChkUserAvailability(UserID)
{
	URL=escape('ajax-request.php')+'?UserID='+escape(UserID);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnUserAvailability;
	xmlHttp.send(null);
}

function returnUserAvailability()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('UserAvailabilityArea').innerHTML = response;			
		}
	}
}

function ChkCustomProjectAvailability(CustomProjectID)
{
	URL=escape('ajax-request.php')+'?CustomProjectID='+escape(CustomProjectID);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnCustomProjectAvailability;
	xmlHttp.send(null);
}

function returnCustomProjectAvailability()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('CustomProjectAvailabilityArea').innerHTML = response;			
		}
	}
}

function ChangeNavigation(id)
{
	URL=escape('ajax-change-navigation.php')+'?NavType='+escape(id);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnNavigationChanged;
	xmlHttp.send(null);
}
function returnNavigationChanged()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('linkList').innerHTML = response;			
		}
	}
}

function CallRefineSearch(param)
{
	URL=escape('ajax_refine_search_result.php')+'?'+param;
	//alert(URL);
	xmlHttp.open("GET", URL, true);
	xmlHttp.onreadystatechange = returnRefineSearchResult;
	xmlHttp.send(null);
}
function returnRefineSearchResult()
{
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		if(response!='') 
		{
			document.getElementById('resultloading').style.display = 'none';
			/*if(response!='No Results Found')
			{*/
				document.getElementById('SearchResult').innerHTML = response;
				document.getElementById('SearchResultText').innerHTML = "";
				document.getElementById('SearchResultPages').innerHTML = "";
				document.getElementById('paging').innerHTML = "";
				
				// reload the gmap in iframe
				document.getElementById("iframeGMap").src = document.getElementById('iframeGmapSrc').value;
			//}
		}
	}
}
