﻿function checkEmailAddr(str) 
{
	atpos = str.indexOf("@");
	if(atpos != str.lastIndexOf("@")) {
		return false;
	} else if(atpos == str.length -1) {
		return false;
	} else if(atpos == -1 || str.indexOf(".") == -1 || str.indexOf(".") == 0) {
		return false;
	} else if(atpos == 0) {
		return false;
	} else if((str.length - (str.lastIndexOf(".") + 1) < 2) || (str.length - (str.lastIndexOf(".") + 1) > 5)) {
		return false;
	} else if(str.indexOf(".", atpos) - atpos == 1) {
		return false;
	} else if(atpos - str.indexOf(".", atpos - 1) == 1) {
		return false;
	} else if(str.indexOf("www") == 0) {
		return false;
	}
	return true;
}

function CheckIsNumeric(infield) 
{
	var number_format = "0123456789";
	var check_char;
	for (var i = 0; i < infield.value.length; i++)	{
		check_char = number_format.indexOf(infield.value.charAt(i));
		if (check_char < 0) {
			return false;
		} 
	}
	return true;
}
	
function getCheckedCount(chkObj) {
	var cnt = 0;
	if(typeof chkObj != 'undefined') {
	    if(typeof(chkObj.length) != 'undefined') {
		for(var i = 0; i < chkObj.length; i++){
			if(chkObj[i].checked)
				cnt++;
		}
	    } else {
		if(chkObj.checked)
		    cnt = 1;
	    }
	}
	return cnt;
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {
			this[i] = 30;
		}
		if (i==2) {
			this[i] = 29;
		}
  } 
  return this;
}

function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
  	// EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function CheckDate(datefield)
{
	//var chkRegExp = /^\d*\.{0,1}\d+$/g;
	//var chkRegExp = /^\d{4}\.\d{2}.\d{2}$/g;

	var chkRegExp = /^((19|20)\d{2})\.(0[1-9]|1[0-2])\.(0[1-9]|[12][0-9]|3[01])$/g
	//var testNum = new String(".1234");
	if(!chkRegExp.test(datefield.value)) {
		return false;
	} else {
		//check day validity
		var daysInMonth = DaysArray(12);
		var nYear = parseInt(datefield.value.substring(0, 4));
		var nMonth = parseInt(datefield.value.substring(5, 7));
		var nDay = parseInt(datefield.value.substring(8, 10));
		if((nMonth == 2 && nDay > daysInFebruary(nYear)) || nDay > daysInMonth[nMonth]) {
			return false;
		} else {
			return true;
		}
	}
}

function errordisp(message, setfocus) 
{
	alert(message);
	setfocus.focus();	
}

function condtoggleitem(item, condval, formitem, defaultitem, defaultval) {
	if(document.getElementById(formitem).value >= condval) {
		//if(document.getElementById(item).style.display=='inline') {
		//	document.getElementById(item).style.display='none';
		//} else {
			document.getElementById(item).style.display='inline';
		//}
	} else {
		document.getElementById(defaultitem).value = defaultval;
		document.getElementById(item).style.display='none';
	}
} 

/*function showPopup(sURL,sTitle){
 window.open (sURL,sTitle,"status=0,toolbar=0,menubar=0,resizable=1,width=640,height=480");
// window.open (sURL,sTitle,"status=0,toolbar=0,menubar=0,resizable=1,width=640");
 return false;
}
*/
function showPopup(sURL,sTitle){

 window.open (sURL,"","status=0,toolbar=0,menubar=0,resizable=1,width=640");

 return false;

}

function condtoggleitem(item, condval, formitem, defaultitem, defaultval) {
	if(document.getElementById(formitem).value >= condval) {
		//if(document.getElementById(item).style.display=='inline') {
		//	document.getElementById(item).style.display='none';
		//} else {
			document.getElementById(item).style.display='inline';
		//}
	} else {
		document.getElementById(defaultitem).value = defaultval;
		document.getElementById(item).style.display='none';
	}
} 

/* preloads */	
/*
buttonplus = new Image; buttonplus.src = "images/minusCold.gif";
buttonminus = new Image; buttonminus.src = "images/plusCold.gif";

function toggle(formitem, imgitem) 
{
	alert('pressed');
	if(document.all[formitem].style.display=='inline') {
		document.all[formitem].style.display='none';
		document.all[imgitem].src=buttonminus.src;
		alert(document.all[imgitem].src);
	} else {
		document.all[formitem].style.display='inline';
		document.all[imgitem].src=buttonplus.src;
	}
}
*/

function openDictionaryPopup(bookmark) {
	var popupURL;
//	if (typeof(dictPopupWindow) <> 'undefined') { alert('Megvan az.'); dictPopupWin.close(); };
	popupURL = "dictionary_popup.cfm" + (bookmark!="" ? ("#" + bookmark) : "");
	dictPopupWin = window.open(popupURL, "", "toolbar=no, dependent=yes, resizable=yes, scrollbars=yes,location=no,width=580,height=300");
	dictPopupWin.moveTo(this.screenLeft+190,this.screenTop+213);
}

function openAnimPopup(file) {
	file = "multimedia/anim.cfm?anim=" + file;
	animPopupWin = window.open(file, "", "toolbar=no, dependent=yes, resizable=no, scrollbars=no,location=no,width=600,height=400");
	animPopupWin.moveTo(this.screenLeft+180,this.screenTop+213);
}

function openVideoPopup(playerfile, videofile) {
	if (typeof(playerfile) != "string" ) {playerfile = "flvvideoplayer"}
	if (typeof(videofile) != "string" ) {videofile = "moa"}
	file = "multimedia/video.cfm?player=" + playerfile + "&video=" + videofile;
	videoPopupWin = window.open(file, "", "toolbar=no, dependent=yes, resizable=yes, scrollbars=no,location=no,width=360,height=324");
	videoPopupWin.moveTo(this.screenLeft+300,this.screenTop+213);
}

function showEmail(id, hash) {
	var element = document.getElementById(id);
	tmp.location.href = 'showemail.cfm?id='+id+'&hash='+hash;
}
