// script to get the querystring values

var $_GET = new Array;

// internal script to parse the $_GET variable
var _uri = location.href;
var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&");
var _temp_get_arr_1 = new Array();
var _temp_get_val_holder = "";
for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){
	_temp_get_val_holder = "";
	_temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("=");
	for (_get_arr_j=1; _get_arr_j<_temp_get_arr_1.length; _get_arr_j++){
		if (_get_arr_j > 1) _temp_get_val_holder += "=";
		_temp_get_val_holder += decodeURI(_temp_get_arr_1[_get_arr_j]);
	}
	$_GET[decodeURI(_temp_get_arr_1[0])] = _temp_get_val_holder;
}
delete _uri; delete _temp_get_arr; delete _temp_get_arr_1; delete _temp_get_val_holder;
var searchvalue = $_GET['searchvalue'];

// shaped windows from mocha UI
var pHost = document.location.host;
var pProt = document.location.protocol;
var pUrl = pProt + "/" + pHost;
document.addEvent('mousemove', function(event) {
	Xcoord = event.page.x;
	Ycoord = event.page.y;
	});
	
var iframeWindow = function($url, $width, $height, $title){
    new MUI.Window({
        type: window,
        x: Xcoord,
        y: Ycoord,
        title: $title,
        loadMethod: 'iframe',
        contentURL: $url,
        minimizable: false,
        draggable:true,
        width: $width,
        height: $height
    });
}

/*var modalWindow = function($url, $width, $height, $title){
	new MUI.Modal({
			title: $title,
			loadMethod: 'iframe',
			contentURL: $url,
			type: 'modal',
			width: $width,
			height: $height
		});
}*/
var modalWindow = function($url, $width, $height, $title,$domid){
	light = new LightFace.IFrame({
		domid:$domid,
		height:$height, 
		width:$width, 
		url: $url, 
		title: $title 
		}).addButton('Schliessen', function() { light.destroy(); },true).open();	
}


window.addEvent('domready', function(){
	/* JsonCall for Login */
	var loginJson = new Request.JSON({url: "/selfcare/ajax/customerLoggedIn", onSuccess: function(json){
	var firstName = "";
	var lastName = "";
	var custtype = "";
	firstName = json.customer.firstName;
	lastName = json.customer.lastName;
	custtype = json.customer.custtype;
       
  if(firstName != ""){     
  	//alert(firstName);
  	//$('greeting').appendText('Hallo '+firstName+' '+lastName);
  	$('greeting').set({'html':'<a style="color:white" href="/selfcare/">Hallo '+firstName+' '+lastName+'</a>'});
		$('toggleLogin').empty();  	
		$('toggleLogin').appendText('ausloggen');
		/*$('toggleLogin').setProperty('href', '/selfcare/restricted/logout.do');*/
		$('toggleLogin').setProperty('id', 'triggerLogOut');
		$('triggerLogOut').addEvent('click', function(){
			var myLogout = new Request({method: 'post', url: '/selfcare/ajax/customerLogout', onComplete: location.reload() });
			myLogout.send();
			});
 	} else {
		//alert('nonName');
		$('greeting').set('text','Ihre Kundenzone Inside 3');
		$('toggleLogin').addEvent('click', function(e){	e = new Event(e);	mySlide.toggle();	e.stop();	});
		
	};
	}}).get();
	
	$('login').setStyle('height','auto');
	var mySlide = new Fx.Slide('login').hide();  //starts the panel in closed state  

});

//### generic rollover
function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function rO(obj,loImg,hiImg){var msie=(document.all&&document.styleSheets)?true:false;var objRef=(msie)?obj.parentNode.parentNode:obj;
if(msie){objRef.style.filter=objRef.style.filter.split(loImg).join(hiImg);}else{var imgSrcName=loImg.split('/');var imgOverName=hiImg.split('/');objRef.src=objRef.src.split(imgSrcName[imgSrcName.length-1]).join(imgOverName[imgOverName.length-1]);}}


//######
//### 
//### geoeffnete pro block wieder ausblenden, aktiven einblenden
function fZusatzSammler(whichOne,whichArray,whichFunction){
	var whichOneFound=false;
	for(var i=0;i<whichArray.length;i++){
		if(whichArray[i]==whichOne){
			
			whichOneFound=true;
		} else {
			whichFunction(whichArray[i],false);
		}
	}
	if(!whichOneFound){
		whichArray.push(whichOne);
	}
	whichFunction(whichOne,(document.getElementById(whichOne+"_div").style.display=="none"));
}
//
//### sammelwerte pro tabellenblock
var Zusatz1=new Array();
var Zusatz2=new Array();
var Zusatz2Active=new Array();
//### hide/show tarif elements block1
function ZusatzBlock1(whichOne,show){
	if(show){
		document.getElementById(whichOne+"_div").style.display="block";
		document.getElementById(whichOne+"_heightFix").style.display="block";
		document.getElementById(whichOne+"_leistung").style.display="none";
	} else{
		document.getElementById(whichOne+"_div").style.display="none";
		document.getElementById(whichOne+"_heightFix").style.display="none";
		document.getElementById(whichOne+"_leistung").style.display="block";
	}
}
function ZusatzBlock2(whichOne,show){
	if(show){
		document.getElementById(whichOne+"_div").style.display="block";
		document.getElementById(whichOne+"_heightFix").style.display="block";
		document.getElementById(whichOne+"_leistung").style.display="none";
	} else{
		document.getElementById(whichOne+"_div").style.display="none";
		document.getElementById(whichOne+"_heightFix").style.display="none";
		document.getElementById(whichOne+"_leistung").style.display="block";
	}
}
function ZusatzBlock2Active(whichOne,show){
	if(show){
		document.getElementById(whichOne+"_div").style.display="block";
		document.getElementById(whichOne+"_heightFix").style.display="block";
		document.getElementById(whichOne+"_leistung").style.display="none";
	} else{
		document.getElementById(whichOne+"_div").style.display="none";
		document.getElementById(whichOne+"_heightFix").style.display="none";
		document.getElementById(whichOne+"_leistung").style.display="block";
	}
}
//### pruefen
function showZusatzBlock1(whichOne){
	fZusatzSammler(whichOne,Zusatz1,ZusatzBlock1);
}
function showZusatzBlock2(whichOne){
	fZusatzSammler(whichOne,Zusatz2,ZusatzBlock2);
}
function showZusatzBlock2Active(whichOne){
	fZusatzSammler(whichOne,Zusatz2Active,ZusatzBlock2Active);
}

