function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function HW_toggle_image(idf, img1, img2) { //v1.0

	
	if (document.getElementById(idf).src == img1) document.getElementById(idf).src = img2;
	else document.getElementById(idf).src = img1;

}


function clearfill(term, elem) {
	if (elem.value == term) {
		elem.value = "";
		elem.className = "light";
	}
	else if (elem.value == "") {
		elem.value = term;
		elem.className = "dark";
	}
}

function clearfill_search(term) {
	if (document.searchform.query.value == term) {
		window.document.searchform.query.value = "";
		window.document.searchform.query.className = "light";
	}
	else if (document.searchform.query.value == "") {
		window.document.searchform.query.value = term;
		window.document.searchform.query.className = "dark";
	}
}
function submitsearch() {
	if (document.searchform.query.value == term || document.searchform.query.value == "") {
		if(lang == "en") alert("Please enter a search word before searching.");
		if(lang == "fr") alert("Veuillez écrire un mot de recherche avant la recherche.");
	}
	else {
		document.searchform.submit();
	}
}
function enable_delete_button(id){
	if(document.getElementById('delete_' + id).disabled == true){
		document.getElementById('delete_' + id).disabled = false;
	}
	else if(document.getElementById('delete_' + id).disabled == false){
		document.getElementById('delete_' + id).disabled = true;
	}
}
function openwindow(path){
  	open(path,'windowname','width=800,height=600,scrollbars,resizable');
    //w.document.write("This is a new window");
	//w.document.write("<img src='" + document.getElementById('building_image').value + "'>");
	//w.document.write(document.getElementById('building_image').value);
}
function ccsubmitresize() {
	document.ccresizeform.submit();
	showccprocessing();
}
function feedback(feedbacktext){
	if ((feedbacktext != null) && (feedbacktext != "")) {
		alert(feedbacktext);
	}
}
function showsearchloading() {
	//setTimeout(showsearchloading,1000); 
	if (! document.getElementById('spinnerdiv') || ! document.getElementById('searchimage')) {
		
		spinnerdiv = document.createElement('div');
		spinnerdiv.setAttribute('id', 'spinnerdiv');
		spinnerdiv.setAttribute('class', 'spinner');
		spinnerdiv.setAttribute('className', 'spinner');
		spinnerdiv.innerHTML = "<h1>Searching ...</h1>";
		
		//spinnerimg = document.createElement('img');
		//spinnerimg.setAttribute('src', 'images/common/loader.gif');
		//spinnerimg.setAttribute('id', 'searchimage');
		
		document.body.appendChild(spinnerdiv);
		//document.getElementById('spinnerdiv').appendChild(spinnerimg);
	}
}

function add_it(form_name, element_used, hidden_element, container_id, new_div_prefix) {

	//Sort out the values
	var formelement = eval("document." + form_name +"." + element_used);
	var hiddenelement = eval("document." + form_name +"." + hidden_element);
	var thevalue = formelement.value;
	var thetext = formelement.options[formelement.selectedIndex].text;

	if(thevalue) {
		//Set the hidden value for updating
		if(hiddenelement.value == "") hiddenelement.value = "," + thevalue + ",";
		else hiddenelement.value += thevalue + ",";
	
		//Add the text to the page
		var container_div = document.getElementById(container_id);
		var new_div = document.createElement("div");
		var div_id = new_div_prefix + thevalue;
		new_div.setAttribute("id", div_id);
		new_div.setAttribute("class", "itemtext");
		new_div.innerHTML = thetext + " <a href=\"javascript:remove_element('" + form_name + "', '" + hidden_element + "', '" + container_id + "', '" + div_id + "', '" + thevalue + "')\">Remove</a>";
		container_div.appendChild(new_div);
	}
}

function remove_element(form_name, hidden_element, container_id, div_id, id) {
	
	//Sort out the values
	var hiddenelement = eval("document." + form_name +"." + hidden_element);
	var hiddenelementvalue = hiddenelement.value;

	//Set the hidden value for updating and clean up
	var regular_only = eval("/^" + id + "$/");
	var regular_only_commas = eval("/^," + id + ",$/");
	var regular_start = eval("/^" + id + "[^0-9]/");
	var regular_middle = eval("/[^0-9]" + id + "[^0-9]/");
	var regular_end = eval("/[^0-9]" + id + "$/");

	var new_hiddenelementvalue = hiddenelementvalue.replace(regular_only, "");
	new_hiddenelementvalue = new_hiddenelementvalue.replace(regular_only_commas, "");
	new_hiddenelementvalue = new_hiddenelementvalue.replace(regular_start, "");
	new_hiddenelementvalue = new_hiddenelementvalue.replace(regular_middle, ",");
	new_hiddenelementvalue = new_hiddenelementvalue.replace(regular_end, "");
	hiddenelement.value = new_hiddenelementvalue;
	
	//Remove text from list
	var container_div = document.getElementById(container_id);
	var div_removed = document.getElementById(div_id);
	container_div.removeChild(div_removed);
}

function edit_file(openedby, id) {
	win = window.open("projectfiles.php?project_id=" + openedby + "&id=" + id, "edit_file", "HEIGHT=480, WIDTH=760, resizable=yes, scrollbars=yes, status=yes");
	win.focus();
}
function clearfill_email(trans) {
	if (document.loginform.email.value == trans) {
		window.document.loginform.email.value = "";
		window.document.loginform.email.className = "light";
	}
	else if (document.loginform.email.value == "") {
		window.document.loginform.email.value = trans;
		window.document.loginform.email.className = "dark";
	}
}
function clearfill_password(trans) {
	if (window.document.getElementById("password_dark")) {
		window.document.getElementById("password_span").innerHTML = "<input id=\"password_light\" name=\"password\" type=\"password\" onmouseout=\"clearfill_password('Password')\"  onBlur=\"clearfill_password('Password')\" value=\"\" class=\"light\">";
		window.document.getElementById("password_light").focus();
		window.document.getElementById("password_light").focus();
	}
	else if (window.document.getElementById("password_light")) {
		window.document.getElementById("password_span").innerHTML = "<input id=\"password_dark\" name=\"password\" type=\"text\" onmouseover=\"clearfill_password('Password')\" onFocus=\"clearfill_password('Password')\" value=\"Password\" class=\"dark\">";
	}
}

function validate_required(field, alerttxt){
	with (field){
		doubleQotPos = value.lastIndexOf("\"");
		singleQotPos = value.lastIndexOf("'");
		
		if (value == null || value == "" || doubleQotPos >= 0 || singleQotPos >= 0){
			alert(alerttxt);
			return false;
		} else { return true; }
	}
}

function validate_email(field, alerttxt){
	with (field){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		doubleQotPos = value.lastIndexOf("\"");
		singleQotPos = value.lastIndexOf("'");
		
		if (apos < 1 || dotpos-apos < 2 || value == null || value == "" || doubleQotPos >= 0 || singleQotPos >= 0){
			alert(alerttxt);
			return false;
		} else { return true; }
	}
}
function validate_user_self_registrate_form(thisform){
	with (thisform){
		if (validate_required(firstname,"Please enter a firstname")==false){
			firstname.focus();
			return false;
		}
		if (validate_required(lastname,"Please enter a lastname")==false){
			lastname.focus();
			return false;
		}
		if (validate_email(user_email,"Please enter a valid email address")==false){
			user_email.focus();
			return false;
		}
	}
}

function norman(text) {
	if(text != null || text != "") alert(text);
}

function openpresentation() {
  	open('presentation.php','presentation','width=640,height=480');
}

