var pagetitle;
function ShowAdvancedSniff() {
 if( document.getElementById("advanced").checked){
   document.getElementById("1").style.display = '';
   document.getElementById("2").style.display = '';
   document.getElementById("3").style.display = '';
   document.getElementById("4").style.display = '';
   document.getElementById("5").style.display = '';
   document.getElementById("6").style.display = '';
   if (!document.getElementById('server').value) {
     uri = parseUri(document.getElementById('httpurl').value);
     if (uri['host']) {
     if (!uri['port']) uri['port'] = "80";
     if (!uri['path']) uri['path'] = "/"; }
     document.getElementById('httpurl').disabled = "1";
     document.getElementById('server').value = uri['host'];
     document.getElementById('port').value = uri['port'];
     document.getElementById('host').value = uri['host'];
     document.getElementById('path').value = uri['path'];
   }
   }else{
   document.getElementById("1").style.display = 'none';
   document.getElementById("2").style.display = 'none';
   document.getElementById("3").style.display = 'none';
   document.getElementById("4").style.display = 'none';
   document.getElementById("5").style.display = 'none';
   document.getElementById("6").style.display = 'none';
   document.getElementById('httpurl').disabled = "";
   if (document.getElementById('host').value) document.getElementById('httpurl').value = "http://" + document.getElementById('host').value + ":" + document.getElementById('port').value + document.getElementById('path').value;
   document.getElementById('server').value = "";
   document.getElementById('port').value = "";
   document.getElementById('host').value = "";
   document.getElementById('path').value = "";
   }

}

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

function xmlhttpPost(strURL, String, Targetid) {

	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage(self.xmlHttpReq.responseText, Targetid);
		}
	}
	self.xmlHttpReq.send(String);
}

function updatepage(str, Targetid){
	document.getElementById(Targetid).innerHTML = str;
}

function getElementValue(formElement)
{
	if(formElement.length != null) var type = formElement[0].type;
	if((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;

	switch(type)
	{
		case 'undefined': return;

		case 'radio':
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].checked == true)
			return formElement[x].value;

		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': return formElement.checked;
	
		default: return formElement.value;
	}
}

function submitform ( formval, pagereq ) {
theForm = document.getElementById(formval);
theStr = '';
for (i=0; i < theForm.elements.length; i++) {
ele = theForm.elements[i];
eleval = getElementValue(theForm.elements[i]);
if (ele.name && eleval) theStr += escape(ele.name) + '=' + escape(eleval) + '&';
}
theStr+= "ajax=1";
updatepage('<center><img src=/template/waiting.gif></center>', 'ajacks');
xmlhttpPost(pagereq, theStr, 'ajacks');
}
