//global variables
var ajaxWrapper;
var http;
var lock_in;
var lock_out;

//reset document location
function transfer(link){
	document.location.href = link;
}

//codierung & encodierung <-> UTF8
var UTF8 = {  
      
    encode : function (string) {  
        string = string.replace(/\r\n/g,"\n");  
        var utftext = "";  
  
        for (var n=0, k=string.length; n < k; n++) {  
            var c = string.charCodeAt(n);  
  
            if (c < 128) {  
                utftext += String.fromCharCode(c);  
            }  
            else if((c > 127) && (c < 2048)) {  
                utftext += String.fromCharCode((c >> 6) | 192);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }  
            else {  
                utftext += String.fromCharCode((c >> 12) | 224);  
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
                utftext += String.fromCharCode((c & 63) | 128);  
            }  
        }  
        return utftext;  
    },  
  
    decode : function (utftext) {  
        var string = "";  
        var i = 0;  
        var c = c1 = c2 = 0;  
  
        while ( i < utftext.length ) {  
            c = utftext.charCodeAt(i);  
            if (c < 128) {  
                string += String.fromCharCode(c);  
                i++;  
            }  
            else if((c > 191) && (c < 224)) {  
                c2 = utftext.charCodeAt(i+1);  
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));  
                i += 2;  
            }  
            else {  
                c2 = utftext.charCodeAt(i+1);  
                c3 = utftext.charCodeAt(i+2);  
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
                i += 3;  
            }  
  
        }  
        return string;  
    }  
}


function runCarousel(no, vert){
    
    rnd = Math.ceil(Math.random()*no);
    jQuery(document).ready(function() {
        jQuery('#team').jcarousel({
            vertical: vert,
            start: rnd,
            size: no,
            scroll: 1,
            visible: 1,
        });
    });

    
    window.setTimeout("idle()",500);
    
}

function confirmation(string){
  ret = confirm(string);
  
  return ret;
}

function idle(){
    document.getElementById("team").style.visibility = "visible";
}

//construct ajax wrapper
function initializeAJAXWrapper(remoteScript){
	 ajaxWrapper = new AJAXWrapper();
     ajaxWrapper.setRemoteScript();
     ajaxWrapper.setMethod("POST");
     ajaxWrapper.setCBI(setUserDetails);
     ajaxWrapper.setRemoteScript(remoteScript);
     http = ajaxWrapper.createRequestObject();
     
     return ajaxWrapper;
}

//set user details in the team view
function setUserDetails(){
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
            
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            user = new Array();
                
                for(i = 1; i < update.length; i++){
                    user[i-1] = update[i];
                }
                
                //document.getElementById("motto").innerHTML = "&raquo;"+user[2]+"&laquo;";
                document.getElementById("pic").src = 'http://www.trirockets.de/dev/smarty/templates/trirockets/img/user_thumbs/tr_'+user[5]+'_action.jpg';
                //alert(document.getElementById("pic").src);
        }
        else{
        	
        }
    
    
	}
}

function img_fade_in(alpha){
	

		if(alpha < 1){
			alpha += 0.05;
			recall = "img_fade_in("+alpha+")";
			document.getElementById("pic").style.opacity = alpha;
			setTimeout(recall,1);
		}

	
}

function img_fade_out(alpha){
	

		/*if(alpha > 0){
			alpha -= 0.1;
			recall = "img_fade_out("+alpha+")";
			document.getElementById("pic").style.opacity = alpha;
			setTimeout(recall,50);
		}*/
		//document.getElementById("motto").innerHTML = "";
		 document.getElementById("pic").src = "";
}

function validate(formular){
	if(formular['cf_email'].value == ""){
		formular['cf_email'].value = "Mailadresse Eingeben !"
		return false;
	}
	else return true;
}
