function toggleAOWListBox(checked){

	if(!checked)
		document.getElementById('divAOW').style.display = 'block';

	else{
		document.getElementById('divAOW').style.display = 'none';
		for (var j=0; j<document.forms[0].chkAOW.options.length; j++) {
				document.forms[0].chkAOW.options[j].selected = false;
			}
		}
}

function setTabStyle(tabID){

	if(document.getElementById('pubTab01')!= null) document.getElementById('pubTab01').className = 'ACTab';
	if(document.getElementById('pubTab02')!= null) document.getElementById('pubTab02').className = 'ACTab';
	if(document.getElementById('pubTab03')!= null) document.getElementById('pubTab03').className = 'ACTab';
	if(document.getElementById('linkTab01')!= null) document.getElementById('linkTab01').className = 'ACTab';
	if(document.getElementById('linkTab02')!= null) document.getElementById('linkTab02').className = 'ACTab';

	document.getElementById(tabID).className = 'ACTabSelected';

}


function initPublicationEdit(){

	if(document.forms[0].chkAOWAll.checked)
		document.getElementById('divAOW').style.display = 'none';

	attachFile(document.forms[0].txtFilePathEn.value, 'en');
	attachFile(document.forms[0].txtFilePathGa.value, 'ga');
	setTabStyle('pubTab01');
	document.getElementById('pubGa').style.display = 'none';
	document.getElementById('pubXtra').style.display = 'none';
	
}

function CopyFromEnglishPublication(){

	var form = document.forms[0];

	form.txtNameGa.value = form.txtNameEn.value;
	form.txtDescriptionGa.value = form.txtDescriptionEn.value;
	form.txtFilePathGa.value = form.txtFilePathEn.value;
	form.txtFilePathGa.value = form.txtFilePathEn.value;
	form.txtFilePathGa.value = form.txtFilePathEn.value;
	form.txtFileSizeGa.value = form.txtFileSizeEn.value;
	form.txtFileTypeGa.value = form.txtFileTypeEn.value;
	
	attachFile(document.forms[0].txtFilePathGa.value, 'ga');
}

function initLinkEdit(){

	if(document.forms[0].chkAOWAll.checked)
		document.getElementById('divAOW').style.display = 'none';

	setTabStyle('linkTab01');
	document.getElementById('linkGa').style.display = 'none';
}

function CopyFromEnglishLink(){

	var form = document.forms[0];

	form.txtNameGa.value = form.txtNameEn.value;
	form.txtDescriptionGa.value = form.txtDescriptionEn.value;
}


function selectPubTab(tabID){

	document.getElementById('pubEn').style.display = 'none';
	document.getElementById('pubGa').style.display = 'none';
	document.getElementById('pubXtra').style.display = 'none';

	switch(tabID){
	
	case 'pubTab01': document.getElementById('pubEn').style.display = 'block'; break;
	case 'pubTab02': document.getElementById('pubGa').style.display = 'block'; break;
	case 'pubTab03': document.getElementById('pubXtra').style.display = 'block'; break;

	}
	
	setTabStyle(tabID)
	
	return false;

}

function selectLinkTab(tabID){

	document.getElementById('linkEn').style.display = 'none';
	document.getElementById('linkGa').style.display = 'none';

	switch(tabID){
	
	case 'linkTab01': document.getElementById('linkEn').style.display = 'block'; break;
	case 'linkTab02': document.getElementById('linkGa').style.display = 'block'; break;

	}
	
	setTabStyle(tabID)
	
	return false;

}



function attachFile(attachfile,lang){

	
	if(attachfile != "" && attachfile != null){
	
		var lastSlashIndex = attachfile.lastIndexOf('/');
		
		if(lang == 'en')
			document.getElementById('fileAttachEn').innerHTML = "<label>File Attached:</label> <strong>" + attachfile.substring(lastSlashIndex + 1, attachfile.length) + "</strong>";
		else{
			document.getElementById('fileAttachGa').innerHTML = "<label>File Attached:</label> <strong>" + attachfile.substring(lastSlashIndex + 1, attachfile.length) + "</strong>";
			document.forms[0].txtFilePathGa.value = attachfile;

			}
		}
	}


function checkLink(url){

	var response = null;

	response= ACLinksList.checkLink(url);

	if (debug&&response.error!=null)
		return false;

	else if(response.value == false)
		return false;

	else
		return true;
}

