/**
 * 
 * 
 * 
 * 
 */
 
$include("dom.js");
$include("taber.js");
$include("calendar.js");
$include("logic.js");
$include("enum.js");
$include("editable.js");
$include("msgBox.js");
$include("event.js");
$include("validator.js");




ServerStub.defaultMethod = "POST";

function getFileExt(){
	ServerStub.sendAsync({ 
			"url"		:	Application.host + "command",
		  	"param"		:	{   sid : Application.sid,
								cmd : "get-accepted-file"
							},
			"handler"	:	function(resp){
								Application.fileExtString = resp;
								Application.fileExt = resp.split(",");
							}
		}
	); 	
}


function processHash(){
//		alert(prefill);
		var locH = getLocationHash();
//		alert(locH.$s());
		
		if(locH.tab == null){
			if(typeof prefill == "string"){
				taber.click($elements.$mi0);	
			} else {
	//			alert(prefill.$s());
				if(prefill.subj == "cars"){
					$elements.$mi1View.refresh = true;
					doGetTable($elements.$mi1View);
				}else if(prefill.subj == "details"){
					$elements.$mi2View.refresh = true;
					doGetTable($elements.$mi2View);
				}else if(prefill.subj == "services"){
					$elements.$mi3View.refresh = true;
					doGetTable($elements.$mi3View);
				}else if(prefill.subj == "partners"){
					$elements.$mi4View.refresh = true;
					doGetTable($elements.$mi4View);
				}else if(prefill.subj == "news"){				
					getNewsByDate();
				}else if(prefill.subj == "docs"){
					taber.click("mi6");
				}else if(prefill.subj == "about"){
					taber.click("mi0");
				}	
			}			
		} else {
			if(locH.tab.indexOf('mi5')==0){
				getNewsByDate(locH.date);
			} else if(locH.tab.indexOf('mi')==0 && locH.tab.length==3){
				taber.click(locH.tab);
			} else if(locH.tab == 'moreNews' && locH.news != null){
				doMoreNews(locH.news);
			} else if(locH.tab == 'propMaster' && locH.id != null){
				doMoreInfo(locH.id);
			} else if(locH.tab == 'regMaster'){
				doOpenRegForm();
			} else {
				alert(locH.tab);
			}
		}		
	
}

load = 
	function(){
//		alert(location.hash);
		
		associate($elements,document);
/**
* Add user event support 
 * 
 * Step 1.	$include("event.js"); 
 * 
 * Step 2. register Event by eventType.
 * 
 * 						registerEvent("validate");
 * 
 * Step 3. lockup Browser event support being with node. For ex. document
 * 
 * 						lockupEventSupport(document);
 * 
 * Step 4. You can use in html tag handlers "on"+eventType. See index.html
 * 
 * <div js="regMasterView" onvalidate="alert('Validate for Dialog Event Stage: ' + event.stage +  event.id);">	
 *	...
 * 			<input onvalidate="alert('Validate for Input Event Stage: ' + event.stage + event.id);event.stage=CANCELED_EVENT; " js="regEmail" class="regInput" type="text" value="" maxlength="500" size="25"/> 
 * 	...
 * </div>
 * 
 * Step 5. You can fire user event. See logic.js doSaveProfile function
 * 
 * 			fireEvent("validate",{stage:CAPTURING_STAGE},$elements.$regMasterView);
 * 
 * The event has stage field that indicates the event handling
 * According with DOM Event Model the stage value may be
 * 
 * 						CAPTURING_STAGE = 1;
 * 						BUBBLING_STAGE  = 3;
 * 						CANCEL_EVENT	= 4;
 *
 * 
 * For stop event set event.stage = CANCEL_EVENT in every user event handler   
 */
		
		
		registerEvent("validate");
		lockupEventSupport(document);

		createEnums();

		//alert($elements.$s());
		//init first level
		
		
		initEditable($elements.$regMasterView);		
		initEditable($elements.$propMasterView);
	
		processHash();	
		 
		
		if (Application.onLoad){
			Application.onLoad();
		}

		// Auto login
		if(autologin != null && autologin.indexOf('#')==-1){
			var params = autologin.split(",");
			setValueToNode($elements.$username,params[0]);
			setValueToNode($elements.$userpass,params[1]);
			doLogin();
		} 
		
		
		var q={};
		associate(q,document.body,"autoinit");		
		for(i in q.$1)if(!(q.$1[i] instanceof Function)){
			processFilteredTable(q.$1[i]);	
		}
		


		if (confirmation.$eq("true")){
			showDialog($elements.$congratuateDialog)
		}
		if (confirmation.$eq("false")){
			showDialog($elements.$apologyDialog)
		}

	}

