/*
	linkwall
	by michael palmer
	c 2008 michaelpalmer.de
*/
  
function checkPwLive(passwort)
{
  var avg = 0;
  var returnDiv = "";
  for(x=0; x < passwort.length; x++)
  {
    if (passwort.charAt(x).match(/^[0-9]$/)) 
    {
      avg += 20;
    }
    else if (passwort.charAt(x).match(/^[a-z]$/)) 
    {
      avg += 5;
    }
    else if (passwort.charAt(x).match(/^[A-Z]$/)) 
    {
      avg += 10;
    }
    else if (passwort.charAt(x).match(/\D/)) 
    {
      avg += 25;
    }
  }
  
  document.getElementById('sec1').style.backgroundColor = "#d90011";
  document.getElementById('sec2').style.backgroundColor = "#cccccc";
  document.getElementById('sec3').style.backgroundColor = "#cccccc";
  document.getElementById('sec4').style.backgroundColor = "#cccccc";
  
  if(avg > 49) document.getElementById('sec2').style.backgroundColor = "#ff6600";
  if(avg > 74 && passwort.length > 4) document.getElementById('sec3').style.backgroundColor = "#ffff33";
  if(avg > 99 && passwort.length > 4) document.getElementById('sec4').style.backgroundColor = "#33cc00";
}

//var check = window.setInterval("checkPwLive()", 2000);
    
window.onload = function() {
		new Draggable ($("div_login"),{revert:true});
}

function changeMainContent(showMainContent)
{
  showMainContent = showMainContent ? showMainContent : 'topRatedToday';
  var url = "../html/"+showMainContent+".php";
  //$('mainContent').innerHTML = '';
    
  new Ajax.Updater({ success: "mainContent", failure: 'mainContent'}, url,
  {
    method: 'get',
    onLoading: showLoadingPicture,
    onLoaded: function(t) {
        
        // subNav ausblenden
        $('subNav').innerHTML = '';
        $('showCats').innerHTML = '';
        hideLoadingPicture();
    }
  }); 

}

function changeComplete(module, see, linkcat, current)
{
  new Ajax.Request('index.php', 
    {method:'get',
    asynchronous:true, 
    onSuccess: function(t) {
        document.documentElement.innerHTML= t.responseText;
        // subNav ausblenden
        $('subNav').innerHTML = '';
        $('showCats').innerHTML = '';
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture, 
    parameters:'module='+module+'&see='+see+'&linkcat='+linkcat+'&current='+current});
}

  /*
    global functions
  */
  function showLoadingPicture(){
    $('ajax_loader').style.visibility = "visible";
    $('busy_layer').style.visibility = "visible";
  }  
  
  function hideLoadingPicture(){
    $('ajax_loader').style.visibility = "hidden";
    $('busy_layer').style.visibility = "hidden";
  }

  function selectCat(catid){
    $('selectedLinkCat').value = catid;
    $('newSee').value = 'all';
    $('selectCategorie').submit();
  }
    
/*
  moderation functions
*/
function doDelete(){
  var question = "Willst Du diesen Eintrag wirklich entfernen?";
  Check = confirm(unescape(question));
  if(Check==true){
  	return true;
  }
  return false;
}

function spamIt(linkID)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 delete work");
        self.location = self.location;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&deleteOption=true'});
}

function deleteLink(linkID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 delete work");
        self.location = self.location;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&deleteOption=true'});
}

function blacklistLink(linkID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 blacklist work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&blacklistOption=true'});
}

function blockLink(linkID)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 block work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&blockOption=true'});
}

function insertLink(linkID)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 insert work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&insertOption=true'});
}

function moveCat(catID, overCatID)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 move work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'CatID='+catID+'&overCatID='+overCatID+'&moveCatOption=true'});
}

function renameCat(catID, name)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 rename work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'catID='+catID+'&name='+name+'&renameCatOption=true'});
}

function deleteCat(catID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 delete work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'CatID='+catID+'&deleteCatOption=true'});
}

function deleteComment(comID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert(":(");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'ComID='+comID+'&deleteComOption=true'});
}

function markAsSpam(linkID, mark)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&mark='+mark+'&markAsSpam=true'});
}

function remakePassword(hash, user, newPW)
{
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        self.location = self.location+'&changed=true&oktext='+t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'hash='+hash+'&newPW='+newPW+'&user='+user+'&remakePasswordFromUser=true'});
}

function blacklistCat(catID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert("thx 4 blacklist work");
        self.location = self.location;
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'CatID='+catID+'&blacklistCatOption=true'});
}

