/************************************************************************************
 *||==============================================================================||*
 *||  -> PROJECT: 3w4you CMS                                                      ||*
 *||  -> AUTHOR: Nicolas Pecher                                                   ||*
 *||  -> VERSION: 1.0                                                             ||*
 *||==============================================================================||*
************************************************************************************/

function popUp(imgUrl, width, height) 
{   
    document.getElementById('dialog').innerHTML = '<img src="' + imgUrl + '" alt="Wetterwarndienst" width="' + width + 'px" height="' + height + 'px" />';
    width = width + 30;
     $.fx.speeds._default = 1000;  
		$( "#dialog" ).dialog({
			show: "bounce",
			hide: "explode",
                        resizable: false,
                        minWidth: width,
                        minHeight: height
		});

}


// --- Formular - delete Value 
function deleteValue(fieldValue, fieldId)
{
    if (document.getElementById(fieldId).value == fieldValue) document.getElementById(fieldId).value = "";
}

// --- Formular - return Value
function returnValue(fieldValue, fieldId)
{
    if (document.getElementById(fieldId).value == "") document.getElementById(fieldId).value = fieldValue;
}

function weatherFormFocus() 
{
    if (document.getElementById("weather-ort").value == "Ort angeben...") 
    {
        document.getElementById("weather-ort").style.color = 'black';
        document.getElementById("weather-ort").value = "";    
    }
}

function weatherFormBlur() 
{
    if (document.getElementById("weather-ort").value == "")
    {
        document.getElementById("weather-ort").style.color = 'gray';
        document.getElementById("weather-ort").value = 'Ort angeben...';
    }
}

function showNews(box)
{
    if (box == 1)
    {
        $("#news_one").fadeIn(1000);
        document.getElementById("news_second").style.display = "none";
        document.getElementById("news_third").style.display = "none";
        document.getElementById("news_fourth").style.display = "none";


        document.getElementById("news_link_one").style.backgroundColor = "#c40001";
        document.getElementById("news_link_one").style.color = "#fff"; 

        document.getElementById("news_link_second").style.backgroundColor = "#ddd";
        document.getElementById("news_link_third").style.backgroundColor = "#ddd";
        document.getElementById("news_link_fourth").style.backgroundColor = "#ddd";
        document.getElementById("news_link_second").style.color = "#c40001"; 
        document.getElementById("news_link_third").style.color = "#c40001"; 
        document.getElementById("news_link_fourth").style.color = "#c40001"; 
    }
    else if (box == 2)
    {
        document.getElementById("news_one").style.display = "none";
        $("#news_second").fadeIn(1000);
        document.getElementById("news_third").style.display = "none";
        document.getElementById("news_fourth").style.display = "none";

        document.getElementById("news_link_second").style.backgroundColor = "#c40001";
        document.getElementById("news_link_second").style.color = "#fff"; 

        document.getElementById("news_link_one").style.backgroundColor = "#ddd";
        document.getElementById("news_link_third").style.backgroundColor = "#ddd";
        document.getElementById("news_link_fourth").style.backgroundColor = "#ddd";
        document.getElementById("news_link_one").style.color = "#c40001"; 
        document.getElementById("news_link_third").style.color = "#c40001"; 
        document.getElementById("news_link_fourth").style.color = "#c40001"; 
    }
    else if (box == 3)
    {
        document.getElementById("news_one").style.display = "none";
        document.getElementById("news_second").style.display = "none";
        $("#news_third").fadeIn(1000);
        document.getElementById("news_fourth").style.display = "none";

        document.getElementById("news_link_third").style.backgroundColor = "#c40001";
        document.getElementById("news_link_third").style.color = "#fff"; 

        document.getElementById("news_link_one").style.backgroundColor = "#ddd";
        document.getElementById("news_link_second").style.backgroundColor = "#ddd";
        document.getElementById("news_link_fourth").style.backgroundColor = "#ddd";
        document.getElementById("news_link_one").style.color = "#c40001"; 
        document.getElementById("news_link_second").style.color = "#c40001"; 
        document.getElementById("news_link_fourth").style.color = "#c40001"; 
    }
    else if (box == 4)
    {
        document.getElementById("news_one").style.display = "none";
        document.getElementById("news_second").style.display = "none";
        document.getElementById("news_third").style.display = "none";
        $("#news_fourth").fadeIn(1000);
        document.getElementById("news_link_fourth").style.backgroundColor = "#c40001";
        document.getElementById("news_link_fourth").style.color = "#fff"; 

        document.getElementById("news_link_one").style.backgroundColor = "#ddd";
        document.getElementById("news_link_second").style.backgroundColor = "#ddd";
        document.getElementById("news_link_third").style.backgroundColor = "#ddd";
        document.getElementById("news_link_one").style.color = "#c40001"; 
        document.getElementById("news_link_second").style.color = "#c40001"; 
        document.getElementById("news_link_third").style.color = "#c40001"; 
    }
}


