﻿// JScript File

function StyleSheet(){}

function getStylesheetName(stylesheetid,objectid){
       if(stylesheetid.length <=0){return;}
       new Ajax.Request("/ajaxservices/stylesheet/stylesheet.aspx", {method:'get',parameters:'stylesheetid=' + stylesheetid +'&action=getstylesheetname', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        obj.value = t.responseText;        
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}

function getStylesheet(stylesheetid, objectid,asyn){
       asyn = asyn == true ? true : false;
       if(stylesheetid.length <=0){return;}
       new Ajax.Request("/ajaxservices/stylesheet/stylesheet.aspx", {method:'get',asynchronous:asyn,parameters:'stylesheetid=' + stylesheetid + '&action=getstylesheet', onSuccess:function(t){
            var obj = document.getElementById(objectid);
            obj.value = t.responseText;
            showSuccessfulMsg("");
            try{
               applyStyleSheet(t.responseText);
            } catch(e){}
        }, onFailure:function(t){
        alert(t.responseText);
    }});    
}

function getStylesheetSelectBox(stylesheetid, objectid){
       if(stylesheetid.length <=0){return;}
       new Ajax.Request("/ajaxservices/stylesheet/stylesheet.aspx", {method:'get',asynchronous:false,parameters:'stylesheetid=' + stylesheetid + '&action=getstylesheets', onSuccess:function(t){
        
        var obj = document.getElementById(objectid);
        obj.innerHTML = t.responseText;            
        }, onFailure:function(t){
        alert(t.responseText);
    }});    
}


function deleteStylesheet(stylesheetid,objectid){
       new Ajax.Request("/ajaxservices/stylesheet/stylesheet.aspx", {method:'get',asynchronous:true,parameters:'stylesheetid=' + stylesheetid + '&action=deletestylesheet', onSuccess:function(t){
           var objSelect = document.getElementById(objectid);
           objSelect.remove(objSelect.selectedIndex);
           objSelect.selectedIndex = objSelect.options.length -1;
           document.getElementById("frm_NewStyleSheetName").value ="";
           document.getElementById("frm_NewStyleSheet").value=".poll{}\n.question{}\n.answer{}\n.othertextbox{}\n.answeroptionbox{}\n.pollbutton{}\n.pagelink{}\n.pagelink:hover{}\n.pagelink:visited{}\n.bar{background-color:green}\n";
          showSuccessfulMsg("<div class='good'>"+lexicon.LEX_STYLESHEET_DELETED+"</div>");   
        }, onFailure:function(t){
          //alert(t.responseText);
          showSuccessfulMsg("<div class='bad'>"+lexicon.LEX_STYLESHEET_DELETE_FAIL+"</div>");
    }});    
}

function saveStyleSheet(stylesheetid,stylesheetname,stylesheet,objectid){     
       new Ajax.Request("/ajaxservices/stylesheet/stylesheet.aspx", {method:'post',asynchronous:true,postBody:'stylesheet=' + escape(stylesheet) + '&stylesheetname=' + escape(stylesheetname) + '&stylesheetid=' + stylesheetid + '&action=savestylesheet', onSuccess:function(t){         
            refreshOptions(t.responseText);
            showSuccessfulMsg("<div class='good'>"+lexicon.LEX_STYLESHEET_SAVED+"</div>");
            default_StatusElement = null;
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}


StyleSheet.prototype.getstylesheetname = getStylesheetName;
StyleSheet.prototype.getstylesheet = getStylesheet;
StyleSheet.prototype.savestylesheet = saveStyleSheet;
StyleSheet.prototype.getstylesheetselectbox = getStylesheetSelectBox;
StyleSheet.prototype.deletestylesheet = deleteStylesheet;

