var __PageURL='';
BrowserProperties = function() {
    this.Name = navigator.appName;
    this.Explorer = null;
    this.Description = navigator.appVersion;
    this.UserAgent = navigator.userAgent;
    this.Width = 0;
    this.Height = 0;
    this.isIE = (/msie/.test(this.UserAgent.toLowerCase())) && !(/opera/.test(this.UserAgent.toLowerCase())) && (/win/.test(this.UserAgent.toLowerCase()));
    switch (this.Name) {
        case "Microsoft Internet Explorer":
            this.Type = 0;
            if (this.Description.indexOf("MSIE 7") >= 0)
                this.Explorer = BrowserProperties.Explorer.IE7;
            else if (this.Description.indexOf("MSIE 6") >= 0)
                this.Explorer = BrowserProperties.Explorer.IE6;
            break;
        case "Netscape":
            this.Type = 1;
			if(/safari/.test(this.UserAgent.toLowerCase()))
				this.Explorer = BrowserProperties.Explorer.Safari;
			else if(/chrome/.test(this.UserAgent.toLowerCase()))	
				this.Explorer = BrowserProperties.Explorer.Chorme;
			else if(/firefox/.test(this.UserAgent.toLowerCase()))
				this.Explorer = BrowserProperties.Explorer.Firefox;
            break;
        case "Opera":
            this.Type = 2;
            break;
        default:
            this.Type = -1
            break;
    }


    this.TestWindow = function() {
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE			
            this.Width = window.innerWidth;
            this.Height = window.innerHeight;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'			
            this.Width = document.documentElement.clientWidth;
            this.Height = document.documentElement.clientHeight;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible			
            this.Width = document.body.clientWidth;
            this.Height = document.body.clientHeight;
        }

    }

    this.TestWindow();

    this.CopyToClipboard = function(__Data) {
		if(this.Type==0){
			var __ControlRange;
			switch(typeof(__Data)){
				case 'object':
					if (document.body.createControlRange) {
						__Data.contentEditable = true;
						__ControlRange = document.body.createControlRange();
						__ControlRange.addElement(__Data);
						__ControlRange.execCommand('Copy');
						__Data.contentEditable = false;
					}				
				break;
				case 'string':
					if(window.clipboardData){ 
						clipboardData.setData('Text',__Data); 
					}				
				break;
			}
		}
    }

}

BrowserProperties.Explorer = {
		IE6 : '00.10',
		IE7 : '00.11',
		Firefox : '01.10',
		Safari : '01.11',
		Chrome : '01.12'
	}

var UsedBrowser=new BrowserProperties();

function $(__Id) {
    var __Element = document.getElementById(__Id);
    if (__Element == null) {
        var __Test = document.getElementsByName(__Id);        
        __Element = __Test[0];
    }
    return __Element;
}

function setClassName(__Element,__ClassName){
	__Element.setAttribute('class',__ClassName);
	__Element.setAttribute('className',__ClassName);
}


function Replacer(__Input,__OldChar,__NewChar){
	var __Output='';
	for(var __i=0;__i<__Input.length;__i++){
		if(__Input.charAt(__i)==__OldChar)
			__Output += __NewChar;
		else
			__Output += __Input.charAt(__i);
		}
	return __Output;
	}
	
function NumberControl(__Input,__DotFree,__Minus){
	if(__DotFree==null)__DotFree=false;
	if(__Minus==null)(__Minus=false);
	var __Output='';
	var __DotCount=0;
	var __ValidChars='1234567890';
	var __StartIndex=0;
	if(__Input.charAt(0)=='-' && __Minus){
		__Output += '-';
		__StartIndex=1;
		}
	for(var __i=__StartIndex;__i<__Input.length;__i++){
		if(__ValidChars.indexOf(__Input.charAt(__i))!=-1){
			__Output += __Input.charAt(__i);								   
			}
		else if(__DotFree && __DotCount==0){
		    //if(__Input.charAt(__i)=="."){
		        __Output += __Input.charAt(__i);
		        __DotCount++;
		       // }
		    }
		}
	if(__Output=='-')__Output=0;
	if(__Output=='')__Output=0;
	return __Output;
	}

function appendStyle(__Element,Styles){
	if(Styles!=null){
		for(__Key in Styles)
			__Element.style[__Key]=Styles[__Key];
		}
	}
	
