// Show Hide Function
function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block') e.style.display = 'none';
	else e.style.display = 'block';
}

function hide_results(id, myns, mynum, myname, mysearch) {
	document.getElementById(id).innerHTML = '<a href="javascript:;" onclick="toggle_visibility(\'ns' +  myns + '\'); show_results(\'nslink' + myns + '\', \'' + myns + '\', ' + mynum + ', \'' + myname + '\', \'' + mysearch + '\');"><img src="/wiki/skins/images/arrow-less.gif" width="8" height ="5" border="0" style="margin-bottom:2px;" />  Hide ' + mynum + ' results in ' + myname + '</a>  &nbsp; &nbsp; &nbsp; <a href="/wiki/index.php/Special:Search?ns' + mynum + '=1&limit=100&fulltext=Search&showall=1&search=' + mysearch + '"><img src="/wiki/skins/images/arrow-more.gif" width="5" height ="8" border="0" style="margin-bottom:1px;" /> Show all results in ' + myname + '</a>';
	
	document.getElementById('showing'+myns).innerHTML = '';
	
}


function show_results(id, myns, mynum, myname, mysearch) {
	document.getElementById(id).innerHTML = '<a href="javascript:;" onclick="toggle_visibility(\'ns' +  myns + '\');  hide_results(\'nslink' + myns + '\', \'' + myns + '\', ' + mynum + ', \'' + myname + '\', \'' + mysearch + '\');"><img src="/wiki/skins/images/arrow-more.gif" width="5" height ="8" border="0" style="margin-bottom:1px;" />  Show ' + mynum + ' more results in ' + myname + '</a> &nbsp; &nbsp; &nbsp; <a href="/wiki/index.php/Special:Search?ns' + mynum + '=1&limit=100&fulltext=Search&showall=1&search=' + mysearch + '"><img src="/wiki/skins/images/arrow-more.gif" width="5" height ="8" border="0" style="margin-bottom:1px;" /> Show all results in ' + myname + '</a>';
	
		document.getElementById('showing'+myns).innerHTML = ' (Showing First 10)';
	
}

// 5 custom GHN function (not really AJAX)

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}


function nominateSTARS(myform) {

	var missing;
	var myFields=new Array('name','category');
	
	if(!document.getElementById('name').value) missing = document.getElementById('name');
	else if(!document.getElementById('category').value && !missing) missing = document.getElementById('category');
	
	if (missing) alert('Please complete both fields form before submitting your nomination.');
	if (missing) missing.focus();
	if (missing) return false;
	
	myform.title.value='STARS-Candidate:'+myform.name.value;
	myform.content.value='[[Category:' + myform.category.value.replace(/(<([^>]+)>)/ig,"") + ']]';
	
	alert('Thank you for your participation in the IEEE STARS Program.');

}



function makemynom(myform) {

myform.title.value='Milestone-Nomination:'+myform.mytitle.value;

myform.content.value='{{ProposalNomination|docketid= ' + myform.docketid.value + '|proplink=' + myform.a1.value + '}}' + myform.temp.value;


alert('Proposal Approved.');


}




