function JStrim (strObject) {
    return strObject.replace(/(^\s*)|(\s*$)/g,"");
}

function checkEmail(emailValue) {
  var re = /^( *)[^@]+@[^@\. ]+.[^@\. ]+[\.]{0,1}[^@\. ]*[\s]*$/;
  if (emailValue.match(re) != null) return true;
  return false;
}

function isHttpUrl(strObject) {
    var re = /^http:\/\/[\S]+$/;
    if (strObject.match(re) != null) return true;
    return false;
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function clearCookie( cookieName ) {
    expdate = "Thu, 01-Jan-70 00:00:01 GMT";
    if( getGookie( cookieName )) {
        document.cookie = cookieName + "=" + ";expires=" + expdate;
    }
    return unescape( getGookie( cookieName ));
}

function centerWindow(windowWidth, windowHeight, otherStr) {
  var x = 0;
  var y = 0;

  if (ie4) {
    var dopX = window.document.body.offsetWidth/2 - windowWidth/2;
    var dopY = window.document.body.offsetHeight/2 - windowHeight/2;

    x = (dopX > 0 && dopY > 0) ? dopX + window.screenLeft - 15: window.screen.availWidth/2 -  windowWidth/2;
    y = (dopX > 0 && dopY > 0) ? dopY + window.screenTop - 20: window.screen.availHeight/2 - windowHeight/2;
  } else {
    x = window.screen.availWidth/2 -  windowWidth/2;
    y = window.screen.availHeight/2 - windowHeight/2;
  }

  if (otherStr == null) otherStr = "resizable=no,scrollbars=no,status=no,toolbar=no,width=";
  var str = otherStr + windowWidth +", height=" + windowHeight + ", top=" + y + ", left=" + x;
  return str;
}

function openWindow(url, name, sessid) {
  window.open(url + "?PHPSESSID=" + sessid, name, centerWindow(550, 320));
}

function vlI(name, message)
{	
	var i=0; var j=0; var c; var n;
	var nstr="1234567890.";
	var str="";
	var isOk = false;
	var astr = "";
	astr = JStrim(document.getElementById(name).value);
	c = astr.substring(0,1);
	if (c=="-"){
		str = astr.substring(1,astr.length);
	}else{
		str = astr;
	}
	
	for (i=0;i<str.length;i++)
	{
		c = str.substring(i,i+1);
		isOk=false;
		for (j=0;j<nstr.length;j++){
			n = nstr.substring(j,j+1);
			if (c==n){
				isOk=true;
				break;
			}
		}
		if (isOk==false) break
		else continue
	}
	if (!isOk) { 
		document.getElementById('err_' + name).innerHTML = "* " + message;
		document.getElementById(name).focus();
	} else {
		document.getElementById('err_' + name).innerHTML = "* ";
	}
	return isOk;
}

function vl(name, message) {
	var txtValue = JStrim(document.getElementById(name).value);
	if ("" == txtValue) {
		document.getElementById('err_' + name).innerHTML = "* " + message;
		document.getElementById(name).focus();
		return false;
	} else {
		document.getElementById('err_' + name).innerHTML = "* ";
	}
	return true;
}