function removeLink(linkID)
{
  if(doDelete())
  new Ajax.Request('../bin/clsModeration.php', 
    {asynchronous:true, 
    onSuccess: function(t) {
        //alert(":(");
        // jump out
        self.location = "";
        //$('mainContent').innerHTML = t.responseText;
    },
    onLoading: showLoadingPicture,
    onLoaded: hideLoadingPicture,
    parameters:'LinkID='+linkID+'&removeLinkOption=true'});
}

/*
  end of moderation functions
*/

/*
  bewertungen
*/
var RATING_IMG_FULL='star_full_gif';
var RATING_IMG_HALF='star_half_gif';
var RATING_IMG_EMPTY='star_empty_gif';

function addClass(element,_class){
  element.className=_class;
}

function removeClass(element,_class){
  element.className="";
}

function colorStars(starNum,linkId){
  for(var i=1;i<=starNum;i++)
  {
    removeClass($('star_'+linkId+"_"+i),RATING_IMG_EMPTY);
    removeClass($('star_'+linkId+"_"+i),RATING_IMG_HALF);
    addClass($('star_'+linkId+"_"+i),RATING_IMG_FULL);
  }
}

function makeClass4Half(starNum,linkId){
  removeClass($('star_'+linkId+"_"+starNum),RATING_IMG_EMPTY);
  removeClass($('star_'+linkId+"_"+starNum),RATING_IMG_FULL);
  addClass($('star_'+linkId+"_"+starNum),RATING_IMG_HALF);
}

function greyStars(linkId){
  for(var i=1;i<=5;i++)
  {
    removeClass($('star_'+linkId+"_"+i),RATING_IMG_FULL);
    removeClass($('star_'+linkId+"_"+i),RATING_IMG_HALF);
    addClass($('star_'+linkId+"_"+i),RATING_IMG_EMPTY);
  }
}

function clearStars(starNum,linkId){
  greyStars(linkId);
  setStars(starNum,linkId);
}

function showStars(starNum,linkId){
  greyStars(linkId);
  colorStars(starNum,linkId);
}

function setStars(starNum, linkID){
  if(starNum > 0)
    colorStars(starNum,linkID);
  if(starNum>1 && starNum<2) makeClass4Half(2,linkID);
  else if(starNum>2 && starNum<3) makeClass4Half(3,linkID);
  else if(starNum>3 && starNum<4) makeClass4Half(4,linkID);
  else if(starNum>4 && starNum<5) makeClass4Half(5,linkID);
}

function makeStars(starNum, linkID){
  new Ajax.Request('../cfg/insertRate.php', {asynchronous:true, 
    onSuccess: function(t) {
        //$('showRate_'+linkID).innerHTML = "";
        //$('makeRate_'+linkID+'_show2').innerHTML = "";
        //$('showRate_'+linkID).style.visibility = "hidden";
        //$('makeRate_'+linkID+'_show2').style.visibility = "hidden";
        $('showRate_'+linkID).style.display = "none";
        $('makeRate_'+linkID+'_show2').style.display = "none";
        //$('makeRate_'+linkID+'_hidden').style.width = "100%";
        //$('makeRate_'+linkID+'_hidden').style.width = "";
        //$('makeRate_'+linkID+'_hidden').style.visibility = "visible";
        $('makeRate_'+linkID+'_hidden').style.display = "inline"; 
    },
    // Handle 404
    on404: function(t) {

    },
    // Handle other errors
    onFailure: function(t) {

    },
    parameters:'rate='+starNum+'&linkID='+linkID+'&rateNOW=true'});
}

/*
  show helps texts
*/
// find out if ie runs in quirks mode
//
var docEl = (
             typeof document.compatMode != "undefined" && 
             document.compatMode        != "BackCompat"
            )? "documentElement" : "body";

function showHelps(name, e, direction){
  // position where mousemove fired
  //
  if(e || window.event){
    var xPos    =  e? e.pageX : window.event.x;
  	var yPos    =  e? e.pageY : window.event.y;
  }
	
	// for ie add scroll position
	//
	if (document.all && !document.captureEvents) {
	    xPos    += document[docEl].scrollLeft;
	    yPos    += document[docEl].scrollTop;
  }

  if(direction) {yPos+=30;xPos+=150;}
  
  $(name).style.display = "inline";
  $(name).setStyle({
    top: -5+yPos+"px",
    left: -150+xPos+"px"
  });
  
  if (document.layers) routeEvent(e);
}

function hideHelps(name){
  $(name).style.display = "none"; 
}


/*
  eof
*/
