

/* http://www.askthecssguy.com/2006/12/row_locking_with_css_and_javas.html */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function highlightRows()
{
  if(!document.getElementsByTagName) return false;
  var tbodies = document.getElementsByTagName("ul");
  for (var j=0; j<tbodies.length; j++)
  {
    var rows = tbodies[j].getElementsByTagName("li");
    for (var i=0; i<rows.length; i++)
    {
      if (rows[i].className.indexOf("selectedx") == -1)
      {
        rows[i].oldClassName = rows[i].className;
        rows[i].onmouseover = function() {
          addClass(this,"highlightx");
        }
        rows[i].onmouseout = function() {
          this.className = this.oldClassName
        }
      }
    }
  }
}

function lockRow(ulid, liid)
{
  var tbodies = document.getElementById("ul_"+ulid);

  var rows = tbodies.getElementsByTagName("li");
  for (var i=0; i<rows.length; i++)
  {
    rows[i].oldClassName = rows[i].className;
  }
  var selectedli = document.getElementById("li_"+liid);
  if (selectedli.className.indexOf("selectedx") != -1)
  selectedli.className = this.oldClassName;
  else addClass(selectedli, "selectedx");
  for (var i=0; i<rows.length; i++)
  {
    if(rows[i].id != selectedli.id) {
      rows[i].className = "";
      rows[i].oldClassName = "";
    }
  }
}

addLoadEvent(highlightRows);
//addLoadEvent(lockRow);



/**
* myutil.js
*
* @package    yobombo
* @subpackage myutil
* @author     Ahmet ERtek
* @version    1.0
* @desc       selects all/none options in a select box
*/
function selectboxAll(selectBoxObject,selectStatus)
{
  if(selectBoxObject)
  {
    var len=selectBoxObject.length;
    for(var i=0;i<len;i++)
    {
      selectBoxObject.options[i].selected=selectStatus;
    }
  }
}

/**
* myutil.js
*
* @package    yobombo
* @subpackage myutil
* @author     Ahmet ERtek
* @version    1.0
* @desc       selects all/none checkboxes using their id
*
*/
function selectAllDiffCheckBoxesById(checkboxId, CheckValue,checkboxCount)
{
  for(var i = 1; i <= checkboxCount; i++)
  {
    objCheckBox=document.getElementById(""+checkboxId+i);
    if(objCheckBox)
    objCheckBox.checked = CheckValue;
  }
}

/**
* myutil.js
*
* @package    yobombo
* @subpackage myutil
* @author     Ahmet ERtek
* @version    1.0
* @desc       selects all/none checkboxes using their form name and their name
*
*/
function selectAllCheckBoxes(FormName, FieldName, CheckValue)
{
  if(!document.forms[FormName])
  {
    return;
  }

  var objCheckBoxes = document.forms[FormName].elements[FieldName];
  if(!objCheckBoxes)
  {
    return;
  }
  var countCheckBoxes = objCheckBoxes.length;
  if(!countCheckBoxes)
  objCheckBoxes.checked = CheckValue;
  else
  // set the check value for all check boxes
  for(var i = 0; i < countCheckBoxes; i++)
  objCheckBoxes[i].checked = CheckValue;
}


function highlight_stars(id, note, do_highlight)
{
  for (var i = 1 ; i <= note ; i++)
  {
    if(do_highlight)
    Element.addClassName($('vote_'+id+'_'+i), 'ratehover');
    else
    Element.removeClassName($('vote_'+id+'_'+i), 'ratehover');
  }
}

function highlight_VotedStars(id, note, do_highlight)
{
  for (var i = 1 ; i <= note ; i++)
  {
    if(do_highlight)
    {
      if(!Element.hasClassName(document.getElementById('voted_'+id+'_'+i), 'ratehover'))
      Element.addClassName(document.getElementById('voted_'+id+'_'+i), 'ratehover');
    }
    else
    {
      if(Element.hasClassName(document.getElementById('voted_'+id+'_'+i), 'ratehover'))
      Element.removeClassName(document.getElementById('voted_'+id+'_'+i), 'ratehover');
    }
  }
}

function checkTestProfil(F) 
{
  var string = trim(F.elements[0].value);
  var name = (F.name == 'test_form') ? 'Test' : 'Kullanıcı';
  
  if(string.length < 3) {
  	alert(name+' aramak için en az 3 karakter girmelisiniz');
  	return false;
  }
	
  return true;	
}

function checkEmail(mailfield) 
{
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (!filter.test(mailfield.value)) 
  {
    alert('Lütfen geçerli bir e-posta adresi giriniz');
    mailfield.focus;
    return false;
  }
  return true;
}

function deletePicture()
{
  if(confirm('Resmi silmek istediğinize emin misiniz?')) {
  	window.document.forms['profil_form'].elements['resmi_sil'].value = 1;
  	window.document.forms['profil_form'].elements['fotograf_sil'].value = 0;
  	window.document.forms['profil_form'].elements['video_sil'].value = 0;
    return true;
  }
  return false;
}

function deletePhotos(F, photoCount)
{
  var counter = 0;  
  for(i=1; i<=photoCount; i++)
  {
  	if(F.elements['photo_'+i].checked == true) counter++;
  }
  if(counter == 0) {
  	alert('Lütfen silmek istediğiniz fotoğrafları seçiniz!');
  	return false;
  }
  else if(confirm('Seçili fotoğraf(lar)ı silmek istediğinize emin misiniz?')) {
  	window.document.forms['profil_form'].elements['fotograf_sil'].value = 1;
  	window.document.forms['profil_form'].elements['resmi_sil'].value = 0;
  	window.document.forms['profil_form'].elements['video_sil'].value = 0;
    return true;  	
  }
  return false;
}

function deleteVideos(F, videoCount)
{
  var counter = 0;  
  for(i=1; i<=videoCount; i++)
  {
  	if(F.elements['video_'+i].checked == true) counter++;
  }
  if(counter == 0) {
  	alert('Lütfen silmek istediğiniz videoları seçiniz!');
  	return false;
  }
  else if(confirm('Seçili video(lar)ı silmek istediğinize emin misiniz?')) {
  	window.document.forms['profil_form'].elements['video_sil'].value = 1;
  	window.document.forms['profil_form'].elements['resmi_sil'].value = 0;
  	window.document.forms['profil_form'].elements['fotograf_sil'].value = 0;
    return true;  	
  }
  return false;
}

function hideDisplay(source, dest)
{
  document.getElementById(source).style.display = 'none';  	
  document.getElementById(dest).style.display   = 'block';
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

