function isArray(com) {
	if (typeof(com.length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function isArraySelectBox(com) {
	if (typeof(com[0].length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function trim(str) {
	var strTrim = "";
	var i, j;
	
	if (isEmpty(str)) return strTrim;
	
	for (i=0; i<str.length; i++) {
		if (str.charAt(i) != " ") break;
	}
	for (j=str.length-1; j>=0; j--) {
		if (str.charAt(j) != " ") break;
	}
	
	strTrim = str.substr(i, j-i+1);
	return strTrim;
}

function isEmpty(str) {
	return ((str==null) || (str.length==0));
}

function isWhiteSpace(str) {
	return isEmpty(trim(str));
}

function isDigit(d) {
	return ((d >= "0") && (d <= "9"));
}

function isLetter(c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
}

function isNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr)) {
			return false;
		}
	}
	return true;
}
function isInteger(s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isAlphaNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr) && !isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isAlphaOnly(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isRange(formObj, min, max)
{
	if(formObj.length < min || formObj.length > max)
	{
		return false;
	}
	return true;
}


function isEmail(s)
{   
	
	//alert(s); 
   	// is s whitespace?
    //if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++;
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else
	return true;
}

//Function to check whether the string is a valid integer
//Function to check whether the zipcode is a valid US zip code
function isZIPCode(field) 
{
	var valid = "0123456789";
	var hyphencount = 0;
	
	if (field.length!=5) {
	alert("Please enter your 5 digit zip code.");
	return false;
	}
	for (var i=0; i < field.length; i++) {
	temp = "" + field.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
	alert("Invalid characters in your zip code.  Please try again.");
	return false;
	}

	}
	return true;
}

function isMoney(str) 
{
	var valid = "0123456789.-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isPhoneNumber(str) 
{
	var valid = "0123456789()-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isCheckedRadio(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(count == 1) {
			checked = objRadio.checked;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = true;
				}
			}
		}
	}
	return checked;
}

function getRadioVal(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(count == 1) {
			checked = objRadio.value;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = objRadio[i].value;
				}
			}
		}
	}
	return checked;
}


function isSelected(frmObjSelect)
{
	if (frmObjSelect.value == -1) {
		return false;
	}
	else {
		return true;
	}
}



/* Delete Confirmation Check */
function confirmDelete(ID,NAME) {
	if(confirm('Are you sure you want to delete the selected web board '+NAME+'?\nDelete operation cannot be undone.')) {
		document.location = 'admin.remove.board.php?bid=' + ID + '&bname=' + NAME;
	}
}

/* Delete Confirmation Check - for restricted board messages */
function confirmDelete_article(FILE_NAME,BOARD,ID) {
	if(confirm('Are you sure you want to delete this article?\nDelete operation cannot be undone.')) {
		document.location = FILE_NAME + '?board=' + BOARD + '&kmode=remove.ok&id=' + ID;
	}
}

/* Delete Confirmation Check - for restricted board messages */
function confirmDelete_board_article(BOARD,ID,PAGE) {
	if(confirm('Are you sure you want to delete this article?\nDelete operation cannot be undone.')) {
		document.location = 'board.php' + '?board=' + BOARD + '&kmode=remove&id=' + ID + '&page=' + PAGE;
	}
}

/* Check Search Form */
function SFormCheck() {
	var g = this.document.SForm;
	if(isWhiteSpace(g.keyword.value)) {
		alert('Missing Search Keyword');
		g.keyword.value = "";
		g.keyword.focus();
		return false;
	}
}