function tframes()
{
    var frames = document.formular.query.value.length;
    if (frames > 150)
    {
        document.formular.query.value = document.formular.query.value.substr(0, 150);
        document.formular.frames.value = 0;
    }
    else
    {
        document.formular.frames.value = 150 - frames;
    }
}  

function showFadeInBox()
{
    $("#fadeInBox").fadeIn(1000);
}   

function hideFadeInBox()
{
    $("#fadeInBox").fadeOut(1000);
}            

	$(document).ready(function(){
	$('a[href*=#code]').click(function() {
	if (location.pathname.replace(/^\//,") == this.pathname.replace(/^\//,")
	&& location.hostname == this.hostname) {
	var $target = $(this.hash);
	$target = $target.length && $target
	|| $('[name=' + this.hash.slice(1) +']');
	if ($target.length) {
	var targetOffset = $target.offset().top;
	$('html,body')
	.animate({scrollTop: targetOffset}, 1000);
	return false;
	}
	}
	});
	});

function ImageMap(select){
   document.Formel.n[select].click()
  }
 
  function Farbpalette(){
   var Pinsel = document.Formel.Palette.options[document.Formel.Palette.selectedIndex].value
   if (document.Formel.n[0].checked==true) {document.Formel.A.value=Pinsel; document.Formel.A.select(); AA.style.background=Pinsel}
   if (document.Formel.n[1].checked==true) {document.Formel.B.value=Pinsel; document.Formel.B.select(); BB.style.background=Pinsel}
   if (document.Formel.n[2].checked==true) {document.Formel.C.value=Pinsel; document.Formel.C.select(); CC.style.background=Pinsel}
   if (document.Formel.n[3].checked==true) {document.Formel.D.value=Pinsel; document.Formel.D.select(); DD.style.background=Pinsel}
   if (document.Formel.n[4].checked==true) {document.Formel.E.value=Pinsel; document.Formel.E.select(); EE.style.background=Pinsel}
   if (document.Formel.n[5].checked==true) {document.Formel.F.value=Pinsel; document.Formel.F.select(); FF.style.background=Pinsel}
   if (document.Formel.n[6].checked==true) {document.Formel.G.value=Pinsel; document.Formel.G.select(); GG.style.background=Pinsel}
  }
 
  function CSScode_anzeigen(){
   document.Formel.code.value = '<style type="text/css">\r <!--\r  body {scrollbar-face-color:#'+document.Formel.A.value+';\r  scrollbar-track-color:#'+document.Formel.B.value+';\r  scrollbar-arrow-color:#'+document.Formel.C.value+';\r  scrollbar-highlight-color:#'+document.Formel.D.value+';\r  scrollbar-shadow-color:#'+document.Formel.E.value+';\r  scrollbar-3dlight-color:#'+document.Formel.F.value+';\r  scrollbar-darkshadow-color:#'+document.Formel.G.value+'}\r -->\r</style>'
  }
 
 function CSScode_vorschau(){
  var doc = parent.window.open("","fenster","directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,width=300,height=200");
  doc.document.open("text/html");
  doc.document.writeln("<title>Scrollbar Vorschau</title>")
  doc.document.writeln("<p>&nbsp;</p><h2 align=center>Scrollbar Vorschau</h2><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>")
  doc.document.writeln('<style type="text/css">\r <!--\r  body {scrollbar-face-color:#'+document.Formel.A.value+';\r  scrollbar-track-color:#'+document.Formel.B.value+';\r  scrollbar-arrow-color:#'+document.Formel.C.value+';\r  scrollbar-highlight-color:#'+document.Formel.D.value+';\r  scrollbar-shadow-color:#'+document.Formel.E.value+';\r  scrollbar-3dlight-color:#'+document.Formel.F.value+';\r  scrollbar-darkshadow-color:#'+document.Formel.G.value+'}\r -->\r</style>')
  doc.document.close()
  doc.document.focus()
}

function generate(){
 var bordsize = document.formname.bordsize.value;
 var bgurl = document.formname.bgurl.value;
 var delay = document.formname.delay.value;
 var samount = document.formname.samount.value;
 var wid = document.formname.wid.value;
 var hite = document.formname.hite.value;
 var yourimg = document.formname.yourimg.value;
 
 for (var i=0; i<document.formname.behave.length; i++)
 if (document.formname.behave[i].checked){
  var behave = document.formname.behave[i].value;
  break;
 }
 if(document.formname.loops[1].checked){
  var loops="false";
 }
 else{
  var loops="true";
 }
 if(document.formname.direct[1].checked){
  var direct="right";
 }
 else{
 var direct="left";
 }
 
 document.formname.gencode.value='<table border="'+bordsize+'">\n <tr>\n  <td style="background-image: url('+bgurl+');">\n   '+
 '<marquee direction="'+direct+'" scrolldelay="'+delay+'" behavior="'+behave+'" scrollamount="'+samount+'" width="'+wid+'" height="'+hite+'" loop="'+loops+'">\n'+
 '<img src="'+yourimg+'">\n'+
 '   <\/marquee>'+
 '\n  <\/td>\n <\/tr>\n<\/table>';
}
 
function preview() {
 if(document.formname.gencode.value){
  var look=open("","Preview","width=750,height=250,top=0,left=0,'resizable=1,status=0,menubar=0,toolbar=0,scrollbars=1,location=0,directories=0");
  look.document.write(document.formname.gencode.value);
 }
 else{
  alert('Bitte erst den Code erstellen!');
 }
}            

function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra) {
var numberChars = "0123456789";
var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
var charSet = extra;
if (number == true)
charSet += numberChars;
if (lower == true)
charSet += lowerChars;
if (upper == true)
charSet += upperChars;
if (other == true)
charSet += otherChars;
return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
latterNumber, latterLower, latterUpper, latterOther) {
var rc = "";
if (length > 0)
rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
for (var idx = 1; idx < length; ++idx) {
rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
}
return rc;
}            

