// JavaScript Document


// String functions
String.prototype.addslashes = function() { return this.replace(/\'/g,'\\\'').replace(/\"/g,'\\"').replace(/\0/g,'\\0');}
String.prototype.trim = function () { return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); };
String.prototype.replaceAll = function(pcFrom, pcTo){
      var i = this.indexOf(pcFrom);
      var c = this;
      while (i > -1){
      c = c.replace(pcFrom, pcTo);
      i = c.indexOf(pcFrom);
      }
      return c;
}
String.prototype.toUpper= function(){
	var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
	var b = [];
	var a = this.split(/\s+/g); // split the sentence into an array of words
	for (var i = 0 ; i < a.length ; i++ ){
		if(a[i].trim()=='')
			continue;
		var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
		var firstLetter = parts[1].toUpperCase();
		var restOfWord = parts[2].toLowerCase();
		b.push(firstLetter + restOfWord);
	}
	return b.join(' ');
}
	
function toUpper(str) {
	return str.toUpper();
}

function echeck(address) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(address) == false) {
		return false;
	}
	return true;
}

function $id(id){
	return document.getElementById(id);
}


//utf8 decoding for ajax requests responses
 var l1=true;
  
   var Url = {

// public method for url encoding
encode : function (string) {
return escape(this._utf8_encode(string));
},

// public method for url decoding
decode : function (string) {
return this._utf8_decode(unescape(string));
},

// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
},

// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;

while ( i < utftext.length ) {

c = utftext.charCodeAt(i);

if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}

}

return string;
}

}
  
function trim(s){
	s +='';
	return s.trim(); 
}

function addslashes(str) {
  str+='';
return str.addslashes();
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
	
	function function_exists( function_name ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Steve Clay
    // +   improved by: Legaev Andrey
    // *     example 1: function_exists('isFinite');
    // *     returns 1: true
 
 
    if (typeof function_name == 'string'){
        return (typeof window[function_name] == 'function');
    } else{
        return (function_name instanceof Function);
    }
}


function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findClientXY(){
	var bodyX, bodyY;
	if (self.innerHeight) // all except Explorer
	{
		bodyX = self.innerWidth;
		bodyY = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		bodyX = document.documentElement.clientWidth;
		bodyY = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		bodyX = document.body.clientWidth;
		bodyY = document.body.clientHeight;
	}	
	var r=new Array();
	r['x'] = bodyX;
	r['y'] = bodyY;
	return r;
}