

$(document).ready(function() {

 $('input[name="login"], input[name="password"]').keypress(function(e) {
    if(e.keyCode == 13) {
        ChekUserForma();                                                             // НАЖАТИЕ ЭНТЕРА
   }
 });

 $('input[name=words]').focus(function() { if (  $(this).val() == 'Я ищу...' ) $(this).val('') });
 $('input[name=words]').blur(function()  { if (! $(this).val() ) $(this).val('Я ищу...') });


 $('input[name=login]').val('Имя пользователя'); 
 $('input[name=login]').focus(function() { if (  $(this).val() == 'Имя пользователя' ) $(this).val('') });
 $('input[name=login]').blur(function()  { if (! $(this).val() ) $(this).val('Имя пользователя') });


 $('span.price2').each (function(){
 	if ($(this).html()) $(this).next('span.price').css('color', '#ff9d00');
 }); 
      


 $("div[align*='center']").find("a:contains('Создание Интернет-магазина'), a:contains('PHPShop')").each(function(index,elem){ 
	        $("div.footerin ul#doomquake").after($(elem).parent().parent().outerHTML());
		$(elem).parent().parent().remove(); 
		$("div.footerin ul#doomquake").find("a:contains('Создание Интернет-магазина'), a:contains('PHPShop')").parent().addClass("phpshopcopy");
 });


 
             	
  $("h2:contains('Товаров выбранного типа сегодня нет в продаже')").parent().parent().prev("div.hot").remove(); 
  $("h2:contains('Товаров выбранного типа сегодня нет в продаже')").parent().parent().remove();            	            
  

  // НЕ РАЗВОРАЧИВАТЬ МЕНЮ
              
 
  found0 = document.location.href.match(/CID_(\d+)\./);
  var currentcid = found0 ? found0[1] : 0; 
  $("span").each(function(){
       	if (found = $(this).outerHTML().match(/pressbutt\((\d+?)\,/i))
	{
                                                                      		
			var cid = found[1];       			
			var newlocation = "/shop/CID_" + cid + ".html";
        		                    
			$(this).attr("onclick", "");
		
			$(this).click(function(e){
                        	document.location.href='http://topspin-shop.ru' + newlocation;
				e.preventDefault();
			});                  
			
			$(this).css("cursor", "pointer") ;
        		if (cid == currentcid) $(this).parent().attr("id", "currentmenu");
			                          		
	}	

  });
                
  $("li.catalog a").each(function(){
	if (found2 = $(this).attr("href").match(/CID_(\d+)\./)) { 
		if (found2[1] == currentcid) {
			$(this).parent().attr("id", "currentmenu") 
		}
	}
 });	


 /**********************/
  


 if ($("div#price3").text().length <3) { $("div#price3").css("display", "none"); }    // если пустая цена


 // ВЫБИРАЛКА ИЗ ДРОПДАУНА
 if ($basket1 = $("a[href*='AddToCartParent']"))
 {

	if ($("select#parentId option").length)
	{


    
		$("select#parentId").parent().parent().css("display", "none");
 		$("select#parentId option").each(function(index, value){



        		$newbasket1 = $($basket1).clone();
			$newbasket1.data('srcelem', $(this));  

 			$newbasket1.click(function(e){
				
				$(this).data('srcelem').parent().val($(this).data('srcelem').val());  // =)         
				//console.log ($(this));
				
				//e.preventDefault();
			});

			$table1 = $("table#table-addtocart");


			if (found = $(this).text().match(/(.*)\s*\-.*?\((.*)\)/))
			{
				nazv  = found[1];
				price = found[2]; 		
				//$table1.append($('<tr><td class="buytovarname">' + nazv + '</td><td class="buytovarprice">' + price + '</td><td class="buytovarbuy">' + $($newbasket1).outerHTML() + '</td></tr>')); 	   	
				$table1.append($('<tr><td class="buytovarname">' + nazv + '</td><td class="buytovarprice">' + price + '</td><td class="buytovarbuy"><div name="nbd' + index + '"></div></td></tr>')); 	   	
				$("div[name='nbd" + index + "']").append ($newbasket1);
         	       }
 		});
 	}
 

	if ($("select#parentId").length && !$("select#parentId option").length)     // пустой селект
	{
    
      		$("table#table-addtocart").remove();
		$("select#parentId").remove();
		$("a[href*='AddToCartParent']").addClass("vcartnew");
		$("a[href*='AddToCartParent'] img").remove();
		$("div.tovarsaddtocart table").first().css("width", "100%");

		$("a[href*='AddToCartParent']").attr("href", $("a[href*='AddToCartParent']").attr("href").replace("Parent", "")); // удаляем Parent в href 


 	}




 }
             
 if ($("select#parentId").length==0) { $("table#table-addtocart").remove(); }                       
 $("div:contains('Доступно изображений')").last().remove(); 


 $("div.supernav").each(function() { 
	$(this).html($(this).html().replace(/Страница\:/, "<div></div>"));
 });
 
 if (document.location.href.match(/newtip|spec|newprice|search/)) {
	console.log ("THIS");
	$("div:contains('Страница:'), tr:contains('Страница:'),  td:contains('Страница:')").each(function() { 
		$(this).html($(this).html().replace(/Страница:/, "<div></div>"));
	})
 } 

 if (document.location.href.match(/order/))
 {      
 	$("div.cartcontent tr:odd td[class*='product']").addClass("bg_odd");
	$("div.cartcontent tr:even td[class*='product']").addClass("bg_even");
 }

 if (document.location.href.match(/CID_124\.html/) || document.location.href.match(/CID_124_.*?\.html/))
 {      
 	$("div.bluenavbuttons div.supernav").remove();
 	$("div.supernav").find(":contains('Страница')").parent().remove();
 }

 

 if (document.location.href.match(/(CID_45|CID_1|CID_17588|CID_93)\.html/))
 {      
	$("div.supernav").remove(); 
 }

	

 


});

          

