
function roll(theimg, imgname, ext, mode){
	switch(mode){
		case 1:{
			theimg.src = imgname + "_on." + ext;
		}
		break;
		case 0:{
			theimg.src = imgname + "_off." + ext;
		}
		break;
		default:{
			theimg.src = imgname + "_off." + ext;
		}
	}
}

var news_url = "/mhz/templates/mhz_files/get_news_item.php?lastid=";
var current_newsid = "";

function handleNewsItem(){
	var str_news = "";
	if (http.readyState == 4) {
		//response format -- id, title, date, link
		newsinfo = http.responseText.split(",");
		var newsid = newsinfo[0];
		var newstitle = newsinfo[1];
		var newsdate1 = newsinfo[2];
		var newslink = newsinfo[3];
		
		var newsdate2 = newsdate1.replace('-', ', ');
		
		
		str_news = '<div class="hp_right_announcement_item">' +
				'<div class="title"><a href="' + newslink + '">' + newstitle + '</a></div>' + 
				'' + newsdate2 + '</div>';
		
		document.getElementById("hp_right_announcements").innerHTML = str_news;
		current_newsid = newsid;
		
		//alert(http.responseText);
	}
}

function getnews(){
	newsid = current_newsid;
	if(newsid == "undefined"){
		lastid = "";
	}
	
	if(newsid == "0"){
		lastid = "";
	}
	else{
		lastid = newsid;
	}
	http.open("GET", news_url + lastid, true);
	http.onreadystatechange = handleNewsItem;
	http.send(null);
	setTimeout("getnews()", 10000);
	
	//alert(featured_url + vehicleid);
}

var whatson_url = "/templates/mhz_files/get_whatson_item.php?curdate=";
var whatson_element;
function handleWhatsonItem(){
	var str_whatson = "";
	if (http.readyState == 4) {
		//response format -- id, title, date, link
		//whatsoninfo = http.responseText.split(",");
		 whatsonline = http.responseText.split(",");
		 if(whatsonline.length >= 1){
		    for(i=0;i<whatsonline.length;i++){
			    whatsoninfo = whatsonline[i].split("|");
			    whatson_title = whatsoninfo[0];
			    whatson_time = whatsoninfo[1];
			    
			    str_whatson = str_whatson + '<li>' + whatson_time + ' ' + whatson_title + '</li>';
		    }
		}
		document.getElementById("left_whatson_content").innerHTML = str_whatson;
		
		
	}
}
function handleWhatsonItemRotate(){
	var str_whatson = "";
	if (http.readyState == 4) {
		//response format -- id, title, date, link (last item after comma is return channel)
		//whatsoninfo = http.responseText.split(",");
		 whatsonline = http.responseText.split(",");
		 if(whatsonline.length >= 1){
		    datalength = whatsonline.length - 1;
		    for(i=0;i<datalength;i++){
			    whatsoninfo = whatsonline[i].split("|");
			    whatson_title = whatsoninfo[0];
			    whatson_time = whatsoninfo[1];
			    
			    str_whatson = str_whatson + '<div class="int_whatson_left_item"><span class="int_whatson_left_item_title">' + whatson_time + '</span>&nbsp;&nbsp;' + whatson_title + '</div>';
			    //str_whatson = str_whatson + '<li>' + whatson_time + ' ' + whatson_title + '</li>';
		    }
		    retchannel = whatsonline[datalength];
		   // alert("handle retchannel: " + retchannel);
		    document.getElementById("retchannel").value = retchannel;
		    //alert("hanle retchannel field val: " + document.getElementById("retchannel").value);
		    	
			whatson_element.innerHTML = str_whatson;	    
		}
		
	}
}


function getwhatson(channel){
	with (new Date){
		var currdate = getFullYear() + "-" + (getMonth() + 1) + "-" + getDate() + " " + getHours() + ":" + getMinutes() + ":" + getSeconds();
	
	}
	//document.write(currdate);
	currdate = escape(currdate);
	//document.write(whatson_url + currdate + '&channel=' + channel);
	http.open("GET", whatson_url + currdate + '&channel=' + channel, true);
	http.onreadystatechange = handleWhatsonItem;
	http.send(null);
	//setTimeout("getwhatson()", 900000);
	
	//alert(currdate);
	
	//alert(featured_url + vehicleid);
}

