﻿
// Browser flags

var tti_u = "undefined";
var tti_db = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body? document.body : null,
tti_n = navigator.userAgent.toLowerCase();

// Browser flags
var tti_op = !!(window.opera && document.getElementById),
tti_op6 = tti_op && !document.defaultView,
tti_op7 = tti_op && !tti_op6,
tti_ie = tti_n.indexOf("msie") != -1 && document.all && tti_db && !tti_op,
tti_n4 = (document.layers && typeof document.classes != tti_u),
tti_n6 = (!tti_op && document.defaultView && typeof document.defaultView.getComputedStyle != tti_u),
tti_w3c = !tti_ie && !tti_n6 && !tti_op && document.getElementById;

tti_n = "";

// Element Detection
function tti_GetDiv(t_id)
{
 return(
  tti_n4? (document.layers[t_id] || null)
  : tti_ie? (document.all[t_id] || null)
  : (document.getElementById(t_id) || null)
 );
}

function EmptyDate(day_id, month_id, year_id, err_text)
{
    var oday = tti_GetDiv(day_id);
    var omonth = tti_GetDiv(month_id);
    var oyear = tti_GetDiv(year_id);
    
    if(oday!=null && omonth!=null && oyear!=null)
    {
      var iday = oday.value;      
      var imonth = omonth.value;      
      var iyear = oyear.value;
      if(iday<=0 || imonth<=0 || iyear<=0)
        return err_text;
    }
    return '';
}

function RightDate(day_id, month_id, year_id, err_text)
{
    var oday = tti_GetDiv(day_id);
    var omonth = tti_GetDiv(month_id);
    var oyear = tti_GetDiv(year_id);
    
    if(oday!=null && omonth!=null && oyear!=null)
    {
      var iday = oday.value;      
      var imonth = omonth.value;      
      var iyear = oyear.value;
      if(iday>0 && imonth>0 && iyear>0)
      {
    	  var mdays = new Array(-1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	      if (iday > mdays[imonth])
   	      return err_text;
      }
    }

    return '';
}

function OldEnough(day_id, month_id, year_id, max_age, err_text)
{
    var oday = tti_GetDiv(day_id);
    var omonth = tti_GetDiv(month_id);
    var oyear = tti_GetDiv(year_id);
    
    if(oday!=null && omonth!=null && oyear!=null)
    {
      var iday = oday.value;      
      var imonth = omonth.value;      
      var iyear = oyear.value;
      if(iday>0 && imonth>0 && iyear>0)
      {
        udate = new Date(iyear, imonth, iday);
        curdate = new Date();
        var ddiff = (curdate - udate)/31536000000;
        if(ddiff < max_age)
   	      return err_text;
      }
    }

    return '';
}

function open_edit_window(url, w, h)
{
    open_edit_window(url, 'PrizeEdit', w, h)
}


function open_edit_window(url, name, w, h)
    {
       var ww = 600;
       var wh = 800;

       if(w!=null)
         ww = w;
       if(h!=null)
         wh = h;
       
       var nn = 'Prize';
       
       if(name!=null)
         nn = name;
       
       window.open(url, nn, 'width='+ww+', height='+wh+', location=0, menubar=0, toolbar=0, status=0, resizable=1, scrollbars=1');
    }
    
    
function showFlash(o){
	var bg,q,s,v;
	if(o.bgcolor){bg=o.bgcolor;}else{bg="#FFFFFF";}
	if(o.quality){q=o.quality;}else{q="high";}
	if(o.scale){s=o.scale;}else{s="noscale";}
	if(o.ver){v=o.ver;}else{v=6;}
	var str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+v+',0,0,0" ';
	str+='id="'+o.id+'" ';
	if(o.base){str+='base="'+o.base+'" ';}
	if(o.align){str+='align="'+o.align+'" ';}
	str+='width="'+o.width+'" height="'+o.height+'"><param name="movie" value="'+o.name+'"/><param name="bgcolor" value="'+bg+'"/><param name="quality" value="'+q+'"/>';
	if(o.flashvars){str+='<param name="flashvars" value="'+o.flashvars+'"/>';}
	if(o.allowScriptAccess){str+='<param name="allowScriptAccess" value="'+o.allowScriptAccess+'"/>';}
	if(o.salign){str+='<param name="salign" value="'+o.salign+'"/>';}
	if(o.wmode){str+='<param name="wmode" value="'+o.wmode+'"/>';}
	str+='<param name="scale" value="'+s+'"/><embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" id="'+o.id+'-embed" src="'+o.name+'" bgcolor="'+bg+'" ';
	if(o.flashvars){str+='flashvars="'+o.flashvars+'" ';}
	if(o.swLiveConnect){str+='swLiveConnect="'+o.swLiveConnect+'" ';}
	if(o.allowScriptAccess){str+='allowScriptAccess="'+o.allowScriptAccess+'" ';}
	str+='quality="'+q+'" ';
	if(o.base){str+='base="'+o.base+'" ';}
	if(o.wmode){str+='base="'+o.wmode+'" ';}
	if(o.salign){str+='salign="'+o.salign+'" ';}
	str+='scale="'+s+'" width="'+o.width+'" height="'+o.height+'"></embed></object>';
	document.writeln(str);
}

/*
		Описание аттрибутов:
		Автоматические:
			align		- HTML выравнивание (необязательный)
			allowScriptAccess - взаимодействие между flash и html. Значения: never | always | sameDomain (необязательный, по умолчанию sameDomain) Flash Player 7 и выше
			bgcolor		- цвет фона флеша (необязательный, по умолчанию белый)
			height		- высота флеша
			id			- id object (необязательный)
			name		- имя файла
			quality		- качество (необязательный, по умолчанию high)
			salign		- Stage.align (необязательный)
			scale		- маштаб (необязательный)
			swLiveConnect - загрузка JAVA при первичной загрузке Flash Player (необязательный, по умолчанию false) только для embed
			width		- ширина флеша
		Пользовательские:
			base		- цвет фона флеша (необязательный)
			flashvars	- передаваемые флешу переменные (необязательный)
			ver			- минимальная версия флеш-плеера (необязательный, по умолчанию 6)
	*/
	//var o = {};
	//// Автоматические
	//o.align = "";
	//o.allowScriptAccess = "sameDomain";
	//o.bgcolor = "цвет фона";
	//o.height = "высота";
	//o.id = "id объекта";
	//o.name = "имя файла";
	//o.quality = "качество";
	//o.salign = "привязка Stage";
	//o.swLiveConnect = "true";
	//o.width = "ширина";
	//// Пользовательские
	//o.base = "";
	//o.flashvars = "";
	//o.ver = "";
	
	//// Показываем флешку
	//showFlash (o);
