// JavaScript Document
//SendF USAGE SendF('fieldname of field not to be checked / optional fields', 'form id', 'field with email format checking' ,'special checks[YET TO BE BUILT]');
function SendF(elem, f_name, chkemail, splchk)
	{
		var chk, x=document.getElementById(f_name);
		if(splchk)
		{
		var checks = splchk.split("|");
		var retval;
		for(var j=0;j<checks.length;j++)
			{
				flds = checks[j].split(":");
				str = "x."+flds[0]+flds[1]+"x."+flds[2];
				temp_retval = eval(str);
				if(!(temp_retval))
					{
						window.alert(flds[3]);
						return false;
					}
			}
		}
		if(chkemail)
			{
				var res = chkemailformat(eval("x."+chkemail+".value"));
				if (!res)
					{
						return false;
					}
			}
	for (var i=0;i<x.length;i++)
		  {			  
		  	elem.match(x.elements[i].name) ? (chk=false) : (chk=true);
			if(chk)
				{
					
					if(!x.elements[i].value)
						{
							window.alert("Missing Field "+x.elements[i].name.replace("_", " ")); 
							return false;
						}
				}
		  }		  
		return true;
	}
function chkemailformat(test)
	{
		var p=test.indexOf('@');
		if (p<1 || p==(test.length-1)) 
			{
				window.alert('Email must contain an e-mail address.');
				return false;
			}
		else
			{
				return true;
			}
	}
	
function ajax_do(to_do,id,ret_div_id)
  {
	var loading = document.getElementById('loading');
	if(loading)
		{
		  loading.style.display='block';
		}
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
			document.getElementById(ret_div_id).innerHTML = "<div id='cb' class='' onmouseover='this.className=\"close_mo\";' onmouseout='this.className=\"\";'  onclick='document.getElementById(\""+ret_div_id+"\").style.visibility=\"hidden\"; document.getElementById(\""+ret_div_id+"\").innerHTML=\"\";'>X</div><div id='header'></div>";
			document.getElementById(ret_div_id).innerHTML += xmlHttp.responseText;
			if(document.getElementById('page_content'))
				generate_wysiwyg('page_content', '800', '300');
			else if(document.getElementById('description'))
				generate_wysiwyg('description', '800', '300');
		  loading.style.display='none';
		  return true;
        }
      }
    //xmlHttp.open("GET","functioner.php?do="+to_do+"&id="+id,true);
	
		var params = "do="+to_do+"&id="+id;
		xmlHttp.open("POST","functioner.php",true);
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		
    //xmlHttp.send(null);
		xmlHttp.send(params);
  }
function initiate()
	{
		if(document.getElementById('add_page'))
		document.getElementById('add_page').style.width=(parseInt(window.screen.width) - 60) + 'px';
		if(document.getElementById('add_links'))
		document.getElementById('add_links').style.width=(parseInt(window.screen.width) - 60) + 'px';
}



function goto(url)
  {
	  var div_id='keywords_list';
		var loading = document.getElementById('loading');
	  loading.style.display='block';
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
		    loading.style.display='none';
			document.getElementById(div_id).innerHTML = xmlHttp.responseText;
        }
      }
	url = url + "&from_date=" + document.getElementById('date_from').value + "&to_date="+ document.getElementById('date_to').value;
    if(document.getElementById('forthissite'))
  		{
			if(document.getElementById('forthissite').checked)
				url = url + "&forthissite=true";
		}
	xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
function generate_graph(url)
	{
	  var loading = document.getElementById('loading');
	  loading.style.display='block';
	  url = url + "&from_date=" + document.getElementById('date_from').value + "&to_date="+ document.getElementById('date_to').value;
      if(document.getElementById('forthissite'))
  		{
			if(document.getElementById('forthissite').checked)
				url = url + "&forthissite=true";
		}

	  var div_id='graph_div';
	  document.getElementById(div_id).style.display='block';
		document.getElementById(div_id).innerHTML = "<button onclick='document.getElementById(\"graph_div\").innerHTML=\"\";document.getElementById(\""+div_id+"\").style.display=\"none\";'>CLOSE</button><table><tr><td><img src='"+url+"' /></td><td><img src='"+url+"&plot_type=bar' /></td></tr><tr><td><img src='"+url+"&fld=country' /></td><td><img src='"+url+"&fld=country&plot_type=bar' /></td></tr><tr><td><img src='"+url+"&fld=keyword' /></td><td><img src='"+url+"&fld=keyword&plot_type=bar' /></td></tr></table>";
	  setTimeout("document.getElementById('loading').style.display='none';",2000);
//		document.getElementById(div_id).innerHTML .= "<button onclick=''></button>";//document.getElementById(\""+div_id+"\").innerHTML=\"\";document.getElementById(\""+div_id+"\").style.display=\"none\";'>CLOSE</button>";
	}
function generate_sitenav_graph(url)
	{
	  var loading = document.getElementById('loading');
	  loading.style.display='block';
	  url = url + "&from_date=" + document.getElementById('date_from').value + "&to_date="+ document.getElementById('date_to').value;
      if(document.getElementById('forthissite'))
  		{
			if(document.getElementById('forthissite').checked)
				url = url + "&forthissite=true";
		}

	  var div_id='graph_div';
	  document.getElementById(div_id).style.display='block';
		document.getElementById(div_id).innerHTML = "<button onclick='document.getElementById(\"graph_div\").innerHTML=\"\";document.getElementById(\""+div_id+"\").style.display=\"none\";'>CLOSE</button><table><tr><td><img src='"+url+"' /></td><td><img src='"+url+"&plot_type=bar' /></td></tr><tr><td><img src='"+url+"&fld=user_agent' /></td><td><img src='"+url+"&fld=user_agent&plot_type=bar' /></td></tr><tr><td><img src='"+url+"&fld=ip' /></td><td><img src='"+url+"&fld=ip&plot_type=bar' /></td></tr></table>";
	  setTimeout("document.getElementById('loading').style.display='none';",2000);
	}
function get_click_graph(url)
	{
	  var loading = document.getElementById('loading');
	  loading.style.display='block';
	  var div_id='external_link_graph';
		document.getElementById(div_id).style.display='block';
		document.getElementById(div_id).innerHTML = "<button onclick='document.getElementById(\"external_link_graph\").innerHTML=\"\";document.getElementById(\""+div_id+"\").style.display=\"none\";'>CLOSE</button><table><tr><td><img src='"+url+"' /></td></tr></table>";
	  setTimeout("document.getElementById('loading').style.display='none';",2000);
	}
function page_graph(url)
	{
	  var loading = document.getElementById('loading');
	  loading.style.display='block';

		var div_id='external_link_graph';
		document.getElementById(div_id).style.display='block';
		
		document.getElementById(div_id).innerHTML = "<button onclick='document.getElementById(\"external_link_graph\").innerHTML=\"\";document.getElementById(\""+div_id+"\").style.display=\"none\";'>CLOSE</button><table><tr><td><img src='"+url+"' /></td><td><img src='"+url+"&plot_type=bar' /></td></tr></table>";
	  setTimeout("document.getElementById('loading').style.display='none';",2000);
	}

function reorder(order_what,max_id)
		{
			var orders = order_what + "=>";
			for (var i =0; i < max_id; i++)
				{
					orders += document.getElementById(order_what+"order_id_"+i).value + "="+document.getElementById(order_what+"order"+i).value+":::";
				}
			var done = ajax_do('order',orders,'order_result');
			setTimeout("document.location.href = document.location.href;",2000);
		}