if (!docWin) var docWin = null;
function DocumentWindow( AnchorObject, w, h )
{
    var DocumentFilePath = AnchorObject.href;    
    if (!w)       var w = 550;
    if (!h)       var h = 400;
    w+=20; h+=20;

    if (docWin && !docWin.closed) docWin.close();
    WinFeatures  = "width="+w+",height="+h+",toolbar=no,location=no,directories=no,status=no,statusbar=no,menubar=no,resizable=yes,scrollbars=no";
    docWin       = window.open( DocumentFilePath, "DocumentWindow", WinFeatures );
    docWin.title = AnchorObject.title;
    if (!docWin.opener) docWin.opener = self;
    
    leftPos = (screen.width / 2) - ( w / 2);
    topPos  = (screen.height / 2) - ( h / 2) - 60;
    docWin.moveTo( leftPos, topPos );
    docWin.focus();

    return true;
}

function flash(file,width,height,flashvars,winmode,id,classs,alternative) {

	var shockmode = false;
	if(id!=''){
		id=' id="'+id+'"';
	}
	if(classs!=''){
		classs=' class="'+classs+'"';
	}
	var mimetype = 'application/x-shockwave-flash';

	if (navigator.mimeTypes) {
		if (navigator.mimeTypes[mimetype] != null) {
			if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
				shockmode = true;
		      }
		}
	}
	if (!shockmode && navigator.appVersion.indexOf('MSIE') !=-1) {
		shockmode = true;
	}
	if (shockmode) {
		document.write('<object'+id+' type="application/x-shockwave-flash" data="'+file+'"'+classs+' width="'+width+'" height="'+height+'">');
		document.write('<param name="movie" value="'+file+'" />');
		document.write('<param name="menu" value="false" />');
		document.write('<param name="wmode" value="'+winmode+'" />');
		if(flashvars!=''){
			document.write('<param name="flashvars" value="'+flashvars+'" />');
		}
		document.write(alternative);
		document.write('</object>');
	}
	else {
		document.write(alternative);
	}
}

// Otevreni pop up okna - dokument
var docWin=null;
function DocOpen(DocName,w,h,idw) //DocName - jmeno souboru,w - sirka,h - vyska,idw - identifikator okna
{
	if (!idw) cesta = "Radegast";		//def hodnota
	 w+=2; h+=2;
	winFeatures="width="+w+",height="+h+",toolbar=no,location=no,"+
	"directories=no,status=no,menubar=no,resizable=no,scrollbars=no";
	docWin = "";
	docWin = window.open(DocName, idw, winFeatures);
	window.open(DocName, idw, winFeatures);
}

/*****/
function play_puzzle(cid,game) {  // otevira puzzle
	if (!arguments[0]) return;
	cid =  arguments[0];
	window.open("/zabava/souteze-o-ceny/"+game+"/src/"+cid,"xxx","width=725,height=400,scrollbars=auto,resizable=yes");
}
function play_trubky(cid,game) {  // otevira puzzle
	if (!arguments[0]) return;
	cid =  arguments[0];
	window.open("/zabava/souteze-o-ceny/"+game+"/src/"+cid,"xxx","width=725,height=545,scrollbars=auto,resizable=yes");
}


function sendToFriend()
{
	var data;
	data = "&aid=" + document.getElementById("aid").value;
	data += "&url=" + document.getElementById("url").value;
	data += "&name=" + document.getElementById("name").value;
	data += "&emailfrom=" + document.getElementById("emailfrom").value;
	data += "&emailto=" + document.getElementById("emailto").value;
	data += "&text=" + document.getElementById("text").value;
	data += "&robot=" + document.getElementById("protirobotum").value;
	
	var ajax = new EasyAjax("POST", data, "/smallapp/ajax/sendtofriend");
	ajax.onLoading("loadingSendToFriend");
	ajax.onSuccess("getSendToFriendStatus");
    ajax.doRequest();
}

// future control.modal object. will be created in naex article.phtml
// used to close modal window
var sendToFriendModal = null; 

function getSendToFriendStatus(json)
{
	var res = eval("("+json+")");
	switch (res.status)
	{
		case 'ALL_OK':
			with(document.getElementById('result')){
				innerHTML = "Odesláno.";
				closeSendBox();
			}
			break;
		case 'ERROR_EMAIL_FROM':
			document.getElementById('result').innerHTML = "Špatná e-mailová adresa odesílatele!";
			break;
		case 'ERROR_EMAIL_TO':
			document.getElementById('result').innerHTML = "Špatná e-mailová adresa příjemce!";
			break;
		case 'ERROR_SEND':
			document.getElementById('result').innerHTML = "Chyba při odesílání zprávy.";
			break;
		case 'ERROR_NAME':
			document.getElementById('result').innerHTML = "Položku Jméno musíš vyplnit!";
			break;
		case 'ERROR_ROBOT':
			document.getElementById('result').innerHTML = "Spambot!";
			break;
	}
}
function loadingSendToFriend()
{
	document.getElementById('result').innerHTML = "Momentík...";
}

function loadModal(){
        new Control.Modal('sendtofriend',{
		        opacity: 0.7,
		        width: 350,
		        height: 270,
		        afterOpen: function(){
			    	sendToFriendModal = this;
			    }
	    });
}

function closeSendBox(){
  document.getElementById('sendtofriend').style.display = 'none';
}
