﻿function isPosInteger(inputVal) {
	inputStr = inputVal.toString() ;
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i) ;
		if ((oneChar < '0' || oneChar > '9') && !(i == 0 && oneChar == "-")) {
			return false;
		}
	}
	return !isNaN(parseInt(inputVal));
}

function isPosFloat(inputVal) {
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if ((oneChar < '0' || oneChar > '9') && !(i == 0 && oneChar == "-") && !(i > 0 && oneChar == '.')) {
			return false;
		}
	}
	return !isNaN(parseFloat(inputVal));
}

function evtTrim(iStr) {
	iStr = iStr.toString() + " ";
	return iStr.replace(/^\s+|\s+$/g, "");
}

function isEmail(sEmail) {
	if (sEmail.length > 0) {
		sEmail = evtTrim(sEmail);
		result1 = sEmail.indexOf("@");
		result2 = sEmail.indexOf(".");
		return !((sEmail.length < 6) || (result1 < 1) || (result1 > sEmail.length - 2) || (result2 < 3)  || (result2 > sEmail.length-2));
	} else {
		return false;
	}
}

function Show_TV(tv_iIdx, tv_iItem, tv_iTimeout) {
	if (isPosInteger(tv_iIdx) && eval("tv" + tv_iItem + "Img").id && eval("tv" + tv_iItem + "Name").id && eval("arrTV" + tv_iItem).length) {
		var tv_iImg = eval("tv" + tv_iItem + "Img");
		var tv_iHref = eval("tv" + tv_iItem + "Name");
		var tv_iArray = eval("arrTV" + tv_iItem);

		if (tv_iIdx > tv_iArray.length - 1) tv_iIdx = 0;

		// hidden old img
		tv_iImg.filters.item(0).apply();
		tv_iImg.filters.item(0).transition = 12;
		tv_iImg.style.visibility = "hidden";
		tv_iImg.filters(0).play(1.0);

		tv_iImg.parentElement.href = tv_iArray[tv_iIdx][1];
		tv_iImg.src = tv_iArray[tv_iIdx][2];
		tv_iImg.alt = tv_iArray[tv_iIdx][3]

		// show new img
		tv_iImg.filters.item(0).apply();
		tv_iImg.filters.item(0).transition = 12;
		tv_iImg.style.visibility = "";
		tv_iImg.filters(0).play(1.0);

		// set new company name
		tv_iHref.innerHTML = "<a href='" + tv_iArray[tv_iIdx][1] + "' title='" + tv_iArray[tv_iIdx][3] + "'>" + tv_iArray[tv_iIdx][0] + "</a>";

		tv_iIdx += 1;
		if (tv_iIdx > tv_iArray.length - 1) tv_iIdx = 0;

		setTimeout("Show_TV(" + tv_iIdx + ", '" + tv_iItem + "', " + tv_iTimeout + ")", tv_iTimeout);
	}
}

function Show_TV_Old() {
	// hidden old img
	tvCompanyImg.filters.item(0).apply();
	tvCompanyImg.filters.item(0).transition = 12;
	tvCompanyImg.style.visibility = "hidden";
	tvCompanyImg.filters(0).play(1.0);

	tvCompanyImg.parentElement.href = arrTVCompany[iIndex][1];
	tvCompanyImg.src = arrTVCompany[iIndex][2];
	tvCompanyImg.alt = arrTVCompany[iIndex][3]

	// show new img
	tvCompanyImg.filters.item(0).apply();
	tvCompanyImg.filters.item(0).transition = 12;
	tvCompanyImg.style.visibility = "";
	tvCompanyImg.filters(0).play(1.0);

	// set new company name
	tvCompanyName.innerText = arrTVCompany[iIndex][0];
	tvCompanyName.href = arrTVCompany[iIndex][1];
	tvCompanyName.title = arrTVCompany[iIndex][3];

	iIndex += 1;
	if (iIndex > arrTVCompany.length - 1) iIndex = 0;

	setTimeout("Show_TV()",5000)
}

function isValidString(inputVal) {
	for (var i=0; i<inputVal.length; i++) {
		var cc = inputVal.charAt(i);
		if (!((cc >= "0" && cc <= "9") || (cc >= "a" && cc <= "z") || (cc >= "A" && cc <= "Z") || (cc == "-") || (cc == "_"))) {
			return false;
		}
	}
	return true;
}

function isDate(sVal) {
	var re = /\b(1[0-2]|0?[1-9])[\-\/](0?[1-9]|[12][0-9]|3[01])[\-\/]((19|20)\d{2})\b/;
	return re.test(sVal);
}

function isTelFax(iObj, iVal) {
	vObj = iObj.value;
	for (var i=0; i<vObj.length; i++) {
		var oneChar = vObj.charAt(i);
		if ((oneChar < "0" || oneChar > "9")) {
			alert("Please input the correct 0 - 9 number char !");
			iObj.focus();iObj.select();return false;
		}
	}return true;
}

var glbWin = null;
function evtShowHelp(sURL, sWidth, sHeight, sStatus) {
	glbWin = window.open(sURL, "mHelp", "width=" + sWidth + ",height=" + sHeight + ",left=" + ((screen.width-sWidth)/2) + ",top=" + ((screen.height-sHeight)/2) + ",toolbar=no,directories=no,status=" + (sStatus ? sStatus : "yes") + ",scrollbars=no,resizable=no,menubar=no"); 
	glbWin.moveTo((screen.width-sWidth)/2, (screen.height-sHeight)/2);
	glbWin.resizeTo(sWidth + 10, sHeight + 50);
	glbWin.focus();
}

function evtShowWindow(sURL, sWidth, sHeight, sTitle, sStatus, sResizable) {
	var cWin = null;
	cWin = window.open(sURL, sTitle, "width=" + sWidth + ", height=" + sHeight + ", left=" + ((screen.width-sWidth)/2) + ", top=" + ((screen.height-sHeight)/2) + ",toolbar=no,directories=no,status=" + (sStatus ? sStatus : "yes") + ",scrollbars=no,resizable=" + (sResizable ? sResizable : "no") + ",menubar=no"); 
	cWin.moveTo((screen.width-sWidth)/2, (screen.height-sHeight)/2);
	cWin.resizeTo(sWidth + 10, sHeight + 50);
	cWin.focus();
}