
var include = {
    js : function(filename){
    	var head = document.getElementsByTagName('head').item(0);
		script = document.createElement('script');
		script.src = filename;
		script.type = 'text/javascript';
		head.appendChild(script);
    },
    div : function(div_name,class_name,display){
	    var body = document.getElementsByTagName('body').item(0);
	    div = document.createElement('div');
	    body.appendChild(div);
	    div.id = div_name;
	    div.className = class_name;
	    div.style.display = display;
    },
    css : function(filename){
    	var head = document.getElementsByTagName('head').item(0);
		link = document.createElement('link');
		link.href = filename;
		link.rel = 'stylesheet';
		head.appendChild(link);
    }
}

var validator = {
    id : null,
    email : function(id){
    	this.id = id;
    	var _email = $(id).value;
    	if(_email.length <= 0)
	  		return ['empty','ÐÐµ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¾ Ð¿Ð¾Ð»Ðµ Email'];
		var splitted = _email.match("^(.+)@(.+)$");
		if(splitted == null)
			return ['wrong','ÐÐµÐ²ÐµÑÐ½ÑÐ¹ ÑÐ¾ÑÐ¼Ð°Ñ Email'];
		if(splitted[1] != null){
      		var regexp_user=/^\"?[\w-_\.]*\"?$/;
      		if(splitted[1].match(regexp_user) == null)
      			return ['wrong','ÐÐµÐ²ÐµÑÐ½ÑÐ¹ ÑÐ¾ÑÐ¼Ð°Ñ Email'];
    	}
    	if(splitted[2] != null){
      		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,5}$/;
      		if(splitted[2].match(regexp_domain) == null){
	    		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    		if(splitted[2].match(regexp_ip) == null)
	    			return ['wrong','ÐÐµÐ²ÐµÑÐ½ÑÐ¹ ÑÐ¾ÑÐ¼Ð°Ñ Email'];
      		}
		}
		return false;
    },
    emailConfirm : function(id,id_first){
		this.id = id;
		var _email = $(id_first).value;
		var _emailConf = $(id).value;
		if(_emailConf !== _email){
			if(_emailConf.length >= _email.length){
	  			return ['complete_difference','ÐÐ²ÐµÐ´ÐµÐ½Ð½ÑÐµ email-Ñ Ð¾ÑÐ»Ð¸ÑÐ°ÑÑÑÑ'];
	  		}
	  		else{
	  			return ['difference','ÐÐ²ÐµÐ´ÐµÐ½Ð½ÑÐµ email-Ñ Ð¾ÑÐ»Ð¸ÑÐ°ÑÑÑÑ'];
	  		}
	  	}
    	return false;	
    },
    password : function(id){
		this.id = id;
		var _password = $(id).value;
		if(_password.length <= 0)
	  		return ['empty','ÐÐµ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¾ Ð¿Ð¾Ð»Ðµ ÐÐ°ÑÐ¾Ð»Ñ'];
		var illegalChars = /[\W_]/; // allow only letters and numbers
    	if (illegalChars.test(_password))
      		return ['illegal_chars','ÐÐµÐ´Ð¾Ð¿ÑÑÑÐ¸Ð¼ÑÐµ ÑÐ¸Ð¼Ð²Ð¾Ð»Ñ'];
    	else if(_password.length > 15)
    		return ['long','ÐÐ»Ð¸Ð½Ð° Ð½Ðµ Ð±Ð¾Ð»ÐµÐµ 15 ÑÐ¸Ð¼Ð²Ð¾Ð»Ð¾Ð²'];
    	else if(_password.length < 5)
      		return ['short','ÐÐ»Ð¸Ð½Ð° Ð½Ðµ Ð¼ÐµÐ½ÐµÐµ 5 ÑÐ¸Ð¼Ð²Ð¾Ð»Ð¾Ð²'];
    	return false;	
    },
    passwordConfirm : function(id,id_first){
		this.id = id;
		var _password = $(id_first).value;
		var _passwordConf = $(id).value;
		if(_passwordConf !== _password){
			if(_passwordConf.length >= _password.length){
	  			return ['complete_difference','ÐÐ²ÐµÐ´ÐµÐ½Ð½ÑÐµ Ð¿Ð°ÑÐ¾Ð»Ð¸ Ð¾ÑÐ»Ð¸ÑÐ°ÑÑÑÑ'];
	  		}
	  		else{
	  			return ['difference','ÐÐ²ÐµÐ´ÐµÐ½Ð½ÑÐµ Ð¿Ð°ÑÐ¾Ð»Ð¸ Ð¾ÑÐ»Ð¸ÑÐ°ÑÑÑÑ'];
	  		}
	  	}
    	return false;	
    },
    login : function(id){
		this.id = id;
		var _login = $(id).value;
		if(_login.length <= 0)
	  		return ['empty','ÐÐµ Ð·Ð°Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¾ Ð¿Ð¾Ð»Ðµ ÐÐ¾Ð³Ð¸Ð½'];
		var illegalChars = /[\W_]/; // allow only letters and numbers
    	if (illegalChars.test(_login))
      		return ['illegal_chars','! ÐÐ¾Ð¿ÑÑÐºÐ°ÑÑÑÑ Ð»Ð°ÑÐ¸Ð½ÑÐºÐ¸Ðµ Ð±ÑÐºÐ²Ñ Ð¸ ÑÐ¸ÑÑÑ'];
    	else if(_login.length > 15)
    		return ['long','! ÐÐ»Ð¸Ð½Ð° Ð½Ðµ Ð±Ð¾Ð»ÐµÐµ 15 ÑÐ¸Ð¼Ð²Ð¾Ð»Ð¾Ð²'];
    	else if(_login.length < 5)
      		return ['short','! ÐÐ»Ð¸Ð½Ð° Ð½Ðµ Ð¼ÐµÐ½ÐµÐµ 5 ÑÐ¸Ð¼Ð²Ð¾Ð»Ð¾Ð²'];
    	return false;	
    },
    nameRu : function(id){
		this.id = id;
		var _text = $(id).value;
		var illegalChars = /[^Ð-Ð¯Ð°-Ñ-]/; // allow only letters and numbers
    	if (illegalChars.test(_text))
      		return ['illegal_chars','! ÐÐ¾Ð¿ÑÑÐºÐ°ÑÑÑÑ Ð±ÑÐºÐ²Ñ Ð¸ ÑÐ¸ÑÑÑ'];
    	return false;	
    },
    latinAndNumber : function(id){
		this.id = id;
		var _text = $(id).value;
		var illegalChars = /[^A-Za-z0-9-_]/; // allow only letters and numbers
    	if (illegalChars.test(_text))
      		return ['illegal_chars','! ÐÐ¾Ð¿ÑÑÐºÐ°ÑÑÑÑ Ð±ÑÐºÐ²Ñ Ð¸ ÑÐ¸ÑÑÑ'];
    	return false;	
    },
    testKeyNameRu : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[Ð-Ð¯Ð°-Ñ-]/.test(key);
	},
	testKeyLatinAndNumber : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /[A-Za-z0-9-_]/.test(key);
	},
	testKeyNumOnly : function(e){
		// Make sure to use event.charCode if available
		var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

		// Ignore special keys
  		if (e.ctrlKey || e.altKey || key < 32)
    	return true;

		key = String.fromCharCode(key);
		return /\d/.test(key);
	}
}

