﻿/*
API
File Type :Javascript
File Name:JS_CONTROL_MASTER_API.js
File Creater:Amit Kalra
File Created Date:6Jan 2009
File Description:Html Control Creation Module.

*/
function createControl(Control,Control_Type){
    var Element = document.createElement(Control);
    if(Control_Type!=""){
        Element.type = Control_Type;
    }
    return Element;
}

function setControlId(Control,Id){
    Control.id = Id;
}

function setinnerText(Control,Data){
    Control.innerText = Data;
}

function setText(Control,Data){
    Control.text = Data;
}

function setContent(Control,Data){
    Control.textContent = Data;
}

function setHTML(Control,Data){
    Control.innerHTML = Data;
}

function getHTML(Control,Data){
    return Control.innerHTML;
}

function setValue(Control,Data){
    Control.value = Data;
}

function AppendControl(Container,childElement){
    Container.appendChild(childElement);
}

function ClearData(_id){
if(document.getElementById(_id)!=null)
{
    document.getElementById(_id).innerHTML="";
}
}

function ProgressStatus(_id,ControlType,Msg){
    if(ControlType=="select"){
        document.getElementById(_id).options[0] = new Option("Please Wait!!");
        document.getElementById(_id).options[0].text = Msg;
        document.getElementById(_id).options[0].value = 0;
    }
}

function setAlternativetext(ControlType,Msg){
    ControlType.alt=Msg;
}

function setControlIndex(_id,ControlType,index){
    if(ControlType=="select"){
    if(document.getElementById(_id)!=null)
    {
        if(document.getElementById(_id).options.length!="0"){
            document.getElementById(_id).options[index].selected = true
        }
        }
    }
    else if(ControlType=="checkbox"){
        if(document.getElementById(_id)!=null){
            document.getElementById(_id).checked = true;
        }
        
    }
}


function getControlSelectedValue(_id,ControlType){
    if(ControlType=="select"){
        return document.getElementById(_id).options[document.getElementById(_id).selectedIndex].value;
    }
}
//=====================Arpit================================//
function getControlSelectedText(_id,ControlType){
    if(ControlType=="select"){
        return document.getElementById(_id).options[document.getElementById(_id).selectedIndex].text;
    }
}
//===========================================================//
function setControlSelectedValue(_id,ControlType,value){
    var Indexval="";
    if(ControlType=="select"){
        var Element = document.getElementById(_id);
        for(var i=0;i<=Element.options.length-1;i++){
            if(Element.options[i].value==value){
                try
                {
                    Element.options[i].selected=true;
                }
                catch(e)
                {
                    
                }
                Indexval=i;
                break;
            }
        }
    }
    else if(ControlType=="radio"){
        for(var i=0;i<=_id.length-1;i++){
            if(document.getElementById(_id[i]).value==value){
                document.getElementById(_id[i]).checked=true;
                Indexval=_id[i];
            }
        }
    } 
    else if(ControlType=="checkbox"){
        var Element = document.getElementById(_id).getElementsByTagName('input');
        for(var i=0;i<=Element.length-1;i++){
            var getSplitPublication = value.split('+');
            for(var j=0;j<=getSplitPublication.length-1;j++){
                if(getSplitPublication[j]!=""){
                    if(Element[i].value==getSplitPublication[j]){
                        Element[i].checked=true;
                        Indexval="";
                    }
                }
            }
            
        }
    }
    return Indexval;
}
