function showTopics(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    var topicdisplay = document.getElementById("topics");
    if (topicdisplay.style.display == "none"){
    	topicdisplay.style.display = "block";
    } else if (topicdisplay.style.display == "block"){
    	topicdisplay.style.display = "none";
    }
}

function showCountries(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    var countrydisplay = document.getElementById("countries");
    if (countrydisplay.style.display == "none"){
    	countrydisplay.style.display = "block";
    } else if (countrydisplay.style.display == "block"){
    	countrydisplay.style.display = "none";
    }
}

function showLocTwo(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var mydisplay = document.getElementById("addressbox");
    if (mydisplay.style.display == "none"){ //open if closed
    	mydisplay.style.display = "block";
    	openarrow();
    } else if (mydisplay.style.display == "block"){ //close if open
    	mydisplay.style.display = "none";
    	closearrow();
    }

}

function showTypes(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    var topicdisplay = document.getElementById("types");
    if (topicdisplay.style.display == "none"){
    	topicdisplay.style.display = "block";
    } else if (topicdisplay.style.display == "block"){
    	topicdisplay.style.display = "none";
    }
}

function showJournal(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    toggleElementDisplay("journal");
}


function showDiv(evt,divname){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    var topicdisplay = document.getElementById(divname);
    topicdisplay.style.display = "block";
}

function linkType(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var up = document.getElementById("upload");
    var xl = document.getElementById("xlink");
    
    if (document.forms[1].linktype[0].checked){ //choice = upload
    	//display upload, hide url box
    	up.style.display = "block";
    	xl.style.display = "none";
    	
    } else if (document.forms[1].linktype[1].checked){ //choice = ext. link
    	//hide upload, display url box
    	up.style.display = "none";
    	xl.style.display = "block";
    } else if (document.forms[1].linktype[2].checked){ //choice = citation
    	//hide both
    	up.style.display = "none";
    	xl.style.display = "none";
    }

}

function showCountryList(evt){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var mydisplay = document.getElementById("countrylist");
    if (mydisplay.style.display == "none"){ //open if closed
    	mydisplay.style.display = "block";
    	document.images.arrow2.src = "/img/singlearrow_d.gif";
    } else if (mydisplay.style.display == "block"){ //close if open
    	mydisplay.style.display = "none";
    	document.images.arrow2.src = "/img/singlearrow_r.gif";
    }
    
}

function toggleLinkOptions(evt, linktype){
	evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    
    var linkoptions = document.getElementById("linkoptions");
    var up = document.getElementById("upload");
    var xl = document.getElementById("xlink");
    
	if (document.forms[1].changelink.checked){ 
		linkoptions.style.display = "block";
		if (linktype == 1){
			up.style.display = "block";
		}
		if (linktype == 2){
			xl.style.display = "block";
		}
	} else {
		linkoptions.style.display = "none";
		//hide link input boxes too
		up.style.display = "none";
		xl.style.display = "none";
	}
}

function confirmDelete(){
	var agree=confirm("Are you sure you want to delete this record?");
	if (agree){
		return true ;
	} else {
		return false ;
	}
}

