// JavaScript Document

var http = createRequestObject();

// div fader
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 



// menu show
// this function will fade the div out load the menu then fade the div in
function show_menu(id,link_id)
		{
			
			
			//change the link color
			document.getElementById(link_id).style.color = "#CC0000";
			// run through link array and turn of the others if there on
			for(i=0;link_array.length>i;i++)
				{
					//alert(link_id);
					if(link_array[i] != link_id)
						{
							change_link = link_array[i];
							//alert(change_link);
							new_link_color = document.getElementById(change_link);
							new_link_color.style.color = "#000000";
						
						}
				}
			
			// Fade div out
			opacity(submenu_div, 100, 0, millisec);
			//shiftOpacity(submenu_div, millisec)
			//alert(id);
			setTimeout("load_submenu('"+id+"')",millisec);
			
			// Fade div in
			//shiftOpacity(submenu_div, millisec)
			setTimeout("opacity('"+submenu_div+"', 0, 100, '"+millisec+"')",millisec);
			
			
		}

function load_submenu(id)
		{
			// get content of menu
			menu = document.getElementById(id).innerHTML;
			// load content of menu
			document.getElementById(submenu_div).innerHTML = menu;
			
		}
		
function resize_main()
		{
			content_base =  document.getElementById('content_area_div').clientHeight;
			content_offset = document.getElementById('content_area_div').offsetTop;
			document.getElementById('main').style.height = content_base+content_offset+"px";
			
		}
		
		
		
function newsletter_sign_up() {
//alert(url);
 var name = document.getElementById("newsletter_name").value
 var email = document.getElementById("newsletter_email").value; 
 var url = "/scripts/newsletter_sign_up.php?name="+encodeURI(name)+"&email="+encodeURI(email);
 sndReq(url,'test');  
}


function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

//var http = createRequestObject();

function sndReq(url,id) {
    http.open('get',url);
   
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('newsletter_form_div').innerHTML = response;
       
    }
}		