﻿var IsLogin=false;
var TabDifficultWord=new Array();

function PostBackBetweenPages(width, height)
{
    var Separator='?';
    var Params="scrollbars=1,";
    if (PostBackBetweenPages.arguments.length==2)
        Params+="left="+((screen.width-width)/2)+", top="+((screen.height-height)/2)+" width="+width+", height="+height;
    var idWindow=window.open("", "PostBackBetweenPages", Params);
    window.setTimeout("document.forms[0].target='_self';document.forms[0].action='"+document.forms[0].action+"'",300);
    document.forms[0].target = "PostBackBetweenPages";
    if (document.forms[0].action.indexOf(Separator)>-1) Separator='&';
    document.forms[0].action = document.forms[0].action+Separator+"print=T";
    return false;
}

function onPageLoaded(sender, args)
{
    if (eval("typeof InitTableManage == 'function'")) 
    {
        InitTableManage(document.body.clientWidth, document.body.clientHeight, document.documentElement.scrollLeft, document.documentElement.scrollTop);
    }
    var wsk = document.getElementById('DivComments');
    var wsk1=document.getElementById('DivComments1');
    if (wsk!=null && wsk1!=null)
        if (wsk.clientHeight!=0 && wsk1.style.height=="") wsk1.style.height=(wsk1.clientHeight+wsk.clientHeight/2)+'px';
}

function LoginAlert()
{
    if (IsLogin==false) 
    {
        alert('Operacja nie jest dozwolona.\nNie jesteś zalogowany.');
        return false;
    }
    else return true;
}

function CommentsAlert(element)
{
    var value = document.getElementById(element).value;
    if (value=='Tutaj dodaj swój komentarz' || value=='')
    {
        alert('Nie wpisałeś swojego komentarza');
        return false;
    }
    return true;
}

function IsEmail(val, args)
{
    var pattern=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
    if (args.Value=='' || !pattern.test(args.Value))
    {
        alert("Błędny adres");
        args.IsValid = false;
    }
    else
        args.IsValid = true;
}

function ShowDifficultWord(e, id)
{
    var result="";
    var i=0;
    document.getElementById('DivDifficultWord').style.left = (e.clientX+10)+'px';
    document.getElementById('DivDifficultWord').style.top = (e.clientY-1)+'px';
    for(i=0; i<TabDifficultWord.length; i++)
    {
        if (TabDifficultWord[i][0]==id)
        {
            result=TabDifficultWord[i][1];
            break;
        }
    }
    if (result=="")
    {
        result=ajax('../../Handlers/DifficultWord.ashx?id='+id);
        TabDifficultWord[TabDifficultWord.length]=new Array();
        TabDifficultWord[TabDifficultWord.length-1][0]=id;
        TabDifficultWord[TabDifficultWord.length-1][1]=result;
    }
    document.getElementById('DivDifficultWord').innerHTML=result;
    document.getElementById('DivDifficultWord').style.display="block";
}

function HiddenDifficultWord()
{
    document.getElementById('DivDifficultWord').style.display="none";
}

function HiddenSwf()
{
    document.getElementById("DivSwf1").style.visibility="hidden";
    document.getElementById("DivSwf2").style.visibility="hidden";
}

function ShowSwf()
{
    if (document.getElementById("DivSwf1")!=null)
    {
        document.getElementById("DivSwf1").style.visibility="visible";
        document.getElementById("DivSwf2").style.visibility="visible";
    }
}

function addPageToFavorite() {

    var tytul = document.title;
    var adres = document.location;

    //FireFox
    if (window.sidebar) { 

        window.sidebar.addPanel(tytul, adres, ""); 

    //IE
    } else if (window.external) {

        window.external.AddFavorite(adres, tytul); 

    //Opera
    } else if (window.opera && window.print) {

        var a = document.createElement('a');
        a.setAttribute('href', adres);
        a.setAttribute('title', tytul);
        a.setAttribute('rel','sidebar');
        a.click();
    }
}
function setHomePage(obj) {
	if(navigator.userAgent.indexOf('MSIE') > -1) {
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage("http://www.fabrykadiet.pl");
	}
	else if(window.opera && window.print) {
		alert('Twoja przeglądarka nie pozwala na zmianę strony domowej. By zrobić to ręcznie, kliknij w menu przeglądarki "Narzędzia" > "Ustawienia" > "Użyj bieżącej"');
	}
	else {
		alert('Twoja przeglądarka nie pozwala na zmianę strony domowej. By zrobić to ręcznie, przeciągnij link "Ustaw jako stronę domową" na przycisk "Strona domowa" w pasku nawigacji przeglądarki.');
	}
}

function showDivUserEmail(ev)
{
  //document.getElementById('DivDifficultWord').innerHTML=result;
    document.getElementById('DivUserEmail').style.display="block";
    document.getElementById("DivUserEmail").style.left=ev.clientX + document.body.scrollLeft - 150;
    document.getElementById("DivUserEmail").style.top=0;

}

function WindowAlert(message)
{
    alert(message);
    return false;
}