function setHPage(){
    HomePage.setHomePage("http://www.fotbolti.net");
}
function sendmail(){
    window.open("mailfriend.html","WoodenFrame","width=300,height=110, status=no,toolbar=no,menubar=no,resizable=no");
}

function bookMark(){
    if (document.images){
        var url=this.document.location;
        var title=this.document.title;
        window.external.AddFavorite(url,title);
    }
}
function calcCurrency2() {
    var origin = lastInput;
    var userin = fixfloat(eval('document.curr_frm._value_'+origin+'.value'));
    var equivalent = arrCurrency[origin].factor;
    if (userin == 0 || isNaN(userin) )
    {
        ClearForm();
        return false;
    }
    var v;
    for (i=0; i<arrCurrency.length; i++) {
        if (i!=origin) {
            v = FormatMoney(equivalent/arrCurrency[i].factor*userin);
            eval('document.curr_frm._value_'+i+'.value ='+"v");
        }
    }
    return true;
}
function ClearForm() {
    for (var i=0; i < arrCurrency.length; i++)
    eval('document.curr_frm._value_'+i+'.value = ""');
    return true;
}


function strip(n,s)
{
    var pos=0;
    var len=n.length;
    var res='';
    while (pos<len)
    {
        if (s.indexOf(n.charAt(pos))!=-1)
        res+=n.charAt(pos);

        pos++;
    }
    return(res);
}

function fixfloat(n) {
    var pos;
    var inp;
    var flp;
    var res;

    pos=n.indexOf(',');

    if (pos==-1)
    pos=n.indexOf('.');
    if (pos!=-1) {
        inp=strip(n.substring(0,pos),'0123456789');
        flp=strip(n.substring(pos+1),'0123456789');

        if (inp && flp)
        return eval(inp)+flp/Math.pow(10,flp.length);
        else {
            if (!inp && flp)
            return flp/Math.pow(10,flp.length);
            else {
                if (!inp && !flp)
                return '';
                else if (inp && !flp)
                return eval(inp);
            }
        }
    }
    return(strip(n,'0123456789'));
}

function MakeItem(co,fa) {
    this.code=co;
    this.factor=parseFloat(fa);
    return this;
}
function calcCurrency(origin, calc) {
    lastInput = origin;
    if (calc == 1)
    calcCurrency2();
}
function formatThousand(szIn) {
    var sz = szIn;
    var szNew = '';
    while (sz.length > 3)
    {
        if (szNew != '') szNew = '.' + szNew;
        szNew = sz.slice((sz.length-3),sz.length) + szNew;
        sz = sz.slice(0,(sz.length-3));
    }
    if (szNew != '') szNew = '.' + szNew;
    szNew = sz + szNew;
    return(szNew);
}
function FormatMoney(amt) {
    var tmpn=0;
    var tmps="";
    if (Math.round(amt) != 0) {
        amt = Math.round(amt);
    }
    tmpn=Math.round(amt*100);
    if (tmpn < 0 || tmpn > 99999999999999)
    return "*********";
    else if (tmpn < 10)
    tmps="00"+tmpn;
    else if (tmpn < 100)
    tmps="0"+tmpn;
    else tmps=""+tmpn;

    var before = formatThousand(tmps.substring(0,(tmps.length-2)));
    if (tmps.substring((tmps.length-2),tmps.length) != '00') {
        before = before + "," + tmps.substring((tmps.length-2),tmps.length)
    }
    return before;
}
function init(i) {
    if (i != -1)
    calcCurrency(0,1);
}

function openWindow ( w, h, url, id){
    if (id){
        urlStr = url+'&id='+id;
    }else{
        urlStr = url;
    }
    myWindow = window.open(urlStr,'Popup','width='+w+', height='+h+', scrollbars=yes,resize=no');
}

