var dom = (document.getElementById) ? true : false;
var nn4 = (document.layers) ? true : false;
var ie = (document.all) ? true : false;
var ie4 = (!dom && ie) ? true : false;
var moz = (dom && (navigator.appName=="Netscape")) ? true : false;
var opr = (dom && window.opera) ? true : false;
var op7 = (opr && (navigator.userAgent.indexOf("Opera 7") > 0 || navigator.userAgent.indexOf("Opera/7") >= 0)) ? true : false;

var hintsObj = null;

function moveHintsN(e) {

	if (hintsObj == null) return;
	if (nn4) {
		document.layers['hints'].left = e.pageX + 15;
		document.layers['hints'].top = e.pageY - 120;
		document.layers['hints'].visibility = "show"
	} else if (moz || op7) {
		document.getElementById('hints').style.left = window.pageXOffset + e.clientX + 15 + "px";
		document.getElementById('hints').style.top = window.pageYOffset + e.clientY - 120 + "px";
		document.getElementById('hints').style.visibility = "visible";
	}
}

function hideHintsN(e) {

	if (hintsObj == null) return;
	document.releaseEvents(Event.MOUSEMOVE);
	document.releaseEvents(Event.MOUSEOUT);
	document.onmousemove = null;
	document.onmouseout = null;
   	if (nn4) {
		document.layers['hints'].visibility = "hide";
		document.layers['hints'].left = 0;
		document.layers['hints'].top = 0;
    } else if (moz || op7) document.getElementById('hints').style.visibility = "hidden";
    hintsObj = null;
}


function moveHints() {

	if (opr || moz || nn4 || (hintsObj == null)) return;

    xoff = 0;
    yoff = 0;
	if (dom || ie) {
		if (dom) q = document.getElementById(hintsObj);
		else q = document.all[hintsObj];
		while (q) {
			xoff += q.offsetLeft;
			yoff += q.offsetTop;
			q = q.offsetParent;
		}
		xoff += window.event.offsetX + 15;
		yoff += window.event.offsetY + -120;
	}

    if (dom) {
		document.getElementById('hints').style.left = xoff;
		document.getElementById('hints').style.top = yoff;
	} else if (ie4) {
		document.all['hints'].style.left = xoff;
		document.all['hints'].style.top = yoff;
	}
}

function hideHints() {

	if (opr || moz || nn4 || (hintsObj == null)) return;

	if (dom) document.getElementById('hints').style.visibility = "hidden";
		else if (ie4) document.all['hints'].style.visibility = "hidden";
    hintsObj = null;
}



function showHints(obj,head,text,lang,slang,janre,coast,cd_class) {

	if ((opr && !op7) || (text == "")) return;

  	contents = "<TABLE border=1 cellspacing=0 cellpadding=5 width=400 class=\'hintshead\'><TR><TD><TABLE cellspacing=0 cellpadding=2 border=1 align=center width=100%><TR><TD align=center><B>" + head + "</B></TD></TR></TABLE><TABLE cellspacing=0 cellpadding=2 border=1 align=center width=100%><TR><TD width=20%><TABLE><TR><TD><B><I>Язык: </I></B></TD><TD>" + lang + "</TD></TR><TR><TD><B><I>Титры: </I></B></TD><TD>" + slang + "</TD></TR><TR><TD><B><I>Жанр: </I></B></TD><TD>" + janre + "</TD></TR><TR><TD><B><I>Тип диска: </I></B></TD><TD>" + cd_class + "</TD></TR><TR><TD><B><I>Стоимость: </I></B></TD><TD>" + coast + "р.</TD></TR></TABLE></TD><TD width=80% valign=top><B><center>Описание: </center></B>" + text + "</TD></TR></TABLE></TD></TR></TABLE>";
	
	hintsObj = obj;
	if (dom) document.getElementById('hints').innerHTML = contents;
	else if (nn4) {
			document.layers['hints'].document.open();
			document.layers['hints'].document.write(contents);
			document.layers['hints'].document.close();
		}
	else if (ie4) document.all['hints'].innerHTML = contents;

	if (nn4 || moz || op7) {
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEOUT);
		document.onmousemove = moveHintsN;
		document.onmouseout = hideHintsN;
		return;
	}
    if (dom || ie) {
		moveHints();
		if (dom) document.getElementById('hints').style.visibility = "visible";
			else if (ie4) document.all['hints'].style.visibility = "visible";
    }
}



function startTimer()
	{
	timerRun=-1;var time=new Date()
	hours=time.getHours()
	mins=time.getMinutes()
	secs=time.getSeconds()
	closeTime=hours*3600+mins*60+secs
	closeTime+=timeout
	Timer()
	}
