
function NavigateToForum(id)
{
    window.location.href = "Forum.aspx?Forum=" + id;
}

function NavigateToMessage(id)
{
    window.location.href = "/Forums/Message.aspx?ForumMessage=" + id;
}

function alltrim(str) {
    return str.replace(/^\s+|\s+$/g, "");
}


function ValidateAddMessage()
{
    var subject = $("input[id$=txtSubject]")[0];
    var video =  $("textarea[id$=txtVideoCode]")[0];
    var clearText = $("input[id$=txtClearText]")[0];
    var isValid = true ;
    var regexVideo = /http:\/\/www\.youtube[^"]+/;
    var regexGoogleVideo = /http:\/\/video\.google[^"]+/;
    
    var regexVideoWidth = /width="[\d+]*"/;
    var regexVideoHeight = /height="[\d+]*"/;
    var a = video.value;
    var o = FCKeditorAPI.Instances.ctl00_ContentZone_ucPost_fck;
    var newEl = document.createElement("SPAN");
    var newElText = "";
    
    newEl.innerHTML = o.GetHTML();
    clearText.value = newEl.innerText || newEl.textContent;
    
    if(clearText.value == "undefined")
        clearText.value = "";
        
    newElText = clearText.value;

    $("#valIncludeType").hide();
    
    if(alltrim(subject.value)=="")
    {
        $("#valSubject").show("slow")
        subject.className += " InputError";
        subject.focus();
        isValid = false;
    }
    else
    {
        $(subject).removeClass("InputError");
        $("#valSubject").hide("slow");
    }
    
    if((a!="") && (!a.match(regexVideo) || !a.match(regexVideoWidth) || !a.match(regexVideoHeight)) && (!a.match(regexGoogleVideo)))
    {
        $("#valVideo").show("slow")
        video.className = "InputError";
        if(isValid)
            video.focus();
        
        if(a!=""){
            $("input[id$=cbxIncludeVideo]")[0].checked=false;
            toggleInclude($("input[id$=cbxIncludeVideo]")[0]);
        }
        
        isValid = false;
    }
    else
    {
        video.className = "";
        $("#valVideo").hide("slow");
        
        if(a!=""){
            $("input[id$=cbxIncludeVideo]")[0].checked=true;
            toggleInclude($("input[id$=cbxIncludeVideo]")[0]);
        }
    }

    if(alltrim(newElText)=="" && newEl.innerHTML.indexOf("<IMG") == -1 && newEl.innerHTML.indexOf("<img") == -1 && newEl.innerHTML.indexOf("<OBJECT") == -1 && newEl.innerHTML.indexOf("<OBJECT") == -1 && newEl.innerHTML.indexOf("<EMBED") == -1 && newEl.innerHTML.indexOf("<embed") == -1 )
    {
        $("#valText").show();
        o.SetData('');
        
        if(isValid)
            o.Focus();
        
        isValid = false;
    }
    else
    {
        $("#valText").hide();
    }
   

    if($("input[id$=rdoTypeRelease]:checked").length >0){
        if($("input[id$=cbxIncludeVideo]:checked").length == 0 && $("input[id$=cbxIncludeAudio]:checked").length == 0) {
            
            if(isValid)
                $("input[id$=rdoTypeRelease]")[0].focus();
            
            $("#valIncludeType").show();
            isValid = false ;
        }
    }
    
    
    return isValid;
 
    //var text = document.getElementById("valSubject");
   
}

function ValidateReply()
{
    var video =  $("textarea[id$=txtVideoCode]")[0];
    var isValid = true ;
    var regexVideo = /http:\/\/www\.youtube[^"]+/;
    var regexGoogleVideo = /http:\/\/video\.google[^"]+/;
    var regexVideoWidth = /width="[\d+]*"/;
    var regexVideoHeight = /height="[\d+]*"/;
    var a = video.value;
    var o = FCKeditorAPI.Instances.ctl00_ContentZone_ucPost_fck;
    var clearText = $("input[id$=txtClearText]")[0];
    var newEl = document.createElement("SPAN");
    
    newEl.innerHTML = o.GetHTML();
    clearText.value = newEl.innerText || newEl.textContent;
    
    if(clearText.value == "undefined")
        clearText.value = "";
    
    if((a!="") && (!a.match(regexVideo) || !a.match(regexVideoWidth) || !a.match(regexVideoHeight)) && (!a.match(regexGoogleVideo)))
    {
        $("#valVideo").show("slow")
        video.className += " InputError";
        video.focus();
        isValid = false;
    }
    else
    {
        $(video).removeClass("InputError");
        $("#valVideo").hide("slow");
        
    }
    
    
    if(alltrim(clearText.value)=="" && newEl.innerHTML.indexOf("<IMG") == -1 && newEl.innerHTML.indexOf("<img") == -1 && newEl.innerHTML.indexOf("<OBJECT") == -1 && newEl.innerHTML.indexOf("<OBJECT") == -1 && newEl.innerHTML.indexOf("<EMBED") == -1 && newEl.innerHTML.indexOf("<embed") == -1 )
    {
        $("#valText").show("slow");
        o.SetData('');
        o.Focus();
        isValid = false;
    }
    else
    {
        $("#valText").hide("slow");
    }
    
    
    return isValid ;
}

function ValidateRegistration()
{

    var name = $("input[id$=txtNickName]")[0];
       
    var birthDay = $("select[id$=cbxBirthDay]")[0];
    var birthMonth = $("select[id$=cbxBirthDate]")[0];
    var birthYear = $("select[id$=cbxBirthYear]")[0];
 
    var email =  $("input[id$=txtEmail]")[0];
    var password = $("input[id$=txtPassword]")[0];
    var password2 = $("input[id$=txtValPassword]")[0];
    var termsOfUse = $("input[id$=chkTermsOfUse]")[0];
    var regexAge = /[0-9]{2}/;
    var regexEmail = /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/
    var regexPassword = /[a-zA-Z0-9_=-]{5}/;
    var isValid=true;
    var passCanEmpty = false;
    
    if($(password).attr("empty") == "true")
    {
        passCanEmpty = true ;
    }
    
    if(alltrim(name.value)=="")
    {
        document.getElementById("valNickName").style.display = "block";
        name.className += " InputError";
        isValid = false ;
    }
    else
    {
        document.getElementById("valNickName").style.display = "none";
        $(name).removeClass("InputError");
    }

    if(birthDay.value == "-1" || birthMonth.value == "-1" || birthYear.value == "-1")
    { 
        document.getElementById("valAge").style.display = "block";
        birthDay.className += " InputError";
        birthMonth.className += " InputError";
        birthYear.className += " InputError";
        isValid = false ;
    }
    else
    {
        document.getElementById("valAge").style.display = "none";
        $(birthDay).removeClass("InputError");
        $(birthMonth).removeClass("InputError");
        $(birthYear).removeClass("InputError");
    } 
    
    
    if(!email.value.match(regexEmail))
    {
        document.getElementById("valEmail").style.display = "block";
        email.className += " InputError";
        isValid = false ;
    }
    else
    {
        document.getElementById("valEmail").style.display = "none";
        $(email).removeClass("InputError");
    }   
    
    if(passCanEmpty)
    {
        if(alltrim(password.value)!="" && !password.value.match(regexPassword))
        {
            document.getElementById("valPassword").style.display = "block";
            password.className += " InputError";
            isValid = false ;
        }
        else
        {
            document.getElementById("valPassword").style.display = "none";
            $(password).removeClass("InputError");
        }  
    }
    else
    {
        if(!password.value.match(regexPassword))
        {
            document.getElementById("valPassword").style.display = "block";
            password.className += " InputError";
            isValid = false ;
        }
        else
        {
            document.getElementById("valPassword").style.display = "none";
            $(password).removeClass("InputError");
        }  
    }
    
    if(password.value!=password2.value)
    {
        document.getElementById("valPassword2").style.display = "block";
        password2.className += " InputError";
        isValid = false ;
    }
    else
    {
        document.getElementById("valPassword2").style.display = "none";
        $(password2).removeClass("InputError");
    }  
    
    if(termsOfUse)
    {
        if(!termsOfUse.checked)
        {
            document.getElementById("valTerms").style.display = "block";
            document.getElementById("termsText").style.color = "yellow";
            termsOfUse.className += " InputError";
            isValid = false ;
        }
        else
        {
            document.getElementById("valTerms").style.display = "none";
            document.getElementById("termsText").style.color = "white";
            $(termsOfUse).removeClass("InputError");
        } 
    }
    
    return isValid;

}



function ValidateEmail(elId,errorFieldId, oldCss)
{
    var regexEmail = /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/
    var el = $("input[id$="+elId+"]")[0];
    if(!el.value.match(regexEmail))
    {
        el.className = "InputError";
        $("#" + errorFieldId)[0].style.display="block";
        return false;
    }
    
    el.className = oldCss || "";
    $("#" + errorFieldId)[0].style.display="none";
    return true ;
}

function ShowAbuseMessage()
{
    $("#abuseMessage").show("slow");
}


function ValidateAllEmailsInvite(emails)
{
    var splt = emails.split(",");
    var flag = true;

    for(var i=0; i<splt.length; i++)
    {
        if(alltrim($("input[id$=" + splt[i] + "]")[0].value)!="")
        {
            
            flag = ValidateEmail(splt[i], (splt[i] + "Val"));
            if(flag==false)
            {
                return false;
            }
        }
    }
    
    
}

function validateSendEmail()
{
    var subject = $("input[id$=txtSubject]")[0];
    if(alltrim(subject.value)=="")
    {
        subject.className+=" InputError";
        $("#valSubject").show();
        return false;
    }   
    else
    {
        $(subject).removeClass("InputError");
        $("#valSubject").hide();
    }
}

function toggleChk(name, e)
{
    var el = document.getElementsByName(name);
    for(var i=0; i<el.length;i++)
    {
        el[i].checked=e.checked ;
    }
}

function setAllChecked(el, id)
{
    if(el.checked==false)
        document.getElementById(id).checked = false; 
}

function showAdminMenu(id)
{
    
}

function DeleteThread(id)
{
    if(confirm("Are you sure? \nThis thread will delete permanently!"))
    {
        window.location.href="DeleteThread.aspx?id=" + id;
    }
}

function changeSearchType()
{
    if(!document.getElementById("srchRegular").checked)
    {
        document.forms[0].action = "/SearchResults.aspx";
        document.forms[0].id = "cse-search-box";
        document.forms[0].method="get";
        
        document.getElementById("__EVENTTARGET").value="";
        document.getElementById("__VIEWSTATE").value="";
        
        document.forms[0].submit();
        return false;
    }
    else
    {
       document.forms[0].action = "/Discography/SearchResults.aspx";
       document.forms[0].method="get";
       document.getElementById("__VIEWSTATE").value="";
       document.forms[0].submit();
    }
}


function GetContent(id)
{
    document.getElementById("WzBoDyI").innerHTML = "Loading...";
    if(document.getElementById("c"+id))
    {
        if(document.getElementById("WzBoDyI"))
        {
            document.getElementById("WzBoDyI").innerHTML=document.getElementById("c"+id).innerHTML;
            return;    
        }
    }
    
    
    OfferNissimFans.Forums.Default.GetForumContent(parseInt(id), function(response) {
        
        var html="<table class=\"ForumPreviewTable\" cellspacing=1 cellpadding=0>";
        if(response.error!=null)
            return;
        else
        {
            var arr = response.value ;
            var obj ;
            var pic;
            if(arr.length == 0)
                html="<div class=\"NoMessages\">No Messages.</div>";
            
            for(i=0;i<arr.length;i++)
            {
                pic = arr[i]["First"];
                obj = arr[i]["Second"]; 
                html+="<tr>";
                html+="<td  class=\"ForumPreviewTableCell ForumPreviewPicCell\"><img src=\""+ (pic == "" ? nopic : pic)  +"\" width=50 height=50 style=\"vertical-align:top;\"/></td>";
                html+="<td class=\"ForumPreviewTableCell\" style=\"width:246px;\">"+ obj.Subject +"</td>";
                html+="</tr>";
            }
        }
        html+="</table>";
        
        var el = document.createElement("span");
        el.id  = "c"+id;
        el.innerHTML = html ;
        document.appendChild(el);
        
        if(document.getElementById("WzBoDyI"))
            document.getElementById("WzBoDyI").innerHTML=html;

    })
    
}
var arrDontShow = new Array();

function GenerateAlerts()
{
    $("div.useralert").each(function(i,n) {
        if(n.getAttribute("autodelete") == "false")
            arrDontShow[arrDontShow.length] = n.id.replace("alert_","");
    })
    

    AlertMove(0);
}


function AlertMove(index)
{
    var alerts = $("div.useralert");
    var total = alerts.length;
    var alert = $("div.useralert[index="+index+"]")[0];
    var checked = "" ;
    
    for(var i=0; i< arrDontShow.length ; i++)
    {
        if(arrDontShow[i] == alert.id.replace("alert_",""))
        {
            checked="checked=checked";
            break;
        }
    }
    

    if(alert.getAttribute("autodelete") == "true")
        $("#dvDontShowAgain").html('this alert will be deleted automaticly.');
    else
        $("#dvDontShowAgain").html('<input type="checkbox" id="donotshowAlert" '+ checked +' value="'+ alert.id.replace("alert_","") +'" onclick=\"setDontShow(this)\" /> Don\'t show again');
    
    if(index==0 && document.getElementById("leftAlertImg"))
        document.getElementById("leftAlertImg").style.display = "none";
      
    var type = parseInt(alert.getAttribute("type"));
    
    if(type == 1)
    {
       document.getElementById("imgAlertType").src ="/images/regularAlert.png";
       $("#alertTitle").html('Attention alert');
    }
    else if(type == 2)
    {
        $("#alertTitle").html('Warning alert');
        document.getElementById("imgAlertType").src ="/images/warningAlert.png";
    }
    else if(type == 3)
    {
        $("#alertTitle").html('Tip');
        document.getElementById("imgAlertType").src ="/images/TipAlert.png"; 
    }
    else
    {
        $("#alertTitle").html('Welcome!');
        document.getElementById("imgAlertType").src ="/images/TipWelcome.png"; 
    }
        
    $("#dvAlertContent").html(alert.innerHTML);  
   
    if(total > index+1)
        $("#rightAlertImg").show()[0].onclick = function() {AlertMove(index+1); }
    else
        $("#rightAlertImg").hide();    
        
   if(index > 0 && index <= total)
        $("#leftAlertImg").show()[0].onclick = function() {AlertMove(index-1); }
   else
        $("#leftAlertImg").hide();   
}

function setDontShow(e)
{
    var val = e.value ;
    var exist = false;     
        
    for(var i=0; i<arrDontShow.length; i++)
    {
        if(arrDontShow[i] == val)
            {
                if(e.checked)
                {
                     if(val == arrDontShow[i])
                        {
                            exist = true;
                            break ;
                        }       
                }
                else
                {
                    arrDontShow = arrDontShow.slice(0,i).concat( arrDontShow.slice(i+1) );
                    break;
                }
            }
    }
         
    if(e.checked && !exist)
        arrDontShow[arrDontShow.length] = val;                 
}

function SaveAlerts()
{
    if(arrDontShow.length > 0)
    {
        PageMethods.SaveAlerts(arrDontShow);
    }
} 

function GetMoveToForums(id)
{
     var container = $("#boxForums")[0];
     var list = $("#forumlistMoveTo")[0];
     
     $(container).toggle();
     if($(list).html().indexOf("<UL>") > -1 || $(list).html().indexOf("<ul>") > -1)
        return;
     
     $(list).html("Loading...");
     
     PageMethods.GetMoveToForums(function(response) {
     
        var arr = response;
        var str = "";
        
        str = "<UL>";
        
        for(var i=0; i < arr.length; i++)
        {
            str += "<li><a href=\"MakeForward.aspx?forumId="+ arr[i]["First"] +"&id="+ id +"\">"+ arr[i]["Second"] +"</a></li>";
        }
        
        str += "</UL>";
        
        list.innerHTML = str;
        
     }, function(response) {
        
        //error
     });
     
}

function toggleType(e) {
    $(e).parent().parent().find("td").css("font-weight", "normal");
    $(e).parent().css("font-weight", "bold");
}

function toggleInclude(e) {
    if(e.checked)
        $(e).parent().css("font-weight", "bold");
    else
        $(e).parent().css("font-weight", "normal");
}

function bookmark(){
var title = 'Offer Nissim Fans';
var url = 'http://www.offernissimfans.com/';
   if (document.all)
     window.external.AddFavorite(url, title);
   else if (window.sidebar)
     window.sidebar.addPanel(title, url, "")
   else if (window.sidebar&&window.sidebar.addPanel)
     window.sidebar.addPanel(title,url,"");
}
function openPopup(url, width, height)
{
    window.open(url, "_blank", 'width=' + width  + ', height=' + height);
}


function confirmPaylistFavorite(id)
{
    OfferNissimFans.Playlists.View.MakeFavorite(id, function(response) {
        $("div[id$=pnlMakeFavorite]").html("Favorite saved. <br/><br/>");
        $("a[id$=aBtnFavorite]").hide();
    });
}

function removePaylistFavorite(id)
{
    OfferNissimFans.Playlists.View.RemoveFavorite(id, function(response) {
        $("#removepopupContainer").html("Favorite removed. <br/><br/>");
        $("a[id$=aRemoveFavorite]").hide();
    });
}

function ShareFacebook(url, title)
{
    window.open("http://www.facebook.com/sharer.php?u="+ url +"&t=" + title, "_blank", "width=540, height=400");
}