function showImage ( id, container,imgText,gallImages ){
    var container = document.getElementById(container);
    var popup = document.createElement('DIV');
    var title = document.createElement('DIV');
    var image = document.createElement('IMG');
    var close = document.createElement('A');
    if(!gallImages){
        image.src = 'getImg.php?id='+id+'&table=newspictures&h=*&w=*';
    }else{
        image.src = 'fullStory.php?action=getGalImage&id='+id+'&h=*&w=*';
    }
    popup.id = 'fulStoryImgPopUp';
    close.innerHTML = 'X';
    close.id = 'closeBtn';
    if (imgText){
        title.innerHTML = '<span>'+imgText+'</span>';
    }
    title.appendChild(close);
    title.className = 'title';
    popup.appendChild(title);
    popup.appendChild(image);
    container.appendChild(popup);
    image.oncontextmenu = function(){
        return false;
    }
    image.onclick = function(){
        popup.className = 'hide';
        return false;
    }
    close.onclick = function(){
        popup.className = 'hide';
        return false;
    }    
}

function openWindow ( w, h, url, id){
    if (id){
        urlStr = url+'&id='+id;
    }else{
        urlStr = url;
    }
    window.open(urlStr,'Popup','width='+w+', height='+h+', scrollbars=yes,resize=no');
}

function back(){
    history.back();
}
function showCC(obj){
    var oDiv = document.getElementById('cc_data');
        oDiv.innerHTML = '<b>Nafn korthafa</b><br><input type="text" class="medium" name="cc_name"><br><br>';
        oDiv.innerHTML += '<b>Kortn&uacute;mer</b><br><input type="text" class="medium" name="cc_num"><br><br>';
        oDiv.innerHTML += '<b>Gildist&iacute;mi</b><br><input type="text" class="medium" name="cc_expire"><br><br>';
}
function hideCC(){
    var oDiv = document.getElementById('cc_data');
    var oDiv1 = document.getElementById('cash_data');
    
    oDiv.innerHTML = '';
    oDiv1.innerHTML = '';
}
function showCash(sum){
    var oDiv = document.getElementById('cash_data');
    var oDiv1 = document.getElementById('cc_data');
    oDiv1.innerHTML = '';
    oDiv.innerHTML = 'Bankainnlegg.<br>Vinsamlegast leggi� <b>'+sum+' kr.</b> inn � reikning: 115-26-1730, kennitala: 590307-1730.<br>V�runar ver�a sendar um lei� og millif�rsla hefur borist.';
}
function loadLeagues(id,sid){
    document.getElementById('leaguesTable').className = 'active';
    document.getElementById('topScorers').className = 'inactive';
    document.getElementById('liveMatches').className = 'inactive';
    var loader = new net.ContentLoader('leagues_gsm.php?action=tables&id='+id+'&sid='+sid,showTables,null,'GET',null,null);
}
function loadLeagues_t(cc,lg,y){
    document.getElementById('leaguesTable').className = 'active';
    var loader = new net.ContentLoader("leagues.php?action=tables&cc="+cc+"&lg="+lg+"&y="+y,showTables,null,'GET',null,null);
}
function loadIsLeagues(id){
    document.getElementById('leaguesTable').className = 'active';
    document.getElementById('topScorers').className = 'inactive';
    document.getElementById('liveMatches').className = 'inactive';
    var loader = new net.ContentLoader('isboltinn.php?silient=1&type=s&ligueid='+id,showTables,null,'GET',null,null);
}
function showTables(){
    var oTd = document.getElementById('gsm_table_content');
    oTd.innerHTML = this.data;
}
function loadTopscorers(id){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('topScorers').className = 'active';
    document.getElementById('liveMatches').className = 'inactive';
    var loader = new net.ContentLoader('leagues_gsm.php?action=scorers&id='+id,showTables,null,'GET',null,null);
}
function loadIsTopscorers(id){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('topScorers').className = 'active';
    document.getElementById('liveMatches').className = 'inactive';
    var loader = new net.ContentLoader('isboltinn.php?silient=1&type=l&ligueid='+id,showTables,null,'GET',null,null);
}
function loadLiveMatches(id){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('topScorers').className = 'inactive';
    document.getElementById('liveMatches').className = 'active';
    var loader = new net.ContentLoader('leagues_gsm.php?action=liveMatches&id='+id,showTables,null,'GET',null,null);
}
function loadIsMatches(id){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('topScorers').className = 'inactive';
    document.getElementById('liveMatches').className = 'active';
    var loader = new net.ContentLoader('isboltinn.php?silient=1&type=m&ligueid='+id,showTables,null,'GET',null,null);
}
function loadAllMatches(id,offset){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('topScorers').className = 'inactive';
    document.getElementById('liveMatches').className = 'inactive';
    document.getElementById('allMatches').className = 'active';
    if(offset == 'undefined' || !offset){
        offset = 0;
    }
    var loader = new net.ContentLoader('leagues_gsm.php?action=allMatches&id='+id+'&offset='+offset,showTables,null,'GET',null,null);
}
function loadAllMatches_t(id,y,offset){
    document.getElementById('leaguesTable').className = 'inactive';
    document.getElementById('allMatches').className = 'active';
    if(offset == 'undefined' || !offset){
        offset = 0;
    }
    var loader = new net.ContentLoader('leagues.php?action=allMatches&lg='+id+'&y='+y+'&offset='+offset,showTables,null,'GET',null,null);
}

