﻿window.onload = autorun;

function autorun() {
	if (clientIP!="80.237.26.27") {
		flash();
	}
	text_menu();
	externalLinks();
	subscribe();
	jumps();
}

function subscribe() {
    if (document.getElementById("subscribe-block")) {
        document.getElementById("ctl00_pole_sex_0").onclick = function() {
            document.getElementById("subscribe-block").style.display = "block";
        }
        document.getElementById("ctl00_pole_sex_1").onclick = function() {
            document.getElementById("subscribe-block").style.display = "none";
        }
    }
}

function video(file, w, h) {
	cX=(screen.width-352)/2;
	cY=(screen.height-288)/2;
	if (!w)
		w = 352;
	if (!h) 
		h = 288;
	win = window.open('video.aspx?file='+file+'&w='+w+'&h='+h,'_blank','width='+w+', height='+h+', scrollbars=no, status=no, toolbar=no,left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function text_menu() {
	if (document.getElementById('nav-dreaming')) {
		if (menus) {
			if (menus==1)
				document.getElementById('nav-dreaming').className = 'selected';
			if (menus==2)
				document.getElementById('nav-kitten').className = 'selected';
			if (menus==3)
				document.getElementById('nav-about').className = 'selected';
			if (menus==4)
				document.getElementById('nav-breeds').className = 'selected';
			if (menus==5)
				document.getElementById('nav-menu').className = 'selected';
			if (menus==6)
				document.getElementById('nav-amusements').className = 'selected';
			if (menus==7)
				document.getElementById('nav-act').className = 'selected';
		}
	}
}

function flash() {
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if (version["major"] >= 6) {
		menu();
		calendar();
		ration_test();
		languages_test();
		index_banners();
		catalog_new();
	}
	else {
		document.getElementById('getflash').style.display = 'block';
	}
}

function menu_select(num) {
	if (num==1)
	 window.location = 'dreaming.aspx';
	else if (num==2)
	 window.location = 'kitten.aspx';
	else if (num==3)
	 window.location = 'about.aspx';
	else if (num==4)
	 window.location = 'breeds.aspx';
	else if (num==5)
	 window.location = 'menu.aspx';
	else if (num==6)
	 window.location = 'amusements.aspx';
	else if (num==7)
	 window.location = 'act_news.aspx';
}

function index_banners() {
	if (document.getElementById("banner-1")) {
		var so = new SWFObject("/images/special1.swf", "flash", "295", "200", "6");
		so.write("banner-1");
	}
	if (document.getElementById("banner-2")) {
		var so = new SWFObject("/images/smetanka.swf", "flash", "295", "200", "6");
		so.write("banner-2");
	}
	
	if (document.getElementById("banner-big")) {
		var so = new SWFObject("/images/cat_dream10_nocat.swf", "flash", "650", "200", "6");
		//so.addParam("wmode", "transparent");
		so.write("banner-big")
	}
/*
	if (document.getElementById("banner-big")) {
		//var so = new SWFObject("/images/whiskas_main12.swf", "flash", "650", "200", "6");
		if( (Math.random() * 100) > 50 ){
			var so = new SWFObject("/images/whiskas_video12_rus.swf", "flash", "650", "200", "6");
			so.addParam("wmode", "transparent");
			so.write("banner-big");
		}else{
			var so = new SWFObject("/ua/images/whiskas_registration_650x200.swf", "flash", "650", "200", "6");
			so.addParam("wmode", "transparent");
			so.write("banner-big");
		}
		
		
	}
*/
	/*if (document.getElementById("promo-2")) {
		var so = new SWFObject("/images/magazin2.swf", "flash", "250", "97", "6");
		so.write("promo-2");
	}*/
}

function menu() {
	if (document.getElementById("menu")) {
		var so = new SWFObject("/images/mrus.swf", "flash", "741", "105", "6");
		so.addParam("wmode", "transparent");
		if (menus!='undefined')
			so.addVariable("selected_menu", menus);
		so.write("menu");
	}
}

function calendar() {
	if (document.getElementById("flash-kitten-calendar")) {
		var so = new SWFObject("/images/calendar.swf", "flash", "409", "268", "6", "#F5EFE6");
		so.addVariable("selected_period", period);
		so.write("flash-kitten-calendar");
	}
}

function ration_test() {
	if (document.getElementById("menu-ration-test")) {
		var so = new SWFObject("/images/test.swf", "flash", "414", "289", "6", "#F5EFE6");
		so.write("menu-ration-test");
	}
}

function languages_test() {
	if (document.getElementById("about-language-flash")) {
		var so = new SWFObject("/images/lang.swf", "flash", "414", "289", "6", "#F5EFE6");
		so.write("about-language-flash");
	}
}

function catalog_new() {
	if (document.getElementById("flash-premium")) {
		var so = new SWFObject("/images/premium.swf", "flash", "410", "244", "6");
		so.addParam("wmode", "transparent");
		so.write("flash-premium");
	}
	if (document.getElementById("flash-immuno")) {
		var so = new SWFObject("/images/immuno.swf", "flash", "410", "222", "6");
		so.write("flash-immuno");
	}
	if (document.getElementById("flash-cheese")) {
		var so = new SWFObject("/images/cheese.swf", "flash", "410", "341", "6");
		so.write("flash-cheese");
	}
	if (document.getElementById("flash-meal")) {
		var so = new SWFObject("/images/cow3.swf", "flash", "417", "259", "6");
		so.write("flash-meal");
	}

}

function select_language(num) {
	var captions = document.getElementById('languages').getElementsByTagName('div');
	for (i=0; i<captions.length; i++) {
		captions[i].style.display = 'none';
	}
	captions(num-1).style.display = 'block';
}

function test(result) {
	 window.location = 'menu_ration_result' + result + '.aspx';
}

function select_period(period) {
	if (period > 0 && period < 17) {
		window.location = 'kitten_calendar_week' + period + '.aspx';
	}
	if (period > 16 && period < 25) {
		period = period - 12;
		window.location = 'kitten_calendar_month' + period + '.aspx';
	}
}

function popup(url, width, height) {
	cX=(screen.width-width)/2;
	cY=(screen.height-height)/2;
	var win = window.open('','popup','width='+width+', height='+height+', scrollbars=no, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
	win.document.write('<html><body bgcolor="#F5EFE6" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bottommargin="0" rightmargin="0"><a href="javascript:close();"><img src="'+url+'" border="0" alt="Закрыть окно"></a></body></html>');
}

function popupPic(url) {
	cX=0;
	cY=0;
	var win = window.open('popup.aspx?' + url,'popup','width=80, height=80, scrollbars=no, resizeable=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function rules(url) {
	cX=(screen.width-600)/2;
	cY=(screen.height-400)/2;
	var win = window.open(url,'popup','width=600, height=400, scrollbars=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function allRules() {
	cX=(screen.width-600)/2;
	cY=(screen.height-400)/2;
	var win = window.open('all_rules.aspx','popup','width=600, height=400, scrollbars=yes, left='+cX+',top='+cY+',screenX'+cX+',screenY='+cY);
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var mylink = anchors[i];
   if (mylink.getAttribute("rel") == "external") {
		 //mylink.click = function() { window.open(this.href); return false; };
     mylink.target = "_blank"; 
	 }
 } 
}

function toggle(id) {
    if (document.getElementById(id)) {
        if (document.getElementById(id).style.display=='' || document.getElementById(id).style.display=='none')
            document.getElementById(id).style.display = 'block';
        else
           document.getElementById(id).style.display='none';
    }
}

function jumps() {
	var wrapper = document.getElementById('upload-date');
	if (wrapper) {
		var inputs = wrapper.getElementsByTagName('input');
		var day = inputs[0];
		var month = inputs[1];
		var year = inputs[2];
		
		day.onkeyup = function () {
			var inputs = wrapper.getElementsByTagName('input');
			var month = inputs[1];
			if (this.value.length >= this.maxLength) {
				month.focus();
			}
		}
		day.onfocus = function() {
			this.value='';
		}
		month.onkeyup = function () {
			var inputs = wrapper.getElementsByTagName('input');
			var year = inputs[2];
			if (this.value.length >= this.maxLength) {
				year.focus();
			}
		}
		month.onfocus = function() {
			this.value='';
		}
		year.onfocus = function() {
			this.value='';
		}
	}
}

function feedback() {
	locationstring = "mailto:support@whiskas.ru?subject=%D1%EE%EE%E1%F9%E5%ED%E8%E5 %F1 %F1%E0%E9%F2%E0 Whiskas.ru";
	window.location = locationstring;
}
