function checkEnter(e) {
	var characterCode
	if(e && e.which) {
		e = e
		characterCode = e.which
	} else {
		e = event
		characterCode = e.keyCode
	}
	if(characterCode == 13) return true;
	return false;
}
function clearForm(form) {
  $(':input', form).each(function() {
    var type = this.type;
    var tag = this.tagName.toLowerCase();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = "";
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = 0;
  });
};

function _hide(el) {
	if ( $(el).css("display") == 'block')
		$(el).hide(0);
}
function showhide(el, speed) {
	if ( $(el).css("display") == 'none')
		$(el).show(speed);
	else
		$(el).hide(speed);
}
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
jQuery.fn.el_pos = function (top, left) {
    this.css("position","absolute");
    this.css("top", top + "px");
    this.css("left", left + "px");
    return this;
}

function new_row(id, text, type, mode, lang_id) {
	$.ajax ({
   type: "GET",
   url: "/inc/handlers/new_row.php",
   data: "id="+id+"&text="+encodeURIComponent(text)+"&type="+encodeURIComponent(type)+"&mode="+encodeURIComponent(mode)+"&lang_id="+lang_id,
   success: function(ret) {
	showall(id, 'inter_vari', 'allintervars', lang_id);
   }
 });
}
function showall(id, type, outid, lang_id) {
$('#pleasewait').fadeOut(100);$("#addnewinterrow").fadeIn(100);
$.ajax ({
   type: "GET",
   url: "/inc/handlers/showall.php",
   data: "id="+id+"&type="+encodeURIComponent(type)+"&lang_id="+lang_id,
   success: function(ret) {
   	var oAuto = eval("(" + ret + ")");
	$("#"+outid).html(oAuto.all);
	$("#"+outid).fadeIn(100);
	}
 });
}

function delrow(id, type, lang_id) {
	$.ajax ({
   type: "GET",
   url: "/inc/handlers/delrow.php",
   data: "id="+id+"&type="+encodeURIComponent(type)+"&lang_id="+lang_id,
   success: function(ret) {
   		var oAuto = eval("(" + ret + ")");
		showall(oAuto.section, 'inter_vari', 'allintervars', lang_id);
	}
 });
}

function saverow(id, text, type, lang_id) {
	$.ajax ({
   type: "GET",
   url: "/inc/handlers/saverow.php",
   data: "id="+id+"&text="+encodeURIComponent(text)+"&type="+encodeURIComponent(type)+"&lang_id="+lang_id,
   success: function(ret) {
   		var oAuto = eval("(" + ret + ")");
		showall(oAuto.section, 'inter_vari', 'allintervars', lang_id);
	}
 });
}

function contact(lang_id) {
	 var subjectid = $('#subject').val();
	 var subject = $("#subject option:selected").text();
     var message = $('#c_message').val();
     var name = $('#c_name').val();
     if (name == '') name = $('#c_name').text();
     var email = $('#c_email').val();
     if (email == '') email = $('#c_email').text();
$.ajax ({
   type: "POST",
   url: "/inc/handlers/contact.php",
   data: "subject="+subject+"&subjectid="+subjectid+"&message="+encodeURIComponent(message)+"&name="+encodeURIComponent(name)+"&email="+encodeURIComponent(email)+"&lang_id="+encodeURIComponent(lang_id),
   success: function(ret) {
  	var oRet = eval("(" + ret + ")");	
  	var cont_ok = oRet.cont_ok;
	$('#mess_error').html(oRet.mess_error);
	$('#name_error').html(oRet.name_error);
	$('#email_error').html(oRet.email_error);
	if (oRet.mess_error || oRet.name_error || oRet.email_error) $('#cont_ok').html('');
	if (cont_ok) {
		clearForm("#contact");
		$('#cont_ok').html(cont_ok);
	}
 }
 });
}



function interstart(type,id,lang_id) {
	all_intrchb_arr = new Array(); var o = 0;
	$("form :checkbox[name=var]:checked").each(
		function() { all_intrchb_arr[o] = this.value; o++; }
	);
	all_intrradio_arr = new Array(); var o = 0;
	$("form :radio[name=var]:checked").each(
		function() { all_intrradio_arr[o] = this.value; o++; }
	);

	// if(!all_intrradio_arr.length && !all_intrchb_arr.length)
// 	{
// 		$('#_error').fadeIn(100); 
// 	} 
// 	else 
	$('#_error').fadeOut(100);
	
$.ajax ({
   type: "POST",
   url: "/inc/handlers/interstart.php",
   data: "type="+type+"&id="+id+"&all_intrchb_arr="+all_intrchb_arr+"&all_intrradio_arr="+all_intrradio_arr+"&lang_id="+encodeURIComponent(lang_id),
   success: function(ret) {
  	var oRet = eval("(" + ret + ")");
  	var _ok = oRet._ok; var _error = oRet._error;
  	var _already = oRet._already;
  	var _results = oRet._results;
  	if(_error)
		$('#_error').fadeIn(100).html(_error);
	if (_ok)
		$('#_ok').fadeIn(100).html(_ok);
	if (_already) {
		$('#variants').fadeOut(1);
		$('#_error').fadeIn(100).html(_already);
	}
	if (_results)
		$('#results').fadeIn(100).html(_results);
		
 }
 });
}