function loadEvents(id,section){
    var oSpan = document.getElementById(id);
    if(oSpan.innerHTML == '+'){
        oSpan.innerHTML = '-';
        var extraParams = new Object();
        extraParams.id = id;
        if(section == 'live' || section == 'undefined' || !section){
            var loader = new net.ContentLoader('leagues_gsm.php?action=liveEvents&id='+id,showEventTable,null,'GET',null,null,extraParams);
        }else{
            var loader = new net.ContentLoader('leagues_gsm.php?action=events&id='+id,showEventTable,null,'GET',null,null,extraParams);
        }
    }else{
        oSpan.innerHTML = '+'
        document.getElementById('gsm_events_table_'+id).innerHTML = '';
    }
}
function showEventTable(){
    var oTd = document.getElementById('gsm_events_table_'+this.extraParams.id);
    oTd.innerHTML = this.data;
}
function loadCommentsBar(id){
    var loader = new net.ContentLoader('news.php?action=loadCommentsBar&id='+id,getResponse,null,'GET',null,null,null,'comments','statusLoader');
}
function loadComments(id,goTo){
    var oDiv = document.getElementById('comments_table');
    if(document.all){
        oDiv.style.width = '355px';
    }
    
    if(oDiv.innerHTML !='' && !goTo){
        oDiv.innerHTML =''
    }else{
        if(goTo){
            var loader = new net.ContentLoader('news.php?action=loadComments&id='+id,getCommentsResponse,null,'GET',null,null,null,'comments_table','statusLoader');
        }else{
            var loader = new net.ContentLoader('news.php?action=loadComments&id='+id,getResponse,null,'GET',null,null,null,'comments_table','statusLoader');
        }
    }
}
function getCommentsResponse(){
    var oDiv = document.getElementById(this.container);
    var oDivS = document.getElementById(this.statusContainer);
    if(oDivS){
        if(!document.all){
            oDivS.style.top = oDiv.offsetTop+285+'px';
        }else{
            oDivS.style.top = oDiv.offsetTop+515+'px';
        }
        oDivS.style.left = oDiv.offsetLeft+400+'px';
        oDivS.innerHTML = this.status;
    }
    if (oDiv && this.data && this.async){
        oDiv.innerHTML = this.data;
        oDivS.innerHTML = '';
        location.href='#new_comment';
    }
}
function loadLogin(id){
    var oDiv = document.getElementById('comments_table');
    if(document.all){
        oDiv.style.width = '345px';
    }

    var loader = new net.ContentLoader('news.php?action=loadCommentsLogin&id='+id,getResponse,null,'GET',null,null,null,'comments_table','statusLoader');
}
function makeParams(form){
    var oForm = document.getElementById(form);
    var params = '';
    
    for(i=0;element = oForm.elements[i];i++){
        if(element.type == 'text' || element.type == 'textarea' || element.type == 'hidden' || element.type == 'file' || element.type == 'password'){
            params += element.name+'='+encodeURIComponent(element.value)+'&';
        }
        if(element.type == 'radio' || element.type == 'checkbox'){
//          var oRadio = document.getElementsByName(element.name);
//          for(j=0;oRadio[j];j++){
                if(element.checked == true){
                    params += element.name+'='+encodeURIComponent(element.value)+'&';
                }
//          }
        }
        if(element.type == 'select-multiple'){
            for(j=0;element.options[j];j++){
                if(element.options[j].selected == true){
                    params += element.name+'='+encodeURIComponent(element.options[j].value)+'&';
                }
            }           
        }
        if(element.type == 'select-one'){
            params += element.name+'='+encodeURIComponent(element.options[element.selectedIndex].value)+'&';
        }
    }
    return params;
}

