﻿

function $(id){return document.getElementById(id);}

var search_0 = new Image();
search_0.src = "/assets/i/quiz/T_Search.gif";
var search_1 = new Image();
search_1.src = "/assets/i/quiz/T_SearchOn.gif";	

var voteSml_0 = new Image();
voteSml_0.src = "/assets/i/quiz/H_pVote.gif";
var voteSml_1 = new Image();
voteSml_1.src = "/assets/i/quiz/H_pVoteOn.gif";	

var vote_0 = new Image();
vote_0.src = "/assets/i/quiz/T_pVote.gif";
var vote_1 = new Image();
vote_1.src = "/assets/i/quiz/T_pVoteOn.gif";	


var submit_0 = new Image();
submit_0.src = "/assets/i/quiz/H_pSubmit.gif";
var submit_1 = new Image();
submit_1.src = "/assets/i/quiz/H_pSubmitOn.gif";	


function aOver(elm, id)
{
 elm.style.backgroundColor = '#DDF2BF';
}
function aOut(elm, id)
{
 elm.style.backgroundColor = '#F2FAE5';
}



function aClick(elm, id, type)
{
  if(type == 0)
  {
    $(id).checked = true;
  }
  else
  {
    if($(id).checked)
    {
      $(id).checked = false;
    }
    else
    {
      $(id).checked = true;
    }
  }  
}


function iOver(elm, id)
{
 elm.style.backgroundColor = '#FDFFDC';
}

function iOut(elm, id)
{
 elm.style.backgroundColor = '#FFFFFF';
}
function iClick(elm, id)
{
  window.location = 'poll.cfm?poll_id='+ id;
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function vote(id, poll_other, rand, poll_type,u)
{
 
 var answerString = '';
 var otherText = '';
 
 for(i=0; i<document.formPoll.elements.length; i++)
  {
    if(document.formPoll.elements[i].type=="checkbox" || document.formPoll.elements[i].type=="radio")
    {
      if(document.formPoll.elements[i].checked)
      {
        answerString +=document.formPoll.elements[i].value + ',';
      }
    }
  }
 
 if(poll_other == 1)
 {
   otherText = $('PDI_OtherText').value;
 }

 if(answerString.length > 0 || otherText.length > 0)
 {
   	//Set_Cookie( 'Fatsa_poll_'+id, 'true', 30, '/', '', '' ); 
   location.href = '/quiz/pollVote.cfm?va='+u+'&pt='+poll_type+'&r='+rand+'&p='+ id +'&a='+ answerString +'&o='+ otherText;
 }
 else
 {
   alert('Παρακαλώ επιλέξτε την απάντησή σας πρώτα!');
 }
}

var vote_0 = new Image();
vote_0.src = "/assets/i/quiz/T_pVote.gif";
var vote_1 = new Image();
vote_1.src = "/assets/i/quiz/T_pVoteOn.gif";	

var submit_0 = new Image();
submit_0.src = "/assets/i/quiz/T_pSubmit.gif";
var submit_1 = new Image();
submit_1.src = "/assets/i/quiz/T_pSubmitOn.gif";	

function countChars(elm)
{
  if(elm.value.length >= 4000)
  {
    elm.value = left(elm.value, 4000);
  }
  $('charCount').innerHTML = elm.value.length;
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}


function isEmail(add){
  if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(add))
  {return true;}else{return false;}}			