var AJpopup = {
	interval : '200',
	scrollTop: null, // scrolloing position
	width: null, //inner win width
	height: null, // inner win height
	init : function(width,height,bodyWidth){
		this.active = true;
		this.height = height;
		this.width = width;
		// create structure
		include.div('popup_ext','popup_ext','');
		include.div('popup_inner','popup_inner','');
		var cont =	'<div id="popup_content" class="popup_content">\n';
		cont +=	'<img src="/abs-lib/lib/absJsLib/images/loading.gif" border="0">\n';
		cont +=	'</div>\n';
		this.getWindowSize();
		if(bodyWidth) 
			this.winWidth = bodyWidth;
		this.innerLeft = (this.winWidth - this.width )/2;
		this.innerTop = (this.winHeight - this.height)/2;  
		//alert(this.innerTop);
		this.listener();
		$('popup_inner').setStyle({width: this.width + 'px', height: this.height + 'px'});
		$('popup_inner').update(cont);
		this.adListener();
		
	},
	getScrollTop : function(){
        var t;
        if (document.documentElement && document.documentElement.scrollTop)
                t = document.documentElement.scrollTop;
        else if (document.body)
                t = document.body.scrollTop;
        return t;
 	},
 	adListener : function(){
 		 //if(this.active){
 		 	//alert('adListener');
 		 	this.listener();
 		 	//this.tl = setTimeout(function(){AJpopup.listener()}, this.interval);
 		// }
 	},
 	listener : function(){
 		if(this.active){
	 		var _scroll = this.getScrollTop();
	 		if(_scroll !== this.scrollTop){
	 			this.innerTop = (this.innerTop - this.scrollTop)+_scroll; 
	 			this.scrollTop = _scroll;
	 			this.popupWinPos();
	 			this.innerWinPos();
	 		}
	 		//this.adListener();
	 		this.tl = setTimeout(function(){AJpopup.listener()}, this.interval);
 		}
 	},
 	innerWinPos : function(){
 		//alert(this.innerTop);
 		$('popup_inner').setStyle({left: this.innerLeft+'px', top: this.innerTop+'px' });
 	},
 	popupWinPos : function(){
 		$('popup_ext').setStyle({ top: this.scrollTop });
 	},
 	getWindowSize: function(doc) {
        doc = doc || document;
        var win_w, win_h;
        if (self.innerHeight) {
            win_w = self.innerWidth;
            win_h = self.innerHeight;
        } else if (doc.documentElement && doc.documentElement.clientHeight) {
            win_w = doc.documentElement.clientWidth;
            win_h = doc.documentElement.clientHeight;
        } else if (doc.body) {
            win_w = doc.body.clientWidth;
            win_h = doc.body.clientHeight;
        }
        this.winWidth = win_w;
        this.winHeight = win_h;
    },
    close : function(){
 		$('popup_ext').remove();
 		$('popup_inner').remove();
		this.active = false;
		clearTimeout(this.tl);
		this.innerTop = null;
		this.scrollTop = null;
 	}
}