/*function showFieldsErrors(responce){
    for(obj in responce){
        if(document.getElementById('error_'+obj)){
            if(responce[obj].valid == false){
                document.getElementById('error_'+obj).innerHTML = responce[obj].msg;
            }else{
                document.getElementById('error_'+obj).innerHTML = '';
            }
        }
    }
}*/

function doRegister(){
    var oBut = document.getElementById('regBut');
    var txt = oBut.value;
    oBut.className = 'disabled';
    oBut.value = 'Loading...'
    oBut.disabled = true;
    
    var oName = document.getElementById('name');
    var oEmail = document.getElementById('reg_email');
    var oCEmail = document.getElementById('confirm_email');
    var oPID = document.getElementById('PID');
    var oPass = document.getElementById('reg_password');
    var oCPass = document.getElementById('confirm_password');
    
    var params = makeParams('register_form');
    
    var loader = new net.ContentLoader('news.php?action=checkRegister',getResponse,null,'POST',params,null,null,null,'statusLoader','TEXT',true);
    
    var res = eval('('+loader.data+')');
    
    showFieldsErrors(res);
    if(!res.valid){
        oBut.disabled = false;
        oBut.className = 'button';
        oBut.value = txt;
    }else{
        oBut.disabled = true;
        oBut.style.background = '#CCCCCC';
        oBut.value = 'Loading...'       
        var checkSum = MD5(oEmail.value+oCEmail.value+oPID.value+oPass.value+oCPass.value);
        
        params += '&checkSum='+checkSum;
        var loader = new net.ContentLoader('news.php?action=doRegister',getResponse,null,'POST',params,null,null,'register_form','statusLoader','TEXT',false);
    }
}

function doLogin(id){
    var oBut = document.getElementById('logBut');
    var txt = oBut.value;
    oBut.className = 'disabled';
    oBut.value = 'Loading...'
    oBut.disabled = true;
    
    var oEmail = document.getElementById('login_email');
    var oPass = document.getElementById('login_password');  
    
    var params = makeParams('login_form');
    params += '&checkSum='+MD5(oEmail.value+oPass.value);
    var loader = new net.ContentLoader('news.php?action=checkLogin',getResponse,null,'POST',params,null,null,null,'statusLoader','TEXT',true);
    
    var res = eval('('+loader.data+')');
    
    showFieldsErrors(res);
    if(!res.valid){
        oBut.disabled = false;
        oBut.className = 'button';
        oBut.value = txt;
    }else{
         if(res.login.valid){
            var loader = new net.ContentLoader('news.php?action=loadCommentsBar&id='+id,getResponse,null,'GET',null,null,null,'comments','statusLoader');
            var loader = new net.ContentLoader('news.php?action=loadComments&id='+id,getResponse,null,'GET',null,null,null,'comments_table','statusLoader');
            loadComments(id);
         }else{
            document.getElementById('loginStatus').innerHTML = res.login.msg;
            oBut.disabled = false;
            oBut.className = 'button';
            oBut.value = txt;
         }
    }
    
}
function newComment(id){
    loadComments(id,1);
}

function logout(id){
    var loader = new net.ContentLoader('news.php?action=logout',getResponse,null,'GET',null,null,null,null,'statusLoader','TEXT',true);
    var loader1 = new net.ContentLoader('news.php?action=loadComments&id='+id,getResponse,null,'GET',null,null,null,'comments_table','statusLoader');
    document.getElementById('logout').innerHTML = '';   
    document.getElementById('newComment').onclick = function(){
        loadLogin(id);
    }
}

