var timer;
jQuery(document).ready(function($) {

	$('.input').bind('focus', Function("if(this.value==this.defaultValue) this.value='';"));
	$('.input').bind('blur', Function("if(this.value=='') this.value=this.defaultValue; "));
	

	
$('#closeform').click(function(){
	$('#addFeed').fadeOut(500);
});
$('#sendform').click(function(){
	if ( ValidateForm() )
	{
		$email = $('#email').val();
		$name = $('#name').val();
		$mess = $('#text').val();
		$type = $('#type').val();

		$.post("/index.php?id=18", { action:'SendFeed', name:$name, email:$email, type:$type, mess:$mess },function(data){
		$('#addFeed').fadeOut(500);
		document.location.href = '/feeds.html';

		});
	}
});


});
function ValidateForm()
{
	$('#email').removeClass('error');
	$('#name').removeClass('error');
	$('#text').removeClass('error');
	$valid = 1;
	$email = $('#email').val();
	$name = $('#name').val();
	$mess = $('#text').val();
	$type = $('#type').val();
	
	if ( !isValidEmailAddress($email) ) { $valid=0; $('#email').addClass('error'); }
	if ( strlen($name) < 3 || $name=='Ваше имя') { $valid=0; $('#name').addClass('error'); }
	if ( strlen($mess) < 3 || $mess=='Ваше сообщение' ) { $valid=0; $('#text').addClass('error'); }
	
	if ( $valid == 1 )
	{
		return true;
	}
	else
	{
		return false;
	}
}

/* PHP Analogicus */
function strlen( mixed_var ) {   return mixed_var.length; }
// Преобразует строку в нижний регистр
function strtolower( mixed_var ) {    return mixed_var.toLowerCase();   }
// Преобразует строку в верхний регистр
function strtoupper( mixed_var ) {   return mixed_var.toUpperCase();   }
// возвращает символ находящийся на позиции pos от начала слова. Аналог $string{pos}
function letter_posion(string, position) {   return string.charAt(position);   }
// Возвращает позицию первого вхождения подстроки needle в строку haystack.
function strpos( haystack, needle, offset ) {
   if(offset) offset = offset ;
   else offset = 0 ;
   return haystack.indexOf(needle, offset);
}
// Возвращает массив строк, полученных разбиением строки string с использованием separator в качестве разделителя.
function explode(separator, string, limit) {
   return string.split (seperator , limit);
}
 /* // PHP Analogicus */

function isValidEmailAddress(emailAddress)
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function testKey(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
  return /\w/.test(key);
}
function testFIO(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
  return /^[a-zА-Яа-я]+$/i.test(key);
}
function testKeyD(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {return true;}
  key = String.fromCharCode(key);
 return /[\d\.]/.test(key);
}
function testKeyTel(e)
{
  var key = (typeof e.charCode === 'undefined' ? e.keyCode : e.charCode);
  if (e.ctrlKey || e.altKey || key < 32) {  return true;}
  key = String.fromCharCode(key);
 return /[0+ .123456789 ()\-]/.test(key);
}


