function isValidEmail (email, strict)
{if (email!="")
{
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}
else return false;
}
function isValidinte (chislo)
{ if (chislo!="") return (/([\d])+/).test(chislo);
 else return false;
}
function show_error_message(c){
if(c == -1)
$(".loadtxt").html("<div class=error>Ошибка добавления данных. Нельзя так часто жмакать по кнопке.</div>");
    		else if(c == -2)$(".loadtxt").html("<div class=error>Ошибка добавления данных. Ошибка базы данных.</div>");
    		else $(".loadtxt").html("<div class=error>Ошибка добавления данных.</div>");
   			$(".loadtxt").show();
   			$(".load").hide();
   			$.fn.fancybox.changeItem(0);
   			return false;
    	}
function SendForm()
{  var i=0;

  var minp=$("input[@name='kfam']");
  var kfam=minp.val();
  if (kfam=="")
  {
  	 i++;
  	 minp.css('background-color','red');  }
  else minp.css('background-color','white');
  minp=$("input[@name='kname']");
  var kname=minp.val();
  if (kname=="")
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kdd']");
  var kdd=minp.val();
  if (!isValidinte (kdd))
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kmm']");
  var kmm=minp.val();
  if (!isValidinte (kmm))
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kyy']");
  var kyy=minp.val();
  if (!isValidinte (kyy))
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='ktlf']");
  var ktlf=minp.val();
  if (ktlf=="")
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kemail']");
  var kemail=minp.val();
  if (!isValidEmail(kemail, true))
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kfilename']");
  var kfilename=minp.val();
  if (kfilename=="")
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');
  minp=$("input[@name='kfotogr']");
  var kfotogr=minp.val();
  if (kfotogr=="")
  {
  	 i++;
  	 minp.css('background-color','red');
  }
  else minp.css('background-color','white');

  if (i==0)
  {    return true;
  }else
  {    alert ("Все поля обязательны к заполнению");
    return false;
  }
}

function userpass_ch(comp, val, clas)
{
   if(comp.value=='') comp.value=val;
comp.className=clas;

}

function userpass_blur(comp, val, clas)
{
   if(comp.value==val) comp.value='';

comp.className=clas;
}

function setCookie(name, value) {
      var valueEscaped = escape(value);
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() + 24 * 60 * 60 * 1000);
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
}

function setCookieM(name, value, mon) {
      var valueEscaped = escape(value);
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() + mon*24 * 60 * 60 * 1000);
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
}


function getCookie(name) {
      var prefix = name + "=";
      var cookieStartIndex = document.cookie.indexOf(prefix);
      if (cookieStartIndex == -1) return null;
      var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
      if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
      return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie(name) {
if (getCookie(name)) {
      var valueEscaped = "";
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() - 24 * 60 * 60 * 1000);
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
     }
}

function clcpoll(comp)
{	var parentTag = $(comp).parent().get(0);
	var kids = $(parentTag).children(':input[@name^="polid"]').get(0);
	var id = $(kids).val();

    var PparentTag = $(parentTag).parent().get(0);
    var Pkids = $(PparentTag).children('div#inf').get(0);
    alert(id);
    $.post("http://svadba31.ru/common/ngpolls.php",
    {idp: id},function(data){    	$(Pkids).html(data)
    	alert(data);
    	});


	$(':input[@name^="polid"]').parent().each(function(i) {
   		$(this).fadeOut(500);
   		});

}

function EnabelFilter() {
if (document.filterform.issort.checked || document.filterform.isdate.checked)
{
if (document.filterform.issort.checked)
	{
 		setCookie('isfilter', '1');
		setCookie('filter', document.filterform.filter.value);
 		setCookie('filternapr', document.filterform.filternapr.value);
	}

if (document.filterform.isdate.checked)
	{
 		setCookie('isdate', '1');
		setCookie('fday', document.filterform.fday.value);
 		setCookie('fmonth', document.filterform.fmonth.value);
		setCookie('fyear', document.filterform.fyear.value);
	}
document.location=document.location;
}
else
{
deleteCookie('isfilter');
deleteCookie('filter');
deleteCookie('filternapr');
deleteCookie('isdate');
deleteCookie('fday');
deleteCookie('fmonth');
deleteCookie('fyear');
document.location=document.location;
}
}

function Mark(id) {

if (document.SpecMark.SpecialMark.checked)
   {
   setCookie('SpecialMark'+id, '1');
   }
else
   {
   deleteCookie('SpecialMark'+id);
   }
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function hfb()
{
$("div.fancycontentcostom").stop(false, true);
$("div.fancycontentcostom").toggle(500);
	return false;
}

$(document).ready(function()
{
	$("a.tooltipleft > div.hints").hide();
	$(".accordion-head > div.accordion-content").hide();
	$(".accordion > .accordion-head:first-child").children("div.accordion-content").show();

	$(".tooltipleft").mouseover(function(){
	var mysp =$(this).children("div.hints");
    var pos=$(this).offset();
	var left = pos.left-265;
    var top = pos.top-100;

	mysp.css('left', left);
	mysp.css('top', top);
	mysp.stop(false, true);
	mysp.fadeIn(500, function () {mysp.slideDown(500);});
	});

	$(".tooltipleft").mouseout(
	function()
	{
	var mysp =$(this).children("div.hints");
	mysp.stop(false, true);
	mysp.fadeOut(500, function () {mysp.slideUp(500);});
	});

	$(".accordion-head").mouseover(function(){
	$(this).stop(false, true);
	$(this).animate({backgroundPosition: "0px 0px"}, 500);
	});

	$(".accordion-head").mouseout(function(){
	$(this).stop(false, true);
	$(this).animate({backgroundPosition: "0px -35px"}, 500);
	});

	$(".accordion-head").click(function(){
	if ($(this).children("div.accordion-content").is(":hidden")){
	$(this).stop(false, true);
	$(".accordion-head > div.accordion-content:visible").slideUp(500);
	$(this).children("div.accordion-content:hidden").slideToggle(500); }
	});

	 $("#gallery a").fancybox({
    	hideOnContentClick: true,
    	overlayShow: true,
    	overlayOpacity: 0.5,
    	zoomSpeedIn: 1500,
    	zoomSpeedOut:600
    });

    var ccu=getCookie('novis');

    $('div#nevg').hide();
    var left = getClientWidth();
	left = ((left/2)-215).toFixed(0);
    var top = getClientHeight();
    top = ((top/2)-135).toFixed(0);
    $('div#nevg').css('left', left);
    $('div#nevg').css('top', top);

    if (ccu<2) $('div#nevg').show(500);

    $('div#nevg_close').click(function() {
    var ccu=getCookie('novis');
    ccu++;
    setCookieM('novis', ccu, 365);
    $('div#nevg').hide(500);
    });

    $(':input[@name^="submitpoll"]').click(function() {
    clcpoll($(this));
    });

    $("a#fancycontent").click(function(){	var left = getClientWidth();
	left = ((left/2)-200).toFixed(0);
    var top = getClientHeight();
    top = ((top/2)-225).toFixed(0);

	$("div.fancycontentcostom").css('left', left);
	$("div.fancycontentcostom").css('top', top);
	hfb();
	return false;
	});
});