﻿function FormValidateRequired(s, e) {
    var name = e.value;
    if (name == null) return;
    if (name.length < 2) e.isValid = false;
}

/* ----------------------------------------------------- news */
var curTailElement = null;
var loadingDivText = '<div class="LoadingDiv">Laddar&hellip;</div>';

function OnTailClick(newsID, htmlElement) {
    if (!NewsCallback.InCallback() && !IsCurrentNews(htmlElement)) {
        curTailElement = htmlElement;
        ShowNewsPopup(htmlElement, loadingDivText);
        NewsCallback.PerformCallback(newsID);
    }
}
function OnCallbackComplete(result) {
    if (GetNewsPopup().IsVisible())
        ShowNewsPopup(curTailElement, result);
}
function OnNewsControlBeginCallback() {
    GetNewsPopup().Hide();
}
function IsCurrentNews(htmlElement) {
    return (curTailElement == htmlElement) && GetNewsPopup().IsVisible();
}
function ShowNewsPopup(element, contentText) {
    GetNewsPopup().Hide();
    GetNewsPopup().SetContentHTML(contentText);
    GetNewsPopup().ShowAtElement(element);
}
function GetNewsPopup() {
    return NewsDetailPopup;
}

var userControlCache = {};
var userControlInCallback = null;
function ShowPopupSingleId(popupControl, userControl, id) {   
    //campainpopup.Show();

    var parameter = userControl + "/" + id;

    userControlInCallback = userControl;
    campaincallback.PerformCallback(parameter);
}
function CallbackComplete(result, popupControl) { 
    SetPopupContentHTML(result, popupControl);
}
function SetPopupContentHTML(result, popupControl) {
    campainpopup.SetContentHTML(result);
    if (campainpopup.IsVisible())
        campainpopup.UpdatePosition();
}
/* ---------------------------------------------------- Validation */

function OnTextValidation(s, e) {
    var name = e.value;    
    if (name == null)
        return;
    if (name.length < 2) {
        e.isValid = false;
        s.GetMainElement().style.borderColor = "red";
    }
}
function OnCompanyValidation(s, e) {    
    var name = e.value;
    if (rbbill.GetValue() == true) {        
        if (name == null)
            return;
        if (name.length < 2) {
            e.isValid = false;
            s.GetMainElement().style.borderColor = "red";
        }        
    } else e.isValid = true;
}
function OnPayMethodValidation(s, e) {
    var name = e.value;

    if (rbbill.GetValue() != true && rbcard.GetValue() != true) {
        e.isValid = false;
        //s.GetMainElement().style.borderColor = "red";       
        pnlpaymentvalidation.GetMainElement().style.borderStyle = "solid";       
    } else {
        pnlpaymentvalidation.GetMainElement().style.borderStyle = "none";
        e.isValid = true;    
    }
}
function OnTextCheckboxValidation(s, e, upload) {
    var name = upload.GetText();   
    if (name.length < 2 && s.GetChecked() != true) {         
        e.isValid = false;
        s.GetMainElement().style.borderStyle = "solid";
    } else {        
        s.GetMainElement().style.borderStyle = "none";  
        e.isValid = true;           
    }
}