function RemoveAllChilds(__Element){
	if(__Element!=null && __Element.childNodes.length>0){
		var __NodesCount=__Element.childNodes.length;
		var __Child;
		for(var __i=0;__i<__NodesCount;__i++){
			__Child = __Element.childNodes[0];
			RemoveAllChilds(__Child);
			__Element.removeChild(__Child);
			}
		}
	}

function appendAttribute(__Element,__Attributes){
    for(var __Key in __Attributes)
        __Element.setAttribute(__Key,__Attributes[__Key]);
}

function _CreateElementID(TagName){
	var __Date=new Date();
	var __Id='_System'+(TagName!=null?TagName:'Default')+'_'+__Date.valueOf();
	return __Id;
	}
	
function _CreateElement(Properties){
    if(Properties==null)return null;
    if(Properties.TagName==null)return null;
	var __Date=new Date();
	var __Id='_System'+Properties.TagName+'_'+__Date.valueOf();
	var __Element=document.createElement(Properties.TagName);
	__Element.setAttribute("id",(Properties.Name==null?__Id:Properties.Name));
	if(Properties.StyleName!=null)
		appendStyle(__Element,Properties.StyleName);
	if(Properties.Attributes!=null)
	    appendAttribute(__Element,Properties.Attributes);		
	return __Element;
}

//Prototype Functions::Begin

//Object.prototype.isArray=function(){return (this instanceof Array);}	
//Object.prototype.GetType=function(){return typeof(this);}

String.prototype.LTrim=function(){
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}

String.prototype.RTrim=function(){
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}	

String.prototype.Trim=function(){
    return this.LTrim().RTrim();
}

String.prototype.CharReplace = function(__OldChar, __NewChar) {
    var __Output = '';
    for (var __i = 0; __i < this.length; __i++) {
        if (this.charAt(__i) == __OldChar)
            __Output += __NewChar;
        else
            __Output += this.charAt(__i);
    }
    return __Output;
}

Array.prototype.MySearch = function(__Value) {
    for (var _i = 0; _i < this.length; _i++) {
        if (this[_i] == __Value) { return _i; }
    }
    return -1;
}
Array.prototype.Count=function(){return this.length;}
//Prototype Functions::End

//CreateCss::Begin
function createCSS(__className, __Value) {

    var isIE = UsedBrowser.isIE

    var __Style = document.createElement("style");
    __Style.setAttribute("type", "text/css");
    __Style.setAttribute("media", "screen");

    if (!isIE) __Style.appendChild(document.createTextNode(__className + " {" + __Value + "}"));

    document.getElementsByTagName("head")[0].appendChild(__Style);

    if (isIE && document.styleSheets && document.styleSheets.length > 0) {
        var last___Style = document.styleSheets[document.styleSheets.length - 1];
        if (typeof (last___Style.addRule) == "object") last___Style.addRule(__className, __Value);
    }
}
//CreateCss::End

function PageLink(_Values){
	var __FormAction=(_Values.Action!=null?_Values.Action:__PageURL);
	var __Form=_CreateElement({'TagName':'FORM','Attributes':{'name':'LinkForm','method':(_Values.SendMethod!=null?_Values.SendMethod:'POST'),'action':__FormAction}});	
	if(__Form){
		if(_Values.Url!=null){
			for(var __Key in _Values.Url){
				var __Input=_CreateElement({'TagName':'INPUT','Attributes':{'type':'hidden','name':__Key,'value':_Values.Url[__Key]}});
				if(__Input)__Form.appendChild(__Input)
				}
			}
			document.body.appendChild(__Form);
			__Form.submit();
		}
	}
	