function clearForm(type){

if(type == 'links'){

	document.getElementById('errTxtNameEn').innerHTML = "";
	document.getElementById('errTxtNameGa').innerHTML = "";
	document.getElementById('errTxtDescriptionEn').innerHTML = "";
	document.getElementById('errTxtDescriptionGa').innerHTML = "";
	document.getElementById('errTxtEmail').innerHTML = "";
	document.getElementById('errTxtUrl').innerHTML = "";

}
else if(type == 'publications'){

	document.getElementById('errTxtNameEn').innerHTML = "";
	document.getElementById('errTxtNameGa').innerHTML = "";
	document.getElementById('errTxtDescriptionEn').innerHTML = "";
	document.getElementById('errTxtDescriptionGa').innerHTML = "";

}

}

function validate(type){


clearForm(type);

var isValid = true;
var ErrorMessage = '';
var form = document.forms[0];

if(type == 'links'){

var myExp = /^.+@.+\..{2,4}$/;
var email = form.txtEmail.value;

	if(form.txtNameEn && form.txtNameEn.value == ""){ 
		isValid = false; ErrorMessage += '<li>English Link Name missing</li>'; document.getElementById('errTxtNameEn').innerHTML = '*';
		}
	if(form.txtNameGa && form.txtNameGa.value == ""){ 
		isValid = false; ErrorMessage += '<li>Irish Link Name missing</li>'; document.getElementById('errTxtNameGa').innerHTML = '*';
		}
	/*
	if(form.txtDescriptionEn && form.txtDescriptionEn.value == ""){ 
		isValid = false; ErrorMessage += '<li>English Description missing</li>'; document.getElementById('errTxtDescriptionEn').innerHTML = '*';
		}
	if(form.txtDescriptionGa && form.txtDescriptionGa.value == ""){ 
		isValid = false; ErrorMessage += '<li>Irish Description missing</li>'; document.getElementById('errTxtDescriptionGa').innerHTML = '*';
		}
	*/
	if(form.txtEmail && form.txtEmail.value != "" && myExp.test(email) == false){
		isValid = false; ErrorMessage += '<li>Invalid Email</li>'; document.getElementById('errTxtEmail').innerHTML = '*'; 
		}
	if(form.txtUrl && form.txtUrl == ""){
		isValid = false; ErrorMessage += '<li>Link URL missing</li>'; document.getElementById('errTxtUrl').innerHTML = '*'; 
		}
		
	if(form.txtUrl && form.txtUrl != "" && checkLink(form.txtUrl.value) == false){
		isValid = false; ErrorMessage += '<li>Invalid Link URL</li>'; document.getElementById('errTxtUrl').innerHTML = '*';
		}
		
			
	}
else if(type == 'publications'){

	if(form.txtNameEn && (form.txtNameEn.value == "" || form.txtNameEn.value == "Title (EN)")){ 
		isValid = false; ErrorMessage += '<li>English Publication Name missing</li>';  document.getElementById('errTxtNameEn').innerHTML = '*';
		}
	/* if(form.txtDescriptionEn && (form.txtDescriptionEn.value == "" || form.txtDescriptionEn.value == "Description (EN)" )){ 
		isValid = false; ErrorMessage += '<li>English Description missing</li>'; document.getElementById('errTxtDescriptionEn').innerHTML = '*';
		}
	
	if(form.txtFilePathEn && (form.txtFilePathEn.value == "")){ 
		isValid = false; ErrorMessage += '<li>English Document missing</li>'; document.getElementById('errTxtFilePathEn').innerHTML = '*';
		}
	*/
	if(form.txtNameGa && (form.txtNameGa.value != "" && form.txtNameGa.value != "Title (GA)")){

		/*
		if(form.txtDescriptionGa && (form.txtDescriptionGa.value == "" || form.txtDescriptionGa.value == "Description (Ga)")){ 
			isValid = false; ErrorMessage += '<li>Irish Description missing</li>'; document.getElementById('errTxtDescriptionGa').innerHTML = '*';
			}
		
		if(form.txtFilePathGa && (form.txtFilePathGa.value == "")){ 
			isValid = false; ErrorMessage += '<li>Irish Document missing</li>'; document.getElementById('errTxtFilePathGa').innerHTML = '*';
			}
		*/
		}
	}
	
	if(ErrorMessage != ''){
	
		ErrorMessage = '<ul>' + ErrorMessage + '</ul>';
		document.getElementById('ErrorMessage').innerHTML = ErrorMessage;

		}
		
	
	
return isValid;

}


//doesn't seem to work for submit buttons
function initValidate(){

	if(document.getElementById('btnUpdateLink') != null)
		document.getElementById('btnUpdateLink').onclick = function(){ return validate('links')};
		
	if(document.getElementById('btnUpdatePublication') != null)
		document.getElementById('btnUpdatePublication').onclick = function(){ return validate('publications')};
}