function Timer()
	{
	var time=new Date()
	hours=time.getHours()
	mins=time.getMinutes()
	secs=time.getSeconds()
	curTime=hours*3600+mins*60+secs
	if(curTime<closeTime)
		{
		count=closeTime-curTime
		document.timerform.timerwin.value=count
		if(document.timerform.timerwin.value == "")
		stopTimer()
		if(timerRun)
		window.setTimeout("Timer()",1000)
		}
	}
function stopTimer()
	{
	timerRun=0;
	}

function addtofav()
	{
	if(window.external)
		window.external.AddFavorite('http://www.animeshki.ru/')
	else
		alert('Нажмите кнопку OK, а после этого Ctrl+D. и возврвщайтесь к нам!')
	}

function SendForm()
	{
	if (((document.all.eng_name.value == "") && (document.forms.add.eng_name.value.length < 3)) && ((document.all.e_rus_name.value == "") && (document.forms.add.e_rus_name.value.length < 3)))
		{
		alert('Введите Английское или Русское название фильма(не менее 3х знаков)');
		document.all.eng_name.focus();
		return false;
		}
	return true;
}
		
function Oth_enable()
	{
	if(document.all.other_j.checked)
		{
		document.all.other_janr.disabled = false;
		document.all.janr.disabled = true;
		}
		else
		{
		document.all.other_janr.disabled = true;
		document.all.janr.disabled = false;
		}
	}
	
function group_enable()
	{
	if(document.all.new_group.checked)
		{
		document.all.other_group.disabled = false;
		document.all.group.disabled = true;
		}
		else
		{
		document.all.other_group.disabled = true;
		document.all.group.disabled = false;
		}
	}

var newWin

function wow()
	{
	location.href='/anime-cart/'
	newWin.close()
	}


function wow2()
	{
	newWin.close()
	}


function wow3()
	{
	location.href='/anime-cart/remove-all/'
	}

function AddCart(FilmKod,num)
	{
	newWin = window.open('/anime-cart/add-'+FilmKod+'/','newWin','toolbar=no,status=no,resizable=yes,width=450,height='+num+',top=100,left=100');
	}



function jq_AddCart(FilmKod,num)
	{
	$(function() {
		$( "#modal_dialog" ).attr("title","Добавление аниме в корзину");
		$( "#modal_dialog" ).empty().load('/misc/cart.php?q=101&id='+FilmKod+'/').dialog({
			position: ["center",100],
			resizable: true,
			hide: 'puff',
			height: num,
			width:500,
			modal: true,
			buttons: {
				"Продолжить покупки": function() {
					$( this ).dialog( "close" );
				},
				"Перейти к оформлению": function() {
					$( this ).dialog( "close" );
					location.href='/anime-cart/';
				}
			},
			beforeClose: function(event, ui) {
        $( "#cart" ).load('/misc/cookie.php?cds_in_cart=1');
        $( "#cart" ).css("color", "yellow");
	    }
		});
	});
}

function delCart(FilmKod,id_del)
	{
	location.href = '/anime-cart/remove-' + FilmKod + '-' + id_del + '/'
	}
	
	
//$(document).ready(function (){
//	$("#Add_Class" > "option[@value='fig']")
//	});

function figsel()
  {
  var str = "";
  str = $("#Add_Class option:selected").attr("value")

  if (str=="fig") {
    //alert(str);
    $("#fi_ename").empty().append("Название<BR>фигурки:");
    $("#fi_foto").empty().append("Фото:");
    $("#fi_kol").empty().append("Наличие<BR>(>1=да 0=нет):");
    $("#fi_coast").empty().append("Стоимость фигурки:");
    $("#fi_show").empty().append("Показывать фигурку");
    $("#fi_group").load('/misc/group.php?fig=1');

    $("#fi_hide td").each(function () {
    $(this).hide();
    });
  } else {
    $("#fi_ename").empty().append("Английское<BR>название:");
    $("#fi_foto").empty().append("Обложка:");
    $("#fi_kol").empty().append("Количество дисков:");
    $("#fi_coast").empty().append("Стоимость 1 диска:");
    $("#fi_show").empty().append("Показывать диск ");
    $("#fi_group").load('/misc/group.php');
    
    $("#fi_hide td").each(function () {
    $(this).show();
    });
  }
  }
  
$(document).ready(figsel);
  
//alert ($("#Add_Class option[@value='fig']").text());
  //$("option[@value='fig']").attr("selected", "selected");
  
  //$("option[@value='1']").attr("selected", "selected");
  //.(function() {
  //alert("asd");
  //});
  
  //$("#Add_Class").(function() {
  //alert("asd");
 // });

//
  //var sel = $("#Add_Class");
  
  //$("<option></option>")  // создаем требуемый элемент
  //.attr("value", 1)     // устанавливаем значение одного из его атрибутов
  //.html("Пример опции") // записываем в него текст
  //.appendTo(sel);       // прикрепляем к уже существующему элементу