function limitChar(){
    var chrLimit = 1000;
    var txt = document.getElementById('text').value;
    var len = txt.length;
    var limit = document.getElementById('counter');
    
    if(len > chrLimit){
        document.getElementById('text').value = txt.substring(0,chrLimit);
    }else{
        limit.innerHTML = chrLimit - txt.length;
    }
}

function doPost(id){
    var oBut = document.getElementById('postBut');
    var bg = oBut.style.background;
    var txt = oBut.value;
    oBut.style.background = '#CCCCCC';
    oBut.value = 'Loading...'
    oBut.disabled = true;
    
    var oTxt = document.getElementById('text');
    
    var params = makeParams('comment_form');

    var loader = new net.ContentLoader('news.php?action=checkPost',getResponse,null,'POST',params,null,null,null,'statusLoader','TEXT',true);
    
    var res = eval('('+loader.data+')');
    showFieldsErrors(res);
    
    if(!res.valid){
        oBut.disabled = false;
        oBut.style.background = bg;
        oBut.value = txt;
    }else{
//      var checkSum = MD5(id+oTxt.value);
//      params += '&checkSum='+checkSum;
        var loader = new net.ContentLoader('news.php?action=doPost&id='+id,getPostResponse,null,'POST',params,null,null,'comments','statusLoader');
    }
    
}

function getPostResponse(){
    var oDiv = document.getElementById(this.container);
    var oDivS = document.getElementById(this.statusContainer);
    if(oDivS){
        oDivS.style.top = oDiv.offsetTop+285+'px';
        oDivS.style.left = oDiv.offsetLeft+400+'px';
        oDivS.innerHTML = this.status;
    }
    if (oDiv && this.data && this.async){
        oDiv.innerHTML = this.data;
        if(document.all){
            var tab = document.getElementById('comments_table');
            tab.style.width = '355px';
        }         
        oDivS.innerHTML = '';
        location.href = '#top';
    }
}

function getIP(id){
    var test = document.getElementById('popup');
    var oDiv = document.createElement('DIV');
    var oDivC = document.getElementById('comment_'+id);
    
    var loader = new net.ContentLoader('news.php?action=getIP&id='+id,getResponse,null,'GET',null,null,null,null,'statusLoader','TEXT',true);
    
    oDiv.innerHTML = loader.data;
    oDiv.id = 'popup';
    if(!document.all){
        oDiv.style.top = oDivC.offsetTop+350+'px';
    }else{
        oDiv.style.top = oDivC.offsetTop+580+'px';
    }
    oDiv.style.left = oDivC.offsetLeft+400+'px';
    if(test){
        document.body.removeChild(test);
    }
        document.body.appendChild(oDiv);
}

function closePopup(id){
    var oDiv = document.getElementById('popup');
    var oDivC = document.getElementById('comment_'+id);
    document.body.removeChild(oDiv);
}

function deleteItem(id,nid){
    if(confirm('Are you shure to delete this comment?')){
        var loader = new net.ContentLoader('news.php?action=delComment&id='+id+'&news_id='+nid,getPostResponse,null,'GET',null,null,null,'comments','statusLoader');
    }
}

function editComment(id,nid,obj){
    if(!document.getElementById('postButt')){
    var oTd = document.getElementById('text_'+id);
    var oInp = document.createElement('TEXTAREA');
    var oBut = document.createElement('INPUT');
    var oSpan = document.createElement('SPAN');
    var oSpan1 = document.createElement('SPAN');
    var oSpan2 = document.createElement('SPAN');
    
    var txt = oTd.innerHTML;
    
    oInp.value = txt.replace(/<br>/gi,"\n");
    oTd.innerHTML = '';
    oInp.name = 'text';
    oInp.id = 'text';
    oInp.style.width = '100%';
    oInp.cols = 60;
    oInp.rows = 7;
    oInp.onkeydown = function(){
        limitChar();
    }
    oInp.onkeyup = function(){
        limitChar();
    }
    
    oBut.type = 'button';
    oBut.id = 'postButt';
    oBut.onclick = function(){
        doUpdatePost(id,1);
    }
    oBut.className = 'button';
    oBut.value = 'Senda';
    oSpan2.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;';
    oSpan.id = 'counter';
    oSpan.innerHTML = 1000 - txt.length;
    oSpan1.innerHTML = '&nbsp;&nbsp;stafir eftir';
    oTd.appendChild(oInp);
    oTd.appendChild(oBut);
    oTd.appendChild(oSpan2);
    oTd.appendChild(oSpan);
    }
}