function CreateRequestElement()
{
  var xmlHttp=null;
  try{        
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)    {
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

	
function _Send(_Values){  
    if(_Values!=null && _Values!=""){
    xmlHttp=CreateRequestElement();
        if (xmlHttp==null){
            PageLink(_Values);
        }        
        else{   
            try{
                if(!eval(_Values.FunctionName+'_Control(_Values)'))return false;
            }
            catch(ex){
                alert(ex.description);
                return false;
            }
            var _Url = "";
            for (var __Key in _Values.Url){
                _Url += (_Url==""?"":"&")+__Key+"="+escape(_Values.Url[__Key]);
            }     
			_Url += (_Url==""?"":"&")+"isAjax=true";
            xmlHttp.open((_Values.SendMethod==null?"POST":_Values.SendMethod),_Values.Action,(_Values.Sync==null?true:_Values.Sync));	
				
            xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
			//xmlHttp.overrideMimeType('text/xml; charset=iso-8859-9');
            xmlHttp.onreadystatechange=function(){
                if (xmlHttp.readyState==4)	{  
						if(_Values.Wait!=null)
							eval(_Values.Wait+'_Stop(_Values)');
							
						if(_Values.ReturnMethod && _Values.ReturnMethod=='XML'){
							_Values.Result=xmlHttp.responseXML; 
						}
						else{
                        	_Values.Result=xmlHttp.responseText; 
						}
                        eval(_Values.FunctionName+'_Result(_Values)') 
                }
                else if(xmlHttp.readyState==1){
                	if(_Values.Wait!=null)
                    	eval(_Values.Wait+'_Start(_Values)');					   
                }
                else{
                //Waiting ...                 
                }
            }
            xmlHttp.send(_Url);
        }
    }
    else{
        
    }
}

//PointClass::Begin
Point=function(__x,__y){
	this.x=__x;
	this.y=__y;
	
	this.Equals=function(__Obj){
		if(!(__Obj instanceof Point))return false;
		if(__Obj.x!=this.x)return false;
		if(__Obj.y!=this.y)return false;
		return true;
	}
}	
//PointClass::End

//MousePosition::Begin
function GetMousePosition(__Event){
		if(__Event.pageX || __Event.pageY){
			return (new Point(__Event.pageX,__Event.pageY));
		}	
		return (new Point(
						  (__Event.clientX + document.body.scrollLeft - document.body.clientLeft),
						  (__Event.clientY + document.body.scrollTop  - document.body.clientTop)
						  )
				);
}
//MousePosition::End

//GetScrollPosition::Begin
function GetScrollPosition(__Event) {
    var __x = 0, __y = 0;
    
    if (typeof (window.pageYOffset) == 'number') {
        __x = window.pageXOffset;
        __y = window.pageYOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        __x = document.body.scrollLeft;
        __y = document.body.scrollTop;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        __x = document.documentElement.scrollLeft;
        __y = document.documentElement.scrollTop;
    }
    /**/
    return (new Point(__x, __y));
}
//GetScrollPosition::End

//ObjectPosition::Begin
function ObjectPosition(__Element){
	var __left = 0;
	var __top  = 0;
	while (__Element.offsetParent){
		__left += __Element.offsetLeft;
		__top  += __Element.offsetTop;
		__Element     = __Element.offsetParent;
	}
	__left += __Element.offsetLeft;
	__top  += __Element.offsetTop;
	return (new Point(__left,__top));
}
//ObjectPosition::End

//Catch Mouse Position::Begin
function CatchMousePosition(__E){
	__E=(__E || window.event);
	document.MousePosition = GetMousePosition(__E);	
}
//Catch Mouse Position::End

//Catch Scroll Position::Begin
function CatchScrollPosition(__E) {
    __E = __E || window.event;
    document.ScrollPosition = GetScrollPosition();    
}
//Catch Scroll Position::End

//GetStyle::Begin
function GetElementStyle(__Element){
	var CurrentStyle;
    if (__Element.currentStyle)
        CurrentStyle=	__Element.currentStyle;
    else if (window.getComputedStyle)
        CurrentStyle=	document.defaultView.getComputedStyle(__Element, null);
    else
        CurrentStyle=	__Element.style;	
	return CurrentStyle;
}
//GetStyle::End

//DisableSelection::Begin
function disableSelection(target){
	if (typeof(target.onselectstart)!="undefined") //IE route
		target.onselectstart=function(){return false}
	else if (typeof(target.style.MozUserSelect)!="undefined") //Firefox route
		target.style.MozUserSelect="none"
}
//DisableSelection::End

//FixItCss::Begin
function FixItCss(){
	if(UsedBrowser.Type==0){
		var __TestName = "homecontainer" ;
		var __HomeContainer = $(__TestName);
		if(!__HomeContainer){
			__TestName = 'logincontainer';
			__HomeContainer = $('logincontainer');
		}
		if(__HomeContainer){
		UsedBrowser.TestWindow();
		var __Left = (UsedBrowser.Width / 2 - __HomeContainer.offsetWidth / 2 ) + "px";
		createCSS('#'+__TestName,'margin-left:'+__Left+';');	
		}
	}
}
//FixItCss::End