var JsPopupWin = {
	interval : '200',
	scrollTop: null, // scrolloing position
	width: null, //inner win width
	height: null, // inner win height
	init : function(width,height,bgColor,winColor,borderColor,alfa,inner,content,bodyWidth,listenerDisable){
		this.active = true;
		this.height = height;
		this.width = width;
		// create structure
		include.div('popup_ext','popup_ext','');
		$('popup_ext').setStyle({
			position:'absolute',
			width:'100%',
			height:'100%',
			zIndex:'10020',
			top:'0',
			left:'0',
			backgroundColor:bgColor,
			opacity:alfa
		});

		//$('popup_ext').setStyle({backgroundColor:bgColor,opacity:alfa,filter: alpha(opacity=(alfa*100))});
		include.div('popup_inner','popup_inner','');
		$('popup_inner').setStyle({
			position:'absolute',
			zIndex:'10025',
			overflow:'visible',
			backgroundColor:winColor,
			border:'1px solid '+ borderColor
		});
		
		var cont =	'<div id="popup_content" class="popup_content">\n';
		cont +=	'<img src="/abs-lib/lib/absJsLib/images/loading.gif" border="0">\n';
		cont +=	'</div>\n';
		this.getWindowSize();
		if(bodyWidth) 
			this.winWidth = bodyWidth;
		this.innerLeft = (this.winWidth - this.width )/2;
		this.innerTop = (this.winHeight - this.height)/2;  
		//alert(this.innerTop);
		if(!listenerDisable){
			this.listener();
		}
		else{
			this.defaultPosition();
		}	
		$('popup_inner').setStyle({width: this.width + 'px', height: this.height + 'px'});
		$('popup_inner').update(cont);
		if(inner)
			$('popup_inner').update($(inner).innerHTML);
		if(content)
			$('popup_inner').update(content);
		if(!listenerDisable){
			//this.adListener();
		}	
		
	},
	defaultPosition : function(){
		var _scroll = this.getScrollTop();
	 		if(_scroll !== this.scrollTop){
	 			this.innerTop = (this.innerTop - this.scrollTop)+_scroll; 
	 			this.scrollTop = _scroll;
	 			this.popupWinPos();
	 			this.innerWinPos();
	 		}
	},
	changeHeight : function(newHeight){
		if(newHeight)
			$('popup_inner').setStyle({height: newHeight + 'px'});
	},
	getScrollTop : function(documentElement){
        var t;
        if (document.documentElement && document.documentElement.scrollTop)
                t = document.documentElement.scrollTop;
        else if (document.body)
                t = document.body.scrollTop;
        return t;
 	},
 	adListener : function(){
 		 //if(this.active){
 		 	//alert('adListener');
 		 	this.listener();
 		 	//this.tl = setTimeout(function(){AJpopup.listener()}, this.interval);
 		// }
 	},
 	listener : function(){
 		if(this.active){
	 		var _scroll = this.getScrollTop();
	 		if(_scroll !== this.scrollTop){
	 			this.innerTop = (this.innerTop - this.scrollTop)+_scroll; 
	 			this.scrollTop = _scroll;
	 			this.popupWinPos();
	 			this.innerWinPos();
	 		}
	 		//this.adListener();
	 		this.tl = setTimeout(function(){JsPopupWin.listener()}, this.interval);
 		}
 	},
 	innerWinPos : function(){
 		//alert(this.innerTop);
 		$('popup_inner').setStyle({left: this.innerLeft+'px', top: this.innerTop+'px' });
 	},
 	popupWinPos : function(){
 		$('popup_ext').setStyle({ top: this.scrollTop });
 	},
 	getWindowSize: function(doc) {
        doc = doc || document;
        var win_w, win_h;
        if (self.innerHeight) {
            win_w = self.innerWidth;
            win_h = self.innerHeight;
        } else if (doc.documentElement && doc.documentElement.clientHeight) {
            win_w = doc.documentElement.clientWidth;
            win_h = doc.documentElement.clientHeight;
        } else if (doc.body) {
            win_w = doc.body.clientWidth;
            win_h = doc.body.clientHeight;
        }
        this.winWidth = win_w;
        this.winHeight = win_h;
    },
    close : function(){
 		$('popup_ext').remove();
 		$('popup_inner').remove();
		this.active = false;
		clearTimeout(this.tl);
		this.innerTop = null;
		this.scrollTop = null;
 	}
}

