// JavaScript Document
function Time2Time(php_datetime){
	var	tmp	= php_datetime.toString();
	var	date_part	= php_datetime.split(" ")[0];
	var	time_part	= php_datetime.split(" ")[1];
	var date_vect	= date_part.split("-");
	var time_vect	= time_part.split(":");
	var js_datetime	= new Date(date_vect[0], date_vect[1] - 1, date_vect[2], time_vect[0], time_vect[1], time_vect[2]);
	
	return	js_datetime;		
}

//
// Hides a tag
//
function hide_tag(tagName){
	try{
		act_style	= document.getElementById(tagName).style;	
		act_style.display = act_style.display=="none"?"":"none";
		return true;
	}catch(err){
		return false;
	}
}
//
// Post function
//
function ascii2url(url){
	url = url.replace(new RegExp('%2F','g'), '/');
	url = url.replace(new RegExp('%3F','g'), '?');
	url = url.replace(new RegExp('%3D','g'), '=');
	url = url.replace(new RegExp('%26','g'), '&');
	return url;
}

function url2ascii(url){
	url = url.replace(new RegExp('/','g'), '%2F');
	url = url.replace(new RegExp('\\?','g'), '%3F');
	url = url.replace(new RegExp('=','g'), '%3D');
	url = url.replace(new RegExp('&','g'), '%26');
	return url;
}

function post(url){
    if( url == null ) return;

    //Parse the url.
    var link, params;
    if( url.indexOf("?") > -1 ){
        link = url.substring(0, url.indexOf("?"));
        params = url.substring(url.indexOf("?")+1, url.length);
    } else {
        link =url;
        params = 'eF2Zq3Th=0'; // EAS 5.3 hates unless parameter is set, so there is a must to use at least one
    }
    //Create the form.
    var postForm = document.createElement("form");
    postForm.action = link;
    postForm.method = 'POST';
    postForm.name = 'postForm';

    //Add the form to the document.
    document.getElementsByTagName("body")[0].appendChild(postForm);

    //Add parameters
    var arr = params.tokenize("&", "", true);

    for( i = 0; i < arr.length; i++) {

        try{
            var pname = arr[i].substring(0, arr[i].indexOf("="));
            var pvalue = arr[i].substring(arr[i].indexOf("=") + 1, arr[i].length );
			pvalue = ascii2url(pvalue); // restoring some ascii codes to normal characters
		}catch(e){
            continue;
        }
        var param = document.createElement("input");
        param.setAttribute( "type", "hidden" );
        param.setAttribute( "name", pname );
        param.setAttribute( "value", pvalue );
        postForm.appendChild(param);
    }
    //Submit the form
    postForm.submit();
}

String.prototype.tokenize = tokenize;

function tokenize()
{
 var input     = "";
 var separator = " ";
 var trim      = "";
 var ignoreEmptyTokens = true;

 try {
   String(this.toLowerCase());
 }
 catch(e) {
   window.alert("Tokenizer Usage: string myTokens[] = myString.tokenize(string separator, string trim, boolean ignoreEmptyTokens);");
   return;
 }

 if(typeof(this) != "undefined")
   {
      input = String(this);
   }

 if(typeof(tokenize.arguments[0]) != "undefined")
   {
      separator = String(tokenize.arguments[0]);
   }

 if(typeof(tokenize.arguments[1]) != "undefined")
   {
      trim = String(tokenize.arguments[1]);
   }

 if(typeof(tokenize.arguments[2]) != "undefined")
   {
      if(!tokenize.arguments[2])
        ignoreEmptyTokens = false;
   }

 var start = 0;
 var end = 0;
 var token = new Array();
 for(var i=0; i<input.length+1; i++)
   {
      if(input.slice(start, i).indexOf(separator) != -1)
        {
           end = i - separator.length;
           token[token.length] = input.slice(start, end);
           start = i;
        }
      else
        {
           if(i == input.length)
             token[token.length] = input.slice(start);
        }
   }

if(trim)
  for(var i=0; i<token.length; i++)
    {
      while(token[i].slice(0, trim.length) == trim)
        token[i] = token[i].slice(trim.length);
      while(token[i].slice(token[i].length-trim.length) == trim)
        token[i] = token[i].slice(0, token[i].length-trim.length);
    }

var finalToken = new Array();
if(ignoreEmptyTokens)
  {
     for(var i=0; i<token.length; i++)
       if(token[i] != "")
         finalToken[finalToken.length] = token[i];
  }
else
  {
     finalToken = token;
  }

 return finalToken;
}
//
// Pager template
//
function hide_tag_pager(tagName, display){
	try{		
		act_style	= document.getElementById(tagName).style;		
		if( display == 0 ){
			act_style.display = "none";			
		}else if( display == 1 ){
			act_style.display = "";						
		}
		return true;
	}catch(err){
		return false;
	}
}

function Pager(id_prefix, act_index, row_count, page_size, fw_btn_text, bw_btn_text){
	// Properties
	this.id_prefix	= id_prefix;
	this.act_index	= act_index;
	this.row_count	= row_count;
	this.page_size	= page_size;
	this.fw_btn_text= fw_btn_text;
	this.bw_btn_text= bw_btn_text;
	// Functions
	this.turnpage	= turnpage;
	this.initpages	= initpages;
}