function getwhatsonrotate(channel, type){
	var theurl = '';
	with (new Date){
		var currdate = getFullYear() + "-" + (getMonth() + 1) + "-" + getDate() + " " + getHours() + ":" + getMinutes() + ":" + getSeconds();
	
	}
	//alert(currdate);
	//alert('channel: ' + channel);
	if(type == 'wv'){
		channel = '%20World';
	}
	if(channel == ''){
		channel = '1';
	}
	
	currdate = escape(currdate);
	
	theurl = whatson_url + currdate + '&channel=' + channel + '&rotate=1';
		
	http.open("GET", theurl, true);
	
	if(type){
		whatson_element = document.getElementById("int_whatson_left_content_" + type);
	}
	else{
		whatson_element = document.getElementById("int_whatson_left_content");
	}
	
	http.onreadystatechange = handleWhatsonItemRotate;
	http.send(null);
	
	//alert(theurl);
	
	//alert(whatson_url + currdate + '&channel=' + channel + '&rotate=1');
	//setTimeout("getwhatsonrotate('" + channel + "')", 10000);

}

function getajaxdata(){
	//
	getnews();
	setTimeout("getwhatson()", 1000);
}

function emailpage(){
	var url = 'email_art.php?page=' + escape(document.location.href);
	window.open(url, null, 'width=475,height=500,scrollbars=1,resizable=0');
}

function subaccount(theform){
	var retval = true;
	var err_msg = "";
	
	if(theform.txtFName.value == ''){
		if(err_msg == ""){
			err_msg = "The following item(s) require attention:\n";
		}
		err_msg = err_msg + "\nFirst Name cannot be blank";
		retval = false;
	}
	
	if(theform.txtLName.value == ''){
		if(err_msg == ""){
			err_msg = "The following item(s) require attention:\n";
		}
		err_msg = err_msg + "\nLast Name cannot be blank";
		retval = false;
	}
	if(theform.txtEmail.value == ''){
		if(err_msg == ""){
			err_msg = "The following item(s) require attention:\n";
		}
		err_msg = err_msg + "\nEmail Address cannot be blank";
		retval = false;
	}
	
	if(theform.txtPassword.value == ''){
		if(err_msg == ""){
			err_msg = "The following item(s) require attention:\n";
		}
		err_msg = err_msg + "\nYou must enter a password";
		retval = false;
	}
	else{
		if(theform.txtPassword2.value == ''){
			if(err_msg == ""){
				err_msg = "The following item(s) require attention:\n";
			}
			err_msg = err_msg + "\nYou must confirm your password";
			retval = false;
		}
		else{
			if(theform.txtPassword.value != theform.txtPassword2.value){
				if(err_msg == ""){
					err_msg = "The following item(s) require attention:\n";
				}
				err_msg = err_msg + "\nYou must correctly confirm your password";
				retval = false;
			}
		}
		
	}
	
	if(err_msg != ""){
		alert(err_msg);
	}
	return retval;
	
}

function validateZIP() {
	var field=document.support.ZIP.value;
	var valid = "0123456789-";
	var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
return false;
   }
}
return true;
}

function checkSupportForm() {	
	if (document.support.AMOUNT.value.length == 0) {
		alert ("Pledge amount is required");
		document.support.AMOUNT.focus();
		return false;
	}
	parseNum = parseInt(document.support.AMOUNT.value);
	if ((parseNum + "") == "NaN") {
		document.support.AMOUNT.focus();
		alert ("Pledge amount should be numeric");
		return false;
	}
	
	if (document.support.ZIP.value.length == 0) {
		alert ("Zip code is required");
		document.support.ZIP.focus();
		return false;
	}
	
	if (!(validateZIP())) {
		document.support.ZIP.focus();
		alert ("Please enter a valid zipcode.\nValid zipcodes can be 5 digit or 5 digit+4.");
		return false;
	}
	
	if (document.support.PROVIDER.value.length == 0) {
		alert ("Provider is required");
		document.support.PROVIDER.focus();
		return false;
	}
	
	return true;
}
//-->