function makemyform(myform) {


var missing;

var myFields=new Array('a1','a2a','a2b','a3','a4','a5','a6','a7','a8','a9','a10','a11','a12','a13','a13name','a13section','a13position','a13email','a14name','a14ou','a14position','a14email','a15Aname','a15Aemail','a15Bname','a15Bemail','a15Cname','a15Ctitle','a15Corg','a15Caddress','a15Cphone','a15Cemail','');


if(!document.getElementById('a1').value) missing = document.getElementById('a1');
else if(!document.getElementById('a2a').value && !missing) missing = document.getElementById('a2a');
else if(!document.getElementById('a2b').value && !missing) missing = document.getElementById('a2b');
else if(!document.getElementById('a3').value && !missing) missing = document.getElementById('a3');
else if(!document.getElementById('a4').value && !missing) missing = document.getElementById('a4');
else if(!document.getElementById('a5').value && !missing) missing = document.getElementById('a5');
else if(!document.getElementById('a6').value && !missing) missing = document.getElementById('a6');
else if(!document.getElementById('a7').value && !missing) missing = document.getElementById('a7');
else if(!document.getElementById('a9').value && !missing) missing = document.getElementById('a9');
else if(!document.getElementById('a10').value && !missing) missing = document.getElementById('a10');
else if(!document.getElementById('a12').value && !missing) missing = document.getElementById('a12');
else if(!document.getElementById('a13name').value && !missing) missing = document.getElementById('a13name');
else if(!document.getElementById('a13section').value && !missing) missing = document.getElementById('a13section');
else if(!document.getElementById('a13position').value && !missing) missing = document.getElementById('a13position');
else if(!document.getElementById('a13email').value && !missing) missing = document.getElementById('a13email');
else if(!document.getElementById('a14name').value && !missing) missing = document.getElementById('a14name');
else if(!document.getElementById('a14ou').value && !missing) missing = document.getElementById('a14ou');
else if(!document.getElementById('a14position').value && !missing) missing = document.getElementById('a14position');
else if(!document.getElementById('a14email').value && !missing) missing = document.getElementById('a14email');
else if(!document.getElementById('a15Aname').value && !missing) missing = document.getElementById('a15Aname');
else if(!document.getElementById('a15Aemail').value && !missing) missing = document.getElementById('a15Aemail');
else if(!document.getElementById('a15Bname').value && !missing) missing = document.getElementById('a15Bname');
else if(!document.getElementById('a15Bemail').value && !missing) missing = document.getElementById('a15Bemail');
else if(!document.getElementById('a15Cname').value && !missing) missing = document.getElementById('a15Cname');
else if(!document.getElementById('a15Ctitle').value && !missing) missing = document.getElementById('a15Ctitle');
else if(!document.getElementById('a15Corg').value && !missing) missing = document.getElementById('a15Corg');
else if(!document.getElementById('a15Caddress').value && !missing) missing = document.getElementById('a15Caddress');
else if(!document.getElementById('a15Cphone').value && !missing) missing = document.getElementById('a15Cphone');
else if(!document.getElementById('a15Cemail').value && !missing) missing = document.getElementById('a15Cemail');

if (!document.getElementById('a8y').checked && !document.getElementById('a8n').checked && !missing) missing = document.getElementById('a8y');
if (!document.getElementById('a11y').checked && !document.getElementById('a11n').checked && !missing) missing = document.getElementById('a11y');
if (missing) alert('Please complete the entire form before submitting your proposal.');
if (missing) missing.focus();
if (missing) return false;

if(document.getElementById('a8y').checked) mya8 = 'Yes';
else mya8 = 'No';

if(document.getElementById('a11y').checked) mya11 = 'Yes';
else mya11 = 'No';

myform.title.value='Milestone-Proposal:'+myform.a1.value;

myform.content.value='{{Proposal|a1=' + myform.a1.value.replace(/(<([^>]+)>)/ig,"") + '|a2a=' + myform.a2a.value.replace(/(<([^>]+)>)/ig,"") + '|a2b=' + myform.a2b.value.replace(/(<([^>]+)>)/ig,"") + '|a3=' + myform.a3.value.replace(/(<([^>]+)>)/ig,"") + '|a4=' + myform.a4.value.replace(/(<([^>]+)>)/ig,"") + '|a5=' + myform.a5.value.replace(/(<([^>]+)>)/ig,"") + '|a6=' + myform.a6.value.replace(/(<([^>]+)>)/ig,"") + '|a7=' + myform.a7.value.replace(/(<([^>]+)>)/ig,"") + '|a8=' + mya8 + '|a9=' + myform.a9.value.replace(/(<([^>]+)>)/ig,"") + '|a10=' + myform.a10.value.replace(/(<([^>]+)>)/ig,"") + '|a11=' +mya11 + '|a12=' + myform.a12.value.replace(/(<([^>]+)>)/ig,"") + '|a13name=' + myform.a13name.value.replace(/(<([^>]+)>)/ig,"") + '|a13section=' + myform.a13section.value.replace(/(<([^>]+)>)/ig,"") + '|a13position=' + myform.a13position.value.replace(/(<([^>]+)>)/ig,"") + '|a13email=' + myform.a13email.value.replace(/(<([^>]+)>)/ig,"") + '|a14name=' + myform.a14name.value.replace(/(<([^>]+)>)/ig,"") + '|a14ou=' + myform.a14ou.value.replace(/(<([^>]+)>)/ig,"") + '|a14position=' + myform.a14position.value.replace(/(<([^>]+)>)/ig,"") + '|a14email=' + myform.a14email.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname=' + myform.a15Aname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail=' + myform.a15Aemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname2=' + myform.a15Aname2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail2=' + myform.a15Aemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname=' + myform.a15Bname.value.replace(/(<([^>]+)>)/ig,"")  +  '|a15Bemail=' + myform.a15Bemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname2=' + myform.a15Bname2.value.replace(/(<([^>]+)>)/ig,"") +  '|a15Bemail2=' + myform.a15Bemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cname=' + myform.a15Cname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Ctitle=' + myform.a15Ctitle.value.replace(/(<([^>]+)>)/ig,"") + '|a15Corg=' + myform.a15Corg.value.replace(/(<([^>]+)>)/ig,"") + '|a15Caddress=' + myform.a15Caddress.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cphone=' + myform.a15Cphone.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cemail=' + myform.a15Cemail.value.replace(/(<([^>]+)>)/ig,"") + '}}';


alert('Thank you for your participation in the IEEE Milestones Program.  The Milestones Coordinator will evaluate your proposal and respond to you within a month.  This proposal will be locked to protect it from anyone, except you, making changes.');


}