var windowSize = {
	getWindowSize: function(doc) {
    	//alert('getWindowSize');
    	doc = doc || document;
    	var win_w, win_h;
    	if (self.innerHeight) {
    		win_w = self.innerWidth;
            win_h = self.innerHeight;
        } 
        else if (doc.documentElement && doc.documentElement.clientHeight) {
            win_w = doc.documentElement.clientWidth;
            win_h = doc.documentElement.clientHeight;
        }
        else if (doc.body) {
            win_w = doc.body.clientWidth;
            win_h = doc.body.clientHeight;
        }
       // alert('win_w = '+win_w);
        this.winWidth = win_w;
        this.winHeight = win_h;
    },
    _width: function(){
    	//alert('_width');
    	this.getWindowSize();
    	//alert('return winWidth = '+this.winWidth);
    	return this.winWidth;
    },
    _height: function(){
    	this.getWindowSize();
    	return this.winHeight;
    }
}

var keyCatcher = {
	capsLock : {
		on : false,
		_catch : function(id,act){
			//if (!e) e = window.event || null;
			if(!id) obj = document;
			else obj = $(id);
			this.act = act;
			//act();
			if (obj.addEventListener){
				obj.addEventListener("keypress", this.detect, false);
				obj.addEventListener("keydown", this.detect, false);
				
			}
			else if (document.attachEvent){
				obj.attachEvent("onkeypress", this.detect);
				obj.attachEvent("onkeydown", this.detect);
			}
		},
		detect : function(e){
			var n = e.keyCode?e.keyCode:e.charCode;
			if (e.type=="keypress"){
				var c = String.fromCharCode(n);
				var cUC = c.toUpperCase();
				var cLC = c.toLowerCase();
				if (cUC!=cLC) 
					keyCatcher.capsLock.action((e.shiftKey && cLC==c)||(!e.shiftKey && cUC==c));
 			}
 			else if (e.type=="keydown" && n==20) 
 				keyCatcher.capsLock.action(false);
		},
		action : function(pressed){ 
			this.act(pressed);
		}
	}
}