function HTMLtoPHP()
{
    var old = document.Formel.input.value;
    document.Formel.output.value = "<?php \n";
    document.Formel.output.value += "echo '";
    document.Formel.output.value += old.replace(/'/gi, "\\'")+"';";
    document.Formel.output.value += "\n"+"?>";             
}            

function tickergenerator(){
 var o='<html>'
 o+='\r<head>'
 o+='\r<title>Newsticker<\/title>'
 o+='\r'
 o+='\r<script language="JavaScript">'
 o+='\r<!--\r'
 o+=' \/\/ Newsticker von [www.mc-free.com] - Plattfom fuer Kostenloses\r\r'
 o+='var max=0;'
 o+='\rfunction textlist(){max=textlist.arguments.length;for (i=0; i<max; i++) this[i]=textlist.arguments[i];}'
 o+='\rtl=new textlist'
 o+='\r('
 o+='\r" '+document.Form.n1.value+'",'
 o+='\r" '+document.Form.n2.value+'",'
 o+='\r" '+document.Form.n3.value+'",'
 o+='\r" '+document.Form.n4.value+'");'
 o+='\rvar x=0; pos=0;var l=tl[0].length;'
 o+='\rfunction textticker(){document.form1.textfeld.value=tl[x].substring(0,pos)+"_";if(pos++==l){pos=0;'
 o+='\rsetTimeout("textticker()",'+document.Form.pause.value+');'
 o+='\rx++;if(x==max) x=0;l=tl[x].length;} '
 o+='\relse setTimeout("textticker()",'+document.Form.speed.value+');}'
 o+='\r\/\/ -->'
 o+='\r<\/script>'
 o+='\r<\/head>'
 o+='\r'
 o+='\r<body onload="textticker()">'
 o+='\r<div align="center">'
 o+='\r<form name="form1">'
 o+='\r<input type="text" size="50" name="textfeld" value=" Willkommen " style="color: #'+document.Form.Farbe1.value+'; background-color: #'+document.Form.Farbe2.value+'; font-family: '+document.Form.font.value+'; font-size: '+document.Form.size.value+'px; border:0">\r<\/form>'
 o+='\r<\/div>'
 o+='\r'
 o+='\r<\/body>\r<\/html>'
 
 var doc = window.open("","fenster","directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,width=600,height=170");
 doc.document.open("text\/html");
 doc.document.writeln('<title>Newsticker Generator - Vorschau<\/title><center>'+o+'<br><br><br><\/center>')
 doc.document.close()
 document.Form.ausgabe.value=o
}
 
 function pruefeWert(){
  if (document.Form.speed.value > 150)
   {document.Form.speed.value = 150;
   }
 }
 
 function pruefeWert2(){
  if (document.Form.speed.value > 5000)
   {document.Form.pause.value = 1000;
   }
 }
 
 function loescheText(dasfeld){
  if (dasfeld.defaultValue==dasfeld.value)
  dasfeld.value = ""
 }
 
function Farbe_zeigen(A,B) {
 if (B.length == 6) {
  document.getElementById(A).style.backgroundColor=B;
 }
}        

        function diashow() 
        {
            var rand = Math.floor(Math.random()*8);
            if (rand == 0) rand++;
             for (var i = 1; i < 8; i++) {
                var id = "left" + i;
                if (i != rand) document.getElementById(id).style.display = "none";
                else document.getElementById(id).style.display = "block";

            }
        }  

        function diashowRight() 
        {
            var rand = Math.floor(Math.random()*8);
            if (rand == 0) rand++;
            for (var i = 1; i < 8; i++) {
                var id = "right" + i;
                if (i != rand) document.getElementById(id).style.display = "none";
                else document.getElementById(id).style.display = "block";

            }
        } 

/*
  Plugin: iframe autoheight jQuery Plugin
  Version: 1.5.0
  Description: when the page loads set the height of an iframe based on the height of its contents
  see README: http://github.com/house9/jquery-iframe-auto-height 
*/
(function(a){a.fn.iframeAutoHeight=function(b){function e(b,c){d("Diagnostics from '"+c+"'");try{d("  "+a(b,window.top.document).contents().find("body")[0].scrollHeight+" for ...find('body')[0].scrollHeight"),d("  "+a(b.contentWindow.document).height()+" for ...contentWindow.document).height()"),d("  "+a(b.contentWindow.document.body).height()+" for ...contentWindow.document.body).height()")}catch(e){d("  unable to check in this state")}d("End diagnostics -> results vary by browser and when diagnostics are requested")}function d(a){c.debug&&c.debug===!0&&window.console&&console.log(a)}var c=a.extend({heightOffset:0,minHeight:0,callback:function(a){},debug:!1,diagnostics:!1},b);d(c),a(this).each(function(){function f(b){c.diagnostics&&e(b,"resizeHeight");var f=a(b,window.top.document).contents().find("body"),g=f[0].scrollHeight+c.heightOffset;g<c.minHeight&&(d("new height is less than minHeight"),g=c.minHeight+c.heightOffset),d("New Height: "+g),b.style.height=g+"px",c.callback({newFrameHeight:g})}var b=0;d(this),c.diagnostics&&e(this,"each iframe");if(a.browser.safari||a.browser.opera){d("browser is webkit or opera"),a(this).load(function(){var a=0,c=this;c.style.height="0px";var e=function(){f(c)};b===0&&(a=500),d("load delay: "+a),setTimeout(e,a),b++});var g=a(this).attr("src");a(this).attr("src",""),a(this).attr("src",g)}else a(this).load(function(){f(this)})})}})(jQuery);
