/* 
# /scripts/
#
# Copyright (C) 2010 POWERCOMP, LLC. Russia, Moscow.
# Written by Lebedeva Marina, Lebedev Kirill <info@powercomp.ru>
# /scripts/main.js
#
# This file - is main JS functions container
 */


function getHTTPObject() {
    var xhr = false;//set to false, so if it fails, do nothing
    if(window.XMLHttpRequest) {//detect to see if browser allows this method
        var xhr = new XMLHttpRequest();//set var the new request
    } else if(window.ActiveXObject) {//detect to see if browser allows this method
        try {
            var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
        } catch(e) {//if it fails move onto the next
            try {
                var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
            } catch(e) {//if that also fails return false.
                xhr = false;
            }
        }
    }
    return xhr;//return the value of xhr
}

function _setStyle(aElement /* object */, aDeclaration /* CSS Declaration */) {
    try {
        if (aElement) {
            aDeclaration = aDeclaration.replace(/\s+/g,''); // remove all white spaces
            if (document.all) { // IE Hack
                if (aDeclaration.charAt(aDeclaration.length-1)==';')
                    aDeclaration = aDeclaration.slice(0, -1);
                var k, v;
                var splitted = aDeclaration.split(';');
                for (var i=0, len=splitted.length; i<len; i++) {
                    k = rzCC(splitted[i].split(':')[0]);
                    v = splitted[i].split(':')[1];
                    eval("aElement.style."+k+"='"+v+"'");
                }
                return (true);
            } else { // The clean way
                aElement.setAttribute ('style', aDeclaration);
                return (true);
            }
        }
    } catch (e) {
        return (false);
    }
}

function rzCC(s){
    for(var exp=/-([a-z])/;
        exp.test(s);
        s=s.replace(exp,RegExp.$1.toUpperCase()));
    return s;
}