function savemyform(myform) {

if(!document.getElementById('a1').value) {
 alert('Please enter the name of the milestone before saving your proposal.');
 document.getElementById('a1').focus();
 return false;
}

if(document.getElementById('a8y').checked) mya8 = 'Yes';
else mya8 = 'No';

if(document.getElementById('a11y').checked) mya11 = 'Yes';
else mya11 = 'No';


myform.title.value='Milestone-Proposal:'+myform.a1.value;

myform.templates.value ='update';

myform.content.value='{{ProposalEdit|a1=' + myform.a1.value.replace(/(<([^>]+)>)/ig,"") + '|a2a=' + myform.a2a.value.replace(/(<([^>]+)>)/ig,"") + '|a2b=' + myform.a2b.value.replace(/(<([^>]+)>)/ig,"") + '|a3=' + myform.a3.value.replace(/(<([^>]+)>)/ig,"") + '|a4=' + myform.a4.value.replace(/(<([^>]+)>)/ig,"") + '|a5=' + myform.a5.value.replace(/(<([^>]+)>)/ig,"") + '|a6=' + myform.a6.value.replace(/(<([^>]+)>)/ig,"") + '|a7=' + myform.a7.value.replace(/(<([^>]+)>)/ig,"") + '|a8=' + mya8 + '|a9=' + myform.a9.value.replace(/(<([^>]+)>)/ig,"") + '|a10=' + myform.a10.value.replace(/(<([^>]+)>)/ig,"") + '|a11=' +mya11 + '|a12=' + myform.a12.value.replace(/(<([^>]+)>)/ig,"") + '|a13name=' + myform.a13name.value.replace(/(<([^>]+)>)/ig,"") + '|a13section=' + myform.a13section.value.replace(/(<([^>]+)>)/ig,"") + '|a13position=' + myform.a13position.value.replace(/(<([^>]+)>)/ig,"") + '|a13email=' + myform.a13email.value.replace(/(<([^>]+)>)/ig,"") + '|a14name=' + myform.a14name.value.replace(/(<([^>]+)>)/ig,"") + '|a14ou=' + myform.a14ou.value.replace(/(<([^>]+)>)/ig,"") + '|a14position=' + myform.a14position.value.replace(/(<([^>]+)>)/ig,"") + '|a14email=' + myform.a14email.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname=' + myform.a15Aname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail=' + myform.a15Aemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname2=' + myform.a15Aname2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail2=' + myform.a15Aemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname=' + myform.a15Bname.value.replace(/(<([^>]+)>)/ig,"")  +  '|a15Bemail=' + myform.a15Bemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname2=' + myform.a15Bname2.value.replace(/(<([^>]+)>)/ig,"") +  '|a15Bemail2=' + myform.a15Bemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cname=' + myform.a15Cname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Ctitle=' + myform.a15Ctitle.value.replace(/(<([^>]+)>)/ig,"") + '|a15Corg=' + myform.a15Corg.value.replace(/(<([^>]+)>)/ig,"") + '|a15Caddress=' + myform.a15Caddress.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cphone=' + myform.a15Cphone.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cemail=' + myform.a15Cemail.value.replace(/(<([^>]+)>)/ig,"") + '}}';




}


