/* -------------------- form functions -------------------- */

function invalidEmail(str) {
	if (str.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) return false;
	else return true;
}

function countNums(str) {
	var Count = 0;
	for (i=0; i<str.length; i++) {
		if (str.charAt(i).match(/[0-9]/)) Count++;
	}
	return Count;
}

function invalidInput(str) {
	if (str.match (/[^a-zA-Z0-9]/)) return true;
	else return false;
}

function invalidPhoneNumber(str) {
	// fairly strict international-format check
	// if (str.match(/^(\+[0-9]{1,3}(-| )?\(?\d\)?(\s?[0-9]{1,7}){2,3})$/)) return false;
	// else return true;
	if (countNums(str)<5) return true;
	else return false;
}

function checkConfirm(str) {
	if (confirm("Are you sure you want to "+str)) return true;
	else return false;
}

function ExpandCollapse(element, sw) {
	if (element == null) return false;
	else {
		if (element.style.display == "none") {
			$(element).slideDown();
			sw.src = "/images/collapse.gif";
			sw.alt = "Collapse"
		}
		else {
			$(element).slideUp();
			sw.src = "/images/expand.gif";
			sw.alt = "Expand"
		}
		return false;
	}
}

function toggleView(id) {
	if (document.getElementById("category"+id).style.display=="none") $('#category'+id).slideDown();
	else $('#category'+id).slideUp();
	return false;
}

function checkGX(form) {
	if (form.elements['TypeId'].value==5) {
		form.elements['lngEditionIndex'].value=2;
		$('#edition').slideUp();
	}
	else $('#edition').slideDown();
}

/* --------------------  -------------------- */

function showDetails(val) {
	if (val) $('#addinfo').slideDown();
	else $('#addinfo').slideUp();
}

function checkValue(val) {	// might be obsolete now
	if (val==1) document.getElementById('distinfo').style.display="none";
	else document.getElementById('distinfo').style.display="block";
}

/* -------------------- Language -------------------- */

function changeLang(val) {
	if (val.value==1) {
		document.getElementById("english").style.display="block";
		document.getElementById("french").style.display="none";
		document.getElementById("spanish").style.display="none";
	}
	else if (val.value==2) {
		document.getElementById("english").style.display="none";
		document.getElementById("french").style.display="block";
		document.getElementById("spanish").style.display="none";
	}
	else if (val.value==3) {
		document.getElementById("english").style.display="none";
		document.getElementById("french").style.display="none";
		document.getElementById("spanish").style.display="block";
	}
}

function checkSendEmails(id) {
	if (checkConfirm("send these notification emails?")) window.location="/article.php?articleid="+id+"&action=email";
	else return false;
}

/* -------------------- ICTicket -------------------- */

function checkColor(obj) {
	if (obj.value==1) {
		document.getElementById('Priority').style.backgroundColor="red";
		document.getElementById('Priority').style.color="white";
	}
	else if (obj.value==2) {
		document.getElementById('Priority').style.backgroundColor="orange";
		document.getElementById('Priority').style.color="white";
	}
	else if (obj.value==3) {
		document.getElementById('Priority').style.backgroundColor="white";
		document.getElementById('Priority').style.color="black";
	}
}

function checkArticleType(form) {
	var val=form.elements['articletype'].value;
	if ((val=="I") || (val=="R")) $('#Status').slideDown();
	else $('#Status').slideUp();
}

/* -------------------- Translation -------------------- */

function useValue(num) {
	var text=document.getElementById("English_"+num).innerHTML;
	text=text.replace(/&lt;/gi, '<');
	text=text.replace(/&gt;/gi, '>');
	document.getElementById("trns_"+num).value=text;
}

/* -------------------- Advanced Search -------------------- */

function toggleOptions(obj) {
	if (obj.checked) $("input[type='checkbox']").attr('checked', true);
	else $("input[type='checkbox']").attr('checked', false);
}

function checkEntire(obj) {
	if (obj.checked==false) {
		$('#o_site').attr('checked', false);
	}
}

