//
// PediaStaff 2.0
// (C) John Sanderson 2008
//

var miscvar = '';
var frmwindow = '';
var selectedelem = '';
var selectedtoolbar = '';
var newelemwin = '';
var uploadimgwin = '';
var ineditmode = false;
var loadingspinner = '<img src="res/wait.gif" alt="Loading..." title="Loading, Please Wait." style="width: 32px; height: 32px; position: absolute; top: 50%; margin-top: -16px; margin-left: -16px;" />';
fixediewin = false;

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function frm_addaddress(uid, elementid) {
	
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	
	frmwindow = new Window({className: "alphacube", width:350, height:400, 
		zIndex: 150, resizable: true, title: "Add a new address",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.getContent().innerHTML= '<br />Please fill in the details of your address below'
				+ '<form class="niceform" id="fajaxform" method="post" action="pediaxmlhttp.php?'
				+ 'action=addaddress"><div id="fpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<input type="hidden" name="uid" value="' + uid + '" />'
				+ '<label>Line 1:<br /><input type="text" name="line1" id="line1" onKeyPress="return disableEnterKey(event)"/></label><br /><label>'
				+ 'Line 2:<br /><input type="text" name="line2" id="line2" onKeyPress="return disableEnterKey(event)"/></label><br /><label>City:<br />'
				+ '<input type="text" name="city" id="city" onKeyPress="return disableEnterKey(event)"/></label><br /><label>State:<br />'
				+ '<select name="state" id="state"><option value="" selected="selected">Select a State</option><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="DC">District Of Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option> <option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select>'
				+ '</label><br /><label>Zip Code:<br />'
				+ '<input type="text" name="zip" id="zip" onKeyPress="return disableEnterKey(event)"/></label><p><label><input type="radio" name="type" '
				+ 'value="Home" id="type_0" onKeyPress="return disableEnterKey(event)"/>Home</label><label><input type="radio" name="type" value="Work" id="type_1" onKeyPress="return disableEnterKey(event)"/>'
				+ 'Work</label><label><input type="radio" name="type" value="Relative" id="type_2" onKeyPress="return disableEnterKey(event)"/>Relative</label><br />'
				+ '<label><input type="radio" name="type" value="Temporary" id="type_3" onKeyPress="return disableEnterKey(event)"/>Temporary</label><label>'
				+ '<input type="radio" name="type" value="Other" id="type_4" onKeyPress="return disableEnterKey(event)"/>Other</label></p>'
				+ '<a href="#" title="Submit" id="abutton" onKeyPress="return disableEnterKey(event)" onclick="'
				+ "$('fajaxform').request({onComplete: function(r){$('" + elementid + "').innerHTML=r.responseText;frmwindow.destroy();}});"
				+ '"><b>Submit</b></a></div></form>';
	
	frmwindow.showCenter();
	
}

function frm_editaddress(uid, elementid, adid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:400, 
		zIndex: 150, resizable: true, title: "Change an Address",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.setAjaxContent('pediaxmlhttp.php?action=editaddress&aid=' + adid + '&elemid=' + elementid + '&uid=' + uid);
	
	frmwindow.showCenter();
	
}

function frm_deladdress(uid, elementid, adid) {
	
	Dialog.confirm("Are you sure you want to remove this address?", 
		{
			width:300, className: "alphacube",
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {
				new Ajax.Request('pediaxmlhttp.php?action=deladdress&aid=' + adid + '&elemid=' + elementid + '&uid=' + uid, {
					onComplete: function(r){$(elementid).innerHTML=r.responseText;}
				});
				return true;
			} 
		}
	); 
	
}

function frm_addtelephone(uid, elementid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200, 
		zIndex: 150, resizable: true, title: "Add a new phone number",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.getContent().innerHTML= '<br />Please fill in your telephone number below'
				+ '<form class="niceform" id="fajaxform" method="post" action="pediaxmlhttp.php?'
				+ 'action=addtelephone"><div id="fpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<input type="hidden" name="uid" value="' + uid + '" />'
				+ '<label>Phone Number:<br /><input type="text" name="number" id="number" onKeyPress="return disableEnterKey(event)"/></label><br /><p>'
				+ '<label><input type="radio" name="type" value="Home" id="type_0" onKeyPress="return disableEnterKey(event)"/>Home</label><label>'
				+ '<input type="radio" name="type" value="Work" id="type_1" onKeyPress="return disableEnterKey(event)"/>Work</label><label><input '
				+ 'type="radio" name="type" value="Cell" id="type_2" onKeyPress="return disableEnterKey(event)"/>Cell</label><br /><label><input '
				+ 'type="radio" name="type" value="Pager" id="type_3" onKeyPress="return disableEnterKey(event)"/>Pager</label><label><input type="radio" '
				+ 'name="type" value="Other" id="type_4" onKeyPress="return disableEnterKey(event)"/>Other</label></p>'
				+ '<a href="#" title="Submit " id="abutton" onKeyPress="return disableEnterKey(event)" onclick="'
				+ "$('fajaxform').request({onComplete: function(r){$('" + elementid + "').innerHTML=r.responseText;frmwindow.destroy();}});"
				+ '"><b>Submit</b></a></div></form>';
	
	frmwindow.showCenter();
	
}


function frm_edittelephone(uid, elementid, tpid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200, 
		zIndex: 150, resizable: true, title: "Change a Phone Number",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.setAjaxContent('pediaxmlhttp.php?action=edittelephone&tpid=' + tpid + '&elemid=' + elementid);
	
	frmwindow.showCenter();
	
}

function frm_deltelephone(uid, elementid, tpid) {
	
	Dialog.confirm("Are you sure you want to remove this telephone number?", 
		{
			width:300, className: "alphacube", 
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {new Ajax.Request('pediaxmlhttp.php?action=deltelephone&tpid=' + tpid + '&elemid=' + elementid + '&uid=' + uid, {
					onComplete: function(r){$(elementid).innerHTML=r.responseText;}
				});
				return true;} 
		}
	); 
	
}

function frm_addemail(uid, elementid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200, 
		zIndex: 150, resizable: true, title: "Add a new e-mail address",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.getContent().innerHTML= '<br />Please fill in your e-mail address below'
				+ '<form class="niceform" id="fajaxform" method="post" action="pediaxmlhttp.php?'
				+ 'action=addemail"><div id="fpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<input type="hidden" name="uid" value="' + uid + '" />'
				+ '<label>Email-Address:<br /><input type="text" name="email" id="email" onKeyPress="return disableEnterKey(event)"/></label><br /><p>'
				+ '<label><input type="radio" name="type" value="Personal" id="type_0" onKeyPress="return disableEnterKey(event)"/>Personal</label><label>'
				+ '<input type="radio" name="type" value="Work" id="type_1" onKeyPress="return disableEnterKey(event)"/>Work</label><br /><label><input '
				+ 'type="radio" name="type" value="Cell" id="type_2" onKeyPress="return disableEnterKey(event)"/>Cell</label><label><input '
				+ 'type="radio" name="type" value="Other" id="type_3" onKeyPress="return disableEnterKey(event)"/>Other</label></p>'
				+ '<a href="#" title="Submit " id="abutton" onKeyPress="return disableEnterKey(event)" onclick="'
				+ "$('fajaxform').request({onComplete: function(r){$('" + elementid + "').innerHTML=r.responseText;frmwindow.destroy();}});"
				+ '"><b>Submit</b></a></div></form>';
	
	frmwindow.showCenter();
	
}


function frm_editemail(uid, elementid, emid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200, 
		zIndex: 150, resizable: true, title: "Change an e-mail address",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.setAjaxContent('pediaxmlhttp.php?action=editemail&emid=' + emid + '&elemid=' + elementid);
	
	frmwindow.showCenter();

}

function frm_delemail(uid, elementid, emid) {
	
	Dialog.confirm("Are you sure you want to remove this email address?", 
		{
			width:300, className: "alphacube", 
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {new Ajax.Request('pediaxmlhttp.php?action=delemail&emid=' + emid + '&elemid=' + elementid + '&uid=' + uid, {
					onComplete: function(r){$(elementid).innerHTML=r.responseText;}
				});
				return true;} 
		}
	); 
	
}


function frm_addlocation(uid, elementid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200,
		zIndex: 150, resizable: true, title: "Add a new location",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.getContent().innerHTML= '<br />Please fill in the details of the location below'
				+ '<form class="niceform" id="fajaxform" method="post" action="pediaxmlhttp.php?'
				+ 'action=addlocation"><div id="fpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<input type="hidden" name="uid" value="' + uid + '" />'
				+ '<label>State:<br />'
				+ '<select name="state" id="state"><option value="" selected="selected">Select a State</option><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="DC">District Of Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option> <option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select>'
				+ '</label><br /><label>I want to work here: '
				+ '<input type="checkbox" name="desired" id="desired" onKeyPress="return disableEnterKey(event)"/></label><br /><label>I am licensed to work here: '
				+ '<input type="checkbox" name="licensed" id="licensed" onKeyPress="return disableEnterKey(event)"/></label><br /><br />'
				+ '<a href="#" title="Submit " id="abutton" onKeyPress="return disableEnterKey(event)" onclick="'
				+ "$('fajaxform').request({onComplete: function(r){$('" + elementid + "').innerHTML=r.responseText;frmwindow.destroy();}});"
				+ '"><b>Submit</b></a></div></form>';
	
	frmwindow.showCenter();
	
}

function frm_editlocation(uid, elementid, lpid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200,
		zIndex: 150, resizable: true, title: "Change a location",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.setAjaxContent('pediaxmlhttp.php?action=editlocation&lpid=' + lpid + '&elemid=' + elementid);
	
	frmwindow.showCenter();
	
}

function frm_dellocation(uid, elementid, lpid) {
	
	Dialog.confirm("Are you sure you want to remove this location?", 
		{
			width:300, className: "alphacube", 
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {new Ajax.Request('pediaxmlhttp.php?action=dellocation&lpid=' + lpid + '&elemid=' + elementid + '&uid=' + uid, {
					onComplete: function(r){$(elementid).innerHTML=r.responseText;}
				});
				return true;} 
		}
	); 
	
}

function frm_addreference(uid, elementid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200,
		zIndex: 150, resizable: true, title: "Add a new reference",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.getContent().innerHTML= '<br />Please fill in the details of the reference below'
				+ '<form class="niceform" id="fajaxform" method="post" action="pediaxmlhttp.php?'
				+ 'action=addreference"><div id="fpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<input type="hidden" name="uid" value="' + uid + '" />'
				+ '<label>Full name of referee:<br />'
				+ '<input type="text" name="name" id="name" onKeyPress="return disableEnterKey(event)"/></label><br /><label>Phone number or E-Mail:<br />'
				+ '<input type="text" name="contact" id="contact" onKeyPress="return disableEnterKey(event)"/></label><br /><br />'
				+ '<a href="#" title="Submit " id="abutton" onKeyPress="return disableEnterKey(event)" onclick="'
				+ "$('fajaxform').request({onComplete: function(r){$('" + elementid + "').innerHTML=r.responseText;frmwindow.destroy();}});"
				+ '"><b>Submit</b></a></div></form>';
	
	frmwindow.showCenter();
	
}

function frm_editreference(uid, elementid, refid) {
	if (frmwindow&&!frmwindow.closed){
	frmwindow.close();
	}
	frmwindow = new Window({className: "alphacube", width:350, height:200, 
		zIndex: 150, resizable: true, title: "Change a Reference",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});
	
	frmwindow.setAjaxContent('pediaxmlhttp.php?action=editreference&refid=' + refid + '&elemid=' + elementid);
	
	frmwindow.showCenter();
	
}

function frm_delreference(uid, elementid, refid) {
	
	Dialog.confirm("Are you sure you want to remove this reference?", 
		{
			width:300, className: "alphacube", 
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {new Ajax.Request('pediaxmlhttp.php?action=delreference&refid=' + refid + '&elemid=' + elementid + '&uid=' + uid, {
					onComplete: function(r){$(elementid).innerHTML=r.responseText;}
				});
				return true;} 
		}
	); 
	
}


function job_deleteapplication(ref) {
	
	Dialog.confirm("Are you sure you want to remove this job from your applied list?", 
		{
			width:300, className: "alphacube", 
			okLabel: "Yes",
			closeLabel: "No",  
			cancel:	function(win) {return true;}, 
			ok:function(win) {new Ajax.Request('pediaxmlhttp.php?action=deletejobapplication&jobref=' + ref, {
					onComplete: function(r){new Ajax.Updater($$('.ppd_appliedjobs')[0], 'pediaxmlhttp.php?action=appliedjobs');}
				});
				return true;} 
		}
	); 
	
}

function loadTab(pagename, destination) {
	new Ajax.Updater(destination, 'pediaxmlhttp.php?action=getpageastab&if=0&p=' + pagename, {evalScripts: true});
}

function loadTabEx(page, destination, tabs, color) {
	$(tabs).style.borderBottom = '10px solid ' + color;
	loadTab(page, destination);
}

function highlights(e) {
	$$('.resourcetype .imagediv').each(function(s){
		s.style.backgroundPosition = -((s.readAttribute('id').substr(3,1)*128)-128) + "px 0px";
	});
	e.childElements()[1].style.backgroundPosition = -((512+(e.readAttribute('id').substr(3,1)*128))-128) + "px 0px";

}

function editResource() {
	if(ineditmode)
		return;
	else
		ineditmode = true;
	
	$('editlink').innerHTML = "Done";
	$('editlink').writeAttribute('onclick', "window.location = 'resources-" + thisURL + "';");
	
	editPage = new Element("a", {id: "editplink", title: "Edit the page's details", href: "javascript: void(0);", style: "font-size: 14pt; font-weight: bold; margin-left: 10px; margin-right: 10px;"});
	$('editlink').insert({after: editPage});
	editPage.innerHTML = "Edit Page";
	editPage.observe('click', modifyPage);
	
	selectedtoolbar = $('selectedrestoolbar');

	for (i=0; i < $$('.element').length; i++) {
		j = $$('.element')[i];
		if(j.hasClassName('ret_youtube')) {
			j.innerHTML = '<img src="res/v.png"	alt="Youtube Video" title="Video placeholder" />';
		}
		Event.observe(j.readAttribute('id'), 'mouseover', function() {this.setStyle({'background': '#CCC'});});
		Event.observe(j.readAttribute('id'), 'mouseout', function() {if(selectedelem!=this.readAttribute('id'))this.setStyle({'background': 'transparent'});});
		Event.observe(j.readAttribute('id'), 'click', function() {selectedelem=this.readAttribute('id');whatisselected();});
	}
	

	for (i=0; i < $$('#therestoftheresource .elementarea').size(); i++) {
		k = $('ea' + i);
		k.setStyle({'border': 'solid blue 2px'});

		if(k.empty()) {
			newPara = document.createElement("p");
			newText = document.createTextNode("You've not got any elements in this area yet, click on the add element link below to add one!");
			Element.setStyle(newPara, {fontSize: '11px', color: '#333', margin: '10px'});
			newPara.appendChild(newText);
			newPara.addClassName('empty');
			k.appendChild(newPara);
		} else {
			Sortable.create('ea' + i, {onChange: updatePosition, treeTag: 'div', tag: 'div', only: 'element', format: '^re([0-9]*)$'});
		}
		
		newLink = document.createElement("a");
		Element.setStyle(newLink, {fontSize: '12pt', fontWeight: 'bold', display: 'block', float: 'right', marginTop: '5px'});
		newLink.innerHTML = "Add Element";
		newLink.href = "javascript: void(0);";
		k.appendChild(newLink);
		newLink.writeAttribute('earea', i);
		Event.observe(newLink, 'click', addElement.bindAsEventListener(newLink));
	}
}

function whatisselected() {
	for (i=0; i < $$('.element').length; i++) {
		j = $$('.element')[i];
		if(selectedelem != j.readAttribute('id'))
			j.setStyle({'background': 'transparent'});
	}
	$(selectedelem).insert({top: selectedtoolbar});
	selectedtoolbar.setStyle({'display': 'block'});
}

function updatePosition() {
	id = this.element.id;
	var sorted = escape(Sortable.sequence(id));
	new Ajax.Request('pediaxmlhttp.php?action=updaterespos&prid=' + prid + '&x=' + id.replace(/ea/,"") + '&sortorder=' + sorted, {method: 'post'});
}

function addElement(e) {

if (newelemwin&&!newelemwin.closed){
	newelemwin.close();
	}

	newelemwin = new Window({className: "alphacube", width:350, height:300,
		zIndex: 100, resizable: true, title: "Add new element",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	newelemwin.getContent().innerHTML= loadingspinner;
	newelemwin.showCenter();

	y = ($$('#ea' + Event.element(e).readAttribute("earea") + ' .element').size()) + 1;
	reqstr = 'pediaxmlhttp.php?action=newreselem&part=1&prid=' + prid + '&x=' + Event.element(e).readAttribute("earea") + '&y=' + y;

	a = new Ajax.Request(reqstr, { 
		onCreate: function(){ newelemwin.getContent().innerHTML = loadingspinner; },
		onSuccess: function(transport){ newelemwin.getContent().innerHTML= transport.responseText; newelemwin.getContent().innerHTML.evalScripts(); }, 
		onFailure: function(){ newelemwin.getContent().innerHTML = 'Something went wrong...'; }
	});
}

function addElementParameters() {
	f = $('ajaxform').request({ 
		onCreate: function(){ newelemwin.getContent().innerHTML = loadingspinner; },
		onSuccess: function(transport){ newelemwin.getContent().innerHTML= transport.responseText; newelemwin.getContent().innerHTML.evalScripts(); }, 
		onFailure: function(){ newelemwin.getContent().innerHTML = 'Something went wrong...'; }
	});
}

function uploadResume(id) {

	if (uploadimgwin&&!uploadimgwin.closed){
	uploadimgwin.close();
	}

	uploadimgwin = new Window({className: "alphacube", width:700, height:400, right: 0, bottom: 0,
		zIndex: 150, resizable: true, title: "Add a Resume to Application",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	uploadimgwin.getContent().innerHTML= '<br /><h2>1. Click "Browse" to Select a Resume<br />2. Click "Add Resume to Application"</h2>'
				+ '<form class="niceform" id="ajaxform" method="post" target="upload_target" enctype="multipart/form-data" action="pediaxmlhttp.php?'
				+ 'action=imgupload&resume=1"><div id="ulpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<label><input type="file" name="ulfile"'
				+ 'id="ulfile" /></label><br /><br /><input type="submit" value="Add Resume to Application!" id="ulbutton" />'
				+ '</div></form><iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>';

	uploadimgwin.showCenter();
	miscvar = id;
}

function uploadResume2(id) {

	if (uploadimgwin&&!uploadimgwin.closed){
	uploadimgwin.close();
	}

	uploadimgwin = new Window({className: "alphacube", width:350, height:200, right: 0, bottom: 0,
		zIndex: 150, resizable: true, title: "Upload a Resume",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	uploadimgwin.getContent().innerHTML= '<br />Please select the file you want to upload.'
				+ '<form class="niceform" id="ajaxform" method="post" target="upload_target" enctype="multipart/form-data" action="pediaxmlhttp.php?'
				+ 'action=imgupload&resume=1"><div id="ulpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<label>Filename:<br /><input type="file" name="ulfile"'
				+ 'id="ulfile" /></label><br /><br /><input type="submit" value="Upload!" id="ulbutton" />'
				+ '</div></form><iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>';

	uploadimgwin.showCenter();
	
	miscvar = id;

}


function uploadResImage(preptid) {
	if (uploadimgwin&&!uploadimgwin.closed){
	uploadimgwin.close();
	}
	uploadimgwin = new Window({className: "alphacube", width:350, height:200, right: 0, bottom: 0,
		zIndex: 150, resizable: true, title: "Upload an Image",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	uploadimgwin.getContent().innerHTML= '<br />Please type a name for the image and select the file you want to upload.'
				+ '<form class="niceform" id="ajaxform" method="post" target="upload_target" enctype="multipart/form-data" action="pediaxmlhttp.php?'
				+ 'action=imgupload&res=1"><div id="ulpage1" style="text-align:center;position:relative;width:100%;'
				+ 'bottom:0pt;overflow:auto;height:80%;"><br /><br />'
				+ '<label>Filename:<br /><input type="file" name="ulfile"'
				+ 'id="ulfile" /></label><br /><br /><input type="submit" value="Upload!" id="ulbutton" />'
				+ '</div></form><iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>';

	uploadimgwin.showCenter();
	miscvar = preptid;
}

function stopUpload(r) {
	uploadimgwin.getContent().innerHTML= '<br />The file uploaded successfully' //, The URL is displayed below'
				//+ '<div id="ulpage1" style="text-align:center;position:reltaive;width:100%;'


				//+ 'bottom:0pt;overflow:auto;height:80%;color:red;font-weight:bold;">' + r + '</div>';
	$(miscvar).value = r;
	uploadimgwin.destroy();
}

function validateYouTubeURL(url, id, preptid) {
	params = url.toQueryParams();
	miscvar = preptid;
	new Ajax.Request ('pediaxmlhttp.php?action=validateyt&v=' + params['v'], {   
		onCreate: function(){ 
				$('progress' + miscvar).innerHTML = 'Validating, Please wait...<script type="text/javascript">$(\'submitbutton\').disabled = true;</script>';
				$('progress' + miscvar).innerHTML.evalScripts(); },
		onSuccess: function(transport){ 
			if(transport.responseText != 'Invalid YouTube URL') {
				$('progress' + miscvar).innerHTML = 'Valid URL<input type="hidden" name="preptid' + miscvar + '" value="' + transport.responseText + '" />'
					+ '<script type="text/javascript">$(\'submitbutton\').disabled = false;</script>';
				$('progress' + miscvar).innerHTML.evalScripts();
			} else {
				$('progress' + miscvar).innerHTML = 'Invalid YouTube URL';
			} 
		}, 
		onFailure: function(){ $('progress' + miscvar).innerHTML = 'Invalid YouTube URL'; }
	});
}

function deleteElement() {

	newelemwin = Dialog.confirm("Are you sure you want to delete this element?", 
		{width:300, okLabel: "Yes", className: "alphacube",  
		id: "deleteconfirm",
		ok:function(win) {
			a = new Ajax.Request('pediaxmlhttp.php?action=deletereselem&preid=' + selectedelem, { 
				onCreate: function(){ newelemwin.getContent().innerHTML = loadingspinner; },
				onSuccess: function(transport){ document.location.reload(true); }, 
				onFailure: function(){ newelemwin.getContent().innerHTML = 'Something went wrong...'; }
			});
			return true;
		}});
}

function modifyElement() {
	newelemwin = new Window({className: "alphacube", width:350, height:300,
		zIndex: 100, resizable: true, title: "Modify an element",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	newelemwin.getContent().innerHTML= loadingspinner;
	newelemwin.showCenter();

	a = new Ajax.Request('pediaxmlhttp.php?action=modifyreselem&part=1&preid=' + selectedelem, { 
		onCreate: function(){ newelemwin.getContent().innerHTML = loadingspinner; },
		onSuccess: function(transport){ newelemwin.getContent().innerHTML= transport.responseText; newelemwin.getContent().innerHTML.evalScripts();  }, 
		onFailure: function(){ newelemwin.getContent().innerHTML = 'Something went wrong...'; }
	});
}

function modifyPage() {
	newelemwin = new Window({className: "alphacube", width:350, height:300,
		zIndex: 100, resizable: true, title: "Modify Page Details",
		showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
		draggable:true, wiredDrag: true});

	newelemwin.getContent().innerHTML= loadingspinner;
	newelemwin.showCenter();

	a = new Ajax.Request('pediaxmlhttp.php?action=modifypagedetails&part=1&prid=' + prid, { 
		onCreate: function(){ newelemwin.getContent().innerHTML = loadingspinner; },
		onSuccess: function(transport){ newelemwin.getContent().innerHTML= transport.responseText; newelemwin.getContent().innerHTML.evalScripts();  }, 
		onFailure: function(){ newelemwin.getContent().innerHTML = 'Something went wrong...'; }
	});
}

function submitForm() {
	this.request( {
		onSuccess: function(transport){
			this.innerHTML =  transport.responseText;
			frmwindow.destroy;
		},
		onLoading: function() {
			this.innerHTML = '<div><img src="res/wait.gif" alt="Loading..." title="Loading, Please Wait." style="width: 32px; height: 32px;" /></div>';
		}
	})
	return false;
}

function setTopNavColour(id) {
	$$('.navact')[0].removeClassName('navact');
	$(id).addClassName('navact');
}

function ieprotofix() {
	if((fixediewin == false) && (Window != null)) {
		newelemwin = new Window({className: "alphacube", width:1, height:1,
			zIndex: 100, resizable: true, title: "workaround",
			showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff,
			draggable:true, wiredDrag: true});
		
		newelemwin.show;
		newelemwin.destroy;
		fixediewin == true;
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function lastSearchCrawler(str) {
	if(str != "") {
	  str = str.replace(/\+/g," ");
	  sp = str.toQueryParams();
	  
	  if(typeof(sp['proftype']) != "string") {
		  sp['proftype'] = sp['proftype'][0];
	  }
	
	  $$('.jobtype').each(function(s) {s.checked=false;})
	  sp['jobtype'].each(function(s) {$$('.jobtype[value=' + s + ']')[0].checked=true;});
	
	  $$('.termtype').each(function(s) {s.checked=false;})
	  sp['termtype'].each(function(s) {$$('.termtype[value=' + s + ']')[0].checked=true;});
	
	  $$('#proftype option[value=' + sp['proftype'] + ']')[0].selected=true;
	
	  $$('#state option[value=' + sp['state'] + ']')[0].selected=true;
	}	
}

function tesStart(id) {a = new Ajax.PeriodicalUpdater('pp' + id, 'pediaxmlhttp.php?action=getrandomtes&ppid=' + id, {method: 'get', frequency: 30, decay: 1});} 

Prototype.Browser.IE6=Prototype.Browser.IE &&
parseInt(navigator.userAgent.substring
(navigator.userAgent.indexOf("MSIE")+5))==6;
Prototype.Browser.IE7=Prototype.Browser.IE && !Prototype.Browser.IE6;

Event.observe(window, 'load', function () {if(Prototype.Browser.IE7) ieprotofix();});