/*
	Code:	omni.js
	Descr:	Supporting Javascript functions
			for ELSSI Web Site

	Rev.:	R01.00 - 01-Oct-2011 : original version
			R01.01 - 05-Oct-2011 : isInArray function added

	Author:	Omnigo
	Copyright:Omnigo
*/

function validate_email(fld) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

	if (!filter.test(fld.value)) {
		//alert('Please provide a valid email address');
		return false;
	} else {
		return true;
	}
}

/* contact form - contact.php - Validation */
function validate_contactForm(thisForm) {
	document.getElementById("frmMsg2Usr").innerHTML = "";
	if (validate_email(thisForm.frmEmail)==false) {
		document.getElementById("frmMsg2Usr").innerHTML = "Please provide a valid email address";
		thisForm.frmEmail.focus();
		thisForm.frmEmail.select();
		return false;
	}
	var elob = document.getElementById("frmMsg");
	if (elob.value.length==0) {
		document.getElementById("frmMsg2Usr").innerHTML = "You have not written any text message";
		thisForm.frmMsg.focus();
		thisForm.frmMsg.select();
		return false;
	}
	elob = document.getElementById("frmInpBrowse");
	if (elob.value.length>0) {
		var fext = getFileExt(elob.value);
		switch(fext.toLowerCase())
			{
			case 'zip':
				return true;
				break;
			default:
				document.getElementById("frmMsg2Usr").innerHTML = "Only file type 'zip' is accepted";
				thisForm.frmInpBrowse.focus();
				thisForm.frmInpBrowse.select();
				return false;
			}
	}
	return true;
}

function getFileExt(fpname) {
	if(!fpname ) {
		return "";
	}
	if( fpname.length == 0 ) {
		return "";
	}
	var dot = fpname.lastIndexOf(".");
	if( dot == -1 ) {
		return "";
	}
	var extension = fpname.substr(dot+1,fpname.length);
	return extension;
}

function popup_modal_dialog(element, sizeHorz, sizeVert) {
	if(!sizeHorz) { var sizeHorz = 530 };
	if(!sizeVert) { var sizeVert = 370 };
	$( element ).dialog({
		height: sizeVert, width: sizeHorz,
		modal: true
	});
	$(window).resize(function() {
		$(element).dialog("option", "position", "center");
	});

}

/* --- START : accrdList by Omnigo - as used in library.php ---

	see library.php code where the below DOM structure is implemented
	the following javascript code is absolutely customized for this structure ONLY
	
	div
	#accordion_list ---	+
						|
						+----- h3 ----- +	upper level category title e.g. 'Regulatoryt Framerowk'
										|
										+--- div ---+			one library entry slot
													+--- *  ---	+			follows any number/struct 
																|			of HTML tags, 
																+--- *		in the context of this
																+--- *		library entry slot
*/

function accrdList_init_library(accordElem) {
	$(accordElem+' h3 + div').hide();
	
	$(accordElem+' h3').not('h3:has(a)').mouseover(function() {
		$(this).css('cursor', 'pointer');
		$(this).css('text-decoration', 'underline');
	});

	$(accordElem+' h3').not('h3:has(a)').mouseout(function() {
		$(this).css('text-decoration', 'none');
	});

	$(accordElem+' h3').not('h3:has(a)').click(function(){
		var elisvisible = $(this).next('div').is(":visible");
		$(accordElem+' h3 + div').hide();
		if ( elisvisible ) {
			$(this).next('div').hide();
		} else {
			$(this).next('div').show();
		}
		return false;
	});
}
/* --- END   : accrdList by Omnigo - as used in library.php --- */

function isInArray(arr, obj) { 
	for(var i101=0; i101<arr.length; i101++) { 
		if (arr[i101] == obj) return true; 
	}
	return false; 
} 