function initpages(){
	for( i=1; i<=this.row_count; i++ ){
		if( i>=this.act_index && i<=(this.act_index+this.page_size-1) ){
			hide_tag_pager(this.id_prefix+i, 1);
		}else{
			hide_tag_pager(this.id_prefix+i, 0);				
		}
	}
	fw_btn		= document.getElementById(this.id_prefix + "_fw");
	bw_btn		= document.getElementById(this.id_prefix + "_bw");
	fw_btn.value	= this.fw_btn_text + " " + this.act_index;
	bw_btn.value	= this.act_index + this.page_size - 1 + " " + this.bw_btn_text;
	if( this.act_index == 1 ){
		fw_btn.disabled	= "disabled";
		bw_btn.disabled	= "";		
	}else if( this.act_index == this.row_count-this.page_size+1 ){
		bw_btn.disabled	= "disabled";		
		fw_btn.disabled	= "";
	}else{
		fw_btn.disabled	= "";
		bw_btn.disabled	= "";		
	}
}

function turnpage(direction){
	fw_btn		= document.getElementById(this.id_prefix + "_fw");
	bw_btn		= document.getElementById(this.id_prefix + "_bw");
	if( direction == "fw" ){
		this.act_index	-= this.page_size;
	}else{
		this.act_index	+= this.page_size;			
	}
	if( this.act_index < 1 ){
		this.act_index	= 1;
	}else if( this.act_index > (this.row_count-this.page_size+1) ){
		this.act_index	= (this.row_count-this.page_size+1);
	}
	this.initpages();
}
//
// Pager template end
//
function emailCheck (emailStr) {	
//	The following variable tells the rest of the function whether or not
//	to verify that the address ends in a two-letter country or well-known
//	TLD.  1 means check it, 0 means don't.
	var checkTLD=0;
//	The following is the list of known TLDs that an e-mail address must end with.
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|hu)$/;	
//	The following pattern is used to check if the entered e-mail address
//	fits the user@domain format.  It also is used to separate the username
//	from the domain.
	var emailPat=/^(.+)@(.+)$/;	
//	The following string represents the pattern for matching all special
//	characters.  We don't want to allow special characters in the address. 
//	These characters include ( ) < > @ , ; : \ " . [ ]
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";	
//	The following string represents the range of characters allowed in a 
//	username or domainname.  It really states which chars aren't allowed.
	var validChars="\[^\\s" + specialChars + "\]";	
//	The following pattern applies if the "user" is a quoted string (in
//	which case, there are no rules about which characters are allowed
//	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
//	is a legal e-mail address.
	var quotedUser="(\"[^\"]*\")";	
//	The following pattern applies for domains that are IP addresses,
//	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
//	e-mail address. NOTE: The square brackets are required.
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;	
//	The following string represents an atom (basically a series of non-special characters.)
	var atom=validChars + '+';	
//	The following string represents one word in the typical username.
//	For example, in john.doe@somewhere.com, john and doe are words.
//	Basically, a word is either an atom or quoted string.
	var word="(" + atom + "|" + quotedUser + ")";	
	// The following pattern describes the structure of the user	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");	
//	The following pattern describes the structure of a normal symbolic
//	domain, as opposed to ipDomainPat, shown above.
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");	
//	Finally, let's start trying to figure out if the supplied address is valid.
//	Begin with the coarse pattern to simply break up user@domain into
//	different pieces that are easy to analyze.
	var matchArray=emailStr.match(emailPat);	
	if (matchArray==null) {	
//		Too many/few @'s or something; basically, this address doesn't
//		even fit the general mould of a valid e-mail address.
//		alert("Email address seems incorrect (check @ and .'s)");
		return 1;
	}
	var user=matchArray[1];
	var domain=matchArray[2];	
	// Start by checking that only basic ASCII characters are in the strings (0-127).	
	for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
//			alert("Ths username contains invalid characters.");
			return 2;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
//			alert("Ths domain name contains invalid characters.");
			return 3;
		}
	}	
	// See if "user" is valid 	
	if (user.match(userPat)==null) {	
		// user is not valid	
//		alert("The username doesn't seem to be valid.");
		return 2;
	}	
//	if the e-mail address is at an IP address (as opposed to a symbolic
//	host name) make sure the IP address is valid.	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {	
		// this is an IP address	
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
//				alert("Destination IP address is invalid!");CHK_EMAIL_IP_INVALID
				return 4;
			}
		}
		return "";
	}	
	// Domain is symbolic name.  Check if it's valid.	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		//	alert("The domain name does not seem to be valid.");
			return 3;
		}
	}	
//	domain name seems valid, but now make sure that it ends in a
//	known top-level domain (like com, edu, gov) or a two-letter word,
//	representing country (uk, nl), and that there's a hostname preceding 
//	the domain or country.
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		//alert("This address is missing a hostname!");CHK_EMAIL_HOST
		return 5;
	}	
	// If we've gotten this far, everything's valid!
	return 0;
}

function showError(errstr){
	//Dialog.confirm("Add your <b>HTML</b> message here<br/>Better than a classic javascript alert?", 41 {top: 10, width:250, className: "alphacube", okLabel: "Yes", cancelLabel:"No"}); 	
	hide_tag_pager("box_error", 1);
	hide_tag_pager("box_error_header", 1);
	if(NS4){
		document.getElementById("error_message").document.open();
		document.getElementById("error_message").document.write(errstr);
		document.getElementById("error_message").document.close();
		document.getElementById("show_error_loc").document.open();
		document.getElementById("show_error_loc").document.write(errstr);
		document.getElementById("show_error_loc").document.close();
	}
	if(W3C||IE4){
		document.getElementById("error_message").innerHTML=errstr;
	}
	window.location.hash="error_location";
	window.alert(errstr);
}