function doUpdatePost(id,disableBtn){
    if(!disableBtn){
        var oBut = document.getElementById('postBut');
        var bg = oBut.style.background;
        var txt = oBut.value;
        oBut.style.background = '#CCCCCC';
        oBut.value = 'Loading...'
        oBut.disabled = true;
    }
    
    var oTxt = document.getElementById('text');
    var oTd = document.getElementById('text_'+id);

//  var params = 'text='+encodeURIComponent(oTxt.value)+'&id='+id+'&checkSum='+MD5(id+oTxt.value);
    var params = 'text='+encodeURIComponent(oTxt.value)+'&id='+id;
    var loader = new net.ContentLoader('news.php?action=doUpdatePost',getResponse,null,'POST',params,null,null,null,'statusLoader','TEXT',true);

    oTd.innerHTML = loader.data;
}

var Facebook = {
    share: function(url) {
            if (!url) url = location.href;
            if (url.charAt(0) == '/') 
                url = location.protocol + '//' + location.host + url;
                t = document.title;
                window.open('http://www.facebook.com/sharer.php?u='
                        + encodeURIComponent(url)
                        + '&t=' +encodeURIComponent(t),
                        'sharer','toolbar=0,status=0,width=626,height=436');
            },
    clickHandler: function(url) {
        this.share(url);
        return false;
    }
};

function fb() {
    return Facebook.clickHandler();
}

// Floating banner
$(document).ready(function(){
        // Initialize floating banners
        $("#banner10").makeFloat({x:"current",y:"current"});
        $("#banner16").makeFloat({x:"current",y:"current"});
        // Show enlarged image
        $(".lightbox").lightbox({
            fileLoadingImage: "js/libs/jquery/plugins/lightbox/images/loading.gif",
            fileBottomNavCloseImage: "js/libs/jquery/plugins/lightbox/images/closelabel.gif",
            fitToScreen: false,
            loopImages: true,
            imageClickClose: false,
            disableNavbarLinks: true,
            strings : {
                help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery',
                prevLinkTitle: 'previous image',
                nextLinkTitle: 'next image',
                prevLinkText:  '&laquo; Previous',
                nextLinkText:  'Next &raquo;',
                closeTitle: 'close image gallery',
                image: 'Mynd ',
                of: ' af '
            },
            fileBottomNavCloseImage : 'images/closelabel_is.gif'
        });
        //Configure gialogs
        configureSendNewsDialog();
    }
);

//Rollover function
function rollOver(obj){
    var pathChunks = obj.src.split('/');
    var file = pathChunks[pathChunks.length - 1];
    var fileChunks = file.split('_');
    var extChunks = fileChunks[fileChunks.length - 1].split('.');
    var ext = extChunks[extChunks.length - 1];
    var isOver =  extChunks[0];
    
    if(isOver == 'over'){
        url = obj.src.replace(/_over/i,'');
    }else{
        url = obj.src.replace(/\.([a-z]{1,4})$/i,"_over.$1");
    }
    
    obj.src = url;
}
// Send news to field dialog
function sendNewsDialog(id){
    $.ajax({
        async: true,
        type: "POST",
        url: "fullStory.php",
        data: "action=showSendStoryDialog&id="+id,
        success: function(html){
        $("#dialog").html(html);
        $("#dialog").dialog("open");
    }
    });
}
function configureSendNewsDialog(){
    var btnSubmit = "Send";
    var btnCancel = "Cancel";
    var buttons = {};
    buttons[btnSubmit] = function() {
        var dialog = this;
        $("#frm").ajaxSubmit({
            url: $("#frm").attr("action"),
            type: "POST",
            dataType: "json",
            beforeSubmit: function(){
            $(":button:contains('Send')").attr("disabled","disabled"); 
        },
        success: function(responce){
            if(responce.valid != true){
                showError('frm');
                jQuery.each(responce, function(i, val) {
                    if(val.valid == false){
                        $("#"+i).addClass('ui-state-error');
                        $("#"+i).tooltip({
                            delay: 0,
                            bodyHandler: function(){
                            return val.msg;
                        },
                        id: 'tooltipError',
                        fade: 200
                        });
                    }else{
                        $("#"+i).removeClass('ui-state-error');
                        $("#"+i).tooltip();
                    }
                });
                $(":button:contains('Send')").removeAttr("disabled");
            }else{
                showConfirm("frm","The story was sent","news_site",5000);
                showFieldsErrors(responce,"frm");
                $("#frm").clearForm();
                $(":button:contains('Send')").removeAttr("disabled");
            }
        }
        });
    }; 
    buttons[btnCancel] = function() {
        $(this).dialog('close');
    };  
    $("#dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        height: 400,
        width: 400,
        modal: true,
        position: 'top',
        buttons: buttons,
        close: function() {
        hideError();
    }
    });
}