var eventHandler = {
	add : function(object, event, handler){
  		if (typeof object.addEventListener != 'undefined')
    		object.addEventListener(event, handler, false);
		else if (typeof object.attachEvent != 'undefined')
    		object.attachEvent('on' + event, handler);
  		else
    		throw "Incompatible browser";
	},
	remove : function(object, event, handler){
		if (typeof object.removeEventListener != 'undefined')
			object.removeEventListener(event, handler, false);
		else if (typeof object.detachEvent != 'undefined')
			object.detachEvent('on' + event, handler);
		else
			throw "Incompatible browser";
	}
}

/* ================== INPUT SELECT HANDLER ========================= */
var selectHandler = {
    selectObj : null,
    init : function(id){
    	this.selectObj = $(id).getElementsByTagName('option');
    },
    getSelectedValue : function(id){
     	this.init(id);
     	for(var i = 0; i < this.selectObj.length; i++){ 
			if(this.selectObj[i].selected == true){
				return this.selectObj[i].value;
				break;
			}
 		}
	},
	setSelected : function(id,value){
		this.init(id);
		for(var i = 0; i < this.selectObj.length; i++){ 
			if(this.selectObj[i].value == value){
				this.selectObj[i].selected = true;
				break;
			}
 		}
	}
}
/* ==== END ========= INPUT SELECT HANDLER ========================= */

/* ================== INPUT RADIO HANDLER ========================== */
var radioHandler = {
    radioObj : null,
    init : function(id){
    	this.radioObj = $(id).getElementsByTagName('input');
    },
    getCheckedValue : function(id){
     	this.init(id);
     	for(var i = 0; i < this.radioObj.length; i++){ 
			if(this.radioObj[i].checked == true){
				return this.radioObj[i].value;
				break;
			}
 		}
 		return false;
	},
	check : function(id,value){
		this.init(id);
		for(var i = 0; i < this.radioObj.length; i++){ 
			if(this.radioObj[i].value == trim(value)){
				this.radioObj[i].checked = true;
				break;
			}
 		}
	}
}
/* ==== END ========= INPUT RADIO HANDLER ========================== */

/* ================== INPUT CHECBOXES HANDLER ========================= */
var checkboxHandler = {
    checkboxObj : null,
    init : function(id){
    	this.checkboxObj = $(id).getElementsByTagName('input');
    },
    checkAll : function(id){
    	this.init(id);
    	//alert(this.checkboxObj.length);
    	for(var i = 0; i < this.checkboxObj.length; i++){
    		this.checkboxObj[i].checked = true;
    	} 
    },
    uncheckAll : function(id){
    	this.init(id);
    	for(var i = 0; i < this.checkboxObj.length; i++)
    		this.checkboxObj[i].checked = false;
    },
    disableAll : function(id){
    	this.init(id);
    	for(var i = 0; i < this.checkboxObj.length; i++)
    		this.checkboxObj[i].disabled = true;
    },
    enableAll : function(id){
    	this.init(id);
    	for(var i = 0; i < this.checkboxObj.length; i++)
    		this.checkboxObj[i].disabled = false;
    },
	getSelectedString : function(id){
     	this.init(id);
     	var arr = new Array();
     	for(var i = 0; i < this.checkboxObj.length; i++){ 
			if(this.checkboxObj[i].checked == true)
				arr.push(this.checkboxObj[i].value);
 		}
 		if(arr)
 			return arr.join(',');
 		return false;
	},
	setSelectedString : function(id,str){
     	this.init(id);
     	this.uncheckAll(id);
     	//var arr = new Array();
     	var strArr = str.split(',');
     	for(var i = 0; i < this.checkboxObj.length; i++){ 
			//alert('Ð°Ð½Ð°Ð»Ð¸Ð· ÑÐµÐºÐ±Ð¾ÐºÑÐ°: ' + this.checkboxObj[i].value);
			for(var j = 0; j < strArr.length; j++){
				//alert('Ð°Ð½Ð°Ð»Ð¸Ð· ÑÐµÐºÐ±Ð¾ÐºÑÐ°: ' + this.checkboxObj[i].value + ' Ð°Ð½Ð°Ð»Ð¸Ð· ÑÑÑÐ¾ÐºÐ¸: '+strArr[j]);
				if(this.checkboxObj[i].value == strArr[j]){ 
					this.checkboxObj[i].checked = true;
				}
			}
 		}
	}
}
/* ==== END ========= INPUT CHECBOXES HANDLER ========================= */

