
/*
 * * Used in the screens with pop up
 * Fix the problem with the scrollbar
 * 		.pop_up         size = 162
 * 		.pop_up_middle  size = 272
 * 		.pop_up_big     size = 540
 */
$(document).ready(function(){
	
	$('a').click( function() {
				
		var left = $(this).position().left;
		var offset = $(this).offset().left; 
		var winWidth = $(window).width() + $(window).scrollLeft();
		
		var posPopUp = left;
		var posPopUpMiddle = left;
		var postPopUpBig = left;

		if( left + 162 > winWidth ){
			var posPopUp = left - 162;
		}

		if( left + 272 > winWidth ){
			var posPopUpMiddle = left - 272;
		}

		if( left + 542 > winWidth ){
			var postPopUpBig = left - 542;
			if (postPopUpBig < 0) {
				postPopUpBig = 0;
			}
		}

		var nextDivClass = $(this).next().attr('class');
		
		if(nextDivClass === 'pop_up')
		{
			$(this).next().css('left',posPopUp + 'px');			
		}
		if(nextDivClass === 'pop_up_middle')
		{
			$(this).next().css('left',posPopUpMiddle + 'px');			
		}
		if(nextDivClass === 'pop_up_big')
		{
			$(this).next().css('left',postPopUpBig + 'px');		
			
			//required to fix IE 6 Select Problem
			$('.pop_up_big').bgiframe();
		}
			
	});
});



/*-- Hide Left Menu --*/
function hideMenu()
{
	var table_style = document.getElementById("baseTable").className;
	if(table_style == 'two_columns_style'){

		var menu = document.getElementById("navi1");
		menu.style.display = 'none';
		document.getElementById("content").width = 705;
		document.getElementById("pfad").width = 705;
		document.getElementById("mainContent").width = 705;
		document.getElementById("content").colSpan = 2;
		document.getElementById("hideMenu").style.display = 'none';
		document.getElementById("showMenu").style.display = 'block';
		/* set user preferences
		document.location.href='/user/preferences/set/menu_visibility/hide';*/
	}
	if(table_style == 'one_columns_style'){

		var menu = document.getElementById("navi1");
		menu.style.display = 'none';

		document.getElementById("content").colSpan = 4;
		document.getElementById("hideMenu").style.display = 'none';
		document.getElementById("showMenu").style.display = 'block';
	}
}

/*-- Show Left Menu --*/
function showMenu()
{
	/*document.location.href='/user/preferences/set/menu_visibility/show';*/
	document.location.reload(true);
}

/*-- CAD --*/
function reset(field, radio)
{
	field.value = "";
	radio.checked="checked";
}

/*-- SECTION 1 --*/
function getResultSec1Sub1(){


	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub1").append(msg);
		     document.getElementById('load-1-sub1').innerHTML = "(11)";
		   }
		 });
	 });
}

function getResultSec1Sub2(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub2").append(msg);
		     document.getElementById('load-1-sub2').innerHTML = "(12)";
		   }
		 });
	 });
}

function getResultSec1Sub3(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub3").append(msg);
		     document.getElementById('load-1-sub3').innerHTML = "(13)";
		   }
		 });
	 });
}

function getResultSec1Sub4(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub4").append(msg);
		     document.getElementById('load-1-sub4').innerHTML = "(14)";
		   }
		 });
	 });
}

function getResultSec1Sub6(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub6").append(msg);
		     document.getElementById('load-1-sub6').innerHTML = "(16)";
		   }
		 });
	 });
}

function getResultSec1Sub7(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec1-sub7").append(msg);
		     document.getElementById('load-1-sub7').innerHTML = "(17)";
		     document.getElementById('load-1').innerHTML = "(40)";
		   }
		 });
	 });
}

/*-- SECTION 2 --*/

function getResultSec2Sub1(){
	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec2-sub1").append(msg);
		     document.getElementById('load-2-sub1').innerHTML = "(21)";
		   }
		 });
	 });
}

function getResultSec2Sub2(){
	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec2-sub2").append(msg);
		     document.getElementById('load-2-sub2').innerHTML = "(22)";
		   }
		 });
	 });
}

function getResultSec2Sub3(){
	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec2-sub3").append(msg);
		     document.getElementById('load-2-sub3').innerHTML = "(23)";
		   }
		 });
	 });
}

function getResultSec2Sub4(){
	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec2-sub4").append(msg);
		     document.getElementById('load-2-sub4').innerHTML = "(24)";
		   }
		 });
	 });
}

function getResultSec2Sub5(){
	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec2-sub5").append(msg);
		     document.getElementById('load-2-sub5').innerHTML = "(25)";
		     document.getElementById('load-2').innerHTML = "(222)";
		   }
		 });
	 });
}
/*-- SECTION 3 --*/

function getResultSec3(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec3").append(msg);
		     document.getElementById('load-3').innerHTML = "(33)";
		   }
		 });
	 });
}

/*-- SECTION 4 --*/

function getResultSec4(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec4").append(msg);
		     document.getElementById('load-4').innerHTML = "(44)";
		   }
		 });
	 });
}

/*-- SECTION 5 --*/

function getResultSec5(){

	$(document).ready(function () {
		 $.ajax({
		   type: "POST",
		   url: "/cross/view/" + search_text,
		   success: function(msg){
		     $("#content-sec5").append(msg);
		     document.getElementById('load-5').innerHTML = "(55)";
		   }
		 });
	 });
}

/*-- SWAP --*/

function swap(id1, id2){
	var obj1 = document.getElementById(id1);
	var obj2 = document.getElementById(id2);
	if (obj1 && obj2) {
		obj1.className="prod_image_hidden";
		obj2.className="prod_image_visible";
	}
}

function fsearch_visibility(){
	var container = document.getElementById('container');
	if (!container) {
		return;
	}
	
	var sSelectedSection = '';
	var sLoc = location.href;
	var iTabIdx = sLoc.indexOf('tab=');
	if (iTabIdx > 0) {
	    var iTabEnd = sLoc.indexOf('&', iTabIdx);
	    if (iTabEnd > 0) {
		var sSub = sLoc.substring(iTabIdx+4, iTabEnd);
		sSelectedSection = sSub;
		//alert(sSub);
	    }
	    else {
		var sSub = sLoc.substring(iTabIdx+4);
		sSelectedSection = sSub;
	    }
	}
	if (sSelectedSection == '') {
	    if (!location.hash) {
		sSelectedSection = 'section-1';
	    }
	    else {
		sSelectedSection = location.hash;
		sSelectedSection = sSelectedSection.substring(1);
	    }
	}
	//alert("selected Section:" + sSelectedSection);
	for (var i = 1; i < container.childNodes.length; i++) {
		var oChild = container.childNodes[i];
		if (!oChild.id) continue;
		var sCmp = oChild.id;
		if (sCmp == sSelectedSection) {
			//alert("show: " + oChild.id);
			oChild.className = "ui-tabs-container";
		}
		else if (oChild.id) {
			//alert("hide:" + oChild.id);
			oChild.className = "ui-tabs-hide";
		}
	} 
	
	var sSelectedLI = "li-" + sSelectedSection;
	var oSelectedLI = document.getElementById(sSelectedLI);
	if (oSelectedLI) {
		oSelectedLI.className = "ui-tabs-selected";
	}
}


