/*var RequireScriptsIncluder = {
  require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
	document.write('<script type="text/javascript" src="'+libraryName+'"></script>'); 
  },
  load: function() {
		if (dhtml.Opera){
			RequireScriptsIncluder.require(JsPath+'new/cms_xmlhttprequest.js');
			RequireScriptsIncluder.require(JsPath+'opera/adv_opera.js');
		} else {
			RequireScriptsIncluder.require(JsPath+'prototype/base.js');
			RequireScriptsIncluder.require(JsPath+'prototype/string.js');
			RequireScriptsIncluder.require(JsPath+'prototype/ajax.js');
		}
  }
}*/

function dhtml(){
	//Browser Information
	
	this.User_agent = navigator.userAgent.toLowerCase();
	this.version    = this.User_agent;
	this.Opera    	= ( window.opera );
	this.IE       	= ( ( this.User_agent.indexOf("msie") != -1 ) && ( !this.Opera ) );
	this.MAC      	= ( this.User_agent.indexOf("mac") != -1 );
	this.Gecko    	= ( navigator.product == "Gecko" );
	this.Mozilla  	= this.Gecko;
	this.bw			= ( this.IE || this.Opera || this.MAC || this.Gecko || this.Mozilla);
	
	if (this.IE){
		//mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; .net clr 1.1.4322)
		pos = this.User_agent.indexOf('msie')+5;
		this.version = this.User_agent.substring(pos,pos+3)
	} else if (this.Opera) {
		//mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; en) opera 8.0
		pos = this.User_agent.indexOf('opera')+6;
		this.version = this.User_agent.substring(pos,pos+3)
	} else if (this.Gecko) {
		//mozilla/5.0 (windows; u; windows nt 5.1; ru-ru; rv:1.7.12) gecko/20050919 firefox/1.0.7
		pos = this.User_agent.indexOf('gecko')+6;
		this.version = this.User_agent.substring(pos,pos+8)
	} else if (this.MAC) {
		pos = this.User_agent.indexOf('safari')+7;
		this.version = this.User_agent.substring(pos,pos+3)
	}

	//Get object by Id (crossbrowsers)
	this.getById = function(id){
		return (document.getElementById) ? document.getElementById(id) : ((document.all) ? document.all[id] : eval('document.'+id));
	}
	
	//Get objects by ClassName
	this.getElementsByClassName = function(className, parentElement) {
		var children = (parentElement || document.body).getElementsByTagName('*');
		var elements = new Array();
		for (var i = 0; i < children.length; i++) {
			var child = children[i];
			
			if (this.match_class(child, className)){
				elements.push(child);
			}
		}
		return elements;
	} 
	
	//Image Preloader
	this.preloadImages = function(){
		var d = document;
		if(d.images){
			if(!d.pics)
				d.pics = new Array();
			var i,j = d.pics.length, a = this.preloadImages.arguments;
			for(i = 0; i < a.length; i++)
				if (a[i].indexOf("#")!=0){ 
					d.pics[j]=new Image; d.pics[j++].src=a[i]
				}
		} 
	} 
	
	//Show Object
	this.showElem = function(id) {
		if (elem = this.getById(id)) {
			elem.style.visibility = 'visible';
			elem.style.display = 'block';
		}
	}
	//Hide Object
	this.hideElem = function(id) {
		if (elem = this.getById(id)) {
			elem.style.visibility = 'hidden';
			elem.style.display = 'none';
		}
	} 
// ==============================
//     Class functions
// ==============================
	// Check is class exist!
	this.match_class = function (obj, Class_name) {
		return ( Class_name && obj.className && obj.className.length && obj.className.match( new RegExp("(^|\\s+)(" + Class_name +")($|\\s+)") ) );
	}

	// Adding new class into object
	// Can replace old class if Instead is set
	// Instead = className which need to repalce
	this.set_class = function ( obj, Class_name, Instead ){
		if( obj ){
			Class_name = ( Class_name.length ) ? Class_name.replace( /(^\s+|\s+$)/, "" ) : "";
			if( obj.className.length ){
				var Old = Class_name;
				if( Instead && Instead.length ){
					Instead = Instead.replace( /\s+(\S)/g, "|$1" );
					if( Old ){
						Old += "|";
					}
					Old += Instead;
				}
				//obj.className = obj.className.replace( new RegExp("(^|\\s+)(" + Old +")($|\\s+)", "g"), "$1" );
				obj.className = obj.className.replace( new RegExp("(" + Old +")", "g"), "" ).trim();
			}
			obj.className += ( obj.className.length && Class_name ? " " : "" ) + Class_name;
		}
	}
	
	// Replace class with "";
	this.remove_class = function( obj, Class_name ){
		this.set_class( obj, "", Class_name );
	}
	
	return this;
}

// ==========================================
// Init
// ==========================================
var dhtml = new dhtml(); 
var use_enhanced_js;

// -----------------------------------------
// Can we use fancy JS? IE6, Safari, Moz
// and opera 7.6 
// -----------------------------------------
if (( dhtml.IE      && dhtml.version >= 6.0 ) ||
	( dhtml.Gecko   && dhtml.version >= 20030312 ) ||
	( dhtml.Opera   && dhtml.version >= 7.6 ) ||
	( dhtml.MAC     && dhtml.version >= 120 ))
{
	use_enhanced_js = 1;
} else {
	use_enhanced_js = 0;
}

//RequireScriptsIncluder.load();

// ======================================================================= //
//							Utilities									   //
// ======================================================================= //
var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

