//=============================================================================
//
// Copyright (c) 2007 RuanYu
//
// FileName     :net.js
//
// Description  :net 
//
// Author       :RuanYu
//
// Date         :2007-10-12
//
//=============================================================================

if(typeof(RuanYu)=='undefined') RuanYu = {}

RuanYu.Net = {}

RuanYu.Net.Request = Class.create();

RuanYu.Net.Request = {
	 
	initialize : function(){},
	 
	//=========================================================================
	//
	// find all param by location.search . | date:2007-10-12
	//
	//=========================================================================
	
	findAll : function()
	{
	    var outString = "";
	    
	    var list = location.search.substr(1).split('&');
	    
	    var temp;
	    
	    outString = '{';
	    
	    for(var i=0; i<list.length; i++)
	    {
	        temp = list[i].split('=');
	            
	        outString += '"' + temp[0] + '":"' + temp[1] + '"';
	        
	        if(i < list.length-1) 
	            outString+=',';
	    }
	    
	    outString += '}';
	    
	    return outString.toJSON();
	},
	
	//=========================================================================
	//
	// find a param by location.search . | date:2007-10-12
	//
	//=========================================================================
	
 	find : function(value)
 	{
 		var resutl = '';
 		
    	var list = location.search.substr(1).split('&');
        
    	for(var i=0; i<list.length; i++)
    	{
        	if(list[i].indexOf(value) == 0)
        	{
            	resutl = list[i].replace(value + '=', '');
            	break;
        	}
    	}
    
    	return resutl;
	}
}

//=============================================================================
//
// RuanYu.Net.Browser | Date:2007-10-12
//
//=============================================================================

RuanYu.Net.Browser = {
	
	getFullName : function()
	{
		return RuanYu.Net.Browser.getName() + " version:" + RuanYu.Net.Browser.getVersion();
	},
	
	
	getName : function()
	{
		if(navigator.userAgent.indexOf("MSIE")>0)
	   		return "Internet Explorer";
	   	if(isFirefox=navigator.userAgent.indexOf("Firefox") >= 0)
	   		return "Firefox";
	   	if(isSafari=navigator.userAgent.indexOf("Opera") >= 0)
	   		return "Opera";  
	   	if(isSafari=navigator.userAgent.indexOf("Safari") > 0)
	   		return "Safari";   
	   	if(isCamino=navigator.userAgent.indexOf("Camino") > 0)
	   		return "Camino";
	   	if(isMozilla=navigator.userAgent.indexOf("Gecko") > 0)
	   		return "Gecko";
	   	
	   	return "Unknown";
	},
	
	getVersion : function()
	{
		var browserName = RuanYu.Net.Browser.get_name();
		
		var version = navigator.userAgent;
		
		var startValue ;
		var lengthValue;
		
		switch(browserName)
		{
			case "Internet Explorer":
				startValue = version.indexOf("MSIE") + 5;
				lengthValue =  3;
				version = version.substr(startValue,lengthValue) ;
				break;
			case "Firefox":
				startValue = version.indexOf("Firefox") + 8;
				lengthValue =  3;
				version = version.substr(startValue,lengthValue) ;
				break;
			case "Opera":
				startValue = version.indexOf("Opera") + 6;
				lengthValue =  3;
				version = version.substr(startValue,lengthValue) ;
				break;
			case "Safari":
				break;
			case "Camino":
				break;
			case "Gecko":
				break;
			default:
				break;
		}
		
		return version;
	}
}

//=============================================================================
//
// RuanYu.Net.AjaxProsess | Date:2007-10-12
//
//=============================================================================

RuanYu.Net.AjaxProsess = Class.create();
	
RuanYu.Net.AjaxProsess.prototype = {
	
	initialize : function(contextName,showClassName,hiddenClassName)
	{
		this.contextName = (typeof(contextName) == 'undefined') ? contextName : "messageContext" ; //messageContext 
	
		this.showClassName = (typeof(showClassName) == 'undefined') ? showClassName : "window-message-context" ;  // "window-message-context" 
		
		this.hiddenClassName = (typeof(hiddenClassName) == 'undefined') ? hiddenClassName : "hidden" ; //"hidden" 
		
		this.context = $(contextName);
		
		if(typeof(this.context) == 'undefined')
	    {
	    	var div = document.createElement('div');
	  
	 	   	div.id = this.contextName;
	    	div.name = this.contextName;
	    	div.className = this.hiddenClassName;
	    	
	    	div.innerHTML = '';
	      
	    	document.body.appendChild(div);
		}
	},

	open : function(message)
	{
		    var div = this.context ;
		    
		    div.className = this.showClassName;
		  
		    div.innerHTML = ( message == 'undefined' ) ? 'Loading...' : message;
	},

	close : function()
	{
	    this.context = this.hiddenClassName;
	}
}