﻿/*
*Types supported :
*1. tag selector
*2. id selector
*3. class selector
*/

function t(param) {
    var str = param.charAt(0);
    var dest = null;
    if (str == '#') {
        var word = param.substring(1, param.length);
        dest = new IdSel(word);
    }
    else {
        var word = param;
        dest = new TagSel(word);
    }
    return dest;
}
/*
*To load plain XML into your file. Need not be used unless you are working in a sandbox.
*/
function LoadContentInto(url , handler)
{
	var v = new tel.Variables();
    v.URL = url;
    v.fire(handler, v);
}

/*
*@class Interface to represent an object of destination as a generality. 
*This acts as a bridge between all the selectors.
*/
function Dest(dest) {
}
/*
*@class ID selector to direct call for ID.
*/
var IdSel = function (dest) {
    this.main = dest;
}
IdSel.prototype = {
    GetHtml: function () {
        return this.main.innerHTML;
    },
    SetHtml: function (html) {
        document.getElementById(this.main).innerHTML = html;
    },
    Load: function (url) {
        var v = new tel.Variables();
        v.URL = url;
        v.DOM_DEST = this.main;
        v.fire(AjaxLoaderFunction, v);
    },
    Style: function (property, value) {
        eval("document.getElementById('"+ this.main +"').style." + property + " = '" + value + "'");
    },
    AppendHtml: function (html) {
        document.getElementById(this.main).innerHTML += html;
    }
}


/*
*@class Tag selector. Selecting all tags.
*/

var TagSel= function (dest) {
    this.main= dest;	
    this.Tags=document.getElementsByTagName(this.main);
}
TagSel.prototype= {
    	GetHtml: function () {
	var a=new Array();
	for(x in this.Tags)
	{
		try{
		a.push(x.innerHTML);}catch(exp){}
	}
	return a;
        },
	SetHtml: function(html) {
	for(x in this.Tags)
	{
		try{
		x.innerHTML=html;}catch(exp){}
	}
    	},
        Load: function (url) {
	for(x in this.Tags)
	{
	var v = new tel.Variables();
        v.URL = url;
        v.DOM_DEST = x;
        v.fire(AjaxLoaderFunction, v);
    	}
	},
	
	Style: function(property, value) {
	    for(x in this.Tags)
	    {
			try{
              		eval(x+".style." + property + " = '" + value + "'");}catch(exp){}
	    }
	},
	AppendHtml: function (html) {
	for(x in this.Tags)
	{
		try{
		x.innerHTML +=html;}catch(exp){}
	}
    }
}

function AjaxLoaderFunction() {
    var v = tel.Variables.GetVar();
    t("#" + this.Vars.DOM_DEST).SetHtml(this.AJAXObject.responseText);
}