function modmyform(myform) {

if(!document.getElementById('mytitle').value) {
 alert('Please enter the name of the milestone before saving your proposal.');
 document.getElementById('mytitle').focus();
 return false;
}

myform.title.value='Milestone-Proposal:'+myform.mytitle.value;

myform.templates.value ='update';

myform.content.value='{{Proposal|docketid=' + myform.docketid.value + '|a1=' + myform.mytitle.value.replace(/(<([^>]+)>)/ig,"") + '|a2a=' + myform.a2a.value.replace(/(<([^>]+)>)/ig,"") + '|a2b=' + myform.a2b.value.replace(/(<([^>]+)>)/ig,"") + '|a3=' + myform.a3.value.replace(/(<([^>]+)>)/ig,"") + '|a4=' + myform.a4.value.replace(/(<([^>]+)>)/ig,"") + '|a5=' + myform.a5.value.replace(/(<([^>]+)>)/ig,"") + '|a6=' + myform.a6.value.replace(/(<([^>]+)>)/ig,"") + '|a7=' + myform.a7.value.replace(/(<([^>]+)>)/ig,"") + '|a8=' + myform.a8.value.replace(/(<([^>]+)>)/ig,"") + '|a9=' + myform.a9.value.replace(/(<([^>]+)>)/ig,"") + '|a10=' + myform.a10.value.replace(/(<([^>]+)>)/ig,"") + '|a11=' +myform.a11.value.replace(/(<([^>]+)>)/ig,"") + '|a12=' + myform.a12.value.replace(/(<([^>]+)>)/ig,"") + '|a13name=' + myform.a13name.value.replace(/(<([^>]+)>)/ig,"") + '|a13section=' + myform.a13section.value.replace(/(<([^>]+)>)/ig,"") + '|a13position=' + myform.a13position.value.replace(/(<([^>]+)>)/ig,"") + '|a13email=' + myform.a13email.value.replace(/(<([^>]+)>)/ig,"") + '|a14name=' + myform.a14name.value.replace(/(<([^>]+)>)/ig,"") + '|a14ou=' + myform.a14ou.value.replace(/(<([^>]+)>)/ig,"") + '|a14position=' + myform.a14position.value.replace(/(<([^>]+)>)/ig,"") + '|a14email=' + myform.a14email.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname=' + myform.a15Aname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail=' + myform.a15Aemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aname2=' + myform.a15Aname2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Aemail2=' + myform.a15Aemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname=' + myform.a15Bname.value.replace(/(<([^>]+)>)/ig,"")  +  '|a15Bemail=' + myform.a15Bemail.value.replace(/(<([^>]+)>)/ig,"") + '|a15Bname2=' + myform.a15Bname2.value.replace(/(<([^>]+)>)/ig,"") +  '|a15Bemail2=' + myform.a15Bemail2.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cname=' + myform.a15Cname.value.replace(/(<([^>]+)>)/ig,"") + '|a15Ctitle=' + myform.a15Ctitle.value.replace(/(<([^>]+)>)/ig,"") + '|a15Corg=' + myform.a15Corg.value.replace(/(<([^>]+)>)/ig,"") + '|a15Caddress=' + myform.a15Caddress.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cphone=' + myform.a15Cphone.value.replace(/(<([^>]+)>)/ig,"") + '|a15Cemail=' + myform.a15Cemail.value.replace(/(<([^>]+)>)/ig,"") + '}}';

alert('Proposal Saved. ' + myform.docketid.value);




}

function addException(pageid) {
url = '/wiki/except2.php?pid='+pageid;
newwindow=window.open(url,'ieeeghn','height=450,width=400');
	if (window.focus) {newwindow.focus()}
	//return false;

}



// end custom GHN functions

// remote scripting library
// (c) copyright 2005 modernmethod, inc
var sajax_debug_mode = false;
var sajax_request_type = "GET";