Array.prototype.in_array = function (item) {
	var array_item;
	if (typeof item == 'string'){
		item = item.toUpperCase();
	} else {
		return false;
	}
	for(element in this) {
		if (typeof this[element] == 'string'){
			if (item == this[element].toUpperCase()) { 
				return true; 
			} 
		}
   } 
   return false; 
} 

/*
 * Utility. Removes leading and trailing white space
 * from a string
 */
String.prototype.trim =
function() {
  return this.replace( /^[\s\n\r\t]+|[\s\n\r\t]+$/g, "" );
}

/*
 * Utility. Translates a string into a regex. Replaces identifiers
 * (beginning with "$") with corresponding regex fragment
 */
String.prototype.resolve =
function() {
  var resolved = this;
  var regex = /(\$[a-zA-Z0-9]+)/;
  
  while ( regex.test( resolved ) ) {
    resolved = resolved.replace( RegExp.$1, String[ RegExp.$1 ] );
  }
  
  return resolved.replace( / /g,"" );
}
//Remove quotes
String.prototype.removeQuotes =
function() {
  return this.replace( /^['"]|['"]$/g, "" );
}

/*
 * Utility. Like pop(), but does not affect the length
 * of the array
 */
Array.prototype.lastItem =
function() {
  return this[ this.length - 1 ];
}

function addEventToObject(obj, evt, func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}
 

/****************************************************/

function makePopUp(urlValue,widthValue,heightValue, windowId, universal) {
    var leftPos = (screen.availWidth-900) / 2;
    var topPos = (screen.availHeight-600) / 2;
    NewWidthValue=widthValue+20;
    NewHeightValue=heightValue+20;
    windowId=(windowId)?windowId:"PopUpWindow";
    universal=(universal)?universal:"no";
    return window.open(urlValue, windowId,'width='+NewWidthValue+',height='+NewHeightValue+',menubar=0,scrollbars='+universal+',resizable='+universal+',statusbar=no,location=no,titlebar=0,toolbar=0,status=0,top=' + topPos + ',left=' + leftPos);

}

function AddBookmark(){
  if (document.all)
    window.external.AddFavorite(document.location.href,document.title)
}

function GoURL(s){
  document.location = s;
}

function RePopUp(oLink) {
	if (oLink.target == 'PopUp') {
		if (oLink.href.match(/(jpg)|(png)|(gif)$/i)) {
			win = makePopUp(oLink.href,400,330);
			win.document.open("text/html");
			win.document.write('<html><head><title>'+txt_rePopUpTitle+'</title></head><script language="JavaScript" type="text/javascript">function GetLayer(name) {return ((eval(document.all))?(document.all[name]):(document.getElementById(name)))} function doR () { window.resizeTo(GetLayer(\'pimg\').width+13,GetLayer(\'pimg\').height+37)}</script><body onload="doR();" bgcolor="#ffffff" style="margin:0px;text-align:center;"><a href="#" onclick="window.close()"><img src="'+oLink.href+'" name="pimg" id="pimg" alt="" border="0"/></a></body></html>');
			win.document.close();
		} else {
			makePopUp(oLink.href,400,330);
		}	
		return false;
	}
	return true;
} 

function decorlnav(obj){
	A = obj.parentNode.parentNode.cells[1].childNodes[0];
	if (A.type!="active"){
		if (A.className == "active") 
			A.className = "";
		else 
			A.className = "active";
	}
}

function decorbuttons(obj, type){
	type = (type) ? (type) : (".png");
	if (type.indexOf(".png")!=-1){
		if (dhtml.IE){
			//Explorer
			img = obj.style.filter.replace('progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'', ''); 
			img = img.replace('\', sizingMethod=\'crop\')', '');
			img = (img.indexOf("-over"+type)!=-1)?img.replace('-over'+type, type):img.replace(type, '-over'+type);
			obj.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img + '\', sizingMethod=\'crop\')'
		} else {
			//other PNG compatibility browsers
			img = obj.style.backgroundImage;
			img = (img.indexOf("-over"+type)!=-1)?img.replace('-over'+type, type):img.replace(type, '-over'+type);
			obj.style.backgroundImage = img;
		}
	} else {
		source = obj.src;
		source = (source.indexOf("-over"+type)!=-1)?source.replace('-over'+type, type):source.replace(type, '-over'+type);
		obj.src = source;
	}
	return false;
}

function checkSearchForm(keyw,malert,formobj) {
	if (keyw=='') {
		alert(malert);
		return false;
	}else{
		formobj.submit();
		return true;
	}
}

function _checkNumberValue(obj){
	if (isNaN(obj.value)){
		obj.value = (obj.defaultValue)?(obj.defaultValue):('')
	} else {
		obj.defaultValue = obj.value
	}
}

function selectAll(multiselect, check_button){
	for (var i = 0; i < multiselect.options.length; i++)
		multiselect.options[i].selected = check_button.checked;
}

function synchronizeCheck(multiselect, check_button){
	var allChecked = true;
	for (var i = 0; i < multiselect.options.length; i++) {
		if (!multiselect.options[i].selected){
			allChecked = false;
			break;
		}
	}
	check_button.checked = allChecked;
}

function _disableFields(){
	var fields = arguments;
	for (var i=0; i < fields.length; i++){
		dhtml.getById(fields[i]).disabled = true;
	}
}
function _undisableFields(){
	var fields = arguments;
	for (var i=0; i < fields.length; i++){
		dhtml.getById(fields[i]).disabled = false;
	}
}

