var img_ar=Array();
var i=0;var tmp_obj_box=new Object();
var containerHeight=0;
var scrollini=true;
var cache=Math.random();
var error=Array(false,false,false,false);
var pic_index=false;

function reset_error(obj,v){

if(error[v]){document.getElementById(obj+"txt").style.color="black";error[v]=false;}
}

function check_inputs(){
	var send=true;

	if (document.fo2.vorname.value == "") {
	error[0]=true;
	document.getElementById("vornametxt").style.color="red";
	document.fo2.vorname.focus();
	send=false;
	}
	
	if (document.fo2.name.value == "") {
	error[1]=true;
	document.getElementById("nametxt").style.color="red";
	document.fo2.name.focus();
	send=false;
	}

	if (document.fo2.message.value == "") {
	document.getElementById("messagetxt").style.color="red";
	error[2]=true;
	document.fo2.message.focus();
	send= false;
	}
	
	
	if (document.fo2.email.value == ""){
	document.getElementById("emailtxt").style.color="red";
	document.fo2.email.focus();
	error[3]=true;
	send=false;
	}
	
	else if (document.fo2.email.value.indexOf ('@',0) == -1 ||
	document.fo2.email.value.indexOf ('.',0) == -1) {
	document.getElementById("emailtxt").style.color="red";
	document.fo2.email.select();
	document.fo2.email.focus();
	error[3]=true;
	send=false;
	}
	if(send)document.fo2.secure.value=9;
	return send;
}
//===========================================================

function remove_picture_box(action){

if(action==0){
	// Firefox trash_can
	tmp_obj_box.setAttribute('id','');
	var obj=document.getElementById('main_div');
	obj.removeChild(tmp_obj_box);
	obj.style.zIndex=0;

	tmp_obj_focus=false;
	pic_index=false;
	if(ini!=false){chat_refresh=true;refresh_chat();}	

	return false;
}else{
if(tmp_obj_box.id){
if(tmp_obj_box.lastChild){tmp_obj_box.lastChild.removeChild(tmp_obj_box.lastChild.lastChild);
return 2;
}else {
pic_index=false;
if(ini!=false){chat_refresh=true;refresh_chat();}	
return false;
}}
chat_refresh=false;
	return 1;
}}


function show_picture(image_index,action){
var el=new Object();
var init=remove_picture_box(action);
if(init>0 && pic_index==false){
pic_index=image_index;

if(init==1){
var obj=document.getElementById('main_div');
obj.style.height=parseInt(document.body.clientHeight+document.body.scrollTop)+'px';
obj.style.zIndex=2;
//---------------------------------------------------------
// create a main box cause of ie opacitiy
el=document.createElement("DIV");
el.setAttribute("id","catch_box");
el.className="catch_box";

// ie trash-can
el.style.height=obj.clientHeight+'px';
obj.appendChild(el);

// setting this object to global is not really necessary, 
// but speeds up a bit
// filling the container with a white box
tmp_obj_box=el;

//---------------------------------------------------------
}


// that' s enough for here
// now we call the server for content
cache++;
el1=document.getElementById("call");
if(el1.lastChild)el1.removeChild(el1.lastChild);
obj=document.createElement("SCRIPT");
obj.setAttribute('src','set_content.php?in='+image_index+'&init='+init+'&c='+cache);
el1.appendChild(obj);
}}



function change_icon(el,v){
if(v==0  || v==2 || v==4){
tmp_obj_focus=true;
}else{	
tmp_obj_focus=false;
}	

if(v==0)	
el.src="bilder/arr_orange.gif";
else if(v==1)	
el.src="bilder/arr_white.gif";	
else if(v==2)	
el.src="bilder/arr_orange_back.jpg";	
else if(v==3)	
el.src="bilder/arr_white_back.jpg";	
}

function removeDiv(obj,v){
if(obj.lastChild.id=='popimg' || obj.lastChild.id=='picture_box'){
obj.removeChild(obj.lastChild);
obj.removeChild(obj.lastChild);

}
chat_refresh=true;
}


function hide(obj){obj.style.overflowY="hidden";}


function setbackground(c_obj,v){


		if(v==0){v=1;
		c_obj.style.backgroundColor="#FFFFFF";
		c_obj.style.borderColor="#FF00FF";
		}else if(v==1){v=2;
		c_obj.style.backgroundColor="#FF00FF";
		c_obj.style.borderColor="#FFFF00";
		}else if(v==2){v=3;
		c_obj.style.backgroundColor="#FFFF00";	
		c_obj.style.borderColor="#00FFFF";
		}else if(v==3){v=0;
		c_obj.style.backgroundColor="#00FFFF";
		c_obj.style.borderColor="#FFFFFF";	
		}

setTimeout(function(){setbackground(c_obj,v);},1000);	

}

function set_scrollimg(){

if(document.getElementById("container")){

containerHeight=((document.getElementById("container").clientHeight)-200);
/*
if(containerHeight>0){
document.getElementById("srcoll_img").style.visibility="visible";
tmp_obj_box=document.getElementById("sc");
tmp_obj_box.style.top=0;
}
*/
}	
//var c_obj=document.getElementById("change_back");
//setTimeout(function(){setbackground(c_obj,0);},1000);	
}
function scroll_this(v){
scrollini=true;
var tp=parseInt(tmp_obj_box.style.top.replace("px",''));

if(v==2){

	if(Math.abs(tp)<containerHeight){tp-=5;	scroll_to(tp,v);}

}else{ 
	if(tp<0){tp-=5;scroll_to(tp,v);}
}
}

function jump_to(v){
scrollini=true;	
var tp=parseInt(tmp_obj_box.style.top.replace("px",''));

if(v==2){

	if(Math.abs(tp)<containerHeight){
		
		if(containerHeight-Math.abs(tp)>198)
		 tp-=198;
		else tp+=(Math.abs(tp)-containerHeight);
		tmp_obj_box.style.top=tp+"px";}

}else{ 
	if(tp<0){if(Math.abs(tp)>=(containerHeight-198) && tp<-198)tp+=198; else tp-=tp;tmp_obj_box.style.top=tp+"px";}

}
}


function scroll_to(tp,v){
if(scrollini){
setTimeout(function(){scroll_to(tp,v);},10);
if(v==2){
if(Math.abs(tp)<containerHeight){tmp_obj_box.style.top=tp+"px";
tp-=5;}
}else if(v==3){
if(tp<5){tmp_obj_box.style.top=tp+"px";
tp+=5;}
}}
}

function scroll_stop(){
	scrollini=false;
}
function call_server(){

cache++;
var call=document.getElementById("call");
if(call.lastChild)call.removeChild(call.lastChild);
var obj =document.createElement("SCRIPT");
obj.setAttribute('type','text/javascript');
obj.setAttribute("src","functions/serverside.php?c="+cache);
call.appendChild(obj);	
}

