function Screen(myName)
{
	this.ObjName 								= myName;
	this.AjaxObj								= new AjaxGeneric();
	
	this.SelectedTab							= "";
	this.ReloadTad								= false;						//Para ser utilizado navegando dentro da mesma TAB...
	
	this.SelectTabNextStep						= [];
	
	this.TabsBuilder = function()
	{
		var tabs_container 			= document.createElement("DIV");
		tabs_container.id			= "tabs_container";
		
		document.getElementById("big_container").appendChild(tabs_container);
		
		var tab_list_counter	= 0;
		var tab_list 			= [];
		var next_left			= 15;
		var next_top			= 100;
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "desc_compl";
		tab_list[tab_list_counter++]["text"]		= "Descritivo Completo";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "pac_elab";
		tab_list[tab_list_counter++]["text"]		= "Pacotes e-Labore";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "promo";
		tab_list[tab_list_counter++]["text"]		= "Promoções";
		
		
		//tab_list[tab_list_counter]					= [];
		//tab_list[tab_list_counter]["id"]			= "promo_II";
		//tab_list[tab_list_counter]["url"]			= "/php/promo_II/ScreenStarter.class.php?cadastro_email=;";
		//tab_list[tab_list_counter++]["text"]		= "Promoções II";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "revendas";
		tab_list[tab_list_counter++]["text"]		= "Revendas";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "modulos";
		tab_list[tab_list_counter++]["text"]		= "Módulos e-Labore";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "contatos";
		tab_list[tab_list_counter++]["text"]		= "Contatos";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "downloads";
		tab_list[tab_list_counter++]["text"]		= "Downloads";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "novo_rel";
		tab_list[tab_list_counter++]["text"]		= "Novos Releases";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "imprensa";
		tab_list[tab_list_counter++]["text"]		= "Imprensa";
		
		tab_list[tab_list_counter]					= [];
		tab_list[tab_list_counter]["id"]			= "FAQ";
		tab_list[tab_list_counter++]["text"]		= "Perguntas & Respostas";
		
		tab_list = this.MergeSort(tab_list,"text","STR");
		
		for(var i=0;i<tab_list.length;i++)
		{
			var tab_container 				= document.createElement("DIV");
			tab_container.id  				= tab_list[i]["id"];
			tab_container.style.cursor 		= "pointer";
			
			tab_container.appendChild(this.BuildTab(tab_list[i]));
			
			document.getElementById("size_calculator").innerHTML = "";
			document.getElementById("size_calculator").appendChild(tab_container);
			
			var next_size = next_left+document.getElementById("size_calculator").clientWidth;
			if(next_size > 774)
			{
				next_left	= 15;
				next_top	+= 30;
			}	
			
			if(next_left == 15)
			{
				var tab_floor				= document.createElement("DIV");
				tab_floor.className			= "tab_floor";
				tab_floor.style.position	= "absolute";
				tab_floor.style.left		= 0;
				tab_floor.style.top			= next_top+19;
				tab_floor.innerHTML 		= ".";
				
				document.getElementById("tabs_container").appendChild(tab_floor);
			}
			
			tab_container.style.top 	= next_top;
			tab_container.style.left 	= next_left;
			
			next_left += document.getElementById("size_calculator").clientWidth+10;
			
			tab_container.style.position 	= "absolute";
			tab_container.onclick 			= function()
			{
				scr_obj.SelectTab(this.id);
			}
			
			document.getElementById("tabs_container").appendChild(tab_container);
		}
		
		document.getElementById("tabs_container").style.height = next_top-45;
		
		//conteudo da tab selecionada...
		var tab_content 			= document.createElement("DIV");
		tab_content.id				= "tab_content";
		//tab_content.style.margin	= "0px 0px 20px 0px";
		//tab_content.style.height	= "10";
		
		document.getElementById("big_container").appendChild(tab_content);
		
		this.TabList = tab_list;
	}
	
	this.BuildTab = function(tab)
	{
		var tab_table 				= document.createElement("TABLE");
		tab_table.cellPadding		= "0";
		tab_table.cellSpacing		= "0";
		tab_table.border			= "0";
		
		var tab_table_body			= document.createElement("TBODY");
		
		var tab_superior_tr			= document.createElement("TR");
		
		var tab_s_left_td			= document.createElement("TD");
		tab_s_left_td.className		= "tab_left_superior_corner";
		tab_s_left_td.width			= "4";
		tab_s_left_td.id			= tab["id"]+"_tab_s_left_td";
		
		var tab_s_right_td			= document.createElement("TD");
		tab_s_right_td.className	= "tab_right_superior_corner";
		tab_s_right_td.width		= "4";
		tab_s_right_td.id			= tab["id"]+"_tab_s_right_td";
		
		var tab_s_middle_td			= document.createElement("TD");
		tab_s_middle_td.className	= "tab_middle_superior";
		tab_s_middle_td.id			= tab["id"]+"_tab_s_middle_td";
		
		tab_superior_tr.appendChild(tab_s_left_td);
		tab_superior_tr.appendChild(tab_s_middle_td);
		tab_superior_tr.appendChild(tab_s_right_td);
		
		var tab_bottom_tr			= document.createElement("TR");
		
		var tab_b_td				= document.createElement("TD");
		tab_b_td.colSpan			= "3";
		tab_b_td.innerHTML			= tab["text"];
		tab_b_td.className			= "tab";
		tab_b_td.align				= "center";
		tab_b_td.style.padding		= "0px 2px 2px 2px";
		tab_b_td.id					= tab["id"]+"_tab_b_td";
		
		tab_bottom_tr.appendChild(tab_b_td);
		
		tab_table_body.appendChild(tab_superior_tr);
		tab_table_body.appendChild(tab_bottom_tr);
		
		tab_table.appendChild(tab_table_body);
		
		return tab_table;
	}
	
	this.ShowContentLoading = function()
	{
		this.HideContentLoading();
		
		var loading_container			 			= document.createElement("DIV");
		loading_container.className					= "loading_container";
		loading_container.id						= "loading_container";
		
		if(navigator.appName == 'Netscape')
			loading_container.style.height		= "16";
		
		loading_container.innerHTML 				+= " Carregando...";
		
		document.getElementById("tab_content").appendChild(loading_container);
	}
	
	this.HideContentLoading = function()
	{
		try
		{
			document.getElementById("loading_container").parentNode.removeChild(document.getElementById("loading_container"));
			document.getElementById("tab_content").innerHTML = "";
		}
		catch(e)
		{}
	}
	
	this.MarkTabAsSelected = function(tabId)
	{
		if(this.SelectedTab == tabId && this.ReloadTad === false)
			return false;
		
		this.UnselectTab();
		this.ReloadTad = false;
			
		document.getElementById(tabId+"_tab_s_left_td").className		= "tab_left_superior_corner_selected";
		document.getElementById(tabId+"_tab_s_right_td").className 		= "tab_right_superior_corner_selected";
		document.getElementById(tabId+"_tab_s_middle_td").className 	= "tab_middle_superior_selected";
		document.getElementById(tabId+"_tab_b_td").className 			= "tab_selected";
		
		this.SelectedTab = tabId;
		
		return true;
	}
	
	this.SelectTab = function(tabId,useIframe)
	{
		if(useIframe !== false)
			useIframe = true;
		
		if(!this.MarkTabAsSelected(tabId))
			return;

		this.ShowContentLoading();
		
		var base_url = window.location.href.indexOf("#") != -1 ? window.location.href.substr(0,window.location.href.length-1) : window.location.href;
		
		var base_url = base_url.substr(0,base_url.lastIndexOf('/')+1);
		
		try
		{
			for(var i=0;i<this.TabList.length;i++)
			{
				if(this.TabList[i]["id"] == tabId)
				{
					if(this.TabList[i]["url"])
						var the_url 		= base_url+this.TabList[i]["url"];
					else
						var the_url = base_url+"/html/"+tabId+"/index.html";
					
					break;
				}
			}
		}
		catch(err)
		{
			var the_url = base_url+"/html/"+tabId+"/index.html";
		}
		
		
		this.AjaxObj.AjaxReturnDestination 	= 'ExternalFunctionWithAjaxReturnVariable';
		this.AjaxObj.GetAjaxReturn(the_url,this.ObjName+'.TabContent');

		this.IncludeOnceJsScript("./js/"+tabId+"/"+tabId+".js");
		try
		{
			eval(this.SelectTabNextStep[tabId]);
		}
		catch(w)
		{
			"";
		}
		
		var no_back = base_url+"/php/no_back.php?aba="+tabId+"&";
		if(useIframe === true)
			document.getElementById("no_back").src = no_back;
		
		//window.open(no_back);
		//this.SelectTabNextStep = false;
	}
	
	this.TabContent =  function()
	{
		this.HideContentLoading();
		try
		{
			this.ShowContent(this.AjaxObj.AjaxReturnVariable);
		}
		catch(e)
		{
			this.ShowContent("");
		}
	}
	
	this.ShowContent = function(content)
	{
		this.HideContentLoading();
				
		try
		{
			if(typeof(content) == "string")
				document.getElementById("tab_content").innerHTML = content;
			else
			{
				document.getElementById("tab_content").innerHTML = "";
				document.getElementById("tab_content").appendChild(content);
			}
		}
		catch(e)
		{
			document.getElementById("tab_content").innerHTML = "";
		}
	}
	
	this.PositioningCorner = function()
	{
		/*Deprecated...
		var to_calulate 			= document.createElement("DIV");
		to_calulate.innerHTML 		= document.getElementById("tab_content").innerHTML;
		
		var content_dimension = this.GetDimensions(to_calulate);
		
		document.getElementById("corner").style.top 	= content_dimension["height"]+95;
		document.getElementById("corner").style.display = "block";
		*/
	}
	
	this.UnselectTab = function()
	{
		if(this.SelectedTab == "")
			return;
		
		document.getElementById(this.SelectedTab+"_tab_s_left_td").className		= "tab_left_superior_corner";
		document.getElementById(this.SelectedTab+"_tab_s_right_td").className 		= "tab_right_superior_corner";
		document.getElementById(this.SelectedTab+"_tab_s_middle_td").className 		= "tab_middle_superior";
		document.getElementById(this.SelectedTab+"_tab_b_td").className 			= "tab";
		
		document.getElementById("tab_content").innerHTML = "";
		
		this.SelectedTab = "";
	}
	
	this.GetTabById = function(tabId)
	{
		for(var i=0;i<this.TabList.length;i++)
		{
			if(this.TabList[i]["id"] == tabId)
				return this.TabList[i];
		}
	}
	
	this.GetDimensions = function(content)
	{
		var dimensions = [];
		
		document.getElementById("size_calculator").innerHTML = "";
		document.getElementById("size_calculator").appendChild(content);
		
		dimensions["height"] 	= document.getElementById("size_calculator").clientHeight;
		dimensions["width"] 	= document.getElementById("size_calculator").clientWidth;
		
		document.getElementById("size_calculator").innerHTML = "";
		
		return dimensions;
	}
	
	this.MergeSort = function(m,field,dataType)
	{
		var right 	= [];
		var left	= [];
		var result	= [];
		
		if(m.length < 2)
			return m;
		
		var middle = m.length/2;
		
		for(var i=0;i<m.length;i++)
		{
			if(i<middle)
				left[left.length] 	= m[i];
			else
				right[right.length] = m[i];
		}
		
		left 	= this.MergeSort(left,field,dataType);
		right 	= this.MergeSort(right,field,dataType);
		
		result 	= this.Merge(left,right,field,dataType);
		
		return result;
	}
	
	this.Merge = function(left,right,field,dataType)
	{
		var result = [];
		
		while(left.length > 0 && right.length > 0)
		{
			var left_compare 	= left[0][field];
			var right_compare	= right[0][field];
			
			if(dataType == "INT")
			{
				left_compare 	= parseInt(left_compare);
				right_compare	= parseInt(right_compare);
			}
			
			if(left_compare < right_compare)
			{
				result[result.length] = left[0];
				left.shift();
			}
			else
			{
				result[result.length] = right[0];
				right.shift();
			}
		}
		
		if(left.length > 0)
			result = result.concat(left);
		if(right.length > 0)
			result = result.concat(right);
		return result;
	}
	
	this.IncludeOnceJsScript = function(url)
	{
		var url_exploded = url.split("/");
		
		var script_list = document.getElementsByTagName("script");
		var just_exist  = false;
		for(var i=0;i<script_list.length;i++)
		{
			var src_exploded = script_list[i].src.split("/");
			
			if(src_exploded[src_exploded.length-1] == url_exploded[url_exploded.length-1])
				just_exist = true;
		}
		
		if(just_exist !== false)
			return;	
		
		var user_script				= document.createElement("SCRIPT");
		user_script.type 			= "text/javascript";
		user_script.src				= url;
		
		document.body.appendChild(user_script);
	}
	
	this.CreateBackgroundDisabler = function()
	{
		var background_disabler 				= document.createElement('DIV');
		
		background_disabler.id					= 'background_disabler';
		
		background_disabler.style.filter 		= "alpha(opacity=1)";  //IE
		background_disabler.style.MozOpacity 	= 1/100;  // FF
		
		if(navigator.appName == 'Netscape')
		{
			var scroll 					= document.body.scrollTop;
			document.body.scrollTop 	+= 100000*5;
			var height 					= document.body.scrollTop;
			document.body.scrollTop 	= scroll;
		}
		else
		{
			var scroll 								= document.documentElement.scrollTop;
			document.documentElement.scrollTop 		+= 100000*5;
			var height 								= document.documentElement.scrollTop;
			document.documentElement.scrollTop 		= scroll;
		}
		
		background_disabler.style.width			= '100%';
		background_disabler.style.height		= this.GetScreenHeight()+height;
		background_disabler.style.zIndex		= '20';
		
		background_disabler.style.position		= 'absolute';
		background_disabler.style.top			= '0px';
		background_disabler.style.left			= '0px';
		
		background_disabler.style.background	= '#000';
		//background_disabler.className			= "backgroundDisabler";
		
		background_disabler.innerHTML 			= '&nbsp;';
		
		return background_disabler;
	}
	
	this.GetScreenHeight = function()
	{
		//if( typeof(window.innerWidth) == 'number' )//mozilla
			return document.body.clientHeight;
		//else//IE
			return document.documentElement.clientHeight;
	}
	
	this.GetScreenWidth = function()
	{
		if( typeof(window.innerWidth) == 'number' )//mozilla
			return document.body.clientWidth;
		else//IE
			return document.documentElement.clientWidth;
	}
	
	this.GetElementHeight = function(elementId)
	{
		return document.getElementById(elementId).clientHeight;
	}
	
	this.GetElementWidth = function(elementId)
	{
		return document.getElementById(elementId).clientWidth;
	}
	
	this.CentralizeElement = function(elementId)
	{
		element_center_pos = this.GetCenterPosition(this.GetElementHeight(elementId),this.GetElementWidth(elementId));
		
		document.getElementById(elementId).style.top 	= element_center_pos[0]+this.GetScroll();
		document.getElementById(elementId).style.left 	= element_center_pos[1];
	}
	
	this.GetScroll = function()
	{
		if(navigator.appName == 'Netscape')
			return document.body.scrollTop;
		else
			return document.documentElement.scrollTop;
	}
	
	this.GetCenterPosition = function(height,width)
	{
		var center_pos 	= [];
		
		center_pos[0]	= (this.GetScreenHeight()/2)-(height/2);
		center_pos[1]	= (this.GetScreenWidth()/2)-(width/2);
		
		return center_pos;
	}
	
	this.Start = function()
	{
		this.TabsBuilder();
		this.SelectTab("promo");
		
	}
}

var scr_obj = new Screen("scr_obj");
scr_obj.Start();
	