// ================================================================================
// ======================== COOKIE handler functions ==============================
// === 1. function Get_Cookie - return Cookie by name =============================
// === 2. function Set_Cookie - set cookie ========================================
// ================================================================================

function Get_Cookie(name){ 
 	var start = document.cookie.indexOf(name+"="); 
 	var len = start+name.length+1; 
 	if ((!start) && (name != document.cookie.substring(0,name.length))) 
	return null; 
	if (start == -1) 
		return null; 
	var end = document.cookie.indexOf(";",len); 
	if (end == -1) 
		end = document.cookie.length; 
	return unescape(document.cookie.substring(len,end)); 
} 

// This function has been slightly modified
function Set_Cookie(name,value,expires,path,domain,secure) { 
	expires = expires * 60*60*24*1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
	var cookieString = name + "=" +escape(value) + 
		( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
		( (path) ? ";path=" + path : "") + 
		( (domain) ? ";domain=" + domain : "") + 
		( (secure) ? ";secure" : ""); 
	document.cookie = cookieString; 
} 
// ================================================================================
// ====================== END COOKIE handler functions ============================
// == ########################################################################## ==

function getDaysInMonth(month,year){
	if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
		var dayMax = 31;
	else
		var dayMax = 30;
	
	if(month==2){
		var yD = year/4;
		var yR = Math.round(yD);
		if(yD == yR)
			var dayMax = 29;
		else
			var dayMax = 28;
	}
	return dayMax;
} 

/********** mouse position *************




var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0

function getMouseXY(e) {
	if (IE) { 
    	tempX = event.clientX + document.body.scrollLeft
    	tempY = event.clientY + getScrollTop();
	} 
	else {  
    	tempX = e.pageX
    	tempY = e.pageY
  	}  
  	if (tempX < 0){tempX = 0}
  	if (tempY < 0){tempY = 0}  
  	return true
}
** end *** mouse position *************/


function getScrollTop() {
	var t;
	if (document.documentElement && document.documentElement.scrollTop)
    	t = document.documentElement.scrollTop;
	else if (document.body)
		t = document.body.scrollTop;
	else
		t = 0;
	return t;
}
 
function getClientHeight(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function toggle(obj) {
        var el = document.getElementById(obj);
        if ( el.style.display != 'none' ) {
            el.style.display = 'none';
        }
        else {
                el.style.display = '';
        }
}

function formDisabled(id){
	$(id).disabled = !($(id).disabled);
}

function CheckTextStringNonLegalChars(str){ 
 	var nonLegal = ['<','>','?','!',';','%','(',')','|'];
 	var oldStr = str;
 	for(var i = 0; i < nonLegal.length; i++){ 
 		str = str.replace(nonLegal[i],'');
 	}
 	if(oldStr == str){
 		return false;
 	}
 	else{
 		return str + ' ';
 	}
}

function checkOnlyLatin(str){
	var pattern =  /^[\-_A-Za-z0-9]{1,40}$/;
    var result=pattern.test(str);
 	if(result == false)
 		return false;
 	else
 		return true;

 }
 
 
var BrowserDetect = {
	getVersion: function () {
		this.init();
		return this.browser;
	},
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

}; 

function SendMail2Friend(subject,body){
	location.href="mailto:?subject="+subject+"&body="+body;
};
