function show(id)
{
	var button = document.getElementById(id);
	button.style.display = "block";	
}

function hide(id)
{
	var button = document.getElementById(id);
	button.style.display = "none";
}

function CheckComment()
{
	if( document.getElementById('username').value == '' || document.getElementById('comment').value == '' )
	{
		window.scrollTo(0,0);
		show('popup');
		
		return false;
		
	}else{
		
		return true;
	}
}

function CheckUserdata()
{
	if( document.getElementById('username').value == '' || document.getElementById('password_1').value == '' || document.getElementById('password_2').value == '' || document.getElementById('email').value == '' )
	{
		window.scrollTo(0,0);
		show('popup');
		
		return false;
		
	}else{
		
		return true;
	}
}

function rate(id, type)
{
 	if(type == 1)
 	{
	 	document.getElementById('rate_' + id).src = activestar;
	 	document.getElementById("rateval").innerHTML = ratetext[id];
	 	document.getElementById("ratevalue").value = id;
 	
 	}else{
 
 		document.getElementById('rate_' + id).src = normalstar;
 	 	document.getElementById("rateval").innerHTML = '&nbsp;';
 	}	
}

function popup(pdata, psize) 
{
	var daten = psize.split("=");
	var width = daten[1].split(",");
	var fenster_b = width[0];
	var fenster_h = daten[2];
	var sh = screen.height;
	var sb = screen.width;
	var offX = (sb-fenster_b)/2;
	var offY = (sh-fenster_h)/2;
	var popupwin;	

	popupwin = window.open(pdata, '', psize+",left="+offX+",top="+offY,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resize=no');

	if (window.focus) 
	{
		popupwin.focus();
    }
}

function popup_win(url, popup_size)
{
	window.open(url, '', popup_size, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	
	if (window.focus) 
	{
		popupwin.focus();
    }
}

function countCahrs(field, numb)
{
	var max = 160;
	var thefield = field.length + 1
	
	document.getElementById(numb).innerHTML = max - thefield;
	
}

function changeGenres(val, n)
{
	a=document.getElementsByName(n);
    
    for(e=0;e<a.length;++e)
      {
        if(!document.getElementById("multigenre").checked )
        {
          	 a[e].checked = false;
          	 document.getElementById("showGenreInfo").style.display = 'block';
        }
        else
        {
        	 a[e].checked = true;
        	 document.getElementById("showGenreInfo").style.display = 'none';
        }
      }
      
}

function setMultiContent( id, title, target )
{
	document.getElementById(target+'_id').value = id;
	document.getElementById(target+'_title').value = title;
	
/*	var x = 0;
	  for (i = 0; i <document.getElementById(target).length; ++i)
	  {
	    if (document.getElementById(target).options[i].text == title)
	    {
	 		x++;	
	    }
	  }

	if( !x )
	{
		NewItem = new Option(title, id, false, false);
		document.getElementById(target).options[document.getElementById(target).length] = NewItem;	
	}
*/
}

function delete_items( field_id )
{
	document.getElementById(field_id).value = '';

}

var genres;
function getActivGenres()
{
	var boxes=document.getElementsByName("genres");
	genres = '';
	var found=false;
	for(var x=0;x<boxes.length;x++)
	{
		if(boxes[x].checked==true){
			found=true;
		    genres+=x;
			if(x<(boxes.length-1)){
			   	genres+=","
			}
		}
	}
	
	if(found==true){
		document.getElementById("showGenreInfo").style.display = 'none';
		var ablauf = new Date();
		var infuenfTagen = ablauf.getTime() + (5 * 24 * 60 * 60 * 1000);
		ablauf.setTime(infuenfTagen);
		document.cookie = "hlp_genres="+genres+"; path=/; expires=" + ablauf.toGMTString();
	}else{
		document.getElementById("showGenreInfo").style.display = 'block';
	}
	
	
	

}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; 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;
    },

    // private method for UTF-8 decoding
    _utf8_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 serialize( inp ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
 
    var getType = function( inp ) {
        var type = typeof inp, match;
        if(type == 'object' && !inp)
        {
            return 'null';
        }
        if (type == "object") {
            if(!inp.constructor)
            {
                return 'object';
            }
            var cons = inp.constructor.toString();
            if (match = cons.match(/(\w+)\(/)) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
 
    var type = getType(inp);
    var val;
    switch (type) {
        case "undefined":
            val = "N";
            break;
        case "boolean":
            val = "b:" + (inp ? "1" : "0");
            break;
        case "number":
            val = (Math.round(inp) == inp ? "i" : "d") + ":" + inp;
            break;
        case "string":
            val = "s:" + inp.length + ":\"" + inp + "\"";
            break;
        case "array":
            val = "a";
        case "object":
            if (type == "object") {
                var objname = inp.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            var count = 0;
            var vals = "";
            var okey;
            for (key in inp) {
                okey = (key.match(/^[0-9]+$/) ? parseInt(key) : key);
                vals += serialize(okey) +
                        serialize(inp[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
    }
    if (type != "object" && type != "array") val += ";";
    return val;
}


function setGeoData()
{
	
	var ablauf = new Date();
var infuenfTagen = ablauf.getTime() + (5 * 24 * 60 * 60 * 1000);
ablauf.setTime(infuenfTagen);
var valuex;

valuex = 'f_utme::'+document.getElementById('f_utme').value;
valuex += '|f_utmn::'+document.getElementById('f_utmn').value;
valuex += '|f_utmz::'+document.getElementById('f_utmz').value;
valuex += '|f_utme_ln::'+document.getElementById('f_utme_ln').value;
valuex += '|f_utmn_ln::'+document.getElementById('f_utmn_ln').value;
valuex += '|f_utmz_ln::'+document.getElementById('f_utmz_ln').value;
valuex += '|f_utme_rn::'+document.getElementById('f_utme_rn').value;
valuex += '|f_utmn_rn::'+document.getElementById('f_utmn_rn').value;
valuex += '|f_utmz_rn::'+document.getElementById('f_utmz_rn').value;
valuex += '|ctr_code::'+document.getElementById('ctr_code').value;
valuex += '|f_address::'+document.getElementById('f_address').value;



document.cookie = 'hlp_geo='+Base64.encode(valuex)+'; path=/; expires=' + ablauf.toGMTString();
}

function readCookie(name){
	
	var i=document.cookie.indexOf(name+"=");
	var c="";
	if(i>-1){
		var end=document.cookie.indexOf(";",i+name.length+1);
		if(end==-1){
			end=document.cookie.length;
		}
		c=document.cookie.substring(i+name.length+1,end);
	}
	return c;
}

function cookieToArray(name){
	var str=Base64.decode(readCookie(name));
	var temp=new Array();
	if(str!=""){
		str=str.replace(/\|/g,"\",\"");
		str=str.replace(/::/g,"=");
		str='"'+str+'"';
		eval("temp=["+str+"]");
		var c=new Array();
		for(var i=0;i<temp.length;i++){
			var index=temp[i].substring(0,temp[i].search("="));
			var val=temp[i].substring(temp[i].search("=")+1);
			c[index]=val;
		}
		return c;
	}else{
		return false;
	}
}

function setSelectContent( id, title, target )
{
	var x = 0;
	  for (i = 0; i <document.getElementById(target).length; ++i)
	  {
	    if (document.getElementById(target).options[i].text == title)
	    {
	 		x++;	
	    }
	  }

	if( !x )
	{
		NewItem = new Option(title, id, false, false);
		document.getElementById(target).options[document.getElementById(target).length] = NewItem;	
	}

}

function deleteSelectitems( field_id )
{
	for(var i = 0; i < document.getElementById(field_id).options.length; i++)
	{
		if( document.getElementById(field_id).options[i].selected == true )
		{
			document.getElementById(field_id).options[document.getElementById(field_id).selectedIndex] = null;
		}
		//document.getElementById(field_id).options[[i].selectedIndex] = null;
	}
}