String.prototype.trim = function(){
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function submitComment()
{
  var pass = true;
  
  if($('cName').value.trim().length < 1)
  {pass = false;$('cNameErr').style.display = 'block';}
  else{$('cNameErr').style.display = 'none';}

  if(!isEmail($('cEmail').value))
  {pass = false;$('cEmailErr').style.display = 'block';}
  else{$('cEmailErr').style.display = 'none';}
  
  if($('cCap').value.trim().length < 1)
  {pass = false;$('cCapErr').style.display = 'block';}
  else{$('cCapErr').style.display = 'none';}

  if($('cText').value.trim().length < 1)
  {pass = false;$('cTextErr').style.display = 'block';}
  else
  {$('cTextErr').style.display = 'none';}

  if(pass)
  {
    $('formComment').submit();
  }
}

var scrollTO;
function goScroll()
{
  scrollTO = setTimeout('doScroll()',500);
}

function stopScroll()
{
  if(scrollTO)
  {
    clearTimeout(scrollTO);
  }
}

var pointer = 0;
var opacity = 0;

function doScroll()
{
  var EvString = '';
  var thisPointer = pointer;
  var choosenOne = '';
  
  for(count=1; count <= 4; count++)
  {

      if(count == 4)
      {
        choosenOne = 'id="choosenOne" style="opacity:0;"';    
      }
      else
      {
        choosenOne = '';
      }
    switch(Tev[thisPointer].toString().split('|')[0])
    {
      case '1': {EvString = '<div class="item1" '+choosenOne+' style="display:inline-block;">Ψήφος για: <a href="poll.cfm?poll_id='+ Tev[thisPointer].toString().split('|')[1] +'">'+ Tev[thisPointer].toString().split('|')[2] +'</a><br/> <span>('+ Tev[thisPointer].toString().split('|')[3] +')</span></div>'+ EvString; break;}
      case '2': {EvString = '<div class="item2" '+choosenOne+' style="display:inline-block;">Δημιουργήθηκε Ψηφοφορία: <a href="poll.cfm?poll_id='+ Tev[thisPointer].toString().split('|')[1] +'">'+ Tev[thisPointer].toString().split('|')[2] +'</a><br/> <span>('+ Tev[thisPointer].toString().split('|')[3] +')</span></div>'+ EvString; break;}
      case '3': {EvString = '<div class="item3" '+choosenOne+' style="display:inline-block;">Νέο Σχόλιο:  <a href="poll.cfm?poll_id='+ Tev[thisPointer].toString().split('|')[1] +'">'+ Tev[thisPointer].toString().split('|')[2] +'</a><br/> <span>('+ Tev[thisPointer].toString().split('|')[3] +')</span></div>'+ EvString; break;}
    }
    thisPointer++;
    
    if(thisPointer > (Tev.length - 1))
    {
      thisPointer = 0;
    }
  }
  
  pointer++;
  if(pointer > (Tev.length - 1))
  {
    pointer = 0;
  }

  $('TScroller').innerHTML = EvString;
  opacity = 0;
  appear();
  scrollTO = setTimeout("doScroll()",3000);
}



function appear()
{
  if(document.all)
  {
    $('choosenOne').style.filter = 'alpha(opacity=' + opacity + ')';
  }
  else
  {
    $('choosenOne').style.opacity = opacity/100;
  }

  opacity = opacity + 20;
  if(opacity < 100)
  {
    setTimeout("appear()",150);
  }
}


function hChange(type, period)
{
  if(type == 'popular')
  {
    $('recentHead').innerHTML = '<span>Δημοφιλείς</span> | <a href="javascript:hChange(\'recent\',\'all\');">Πρόσφατες</a>';
    if(period == 'week'){$('recentSub').innerHTML = 'Εβδομάδας | <a href="javascript:hChange(\'popular\',\'month\');"><u>Μήνα</u></a> | <a href="javascript:hChange(\'popular\',\'all\');"><u>Πάντα</u></a>';}
    if(period == 'month'){$('recentSub').innerHTML = '<a href="javascript:hChange(\'popular\',\'week\');"><u>Εβδομάδας</u></a> | Μήνα | <a href="javascript:hChange(\'popular\',\'all\');"><u>Πάντα</u></a>';}
    if(period == 'all'){$('recentSub').innerHTML = '<a href="javascript:hChange(\'popular\',\'week\');"><u>Εβδομάδας</u></a> | <a href="javascript:hChange(\'popular\',\'month\');"><u>Μήνα</u></a> | Πάντα';}
  }
  else
  {
    $('recentHead').innerHTML = '<a href="javascript:hChange(\'popular\',\'week\');">Δημοφιλείς</a> | <span>Πρόσφατες</span>';
    $('recentSub').innerHTML = '&nbsp;';
  }
  var params = '?type='+ type +'&period='+ period;
  $('hRec').innerHTML = '<div class="loading">φόρτωση Περιεχομένου...</div>';
  makeRequest('A_recent.cfm', params, $('hRec'));
}


function alertPostContents()
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
    	return true;
		}
		else
		{
    	alert('Ουπς! Υπήρξε ένα πρόβλημα με το αίτημά σας, παρακαλώ ανανεώστε αυτή τη σελίδα και προσπαθήστε πάλι.');
    }
  }
}



function makeRequest(url, params, container, evalCode)
{
  http_request = false;
  if (window.XMLHttpRequest) // Mozilla, Safari,...
  {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType)
    {
      http_request.overrideMimeType('text/xml');
    }
  }
  else if (window.ActiveXObject)
  { // IE
    try
    {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
      }
    }
  }
  if (!http_request)
  {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
  
	http_request.onreadystatechange = function(){
    if (http_request.readyState == 4)
    {
      if (http_request.status == 200)
      {
		    result = http_request.responseText;
		    if(container)
		    {
          container.innerHTML = result;
        }
        eval(evalCode);
		  }
		  else
		  {
        //alert(http_request.responseText);
        
        alert('Υπήρξε κάποιο πρόβλημα με τον κεντρικό υπολογιστή.');
      }
    }
  }
	
  http_request.open('GET', url + params, true);
	http_request.send(null);
}

function T_go(id)
{
  location.href = 'poll.cfm?poll_id='+ id;
}

function T_search()
{
  if($('searchString').value.length == 0)
  {
    alert('Please enter a search term first!');
  }
  else
  {
    location.href= 'search.cfm?s='+ $('searchString').value;
  }
}

function loadComments()
{
  $('comMidIn').innerHTML = '<form method="post" action="submitComment.cfm" name="formComment" id="formComment">'+ $('comMidIn').innerHTML +'</form>';
  $('comMidIn').style.display = 'block';
}

function findX(obj){
  var curleft = 0;
  if(obj.offsetParent)
    while(1) 
    {curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;}
  else if(obj.x)
    curleft += obj.x;
  return curleft;
}

function findY(obj){
  var curtop = 0;
  if(obj.offsetParent)
    while(1)
    {curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;}
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}

