var __PageURL='';
BrowserProperties=function(){
    this.Name=navigator.appName;
    this.Description=navigator.appVersion;
	this.Explorer=-1;
    switch(this.Name){
        case"Microsoft Internet Explorer":
            this.Type=0;
			if(this.Description.indexOf("MSIE 7")>=0){
				this.Explorer=7;
				}
			else if(this.Description.indexOf("MSIE 7")>=0){
				this.Explorer=6;
				}
        break;
        case"Netscape":
            this.Type=1;
        break;
        case"Opera":
            this.Type=2;
        break;
        default:
            this.Type=-1
        break;
    }
}

var UsedBrowser=new BrowserProperties();
var DefaultWaitMessageContainer;

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

function SoryByNumber(__X,__Y){
	if(typeof(__X)!='number')__X=parseInt(__X);
	if(typeof(__Y)!='number')__Y=parseInt(__Y);
	return __X-__Y;
	}

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=true);
	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='';
	if(__Output=='')__Output='';
	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;
		for(var __i=0;__i<__NodesCount;__i++){
			RemoveAllChilds(__Element.childNodes[0]);
			__Element.removeChild(__Element.childNodes[0]);
			}
		}
	}

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;
}

function _CreateDiv(Properties){
	var __Date=new Date
	();
	var __Id='_SystemDiv_'+__Date.valueOf();
	var __Div=document.createElement("DIV");
		
	if(Properties!=null){	
		if(Properties.Name!=null)
			__Div.setAttribute("id",Properties.Name);			
		else
			__Div.setAttribute("id",__Id);
			
		if(Properties.Class!=null)
			__Div.className=Properties.Class;
		if(Properties.Width!=null)
			__Div.style.width=Properties.Width;
		if(Properties.Zindex!=null)
			__Div.style.zIndex=Properties.Zindex;
		if(Properties.BGColor!=null)
			__Div.style.backgroundColor=Properties.BGColor;			
		if(Properties.Font!=null){
			if(Properties.Font.Family!=null)
				__Div.style.fontFamily=Properties.Font.Family;
			if(Properties.Font.Size!=null)
				__Div.style.fontSize=Properties.Font.Size;
			}
		if(Properties.Childs!=null){
			for(var __i=0;__i<Properties.Childs.length;__i++)
				__Div.appendChild(Properties.Childs[__i]);
			}	
			
		if(Properties.StyleName!=null)
			appendStyle(__Div,Properties.StyleName);

		}
		else{
			__Div.setAttribute("id",__Id);
			}

	return __Div;
	}

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==""?"":"&")+"Ajax=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.onreadystatechange=function(){
                if (xmlHttp.readyState==4)	{                    
                        _Values.Result=xmlHttp.responseText; 
                        eval(_Values.FunctionName+'_Result(_Values)') 
						if(_Values.Wait!=null){
							
							}
						else{
							ModalPopup.Close('DefaultWaitMessageContainer');
							}
                }
                else if(xmlHttp.readyState==1){
                       if(_Values.Wait!=null){
                            eval(_Values.Wait+'_Result(_Values)');
					   }
					   else{
							Waiting();
					   }
                }
                else{
                //WAIT ...                 
                }
            }
            xmlHttp.send(_Url);
        }
    }
    else{
        
    }
}
