
//<!-- PrettyPhoto
$(function(){
  $("#lightBox a[rel^='prettyPhoto']").prettyPhoto({
  	theme: 'light_rounded'
  });
});
//-->

// Замена target="_blank"
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

window.onload = externalLinks;

function clearhtml( obj )
{
    $( obj ).html( '' );
}

// Добавление товара в корзину
function addcart( id )
{
   var count = $("#count"+id+" option:selected").val();
   $.get("/modules/basket/addcart.php", { id: id, count: count },
   function(data){
     var val = data.split('|');
     if ( val[2] =='1' )
        $("#basket").html( val[0] );
     else
        $("#basket").append( val[0] );
     $("#sumcart").html( val[1] );
     var note = $("#cartnotice" +id );
     note.html( "Товар добавлен в корзину!" );
     var notex = $("#cartnoticex" +id );
     notex.html("Товар добавлен в корзину!");
     $("#cartlink").attr("href", "/content/order");
     setTimeout( function () { note.html( "<a href='/content/order'>Оформить заказ</a>");notex.html( "");}, 2000 );
   });                           
   return false;
}

// Очистка корзины
function clearcart()
{
   if ( confirm( 'Очистить корзину?' ))
   {
      $.get("/modules/basket/clearcart.php", {},
      function(data){
      $("#basket").html( data );
      $("#sumcart").html( '' );
      });
   }
   return false;
}

/* Функция isValidEmail принимает один или 2 аргумента:
email - электронный адрес для проверки;
strict - необязательный логический параметр (true/false), который 
определяет строгую проверку при которой пробелы до и после адреса 
считаются ошибкой
В качестве результата функция возвращает либо true, либо false
*/

function checkemail( email, strict)
{
 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);
}

function showhide( id_div )
{
	if(document.getElementById(id_div).style.display=="none")
	{
		document.getElementById(id_div).style.display="block";
		document.getElementById(id_div + 'p').innerHTML = "-";
	}
	else
	{
		document.getElementById(id_div).style.display="none";
		document.getElementById(id_div + 'p').innerHTML = "+";
	}
}


function checkorder( validemail )
{
	if ( document.order.name.value=="" )
	{
		window.alert("Не указано имя!");
		return false;
	}
	if ( document.order.phone.value=="" )
	{
		window.alert("Не указан телефон!");
		return false;
	}
	if ( document.order.address.value=="" )
	{
		window.alert("Не указан адрес!");
		return false;
	}
	if ( validemail && document.order.email.value=="" )
	{
		window.alert("Не указан email!");
		return false;
	}
	if ( validemail && !checkemail( document.order.email.value, 0 ))
	{
		window.alert("Вы указали неверный email!");
		return false;
	}
   return true;
}

function checkform( what )
{
   var list = what.split(",");
                                 
   for ( var i = 0; i < list.length; i++ )
   {
	  if ( list[i] == 'name' && document.neoform.name.value=="" )
	     {	window.alert("Не указано имя!"); return false; }
	  if ( list[i] == 'phone' && document.neoform.phone.value=="" )
	     { window.alert("Не указан телефон!"); return false; }
	  if ( list[i] == 'email' )
	  {
	     if ( document.neoform.email.value=="" )
	     	  { window.alert("Не указан email!"); return false; }
        if ( !checkemail( document.neoform.email.value, 0 ))
	     {
		      window.alert("Вы указали неверный email!");
		      return false;
	     }
	  }
	  if ( list[i] == 'subject' && document.neoform.subject.value=="" )
	     	{ window.alert("Не указана тема!"); return false; }
	  if ( list[i] == 'message' && document.neoform.message.value=="" )
	     	{ window.alert("Не введено сообщение!"); return false; }
	  if ( list[i] == 'autocap' && document.neoform.autocap.value=="" )
	     	{ window.alert("Укажите проверочное число!"); return false; }
	}
   return true;
}

