// JavaScript Document

// Genereal functions

function createCookie(name,value,days) { // create cookie
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) { // read cookie
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookie(name) { // delete cookie
	createCookie(name,"",-1);
}


function findObj(theObj, theDoc) // find an object with id or name 

{

  var p, i, foundObj;

  if(!theDoc) theDoc = document;

  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)

  {

    theDoc = parent.frames[theObj.substring(p+1)].document;

    theObj = theObj.substring(0,p);

  }

  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

  for (i=0; !foundObj && i < theDoc.forms.length; i++) 

    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 

    foundObj = findObj(theObj,theDoc.layers[i].document);

  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  

  return foundObj;

}

function countTag (TagName, theDoc) { // count given tag
 
 
 if(!theDoc) theDoc = document;
 
 // find tags
 var count=theDoc.getElementsByTagName(TagName); 
 
 return count;

}

function ie() { // check if client browser is IE  
if (navigator.appName == 'Microsoft Internet Explorer') return true; }

function netscape() { // check if client browser is Netscape  
if (navigator.appName == 'Netscape') return true; }

function opera() { // check if client browser is Opera  
if (navigator.appName == 'Opera') return true; }


function confirmDelete(delUrl, warning) { // delete confirmation
if (confirm(warning)) { 
document.location = delUrl; 
}
}

function disable(obj) { // disable object

findObj(obj).disabled = true; }

function enable(obj) { // enable object

findObj(obj).disabled = false; }

function show(obj) { // show object

findObj(obj).style.visibility = 'visible'; }

function hide(obj) { // hide object

findObj(obj).style.visibility = 'hidden'; }


// Ajax related


function GetXmlHttpObject()
{ 
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
} 


function ajax_load(url, query, Obj) 

{ 
	
function ajax_result() 
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		findObj(Obj).innerHTML=xmlHttp.responseText;
		} 
	} 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
return;
} 
url=url+"?"+query;
url=url+"&sid="+Math.random();

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=ajax_result;

}

//////////////////////////


// Form related
function getRadioValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
//////////////////////////