var browser=navigator.appName;
var userAgent=navigator.userAgent;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var isIE = (userAgent.indexOf("MSIE") != -1) ? true : false;
var isNet = (userAgent.indexOf("Firefox") != -1) ? true : false;
var isSafari = (userAgent.indexOf("Safari") != -1) ? true : false;

var speed = 15;
var delay = 5;

var cortinaDiff = 1;
if (isIE) {
    cortinaDiff = 18;
}

function changeOn(img) {
    img.src = img.src.replace(/-off/,"-on");
}
function changeOff(img) {
    img.src = img.src.replace(/-on/,"-off");
}

function navMouseOver(img, opts) {
    changeOn(img);
    if (typeof(opts) != "undefined") {
        var IDs = opts.split("|");
        for (t=0; t < IDs.length; ++t) {
            var o = document.getElementById(IDs[t]);
            if (o != null) {
                changeOn(o);
            }
        }
    }
}
function navMouseOut(img, opts) {
    changeOff(img);
    if (typeof(opts) != "undefined") {
        var IDs = opts.split("|");
        for (t=0; t < IDs.length; ++t) {
            var o = document.getElementById(IDs[t]);
            if (o != null) {
                changeOff(o);
            }
        }
    }
}
function openCortina(limit) {
    var cortina = document.getElementById("cortina");
    if (parseInt(cortina.style.left) < limit) {
        cortina.style.left = parseInt(cortina.style.left) + speed;
        setTimeout("openCortina("+limit+")", delay);
    } else {
        cortina.style.left = limit;
        document.getElementById("bar").className = "bar_on";
    }
}
function closeCortina() {
    var cortina = document.getElementById("cortina");
    if (parseInt(cortina.style.left) > -480) {
        cortina.style.left = parseInt(cortina.style.left) - speed;
        setTimeout("closeCortina()", delay);
    } else {
        cortina.style.left = -480;
        document.getElementById("bar").className = "bar_off";
    }
}

function moveCortina() {
    var cortina = document.getElementById("cortina");
    if (parseInt(cortina.style.left) != -480) {
        closeCortina()
    } else {
        startCortina(0);
    }
}

function startCortina(sleep) {
    var cortina = document.getElementById("cortina");
    var content = document.getElementById("content");
    var padding = (isIE) ? 0 : 16;
    var limit = ((parseInt(cortina.style.left) * -1) - parseInt(content.style.width) - padding) * -1;
    if (typeof(sleep) == "undefined") {
        sleep = 1000;
    }
    if ( limit > 0 || isSafari) {
        limit += cortinaDiff;
    } else {
        limit += 1;
    }
    setTimeout("openCortina("+limit+")", sleep);
}
function setNav(opts) {
    for (opc=0; opc < opts.length; ++opc) {
        var o = document.getElementById(opts[opc]);
        if (o != null) {
            o.src = o.src.replace(/-off/,"-over");
        }
    }
}
function initCortina() {
    startCortina();
}

function initScroll() {
    
}

function printedForm(o) {
    var frmPrinted = document.getElementById('frmPrinted');
    if (frmPrinted != null) {
        frmPrinted.className = (o.checked) ? "setVisible" : "setHidden";
    }
}

function isEmail(str){
    var RegExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
    var result = str.match(RegExp);
    return result;
}

function contactFrmValidation() {

    var o = document.getElementById('Name');
    if ( o.value == "" ) {
        alert("Please provide your name");
        o.focus();
        return false;
    }

    var o = document.getElementById('E-mail');
    if ( o.value == "" || !isEmail(o.value) ) {
        alert("Please provide a valid e-mail address");
        o.focus();
        return false;
    }

    var o = document.getElementById('Phone');
    if ( o.value == "" ) {
        alert("Please provide a Telephone Number");
        o.focus();
        return false;
    }

    var o = document.getElementById('Subject');
    if ( o.value == "" ) {
        alert("Please provide a Subject");
        o.focus();
        return false;
    }

    var o = document.getElementById('Message');
    if ( o.value == "" ) {
        alert("Please provide a Message");
        o.focus();
        return false;
    }

    var o = document.getElementById('aboutus');
    if ( o.selectedIndex == 0 ) {
        alert("How did you hear about us?");
        o.focus();
        return false;
    }

    var o = document.getElementById('SendPrinted');
    if ( o.checked ) {
        var o = document.getElementById('Address1');
        if ( o.value == "" ) {
            alert("Please provide an Address");
            o.focus();
            return false;
        }

        var o = document.getElementById('City');
        if ( o.value == "" ) {
            alert("Please provide your City");
            o.focus();
            return false;
        }

        var o = document.getElementById('State');
        if ( o.value == "" ) {
            alert("Please provide your State");
            o.focus();
            return false;
        }

        var o = document.getElementById('Postalcode');
        if ( o.value == "" ) {
            alert("Please provide your Postal Code");
            o.focus();
            return false;
        }

        var o = document.getElementById('Country');
        if ( o.value == "" ) {
            alert("Please provide your Country");
            o.focus();
            return false;
        }
    }

    return true;
}

function logoOver(t) {
    var logo = document.getElementById("logo");
    logo.className = "";
}

function logoOut() {
    var logo = document.getElementById("logo");
    logo.className = "Opaco";
}

function changeOpacity(t) {
    logo.style.filter = "alpha(opacity="+t+")";
    logo.style.opacity = ""+(t/100)+"";
}

function GetCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
    return "";
}

//GetCookie('MAKE_PAGE');
//document.cookie = "SHOW_PAGE=; path=/;";

function fn_selectEN() {
	document.cookie = "LANGUAGE=EN; expires=Fri, 7 May 2010 12:00:00 UTC; path=/;";
	document.location.href = "/index.php";
}
function fn_selectSP() {
	document.cookie = "LANGUAGE=SP; expires=Fri, 7 May 2010 12:00:00 UTC; path=/;";
	document.location.href = "/sp/index.php";
}

function flace(id){
    var o = document.getElementById(id);
    if ( o != null ) {
		var s = o.style;
		s.width = '1px';
		s.height = '1px';
		s.overflow = 'hidden';
    }
}

function content(id, w, h){
    var o = document.getElementById(id);
    if ( o != null ) {
		var s = o.style;
		s.width = w + 'px';
		s.height = h + 'px';
		s.overflow = 'hidden';
    }
}