function hideDivById( id )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[id];
  
  vis = elem.style;
  
  vis.display = 'none';
}

function showDivById( id )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[id];
  
  vis = elem.style;
  
  vis.display = 'block';
}

var RotationBaseCode = '';
function SubmitAs(action,f){
    if(action=='rotation'){
    	var box = document.getElementById('rotation_code');
    	if(RotationBaseCode==''){
    	   RotationBaseCode = box.value;
    	}
    	var cbs = document.getElementsByName("r_id[]");
    	var src = '';
    	
    	if(!f.rotation_all.checked){
	    	var sep = '';
	    	for( i = 0; i < cbs.length; i++ ){
	    		if(cbs[i].checked){
	   				src += sep + cbs[i].value;
	    			sep  = ','; 
	    		}
	    	}
    	}
    	
    	/**
    	* ALL
    	**/
    	if(f.rotation_all.checked){
    		if(f.format.selectedIndex>0){
    			src += '&format='+f.format.options[f.format.selectedIndex].value;
    		}
    		if(f.site.selectedIndex>0){
    			src += '&site='+f.site.options[f.site.selectedIndex].value;
    		}
    		if(f.campaign.selectedIndex>0){
    			src += '&campaign='+f.campaign.options[f.campaign.selectedIndex].value;
    		}    		
    		box.value = RotationBaseCode.replace(/#banners#/,src);
    		
    		showDivById('rotation_code');
        showDivById('rotation_code_holder');
    	/**
    	* SELECTED
    	**/
    	}else if(src!=''){
    		src = '&bn=' + src;

    		if(f.campaign.selectedIndex>0){
    			src += '&campaign='+f.campaign.options[f.campaign.selectedIndex].value;
    		}    		

    		box.value = RotationBaseCode.replace(/#banners#/,src);
    		showDivById('rotation_code');
    		showDivById('rotation_code_holder')      
    	}else{
    		hideDivById('rotation_code');
    		alert('Für die Rotation sind noch keine Banner ausgewählt!')
    	}
    	
    }else{
		f.action.value=action;
		f.submit();
	}
}

function CheckBrowser(){
	var is_ie=false;

	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (win_ie_ver >= 5.5) {
		is_ie=true;
	} else { 
		is_ie=false;
	}
	return is_ie;
 }; 
 var isCheckBrowser=CheckBrowser();

 function GetTextToClipboard(elm){
	if(isCheckBrowser)
		elm.createTextRange().execCommand('Copy');
 }
 
 function GetElementByIndex(name,index){
   cbs = document.getElementsByName(name+"[]");
   
   for( i = 0; i < cbs.length; i++ ){
	   if(i==index){
		return cbs[i];
	   }
   }
   return 0;
 }
 // universal pop-up window function
 var remote=null;

 function open_window(w_name,w_url,w_width,w_height) {
	args="width="+w_width+",height="+w_height+",resizable=yes,scrollbars=yes,status=0";
	remote=window.open(w_url,w_name,args);
	if (remote != null) {
		if (remote.opener == null)
			remote.opener = self;
		}
	return false; 
 }

function SelectAllCheckbox(name){
   cbs = document.getElementsByName(name+"[]");
   
   for( i = 0; i < cbs.length; i++ ){
	   cbs[i].checked = true;
   }
 }

 function SelectNoneCheckbox(name){
   cbs = document.getElementsByName(name+"[]");
   
   for( i = 0; i < cbs.length; i++ ){
	   cbs[i].checked = false;
   }
 }

 function InvertSelCheckbox(name){
   cbs = document.getElementsByName(name+"[]");
   
   for( i = 0; i < cbs.length; i++ ){
	   if ( cbs[i].checked == true)
		   cbs[i].checked = false;
		   else
			   cbs[i].checked = true;
   }
 }

 function DownloadGals(f){
   cbs = document.getElementsByName("remind[]");
   action = str;
   for( i = 0; i < cbs.length; i++ ){
	  if( cbs[i].checked == true){
 	    gal_id = document.getElementById("gal_" + cbs[i].value);
		action += '&id[]=' + gal_id . value;
	  }
   }
   document.download.action = action;
   document.download.submit();
 }
 
function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	} else {
	   if(window.event) {
      e = window.event;
    }
    if(e) characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
  if(!characterCode) return false;
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit(); //submit the form
		return false;
	} else {
		return true;
	}
}

function toggleDisplayById( id )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[id];
  
  vis = elem.style;
  
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
}
window.size = function()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

DevMode=document.location.href.indexOf('/dev/')!=-1;

