/* Help boxes */
addLoadEvent(prepareInputsForHints);

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

function helpboxParser(current) {
 	// While the span exists and we didn't find the right one
	for (var j = 0; j < current.parentNode.getElementsByTagName('span').length; j++) {

		// For each attribut
		for(var k = 0; k < current.parentNode.getElementsByTagName('span')[j].attributes.length; k++)
			// If it's the attribut "name" and its value is "help_box"
			if (current.parentNode.getElementsByTagName('span')[j].attributes[k].name === 'name' && current.parentNode.getElementsByTagName('span')[j].attributes[k].nodeValue === 'help_box') {
				// We finaly found it
				return j;
			}
	}
	return -1;
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName('input');
	var found;

	// For each input
	for (var i=0; i<inputs.length; i++) {
		// on focus, show the hint
		inputs[i].onfocus = function () {
			var id = helpboxParser(this);
			if (id > -1)
				this.parentNode.getElementsByTagName('span')[id].style.display = 'inline';
		}
		// when the cursor moves away from the field, hide the hint
		inputs[i].onblur = function () {
		 	var id = helpboxParser(this);
		 	if (id > -1)
				this.parentNode.getElementsByTagName('span')[id].style.display = 'none';
		}
	}
}
/* Help box bitişi*/

/* Maili yazıdır */
function str2email(str,encoding,ucfirst)
{
	str = str.toUpperCase();
	str = str.toLowerCase();


	str = str.replace(/[^a-z0-9@.\s\'\:\/\[\]-]_]/g,'');
	str = str.replace(/[ ]/g,'');
	str = str.replace(/[:]/g,'');


	if (ucfirst == 1) {
		c = str.charAt(0);
		str = c.toUpperCase()+str.slice(1);
	}

	return str;
}
/* Mail Kontrol Bitişi*/
function str2tel(str,encoding,ucfirst)
{
	str = str.toUpperCase();
	str = str.toLowerCase();


	str = str.replace(/[^0-9+\s\'\:\/\[\]-]/g,'');
	str = str.replace(/[\s\'\:\/\[\]-]+/g,' ');



	if (ucfirst == 1) {
		c = str.charAt(0);
		str = c.toUpperCase()+str.slice(1);
	}

	return str;
}





function copy2friendlyURL()
{
	getE('link_rewrite').value = str2url(getE('name').value.replace(/^[0-9]+\./, ''), 'UTF-8');
}

function str2url(str,encoding,ucfirst)
{
	str = str.toUpperCase();
	str = str.toLowerCase();

	str = str.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/g,'a');
	str = str.replace(/[\u00E7]/g,'c');
	str = str.replace(/[\u00E8\u00E9\u00EA\u00EB]/g,'e');
	str = str.replace(/[\u00EC\u00ED\u00EE\u00EF]/g,'i');
	str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8]/g,'o');
	str = str.replace(/[\u00F9\u00FA\u00FB\u00FC]/g,'u');
	str = str.replace(/[\u00FD\u00FF]/g,'y');
	str = str.replace(/[\u00F1]/g,'n');
	str = str.replace(/[\u0153]/g,'oe');
	str = str.replace(/[\u00E6]/g,'ae');
	str = str.replace(/[\u00DF]/g,'ss');

	str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]/g,'');
	str = str.replace(/[\s\'\:\/\[\]-]+/g,' ');
	str = str.replace(/[ ]/g,'-');

	if (ucfirst == 1) {
		c = str.charAt(0);
		str = c.toUpperCase()+str.slice(1);
	}

	return str;
}



function getE(name)
{
	if (document.getElementById)
		var elem = document.getElementById(name);
	else if (document.all)
		var elem = document.all[name];
	else if (document.layers)
		var elem = document.layers[name];
	return elem;
}















/* Help boxes */
addLoadEvent(prepareInputsForHints);

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

function helpboxParser(current) {
 	// While the span exists and we didn't find the right one
	for (var j = 0; j < current.parentNode.getElementsByTagName('span').length; j++) {

		// For each attribut
		for(var k = 0; k < current.parentNode.getElementsByTagName('span')[j].attributes.length; k++)
			// If it's the attribut "name" and its value is "help_box"
			if (current.parentNode.getElementsByTagName('span')[j].attributes[k].name === 'name' && current.parentNode.getElementsByTagName('span')[j].attributes[k].nodeValue === 'help_box') {
				// We finaly found it
				return j;
			}
	}
	return -1;
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName('input');
	var found;

	// For each input
	for (var i=0; i<inputs.length; i++) {
		// on focus, show the hint
		inputs[i].onfocus = function () {
			var id = helpboxParser(this);
			if (id > -1)
				this.parentNode.getElementsByTagName('span')[id].style.display = 'inline';
		}
		// when the cursor moves away from the field, hide the hint
		inputs[i].onblur = function () {
		 	var id = helpboxParser(this);
		 	if (id > -1)
				this.parentNode.getElementsByTagName('span')[id].style.display = 'none';
		}
	}
}

	










