// JavaScript Document
var httpRequest=false;


// Function to send request by get method 
function initRequest()
{ 
	var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
	for (var i = 0; i < msxmlhttp.length; i++) 
	{
		try 
		{ 
			httpRequest = new ActiveXObject(msxmlhttp[i]); 
		}
		catch (e) { httpRequest =false;}
		if(!httpRequest && typeof XMLHttpRequest != "undefined")
		{
			try 
			{ 
				httpRequest = new XMLHttpRequest(); 
			}
			catch (e) { httpRequest = false;}
		}
				
	}
	
	
}

// Function to send request by get method 
function sendRequest(url,updateSection)
{ 
	var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
	for (var i = 0; i < msxmlhttp.length; i++) 
	{
		try 
		{ 
			httpRequest = new ActiveXObject(msxmlhttp[i]); 
		}
		catch (e) { httpRequest =false;}
		if(!httpRequest && typeof XMLHttpRequest != "undefined")
		{
			try 
			{ 
				httpRequest = new XMLHttpRequest(); 
			}
			catch (e) { httpRequest = false;}
		}
				
	}
	
	httpRequest.open("GET", url, true); 
	httpRequest.onreadystatechange = function() {processRequest(updateSection); };
	httpRequest.send(null);
}

// Function to send request by post method 
function sendPostRequest(url, parameters, updateSection) {
      httpRequest = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         httpRequest = new XMLHttpRequest();
         if (httpRequest.overrideMimeType) {
         	// set type accordingly to anticipated content type
            httpRequest.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!httpRequest) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	  httpRequest.onreadystatechange = function() {processRequest(updateSection); };
      httpRequest.open('POST', url, true);
      httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      httpRequest.setRequestHeader("Content-length", parameters.length);
      httpRequest.setRequestHeader("Connection", "close");
      httpRequest.send(parameters);
}

function processRequest(updateSection) 
{ 

    if(httpRequest.readyState == 4) 
    { 
		if(httpRequest.status == 200) 
        {
           	//Update the HTML 
			//alert(httpRequest.responseText);
			var msg = httpRequest.responseText;
			out_arr = msg.split('|');
			
			if(out_arr[1] == 'refreshCode')
			{
				
				document.getElementById('codeBox').innerHTML = out_arr[2];	
				
			}
			else if(out_arr[1] == 'getCaptcha')
			{
				document.getElementById('div_captcha').innerHTML = out_arr[2];	
			}
			else if(out_arr[1] == 'arrangeTeamMember')
			{
					
					document.getElementById(updateSection).innerHTML = out_arr[2];	
			}
			else if(out_arr[1] == 'arrangeAgencyImages')
			{
					
					document.getElementById(updateSection).innerHTML = out_arr[2];	
			}
			else if(out_arr[1] == 'showTeamDetails')
			{
				document.getElementById(updateSection).innerHTML = out_arr[2];	
			}
			else if(out_arr[1] == 'teamShowBack')
			{
				document.getElementById(updateSection).innerHTML = out_arr[2];	
			}
			else if(out_arr[1] == 'changeGroup')
			{
				if(out_arr[2]==1)
				{
					document.getElementById(updateSection).innerHTML = out_arr[3];	
				}
				else
				{
					document.getElementById(updateSection).innerHTML = "No Group Found.";	
				}
			}
			else
			{
					document.getElementById(updateSection).innerHTML = msg;	  
				
			}
			
        } 
        else 
        { 
            alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText); 
        }
    }         
} 



//To get Captch code 
function getCaptcha() 
{
	var url = "zsajax.php?do_action=getCaptcha";
	
	sendRequest(url, '');
	
	return false;
}


function refreshCode()
{
		var url = "zsajax.php?do_action=refreshCode";
		document.getElementById('codeBox').innerHTML = '<img src="images/loading.gif" border="0">'
		sendRequest(url, 'codeBox');
	
		return false;	
}


function changeGroup(townID)
{
	var url = "zsajax.php?do_action=changeGroup&townID="+townID;
	document.getElementById('divWaitBox').innerHTML = '<img src="images/loading.gif" border="0">'
	sendRequest(url, 'divWaitBox');

	return false;	
	
}

function showTeamDetails(memberID)
{
	
	if(memberID!='')
	{
			
		var url = "zsajax.php?do_action=showTeamDetails&memberID="+memberID;
		document.getElementById('team_details').innerHTML = '<img src="images/loading.gif" border="0">'
		sendRequest(url, 'team_details');
	}

	return false;	
	
}


function teamShowBack()
{
		var url = "zsajax.php?do_action=teamShowBack";
		document.getElementById('team_details').innerHTML = '<img src="images/loading.gif" border="0">'
		
		sendRequest(url, 'team_details');
		
		return false;	
}

function arrangeTeamMember(saveString)
{
	var url = "zsajax.php?do_action=arrangeTeamMember&saveString="+saveString;
		
	document.getElementById('divWaitBox').innerHTML = '<img src="images/loading.gif" border="0">'
	sendRequest(url, 'divWaitBox');
	

	return false;	
}

function arrangeAgencyImages(saveString)
{
	var url = "zsajax.php?do_action=arrangeAgencyImages&saveString="+saveString;
		
	document.getElementById('divWaitBox').innerHTML = '<img src="images/loading.gif" border="0">'
	sendRequest(url, 'divWaitBox');
	

	return false;	
}


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function loadeNewpage(pageID)
{
	if(pageID == 1)
	{
	document.location.href = "retailer.php";
	
	}
	else if(pageID == 2)
	{
	document.location.href = "investor.php";
	
	}
	else if(pageID == 3)
	{
		document.location.href = "developer.php";
	
	}

}

