// Global variables
var active_div_replace=false;


// Include the content of a given URL in a div
function replace_content(pURL, pNodeId) {

	// Put a preloader gif
	loader = '<div style=\'position: relative;\'><div style="position: absolute; top:0px; left: 0px;"><img src="http://heinoserver/blueweb/images/ajax-loader.gif" width="16" height="16" border="0" /></div></div>';
	
	//document.getElementById('div_main').innerHTML=loader;
	//document.getElementById('div_main').innerHTML="<br /> <img src='http://heinoserver/blueweb/images/ajax-loader.gif' width='16' height='16' border='0' /> ... Loading";
	document.getElementById('div_main').innerHTML="<br /> <img src='http://www.blueweb.co.ke/web/images/ajax-loader.gif' width='16' height='16' border='0' /> ... Loading";

	if (!active_div_replace){
        
        active_div_replace=true;
		var url=pURL;
		if (arguments.length>=2) {
			rfNodeId=pNodeId;
		}
		//alert(pURL);

		if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
			xmlhttp=new XMLHttpRequest();
			xmlhttp.onreadystatechange=replace_div_HTML;
			xmlhttp.open("GET", pURL, true); // leave true for Gecko
			xmlhttp.send(null);
		} else if (window.ActiveXObject) { //IE
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
			if (xmlhttp) {
				xmlhttp.onreadystatechange=replace_div_HTML;
				xmlhttp.open('GET', pURL, false);

				xmlhttp.send();
			}
		} else {
			alert('Your browser does not appear to support remote scripting.');
			xmlhttp=false;
			active_div_replace=false;
		}

		if ((typeof(xmlhttp))!='object') {
			document.write('You need to upgrade your browser to use this page.\r\nAs of March 2006 more than 98% of the web browsers in use support the remote scripting object. Either your browser does not support remote scripting or the support has been disabled.');
			active_div_replace=false;
		}
		
	}else{
		window.setTimeout("replace_content('"+pURL+"','"+pNodeId+"');",1);
	}
	
}


function tmt_fullscreen(url,winName) 
{
	location.href=url;
}

function showDisable(){
    // disable all functions
	document.getElementById('div_disable').style.visibility='visible';
}

function hideDisable(){
		// enable all functions again
	document.getElementById('div_disable').style.visibility='hidden';
}


// function to replace the HTML of a div produced by the replace_content function
function replace_div_HTML(){
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==200) {
			if (rfNodeId=='') {
				
				document.write(xmlhttp.responseText);
				active_div_replace=false;
			}else{
			    
				document.getElementById(rfNodeId).innerHTML=xmlhttp.responseText;
				active_div_replace=false;
			}
		}
	}
}

// ========= FUNCTIONS FOR WHOIS DOMAIN SEARCHING ======== //

//The following functions are for the WHOIS module// return the variables required for domain hosting types or levels
function returnSelHostingVariables()
{
  URL='';
  for (optionCounter = 0; optionCounter < document.form_hosting_types.length; optionCounter++)
  {
    if (document.form_hosting_types.elements[optionCounter].getAttribute('type')=='select')	//make sure <select type='select' ... > is added
    {
      //if (document.form_contact_groups.elements[optionCounter].checked){
        //URL=URL+'&'+document.form_hosting_types.elements[optionCounter].name+'=true';
        URL=URL+'&'+document.form_hosting_types.elements[optionCounter].name+'='+document.form_hosting_types.elements[optionCounter].value;
      //}
    }else
    {
      // URL=URL+'&'+document.form_contact_groups.elements[optionCounter].name+'='+document.form_contact_groups.elements[optionCounter].value;
    }
  }
  //alert(URL);
  return URL;
}

// return the variables required for the user who registers a domain
function returnFormVariables()
{
  URL='';
  for (optionCounter = 0; optionCounter < document.form_user_data.length; optionCounter++)
  {
        URL=URL+'&'+document.form_user_data.elements[optionCounter].name+'='+document.form_user_data.elements[optionCounter].value;
  }
  //alert(URL);
  return URL;
}

function submitenter(myfield,e)
{	//used by 'whois' searchbox to capture ENTER keypress
	//submitenter(this, event)
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)	//If key is ASCII 13==ENTER
	{	//Do Whatever, like call the search function
		domainname = document.getElementById('query').value;
		replace_content('scripts/example.php?query='+domainname+'&r='+ Math.random(),'div_main');
	}
	else
		return true;
}

// ========= ====================== ==== ======== //


