/*******************************
@ TOGLE TAB APPLET LAYERS
@ PRAMS
	int 		activeindex		[index of tab to be activated]
	string 	tabprefix			[prefix for tab header]
	string 	paneprefix		[prefix for tab  pane divs]
	string 	activeurl			[ajaxcall for tab to be activated]
	string 	actiview			[value for active view]
	string 	searchform		[id for search again for]
	function 	java				[additional script to be executed on activated tab]
*******************************/
function tabCleanOut (activeobject,activeindex,tabprefix,paneprefix,activeurl,activeview,searchform,java,jdata,serialdata, inactivecss, activecss,useajax, chimg) {
	var cnt = 1;
	var TTAB;
	var TPANE;
	var ATAB = $(tabprefix + activeindex);
	var APANE = $(paneprefix + activeindex);
	var FORM = $(searchform);
	//alert (activecss + "1 => " + ATAB.className)
	if (ATAB.className == activecss) return;
	//alert (ATAB)
	while ($(tabprefix + cnt) && $(paneprefix + cnt) && cnt < 100) {
		TTAB =$(tabprefix + cnt);
		
		var ccnt = 0;  
		
		if (TTAB.childNodes && chimg) {
			while (TTAB.childNodes [ccnt] ) {
				
				if (TTAB.childNodes [ccnt].tagName ) {
					if ( TTAB.childNodes [ccnt].tagName.toLowerCase() == "img") {
						TTAB.childNodes [ccnt].src = "images/tab_" +TTAB.childNodes [ccnt].name + "_off.png";
					}
				}
				ccnt ++;
			}
		}
		TPANE = $(paneprefix + cnt);
		if (TTAB.className != inactivecss) {
			TTAB.className = inactivecss;
			TPANE.style.display = "none";
		}
		cnt ++;
	}
	
	ATAB.className = activecss;
	APANE.style.display= BLOCK;
	var ccnt = 0;
	if (APANE.childNodes && chimg) {
		while (APANE.childNodes [ccnt] ) {
			// bottom was APANE
			try{
				if (ATAB.childNodes [ccnt].tagName ) {
					if ( ATAB.childNodes [ccnt].tagName.toLowerCase () == "img") {
						ATAB.childNodes [ccnt].src = "images/tab_" +activeview+ ".png";
					}
				}
			}
			catch(e){ }
			ccnt ++;
		}
	}
	if (FORM ) {
		//FORM.view.value = activeview;
		//alert(activeview);
	}
        
	if (activeurl != '' && activeurl != null && activeurl != 'null') {
		var url =activeurl; 
		if (serialdata) serialdata['view'] = activeview;
		var ajx = new Ajax.Request(url, {
			 method: 'POST', 
			 parameters : serialdata,
			onSuccess: function(transport) {  	
				var data = transport.responseText; 
				APANE.innerHTML = data;
                if (document.getElementById('loader_div')) {
				    document.getElementById('loader_div').style.display = 'none';
                }
                if ($('ccontainer')) {
				    $('ccontainer').style.height = "auto";
                }
			},
			onFailure: function(transport) {
				//alert ("SCRIPT NOT FOUND");
			}
		});
	}
	
	if (java) {
		java(jdata);
	}
		
	activeobject.onclick = function () {
		if (!useajax) {
			activeurl = null;
			java = null;
			jdata = null;
			serialdata = null;
		}
		tabCleanOut (activeobject,activeindex,tabprefix,paneprefix,activeurl,activeview,searchform,java,jdata,serialdata, inactivecss, activecss,useajax,chimg);
		java = null; 
	};
	
	//setTimeout('fixer();', 500);	
}

function submitForm (id) {
        $(id).submit ();
}

function surfto (id) {
        id = $(id);
        if (id && id.value) {
                document.location.href = BASE + id.value;
        }
}

function headerSearch (pckgType, cntry) {
    document.location.href = BASE + 'search/index.php?country='+cntry+'&package_type='+pckgType;
}