// JavaScript Document
function validate() {
    var alert_string = '';

    var comm = document.mainform.ncig_nom_commission;
    comm.style.backgroundColor = '#dddddd';
    if (comm.value.length < 5) {
	alert_string += 'Commission Name must be at least 5 characters\n';
	comm.style.backgroundColor = '#ff9999';
    }
	
	var dt=document.mainform.ncig_date_adoption_texte;
	if (dt.value != ""){
	if (isDate(dt.value)==false){
		dt.style.backgroundColor = '#ff9999';
		alert_string += 'Adoption Date in descripton is invalid\n';
	}}
	
	dt=document.mainform.ncig_date_revision_texte;
	if (dt.value != ""){
	if (isDate(dt.value)==false){
		dt.style.backgroundColor = '#ff9999';
		alert_string += 'Revision Date in descripton is invalid\n';
	}}
	
    for (var i = 0; ; i++) {
	var el = document.mainform.elements['__record_status_ncdir_' + i];
	if (el) {
	    if (el.value == 3) {
		var prefix = el.name.substring(16);
		var name = document.mainform.elements[prefix + '_nom'];
		var heir = document.mainform.elements[prefix + '_hierarchie'];
		var month = document.mainform.elements[prefix +
						       '_debut_fonct_mois'];
		var year = document.mainform.elements[prefix + 
						      '_debut_fonct_an'];

		name.style.backgroundColor = '#dddddd';
		heir.style.backgroundColor = '#dddddd';
		month.style.backgroundColor = '#dddddd';
		year.style.backgroundColor = '#dddddd';

		if (name.value.length < 1) {
	            alert_string += 'Office Holder Name must be entered\n';
		    name.style.backgroundColor = '#ff9999';
	        }
	        if (heir.selectedIndex < 1) {
		    alert_string += 'Office Holder Unesco Title must be entered\n';
		    heir.style.backgroundColor = '#ff9999';
	        }
	        if (month.selectedIndex < 1) {
		    alert_string += 'Office Holder Started In month must be entered\n';
		    month.style.backgroundColor = '#ff9999';
	    	}
	        if (year.value < 1900) {
		    alert_string += 'Office Holder Started In year must be entered\n';
		    year.style.backgroundColor = '#ff9999';
	        }
	    }
	}
	else {
	    break;
	}
    }
	dt=document.mainform.dgvn_dgv_date;
	dx=document.mainform.dgvn_dgv_details;
	dt.style.backgroundColor = '#dddddd';
	
	if(dt.value =="" && dx.value !=""){
		dt.style.backgroundColor = '#ff9999';
		alert_string += 'DG visit must have a date or details and date must both be blank\n';
	}
	else if (dt.value != ""){
		if (isDate(dt.value)==false){
			dt.style.backgroundColor = '#ff9999';
			alert_string += 'DG visit date is invalid\n';
		}
	}

    if (alert_string != '') {
	alert(alert_string);
	return false;
    }
    else {
	return true;
    }
}

function viewActivity(rid) {
    var lc = document.mainform.lc.value;

    location.href = 'index.php?module=activities&mode=browse&rid=' + rid +
		    '&lc=' +  lc;
}

function ChooseRegion(reg) {
    document.mainform.region.value = reg;
	document.mainform.submit();
}


var hierCheck="";
function checkHier(record){

	var hv=eval("document.mainform.ncdir_"+record+"_hierarchie.value")
	if(eval("document.mainform.__record_status_ncdir_"+record)==2)return
	if(hv=="")return
	if(hv>5)return

	i=0
	while(eval("document.mainform.__record_status_ncdir_"+i)){
		if(record==i){i++;continue;}
		if(eval("document.mainform.ncdir_" + i +"_en_fonction.value")==0){i++;continue;}
		if(hv==eval("document.mainform.ncdir_"+i+"_hierarchie.value")){
			opnum=parseInt(hv)+1
			otjob=document.mainform.ncdir_0_hierarchie.options[opnum].text
			otname=eval("document.mainform.ncdir_" + i +"_nom.value")
			conftext=document.mainform.diri_text.value;
			conftext=conftext.replace(/GGGG/, otname)
			conftext=conftext.replace(/HHHH/, otjob)
			alert(conftext)
		}
		i++
	}
}

function archiveDiri(num){
	eval("document.mainform.ncdir_"+num+"_en_fonction.value=0")
	document.getElementById("dir_tabl_"+num).style.display="none"
}

function dgVisits(recid){
	//delete modify or cancel a user
	if(lockxml){lockwarn();return;}
	lockxml=true;
	localxml=true;
	
	if(type_rec=="dgvs")return
	
	type_rec="dgvs"
	//create url for deleting or modifying	
	url="modules/natcomfiles/xmlmaker.php?type=dgvs&value="+recid+"&lc="+document.mainform.lc.value

	urlload()// send the url off to be processed
}
	//alert(xmlhttp.responseText);

function delDGVisit(recid){
	document.getElementById("__record_status_dgv_"+recid).value=2;
	document.getElementById("dvd_"+recid).style.display="none";
}

function toggleDgv(){
	if(document.mainform.dgvn_dgv_type.options[document.mainform.dgvn_dgv_type.selectedIndex].value==1)
		document.getElementById("_dgv_place").style.display=''
	else{
		document.getElementById("_dgv_place").style.display='none'
		document.mainform.dgvn_dgv_place.value=''
	}
}
//document.mainform.enctype="multipart/form-data"
function delDiriImage(num){
	document.getElementById("imgdiri_"+num).style.display="none";
	document.getElementById("ncdir_"+num+"_image").value="";
	document.getElementById("imgdiri_"+num+"_butt").style.display="none";
}
function delAddImage(num){
	document.getElementById("newaddim").style.display="none";
	document.getElementById("nig2_nc2_addrimage").value="";
	document.getElementById("imgadd_butt").style.display="none";
}
function delLogoImage(num){
	document.getElementById("newlogim").style.display="none";
	document.getElementById("nig2_nc2_logoimage").value="";
	document.getElementById("imglog_butt").style.display="none";
}