/* Check Write Form */
function WFormCheck() {
	//RainEditor('raincontents','E');
	var g = this.document.WForm;
	if(isWhiteSpace(g.name.value)) {
  	alert('You forgot your name.');
  	g.name.focus();
  	return false;
	}
	if(!isWhiteSpace(g.passwd.value) && g.passwd.value.length < 4) {
  	alert('Password must be longer than 4 characters.');
  	g.passwd.select();
  	return false;
	}
	if(!isWhiteSpace(g.email.value) && !isEmail(g.email.value)) {
		alert('Please enter a valid email address.');
  	g.email.focus();
  	return false;
	}
	if(isWhiteSpace(g.subject.value)) {
  	alert('You forgot the subject.');
  	g.subject.focus();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Write Form - Restricted */
function WFormCheck_restrict() {
	//RainEditor('raincontents','E');
	var g = this.document.WForm;
	if(isWhiteSpace(g.subject.value)) {
  	alert('You forgot the subject.');
  	g.subject.focus();
  	return false;
	}
	if(g.subject.length > 70) {
  	alert('Title is too long. Make it less than 70 characters.');
  	g.subject.select();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Auth Edit Form */
function auth_EFormCheck() {
	var g = this.document.auth_EForm;
	if(isWhiteSpace(g.password.value)) {
  	alert('Enter your password.\nPassword is needed for this operation.');
  	g.password.select();
  	g.password.focus();
  	return false;
	}
}

/* Check Edit Form */
function EFormCheck() {
	//RainEditor('raincontents','E');
	var g = this.document.EForm;
	if(isWhiteSpace(g.subject.value)) {
  	alert('You forgot the subject.');
  	g.subject.focus();
  	return false;
	}
	if(g.subject.length > 70) {
  	alert('Title is too long. Make it less than 70 characters.');
  	g.subject.select();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Edit Form - Restricted */
function EFormCheck_restrict() {
	//RainEditor('raincontents','E');
	var g = this.document.EForm;
	if(isWhiteSpace(g.subject.value)) {
  	alert('You forgot the subject.');
  	g.subject.focus();
  	return false;
	}
	if(g.subject.length > 70) {
  	alert('Title is too long. Make it less than 70 characters.');
  	g.subject.select();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Reply Form */
function RFormCheck() {
	//RainEditor('raincontents','E');
	var g = this.document.RForm;
	if(isWhiteSpace(g.name.value)) {
  	alert('You forgot your name.');
  	g.name.focus();
  	return false;
	}
	if(g.passwd.length < 4) {
  	alert('Password must be longer than 4 characters.');
  	g.passwd.select();
  	return false;
	}
	if(isWhiteSpace(g.subject.value)) {
  	alert('You forgot the subject.');
  	g.subject.focus();
  	return false;
	}
	if(g.subject.length > 70) {
  	alert('Title is too long. Make it less than 70 characters.');
  	g.subject.select();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Comment Form */
function CFormCheck() {
	
	var g = this.document.CForm;
	if(isWhiteSpace(g.name.value)) {
  	alert('Please enter your name.');
  	g.name.focus();
  	return false;
	}
	if(g.passwd.length < 4) {
  	alert('Password must be longer than 4 characters.');
  	g.passwd.select();
  	return false;
	}
	if(isWhiteSpace(g.passwd.value)) {
  	alert('Please enter your password.');
  	g.passwd.focus();
  	return false;
	}
	if(isWhiteSpace(g.comment.value)) {
  	alert('You forgot the content.');
  	g.comment.focus();
  	return false;
	}
}

/* Check Remove Form */
function auth_RFormCheck() {
	var g = this.document.auth_RForm;
	if(isWhiteSpace(g.password.value)) {
  	alert('Enter your password.');
  	g.password.focus();
  	return false;
	}
	else {
		var ans = confirm("Are you sure you want to erase this message?\nNote: This process cannot be undone.");
		if(!ans) { return false; }
	}
}

/* Check Create Form */
function CreateFormCheck() {
	var g = this.document.CreateForm;
	if(isWhiteSpace(g.boardName.value)) {
  	alert('Enter a new web board name.');
  	g.boardName.focus();
  	return false;
	}
	else {
		var ans = confirm("Are you sure you want to create a new web board?\nNote: Please configure the settings after the board is created.");
		if(!ans) {
			g.boardName.value = '';
			return false;
		}
	}
}

/* Check Setting Form */
function SettingFormCheck() {
	var g = this.document.SettingForm;
	if(isWhiteSpace(g.title.value)) {
  	alert('Enter web board title.');
  	g.title.focus();
  	return false;
	}
	if(isWhiteSpace(g.howMany.value)) {
  	alert('Enter articles per page.');
  	g.howMany.focus();
  	return false;
	}
	if(!isNumeric(g.howMany.value)) {
  	alert('Articles per page only accepts numbers.');
  	g.howMany.select();
  	return false;
	}
	if(g.howMany.value < 5) {
  	alert('Articles per page must be greater than 5.');
  	g.howMany.select();
  	return false;
	}
	if(isWhiteSpace(g.num_page.value)) {
  	alert('Enter number of pages to be displayed at the bottom.');
  	g.num_page.focus();
  	return false;
	}
	if(!isNumeric(g.num_page.value)) {
  	alert('Number of pages only accepts numbers.');
  	g.num_page.select();
  	return false;
	}
	if(g.num_page.value < 3 || g.num_page.value > 10) {
  	alert('Number of pages must be between 3 and 10.');
  	g.num_page.select();
  	return false;
	}
	if(isWhiteSpace(g.width.value)) {
  	alert('Enter table width.');
  	g.width.focus();
  	return false;
	}
	if(!isNumeric(g.width.value)) {
  	alert('Table width only accepts numbers.');
  	g.width.select();
  	return false;
	}
	if(g.width.value < 500 || g.width.value > 900) {
  	alert('Table width must be between 500 and 900 in pixel.');
  	g.width.select();
  	return false;
	}
	if(isWhiteSpace(g.border.value)) {
  	alert('Enter table border.');
  	g.border.focus();
  	return false;
	}
	if(!isNumeric(g.border.value)) {
  	alert('Table border only accepts numbers.');
  	g.border.select();
  	return false;
	}
	if(isWhiteSpace(g.curPassword.value)) {
  	alert('Enter your current password.');
  	g.curPassword.focus();
  	return false;
	}
}

/* Check Admin Setting Form */
function SettingAdminFormCheck(mode) {
	var g = this.document.SettingForm;
	if(isWhiteSpace(g.title.value)) {
  	alert('Enter web board title.');
  	g.title.focus();
  	return false;
	}
	if(isWhiteSpace(g.howMany.value)) {
  	alert('Enter articles per page.');
  	g.howMany.focus();
  	return false;
	}
	if(!isNumeric(g.howMany.value)) {
  	alert('Articles per page only accepts numbers.');
  	g.howMany.select();
  	return false;
	}
	if(g.howMany.value < 5) {
  	alert('Articles per page must be greater than 5.');
  	g.howMany.select();
  	return false;
	}
	if(isWhiteSpace(g.num_page.value)) {
  	alert('Enter number of pages to be displayed at the bottom.');
  	g.num_page.focus();
  	return false;
	}
	if(!isNumeric(g.num_page.value)) {
  	alert('Number of pages only accepts numbers.');
  	g.num_page.select();
  	return false;
	}
	if(g.num_page.value < 3 || g.num_page.value > 10) {
  	alert('Number of pages must be between 3 and 10.');
  	g.num_page.select();
  	return false;
	}
	if(isWhiteSpace(g.width.value)) {
  	alert('Enter table width.');
  	g.width.focus();
  	return false;
	}
	if(!isNumeric(g.width.value)) {
  	alert('Table width only accepts numbers.');
  	g.width.select();
  	return false;
	}
	if(g.width.value < 500 || g.width.value > 900) {
  	alert('Table width must be between 500 and 900 in pixel.');
  	g.width.select();
  	return false;
	}
	if(isWhiteSpace(g.border.value)) {
  	alert('Enter table border.');
  	g.border.focus();
  	return false;
	}
	if(!isNumeric(g.border.value)) {
  	alert('Table border only accepts numbers.');
  	g.border.select();
  	return false;
	}
	if(mode != '1'){
		if(isWhiteSpace(g.curPassword.value)) {
	  	alert('Enter your current password.');
	  	g.curPassword.focus();
	  	return false;
		}
	}
}

/* custom function for tradecaronline.com */
function toggle_over(el) {
	for(i=1; i<=11; i++) {
		eval("submenu"+i+".style").display = 'none';	
	}		
	el.style.display = '';
}
function toggle_out(el) {
	for(i=1; i<=11; i++) {
		eval("submenu"+i+".style").display = 'none';	
	}
	el.style.display = '';
}
function toggle_action(el) {
	if(el.style.display == '') {
		el.style.display = 'none';	
	} else {
		el.style.display = '';
	}
}

function popupWindow(page_url, width, height, opt) {
	window.open(page_url,'popup_window','width='+width+',height='+height+','+opt);
}

function certWindow(page_url,winName, width, height) {
	window.open(page_url,winName,'width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0');
}

function flashWindow(page_url, width, height) {
	window.open(page_url,'popup_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0');
}


function printWindow(page_url,width,height) {
	window.open(page_url,'popup_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=1');
}


function imageWindow(boardname,id,width,height) {
	window.open('image_viewer.php?board='+boardname+'&id='+id,'image_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=1');
}