/**
* if sajax_debug_mode is true, this function outputs given the message into
* the element with id = sajax_debug; if no such element exists in the document,
* it is injected.
*/
function sajax_debug(text) {
	if (!sajax_debug_mode) return false;

	var e= document.getElementById('sajax_debug');

	if (!e) {
		e= document.createElement("p");
		e.className= 'sajax_debug';
		e.id= 'sajax_debug';

		var b= document.getElementsByTagName("body")[0];

		if (b.firstChild) b.insertBefore(e, b.firstChild);
		else b.appendChild(e);
	}

	var m= document.createElement("div");
	m.appendChild( document.createTextNode( text ) );

	e.appendChild( m );

	return true;
}

/**
* compatibility wrapper for creating a new XMLHttpRequest object.
*/
function sajax_init_object() {
	sajax_debug("sajax_init_object() called..")
	var A;
	try {
		// Try the new style before ActiveX so we don't
		// unnecessarily trigger warnings in IE 7 when
		// set to prompt about ActiveX usage
		A = new XMLHttpRequest();
	} catch (e) {
		try {
			A=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				A=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				A=null;
			}
		}
	}
	if (!A)
		sajax_debug("Could not create connection object.");

	return A;
}

/**
* Perform an ajax call to mediawiki. Calls are handeled by AjaxDispatcher.php
*   func_name - the name of the function to call. Must be registered in $wgAjaxExportList
*   args - an array of arguments to that function
*   target - the target that will handle the result of the call. If this is a function,
*            if will be called with the XMLHttpRequest as a parameter; if it's an input
*            element, its value will be set to the resultText; if it's another type of
*            element, its innerHTML will be set to the resultText.
*
* Example:
*    sajax_do_call('doFoo', [1, 2, 3], document.getElementById("showFoo"));
*
* This will call the doFoo function via MediaWiki's AjaxDispatcher, with
* (1, 2, 3) as the parameter list, and will show the result in the element
* with id = showFoo
*/
function sajax_do_call(func_name, args, target) {
	var i, x, n;
	var uri;
	var post_data;
	uri = wgServer +
		((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript) +
		"?action=ajax";
	if (sajax_request_type == "GET") {
		if (uri.indexOf("?") == -1)
			uri = uri + "?rs=" + encodeURIComponent(func_name);
		else
			uri = uri + "&rs=" + encodeURIComponent(func_name);
		for (i = 0; i < args.length; i++)
			uri = uri + "&rsargs[]=" + encodeURIComponent(args[i]);
		//uri = uri + "&rsrnd=" + new Date().getTime();
		post_data = null;
	} else {
		post_data = "rs=" + encodeURIComponent(func_name);
		for (i = 0; i < args.length; i++)
			post_data = post_data + "&rsargs[]=" + encodeURIComponent(args[i]);
	}
	x = sajax_init_object();
	if (!x) {
		alert("AJAX not supported");
		return false;
	}

	try {
		x.open(sajax_request_type, uri, true);
	} catch (e) {
		if (window.location.hostname == "localhost") {
			alert("Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing.");
		}
		throw e;
	}
	if (sajax_request_type == "POST") {
		x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
		x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	x.setRequestHeader("Pragma", "cache=yes");
	x.setRequestHeader("Cache-Control", "no-transform");
	x.onreadystatechange = function() {
		if (x.readyState != 4)
			return;

		sajax_debug("received (" + x.status + " " + x.statusText + ") " + x.responseText);

		//if (x.status != 200)
		//	alert("Error: " + x.status + " " + x.statusText + ": " + x.responseText);
		//else

		if ( typeof( target ) == 'function' ) {
			target( x );
		}
		else if ( typeof( target ) == 'object' ) {
			if ( target.tagName == 'INPUT' ) {
				if (x.status == 200) target.value= x.responseText;
				//else alert("Error: " + x.status + " " + x.statusText + " (" + x.responseText + ")");
			}
			else {
				if (x.status == 200) target.innerHTML = x.responseText;
				else target.innerHTML= "<div class='error'>Error: " + x.status + " " + x.statusText + " (" + x.responseText + ")</div>";
			}
		}
		else {
			alert("bad target for sajax_do_call: not a function or object: " + target);
		}

		return;
	}

	sajax_debug(func_name + " uri = " + uri + " / post = " + post_data);
	x.send(post_data);
	sajax_debug(func_name + " waiting..");
	delete x;

	return true;
}