function emptyvalidation(entered, alertbox){
	// Emptyfield Validation by Henrik Petersen / NetKontoret
	// Explained at www.echoecho.com/jsforms.htm
	// Please do not remove this line and the two lines above.
	with (entered){
		if (value==null || value=="")
		{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
	}
} 

function numbervalidation(entered,alertbox){
	//check if number is greater than 0
	with (entered){
		if (value==0 || value=="" || value =="00" || value =="0")
		{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
	}	
}


function yearvalidation(entered,alertbox){
	with (entered){
		if (value.length != 4 || value=="0000")
		{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
	}
}

function emailvalidation(entered, alertbox){
	// E-mail Validation by Henrik Petersen / NetKontoret
	// Explained at www.echoecho.com/jsforms.htm
	// Please do not remove this line and the two lines above.
	with (entered)
	{
	apos=value.indexOf("@");
	dotpos=value.lastIndexOf(".");
	lastpos=value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
	{if (alertbox) {alert(alertbox);} return false;}
	else {return true;}
	}
} 

function formvalidation(thisform){ //for doc form
	with (thisform){
	//if (emailvalidation(Email,"Illegal E-mail")==false) {Email.focus(); return false;};
	//if (valuevalidation(Value,0,5,"Value MUST be in the range 0-5")==false) {Value.focus(); return false;};
	if (yearvalidation(document.forms[1].year, "Please enter a valid year")==false){document.forms[1].year.focus(); return false;};
	if (emptyvalidation(document.forms[1].title,"Please enter a title")==false) {document.forms[1].title.focus(); return false;};
	if (emptyvalidation(document.forms[1].sub_name,"Please enter your name")==false) {document.forms[1].sub_name.focus(); return false;};
	if (emailvalidation(document.forms[1].sub_email,"Please enter a valid email address where you can be reached")==false) {document.forms[1].sub_email.focus(); return false;};

	}
	
}


function validatePersonForm(thisform){
	with (thisform){
		if (emptyvalidation(document.forms[1].last,"Please enter a last name")==false) {document.forms[1].last.focus(); return false;};
		if (emptyvalidation(document.forms[1].first,"Please enter a first name")==false) {document.forms[1].first.focus(); return false;};
		if (emptyvalidation(document.forms[1].sub_name,"Please enter your name")==false) {document.forms[1].sub_name.focus(); return false;};
		if (emailvalidation(document.forms[1].sub_email,"Please enter a valid email address where you can be reached")==false) {document.forms[1].sub_email.focus(); return false;};
		if (emptyvalidation(document.forms[1].partner,"Please choose an organization")==false) {document.forms[1].partner.focus(); return false;};
	}
	
}

function validateCommentForm(thisform){
	with (thisform){
		if (numbervalidation(document.forms[1].comment_module,"Please select a module/sub module")==false) {document.forms[1].comment_module.focus(); return false;};
		if (emptyvalidation(document.forms[1].comment_name,"Please enter a contact name")==false) {document.forms[1].comment_name.focus(); return false;};
		if (emailvalidation(document.forms[1].comment_email,"Please enter a valid email address where you can be reached")==false) {document.forms[1].comment_email.focus(); return false;};
		if (emptyvalidation(document.forms[1].comment_issue,"Please enter your issue")==false) {document.forms[1].comment_issue.focus(); return false;};
		if (emptyvalidation(document.forms[1].comment_recommend,"Please enter your recommendation")==false) {document.forms[1].comment_recommend.focus(); return false;};
	}
}

function validateEventForm(thisform){
	with (thisform){
		if (emptyvalidation(document.forms[1].sub_name,"Please enter your name")==false) {document.forms[1].sub_name.focus(); return false;};
		if (emailvalidation(document.forms[1].sub_email,"Please enter a valid email address where you can be reached")==false) {document.forms[1].sub_email.focus(); return false;};
		
		if (emptyvalidation(document.forms[1].event_name, "Please enter a valid event name")==false){document.forms[1].event_name.focus(); return false;};
		if (emptyvalidation(document.forms[1].event_location,"Please enter a event location")==false) {document.forms[1].event_location.focus(); return false;};
		
		if (numbervalidation(document.forms[1].month,"Please enter a valid month")==false) {document.forms[1].month.focus(); return false;};
		if (numbervalidation(document.forms[1].day,"Please enter a valid day")==false) {document.forms[1].day.focus(); return false;};
		if (yearvalidation(document.forms[1].year,"Please enter a year")==false) {document.forms[1].year.focus(); return false;};
		if (emptyvalidation(document.forms[1].organisations, "Please enter a valid organisation")==false){document.forms[1].organisations.focus(); return false;};
		if (emptyvalidation(document.forms[1].contact_name,"Please enter a contact name")==false) {document.forms[1].contact_name.focus(); return false;};
		
		if (emailvalidation(document.forms[1].contact_email,"Please enter a contact email")==false) {document.forms[1].contact_email.focus(); return false;};
		
		
	}
	
}

function validateOrgForm(thisform){
	with (thisform){
		if (emptyvalidation(document.forms[1].title,"Please enter a title")==false) {document.forms[1].title.focus(); return false;};
		if (emptyvalidation(document.forms[1].sub_name,"Please enter your name")==false) {document.forms[1].sub_name.focus(); return false;};
		if (emailvalidation(document.forms[1].sub_email,"Please enter a valid email address where you can be reached")==false) {document.forms[1].sub_email.focus(); return false;};

	}
	
}

function preloadArrows(){
	if (document.images){
		var closearrow= new Image(10,10); 
		closearrow.src="/img/singlearrow_r.gif"; 
		var openarrow = new Image(10,10); 
		openarrow.src="/img/singlearrow_d.gif";
	}
}

function closearrow() {
  if (document.images){
    document.images.arrow.src = "/img/singlearrow_r.gif";
  }
}

function openarrow() {
  if (document.images){
    document.images.arrow.src = "/img/singlearrow_d.gif";
   }
}

function toggleElementDisplay(elname){
	var mydisplay = document.getElementById(elname);
    if (mydisplay.style.display == "none"){ //open if closed
    	mydisplay.style.display = "block";
    	openarrow();
    } else if (mydisplay.style.display == "block"){ //close if open
    	mydisplay.style.display = "none";
    	closearrow();
    }
}