// Tynt Read more
tyntVariables = {"ap":"Story from Wsoccernews.com. Read full story: "};

//Add video to playlist
function addToPlaylist(id){
    $.ajax({
        async: true,
        type: "GET",
        url: "video.php",
        data: "action=addToPlaylist&id="+id,
        beforeSend: function(){
        showLoading("btn_add_"+id);
        showLoading("playlist",true);
    },
    success: function(){
        $("#playlist").load("video.php?action=processPlaylist",null,function(){
            hideLoading("playlist");
            hideLoading("btn_add_"+id);
            $("#btn_add_"+id).hide();
        });
    }
    });
}
//Remove video to playlist
function removeFromPlaylist(id){
    $.ajax({
        async: true,
        type: "GET",
        url: "video.php",
        data: "action=removeFromPlaylist&id="+id,
        beforeSend: function(){
            showLoading("playlist",true);
        },
        success: function(){
            $("#playlist").load("video.php?action=processPlaylist",null,function(){
                hideLoading("playlist");
                $("#btn_add_"+id).show();
            });
        }
    });
}
//Play video in player
function playVideo(id,dom,mode){
    if(!mode){
        mode = false;
    }
    $.ajax({
        async: true,
        type: "GET",
        dataType: "json",
        url: "video.php",
        data: "action=getVideoItem&id="+id+"&mode="+mode,
        beforeSend: function(){
            //showLoading("playlist",true);
        },
        success: function(obj){
            $(".item").removeClass("even");
            row = $(dom).parent(); 
            row.addClass("even");
            $("#video_date").html(obj.date);
            $("#video_name").html(obj.u_name);
            $("#video_email").html(obj.u_email);
            $("#video_email").attr("href","mailto:"+obj.u_email);
            $("#video_title a").attr("href","fullStory.php?id="+id);
            $("#video_title a").html(obj.subject);
            player = document.getElementById("ply");
            player.videoID = id;
            if(!mode){
                player.addModelListener("TIME","continious");
            }
            player.sendEvent("STOP","true");
            player.sendEvent("LOAD",obj.video);
            player.sendEvent("PLAY","true");
            if(mode==true){
                location.href="#player";
            }
        }
    }); 
}
// Function for continious playlist playing
function continious(obj){
    if(obj.position == 0 && player.getConfig().state == "COMPLETED"){
        $.ajax({
            async: false,
            type: "GET",
            dataType: "json",
            url: "video.php",
            data: "action=getPlaylist&id="+player.videoID,
            success: function(playlist){
                    if(playlist.id && playlist.id != player.videoID){
                        $(".item").removeClass("even");
                        row.next().addClass("even");
                        row = row.next();
                        $("#video_date").html(playlist.date);
                        $("#video_name").html(playlist.u_name);
                        $("#video_email").html(playlist.u_email);
                        $("#video_email").attr("href","mailto:"+playlist.u_email);
                        $("#video_title a").attr("href","fullStory.php?id="+playlist.id);
                        $("#video_title a").html(playlist.subject);
                        player.videoID = playlist.id;
                        player.sendEvent("LOAD",playlist.video);
                        player.sendEvent("PLAY","true");
                    }
                }
        });
    }
}
