var CIC = CIC || {};

( function () {

var loadedTab8 = false;
var dom = YAHOO.util.Dom;
var event = YAHOO.util.Event;


CIC.TAB8 =  {
 
 	resetTab : function(doInit) {
 		loadedTab8 = false;
 		if ( typeof(doInit) == 'undefined' 
 			|| doInit )
 			this.initialize();
	},
 	
 	initialize : function() {
		if ( !loadedTab8 )  {
			CIC.util.loadingApplication(true);
			CIC.util.loadingDisplay('tab8');
			YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=1', {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',null,null], 
								scope: this });
						
		}
		
	},
 
	handleSuccess:function(o){
 		var html = null;
 		var msg = null;
 		//alert("Writing to div id " + o.argument[0]);
   		var dobj = dom.get( o.argument[0] );
   		var msgIdx = o.responseText.indexOf("--MESSAGE--",0);
   		
   		html = o.responseText;
   		//alert(html);
   		if ( msgIdx >= 0 ) {
   			html = o.responseText.substring(0,msgIdx);
   			msg = o.responseText.substring(msgIdx+11);
    	} 

		if ( msg != null ) {
			CIC.util.loadingApplication(false);
			alert(msg);
			return;
		}
			
		CIC.util.loadingApplication(false);

		scroll(0,0);

		if (o.argument[0] == "tab8" && !loadedTab8 ) { 
			dobj.innerHTML = html;	
		 	loadedTab8 = true;
			if ( document.getElementById( 'submitSearchButton' ) != null ) {		  
				var oSubmitButton2 = new YAHOO.widget.Button("submitSearchButton");  
		    	oSubmitButton2.addListener("click", this.searchTab, this, true);
		    }   
			if ( document.getElementById( 'cancelSearchButton' ) != null ) {		  
				var oSubmitButton3 = new YAHOO.widget.Button("cancelSearchButton");  
		    	oSubmitButton3.addListener("click", this.cancelSearchTab, this, true);
		    }   
	 	} 
	 	
	 	if ( o.argument[1] ) {
			o.argument[1].call(this,o);
	 	}
	 		 	
	},

	handleFailure:function(o){
		CIC.util.loadingError();
		loadedTab8 = false;
	},

	focusSearch:function(){
			CIC.TAB1.resetTab(false);
			if ( CIC.TAB2 ) CIC.TAB2.resetTab(false);
			if ( CIC.TAB3 ) CIC.TAB3.resetTab(false);
			if ( CIC.TAB4 ) CIC.TAB4.resetTab(true);
			if ( CIC.TAB5 ) CIC.TAB5.resetTab(false);
			if ( CIC.TAB6 ) CIC.TAB6.resetTab(false);
			if ( CIC.TAB7 ) CIC.TAB7.resetTab(false);

			if ( CIC.TAB9 ) CIC.TAB9.resetTab(false);
			if ( CIC.TAB10 ) CIC.TAB10.resetTab(false);
			if ( CIC.TAB11 ) CIC.TAB11.resetTab(false);
			if ( CIC.TAB12 ) CIC.TAB12.resetTab(false);
			if ( CIC.TAB14 ) CIC.TAB14.resetTab(false);
			if ( CIC.TAB16 ) CIC.TAB16.resetTab(false);
			if ( CIC.TAB17 ) CIC.TAB17.resetTab(false);
			if ( CIC.TAB18 ) CIC.TAB18.resetTab(false);
			if ( CIC.TAB19 ) CIC.TAB19.resetTab(false);
			
			//CIC.TAB8.resetTab(false);
			tabView.set('activeIndex', 3);
	},
 
	focusCancelSearch:function(){
			var tmpIndx = tabView.get('activeIndex');
			var tmpIndexR = tmpIndx + 1;
			var cancelList = new Array(
				CIC.TAB1,
				CIC.TAB2,
				CIC.TAB3,
				CIC.TAB4,
				CIC.TAB5,
				CIC.TAB6,
				CIC.TAB7,
				CIC.TAB8,
				CIC.TAB9,
				CIC.TAB10,
				CIC.TAB11,
				CIC.TAB12,
				CIC.TAB13,
				CIC.TAB14,
				CIC.TAB15,
				CIC.TAB16,
				CIC.TAB17,
				CIC.TAB18,
				CIC.TAB19
				);
				
			for ( var i = 0; i < cancelList.length; i++ )
				if ( cancelList[i] )
					cancelList[i].resetTab(false);
			var y = tabView.getTab(tmpIndx);
			var tabName = new String(y.get("href").substr(1));
			//alert("["+tabName.toUpperCase()+"]");
			//tabView.selectTab(tmpIndx);
			CIC[tabName.toUpperCase()].resetTab(true);
			//tabView.deselectTab(tmpIndx);
			//tabView.selectTab(tmpIndx);
	},

	saveTab : function() {
		CIC.util.loadingApplication(true);
		var formObject = document.getElementById('form8');
		YAHOO.util.Connect.setForm(formObject);
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/cic/PR?button=1', {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',focusSearch,null], 
								scope: this });
	},

	searchTab : function () {
		CIC.util.loadingApplication(true);
		var formObject = document.getElementById('form8');
//		alert(formObject['app'].value+":"+formObject['action'].value);
		YAHOO.util.Connect.setForm(formObject);
		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/cic/PR?search=true', {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',this.focusSearch,null], 
								scope: this });
//		alert(formObject['app'].value+":"+formObject['action'].value);
	},

	cancelSearchTab : function() {
		var cObj = YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=2&cancel=true', {
								success:this.focusCancelSearch,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',null,null], 
								scope: this });
	},

	searchExamGroup : function(t) {
		CIC.util.loadingApplication(true);
		var cObj = YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=2&search=true&s12='+t, {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8skip',this.focusSearch,null], 
								scope: this });
	},

	searchStatus : function(t) {
		CIC.util.loadingApplication(true);
		var cObj = YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=2&search=true&s6='+t, {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',this.focusSearch,null], 
								scope: this });
	},

	searchDaysBefore : function(t) {
		CIC.util.loadingApplication(true);
		var cObj = YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=2&search=true&s7='+t, {
								success:this.handleSuccess,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',this.focusSearch,null], 
								scope: this });
	},

	assumeUser : function (t) {
		CIC.util.loadingApplication(true);
		var cObj = YAHOO.util.Connect.asyncRequest('GET', '/cic/PR?app=8&action=2&search=true&s8='+t, {
								success:this.focusSearch,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',null,null], 
								scope: this });
	},
	
	searchUser:function(t) {
	   CIC.util.loadingApplication(true);
	   YAHOO.util.Connect.asyncRequest('GET', "/cic/PR?app=8&action=2&search=true&s2="+t, {
								success:this.focusSearch,
								failure:this.handleFailure,
							  	cache:false,
							  	timeout: 0, 
							  	argument: ['tab8',null,null], 
								scope: this });
	}
	


};

})();






