function GetXmlHttpObject() 
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function GetGooglePR(URL, ID, textbox)
{
	if(URL != '')
	{
		document.getElementById(ID+'Loading').style.display = '';			
		
		var nocache = Math.random();
		
		xmlhttp2 = GetXmlHttpObject();
		
		var url= "/includes/ajaxProcess.php?action=GooglePagerank&URL="+URL+"&ID="+ID+"&textbox="+textbox;
		
		xmlhttp2.open("GET",url,true);	
		
		xmlhttp2.onreadystatechange = GetGooglePRResult
		
		xmlhttp2.send(null);
	}
	else
	{
		alert("Please enter URL first.");	
	}
}


function GetGooglePRResult()
{
	if(xmlhttp2.readyState == 4 && xmlhttp2.status==200) 
	{
		html = xmlhttp2.responseText;
		var array = html.split(':;');	
		var pageRank = array[0];
		var TextID = array[1];
		var IsTextBox = array[2];
		
		if(IsTextBox == 'true')
		{
			document.getElementById(TextID).value = array[0];
		}
		else
		{
			document.getElementById(TextID).innerHTML = array[0];
		}
		
		document.getElementById(TextID+'Loading').style.display = 'none';
	}
}

function GetAnalysis(URL,pURL)
{
	if(URL != '')
	{
		document.getElementById('Loading_Alaxa').style.display = '';
		document.getElementById('Loading_GoogleInbound').style.display = '';
		document.getElementById('Loading_YahooInbound').style.display = '';
		
		var nocache = Math.random();
		
		xmlhttp = GetXmlHttpObject();
		
		var url= "/includes/ajaxProcess.php?action=Analysis&URL="+URL+"&pURL="+pURL;
		
		xmlhttp.open("GET",url,true);	
		
		xmlhttp.onreadystatechange = finalxmlHttpupdallprd
		
		xmlhttp.send(null);
	}
	else
	{
		alert("Please enter main URL first.");	
	}
}


function finalxmlHttpupdallprd()
{
	if(xmlhttp.readyState == 4 && xmlhttp.status==200) 
	{
		html = xmlhttp.responseText;
		var array = html.split(':;');	
		document.getElementById('HAlaxa_Rank').value=array[0];
		document.getElementById('Alaxa_Rank').innerHTML=array[0];
		document.getElementById('yahoo_inbound_links').value=array[1];
		document.getElementById('google_inbound_links').value=array[2];
		document.getElementById('yahoo_Outbound_links').value=array[3];
		document.getElementById('google_Outbound_links').value=array[3];		
		document.getElementById('Loading_Alaxa').style.display = 'none';
		document.getElementById('Loading_GoogleInbound').style.display = 'none';
		document.getElementById('Loading_YahooInbound').style.display = 'none';
	}
}


function GetTimeZone(Country, TimeZone)
{
	$.ajax({
		url: "/includes/ajaxProcess.php?action=GetTimeZones&Country="+Country+"&TimeZone="+TimeZone,
		dataType: 'html',
		type: 'GET',
		async: false,
		success: function(html){
			
			if(navigator.appName == 'Netscape')
			{
				document.getElementById('TimeZone').innerHTML = html;
				document.getElementById('TimeZone').disabled = false;
				document.getElementById('TimeZoneContainer').style.display='none';
			}
			else
			{
				document.getElementById('TimeZoneContainer').innerHTML = '<select name="TimeZone" id="TimeZone" style="width:150px">'+html+'</select>';
				document.getElementById('TimeZoneContainerDefault').innerHTML = "";	
				
				document.getElementById('TimeZoneContainer').style.display='';
				document.getElementById('TimeZoneContainerDefault').style.display='none';
			}	
			document.getElementById('TimezoneStatus').innerHTML = '';
		}
	});	
}

function setOBLimit()
{
	Trigger2Limit=document.getElementById('Trigger2Limit').value;
	$.ajax({
		url: "/includes/ajaxProcess.php?action=Trigger2Limit&Trigger2Limit="+Trigger2Limit,
		dataType: 'html',
		type: 'GET',
		async: false,
		success: function(html){
			if(html==1)
			alert("Your outbound limit has been set successfully for this placement.");
			else
			alert("There is some problem encountered while setting outbound limit for this placement.")
		}
	});	
}

function checkTrigger(trg,clink,curl)
{
	document.getElementById('proImg').style.display="block";
	
	var nocache = Math.random();
		
	xmlhttp4 = GetXmlHttpObject();
	
	var url= "/includes/ajaxProcess.php?action=Linkcheck&trg="+trg+"&clink="+encodeURI(clink)+"&curl="+encodeURI(curl);
	
	xmlhttp4.open("GET",url,true);	
	
	xmlhttp4.onreadystatechange = checkTriggerResult
	
	xmlhttp4.send(null);
	
}

function checkTriggerResult()
{
	if(xmlhttp4.readyState == 4 && xmlhttp4.status==200) 
	{
		
		html = xmlhttp4.responseText;
		
		var array = html.split(':;');
		
		var LinkExists = array[0];
		
		var trg = array[1];
		
		document.getElementById('proImg').style.display="none";
		
		if(LinkExists==1)
			document.getElementById('messageSpan'+trg).innerHTML="Link exists";
		else
			document.getElementById('messageSpan'+trg).innerHTML="Link does not exists";
		
	}
}
function checkRankHP(URL)
{
	
	document.getElementById('proImgRank').style.display='';
	
	var nocache = Math.random();
		
	xmlhttp3 = GetXmlHttpObject();
	
	var url= "/includes/ajaxProcess.php?action=RankCheck&URL="+URL;
	
	xmlhttp3.open("GET",url,true);	
	
	xmlhttp3.onreadystatechange = checkRankHPResult
	
	xmlhttp3.send(null);
	
}

function checkRankHPResult()
{
	if(xmlhttp3.readyState == 4 && xmlhttp3.status==200) 
	{
		html = xmlhttp3.responseText;
		
		document.getElementById('messageSpanRank').innerHTML=html;
		
		document.getElementById('proImgRank').style.display='none';
		
	}	
}
