/* AJAX functions */

var xmlHttp
var selectedItem
		
function stateChanged() { 
    if (xmlHttp.readyState==4) { 
			 document.getElementById(selectedItem).innerHTML=xmlHttp.responseText;
    }
}
function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
      xmlHttp=new XMLHttpRequest();
    } catch (e) {
      try {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    return xmlHttp;
}

/* Utility functions */

function hideItem(myElement) {
  if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(myElement).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.myElement.display = 'none';
		}
		else { // IE 4
			document.all.myElement.style.display = 'none';
		}
	}
}

function displayItem(myElement) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(myElement).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.myElement.display = 'block';
		}
		else { // IE 4
			document.all.myElement.style.display = 'block';
		}
	}
}

function login() {
				 displayItem("loginForm");
}

/* Channel actions */
function sortChannels(serial, spid) {
				 selectedItem="messages";
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 var url="startpage/display/modules/ajax_channels_sort.php";
				 var poststr = "serial=" + encodeURIComponent ( serial );
				 poststr = poststr + "&cid=0";
				 poststr = poststr + "&spid=" + encodeURIComponent ( spid );
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open('POST', url, true);
     		 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     		 xmlHttp.setRequestHeader("Content-length", poststr.length);
     		 xmlHttp.setRequestHeader("Connection", "close");
     		 xmlHttp.send(poststr);
}

function addContent(channelID, spID) {
				 scroll(0,0);
				 selectedItem="addContent";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Loading add form...</div>';
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 var url="startpage/display/modules/ajax_content_add.php";
				 url=url+"?cid="+channelID+"&spid="+spID;
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open("GET",url,true);
       	 xmlHttp.send(null);
}

function editContent(channelID, spID) {
				 scroll(0,0);
				 selectedItem="editContent";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Loading edit form...</div>';
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 var url="startpage/display/modules/ajax_content_edit.php";
				 url=url+"?cid="+channelID+"&spid="+spID;
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open("GET",url,true);
       	 xmlHttp.send(null);
}

function refreshChannel(channelID) {
				 var id = 'frame_' + channelID;
				 var f = document.getElementById(id);
				 f.src = f.src;
}

function helpChannel(channelID, spID) {
				 scroll(0,0);
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Loading help data...</div>';
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 var url="startpage/display/modules/ajax_channel_help.php";
				 url=url+"?cid="+channelID+"&spid="+spID;
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open("GET",url,true);
       	 xmlHttp.send(null);
}

function hideChannel(channelID, channelName) {
				 var n = channelName;
				 var id = 'cell_' + channelID;
				 hideItem(id);
				 var f = document.getElementById('topMenu').innerHTML;
				 f=f.replace(/<!--INSERT HERE-->/,'<li><a href="javascript:showChannel(' + channelID + ', \'' + n +  '\')">Display ' + n + '</a></li><!--INSERT HERE-->');
				 document.getElementById('topMenu').innerHTML = f;
}

function deleteChannel(channelID, spID) {
				 var id = 'cell_' + channelID;
				 hideItem(id);
				 scroll(0,0);
				 selectedItem="messages";
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 var url="startpage/display/modules/ajax_channel_delete.php";
				 url=url+"?cid="+channelID+"&spid="+spID;
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open("GET",url,true);
       	 xmlHttp.send(null);
}

function showChannel(channelID, channelName) {
				 var n = channelName;
				 var id = 'cell_' + channelID;
				 displayItem(id);
				 var f = document.getElementById('topMenu').innerHTML;
				 var d = '<li><a href="javascript:showChannel(' + channelID + ', \'' + n +  '\')">Display ' + n + '</a></li>';
				 f=f.replace(d,'');
				 document.getElementById('topMenu').innerHTML = f;
}

/* Edit functions */
function editItemProcess(channelID, spID, itemID, url) {
				 scroll(0,0);
				 xmlHttp=GetXmlHttpObject();
		 		 if (xmlHttp==null) {
     		 		alert("Your browser does not support AJAX.");
    				return;
     		 }
				 var poststr = "cid=" + encodeURIComponent( channelID );
				 poststr = poststr + "&spid=" + encodeURIComponent( spID );
		 		 poststr = poststr + "&itemid=" + encodeURIComponent( itemID );
				 
				 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open('POST', url, true);
     		 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     		 xmlHttp.setRequestHeader("Content-length", poststr.length);
     		 xmlHttp.setRequestHeader("Connection", "close");
     		 xmlHttp.send(poststr);
				 
				 refreshChannel(channelID);
}

function editItem(channelID, spID, itemID) {
				 hideItem('editContentSelect');
				 selectedItem="editContent";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Loading edit form...</div>';
				 var url="startpage/display/modules/ajax_item_edit.php";
		 		 editItemProcess(channelID, spID, itemID, url);
}

function deleteItem(type, channelID, spID, itemID) {
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Deleting item...</div>';
				 xmlHttp=GetXmlHttpObject();
		 		 if (xmlHttp==null) {
     		 		alert("Your browser does not support AJAX.");
    				return;
     		 }
				 var url="startpage/display/modules/ajax_item_delete.php";
				 
				 var temp="";
				 if (type==1) {
				 		 temp = "category" + itemID;
		 				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 }
				 if (type==2) {
				 		 temp = "topCat" + itemID;
		 				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
						 temp = "subCat" + itemID;
		 				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 }
				 if (type==3) {
				 		temp = "category" + itemID;
		 				document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
						temp = "url" + itemID;
		 				document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
						temp = "fileType" + itemID;
		 				document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 }
		 		 temp = "title" + itemID;
		 		 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
		 		 temp = "default" + itemID;
		 		 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
		 		 temp = "editButton" + itemID;
		 		 document.getElementById(temp).innerHTML = '&nbsp;';
		 		 temp = "deleteButton" + itemID;
		 		 document.getElementById(temp).innerHTML = '<img src="images/icon_accept.png" alt="..." title="Item Deleted..." />';
		 		 temp = "setDefault" + itemID;
		 		 document.getElementById(temp).innerHTML = 'Item deleted';
				 
				 editItemProcess(channelID, spID, itemID, url);
				 /*editContent(channelID, spID);*/
}

function setDefault(channelID, spID, itemID) {
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Setting default...</div>';
				 var url="startpage/display/modules/ajax_item_set_default.php";
				 editItemProcess(channelID, spID, itemID, url);
				 /*editContent(channelID, spID);*/
}

function edit_feed_form_validation(channelID, spID, itemID) {
				 /* validate data */
				 var thisform = document.editFeedForm;
				 if (validate_entered(thisform.user_feed_name,"Please input a valid feed name.",thisform.user_feed_name.value.length,1)==false){ 
				 		thisform.user_feed_name.focus(); 
						thisform.user_feed_name.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.user_feed_url,"Please input a valid feed URL.",thisform.user_feed_url.value.length,1)==false){ 
				 		thisform.user_feed_url.focus(); 
						thisform.user_feed_url.select(); 
						return false;
  			 }
				 if (thisform.user_feed_url.value=='http://'){ 
				 		alert("Please input a valid feed URL.");
						thisform.user_feed_url.focus(); 
						thisform.user_feed_url.select(); 
						return false;
  			 }
				 document.getElementById('addFeedButton').innerHTML='&nbsp;';
				 
				 /* Send data */
		 		 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
				 poststr = poststr + "&itemid=" + encodeURIComponent( itemID );
		 		 poststr = poststr + "&user_feed_name=" + encodeURIComponent( thisform.user_feed_name.value );
		 		 poststr = poststr + "&user_feed_url=" + encodeURIComponent( thisform.user_feed_url.value );
		 		 poststr = poststr + "&user_feed_category=" + encodeURIComponent( thisform.user_feed_category.value );
				 
				 content_edit_validate(channelID, spID, poststr,'addFeedButton', '<input type="button" name="submit" id="submit" value="Edit Feed" onclick="edit_feed_form_validation(\''+channelID+'\',\''+spID+'\',\''+itemID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}

function content_edit_validate(channelID, spID, poststr, buttonName, buttonCode) {
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Saving data...</div>';
				 xmlHttp=GetXmlHttpObject();
		 		 if (xmlHttp==null) {
     		 		alert("Your browser does not support AJAX.");
    				return;
     		 }
				 var url="startpage/display/modules/ajax_content_edit_validate.php";
		 		 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open('POST', url, true);
     		 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     		 xmlHttp.setRequestHeader("Content-length", poststr.length);
     		 xmlHttp.setRequestHeader("Connection", "close");
     		 xmlHttp.send(poststr);
				 /*alert(poststr);*/
				 document.getElementById(buttonName).innerHTML = buttonCode;
     		 refreshChannel(channelID);
}


/* Add form elements Feed */
function content_add_validate(channelID, spID, poststr, buttonName, buttonCode) {
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<div class="success">Saving data...</div>';
				 xmlHttp=GetXmlHttpObject();
		 		 if (xmlHttp==null) {
     		 		alert("Your browser does not support AJAX.");
    				return;
     		 }
				 var url="startpage/display/modules/ajax_content_add_validate.php";
		 		 xmlHttp.onreadystatechange=stateChanged;
				 xmlHttp.open('POST', url, true);
     		 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     		 xmlHttp.setRequestHeader("Content-length", poststr.length);
     		 xmlHttp.setRequestHeader("Connection", "close");
     		 xmlHttp.send(poststr);
				 /*alert(poststr);*/
				 document.getElementById(buttonName).innerHTML = buttonCode;
     		 refreshChannel(channelID);
}

function feed_form_validation(channelID, spID) {
				 /* validate data */
				 var thisform = document.addFeedForm;
				 if (validate_entered(thisform.user_feed_name,"Please input a valid feed name.",thisform.user_feed_name.value.length,1)==false){ 
				 		thisform.user_feed_name.focus(); 
						thisform.user_feed_name.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.user_feed_url,"Please input a valid feed URL.",thisform.user_feed_url.value.length,1)==false){ 
				 		thisform.user_feed_url.focus(); 
						thisform.user_feed_url.select(); 
						return false;
  			 }
				 if (thisform.user_feed_url.value=='http://'){ 
				 		alert("Please input a valid feed URL.");
						thisform.user_feed_url.focus(); 
						thisform.user_feed_url.select(); 
						return false;
  			 }
				 document.getElementById('addFeedButton').innerHTML='&nbsp;';
				 
				 /* Send data */
		 		 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
		 		 poststr = poststr + "&user_feed_name=" + encodeURIComponent( thisform.user_feed_name.value );
		 		 poststr = poststr + "&user_feed_url=" + encodeURIComponent( thisform.user_feed_url.value );
		 		 poststr = poststr + "&user_feed_category=" + encodeURIComponent( thisform.user_feed_category.value );
				 
				 content_add_validate(channelID, spID, poststr,'addFeedButton', '<input type="button" name="submit" id="submit" value="Add Feed" onclick="feed_form_validation(\''+channelID+'\',\''+spID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}

function displayTopCategory(topCatValue) {
				 document.addFeedForm.user_feed_category.value=topCatValue;
}

function edit_link_form_validation(channelID, spID, itemID) {
				 var thisform = document.editLinkForm;
				 if (validate_entered(thisform.link_title,"Please input a valid link title.",thisform.link_title.value.length,1)==false){ 
				 		thisform.link_title.focus(); 
						thisform.link_title.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.link_url,"Please input a valid link URL.",thisform.link_url.value.length,1)==false){ 
				 		thisform.link_url.focus(); 
						thisform.link_url.select(); 
						return false;
  			 }
				 if (thisform.link_url.value=='http://'){ 
				 		alert("Please input a valid link URL.");
						thisform.link_url.focus(); 
						thisform.link_url.select(); 
						return false;
  			 }
				 document.getElementById('editLinkButton').innerHTML='&nbsp;';
				 
				 /* Send data */
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
				 poststr = poststr + "&itemid=" + encodeURIComponent( itemID );
		 		 poststr = poststr + "&link_title=" + encodeURIComponent( thisform.link_title.value );
		 		 poststr = poststr + "&link_url=" + encodeURIComponent( thisform.link_url.value );
		 		 poststr = poststr + "&link_top_category=" + encodeURIComponent( thisform.link_top_category.value );
		 		 poststr = poststr + "&link_sub_category=" + encodeURIComponent( thisform.link_sub_category.value );
				 content_edit_validate(channelID, spID, poststr,'editLinkButton', '<input type="button" name="submit" id="submit" value="Edit Link" onclick="edit_link_form_validation(\''+channelID+'\',\''+spID+'\',\''+itemID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}


/* Add form elements Link */
function link_form_validation(channelID, spID) {
				 var thisform = document.addLinkForm;
				 if (validate_entered(thisform.link_title,"Please input a valid link title.",thisform.link_title.value.length,1)==false){ 
				 		thisform.link_title.focus(); 
						thisform.link_title.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.link_url,"Please input a valid link URL.",thisform.link_url.value.length,1)==false){ 
				 		thisform.link_url.focus(); 
						thisform.link_url.select(); 
						return false;
  			 }
				 if (thisform.link_url.value=='http://'){ 
				 		alert("Please input a valid link URL.");
						thisform.link_url.focus(); 
						thisform.link_url.select(); 
						return false;
  			 }
				 document.getElementById('addLinkButton').innerHTML='&nbsp;';
				 
				 /* Send data */
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
		 		 poststr = poststr + "&link_title=" + encodeURIComponent( thisform.link_title.value );
		 		 poststr = poststr + "&link_url=" + encodeURIComponent( thisform.link_url.value );
		 		 poststr = poststr + "&link_top_category=" + encodeURIComponent( thisform.link_top_category.value );
		 		 poststr = poststr + "&link_sub_category=" + encodeURIComponent( thisform.link_sub_category.value );
				 content_add_validate(channelID, spID, poststr,'addLinkButton', '<input type="button" name="submit" id="submit" value="Add Link" onclick="link_form_validation(\''+channelID+'\',\''+spID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}

function displayLinkTopCategory(topCat) {
				 document.addLinkForm.link_top_category.value=topCat.options[topCat.selectedIndex].value;
				 var i = 0;
				 for (var i=1; i<topCat.options.length; i++) {
				 		 if (topCat.options[i].selected==true) {
				 		 		displayItem('sub_link_' + i);
				 		 } else {
				 		 	  hideItem('sub_link_' + i);
				 		 }
				 }
}

function displayLinkSubCategory(subCatValue) {
				 document.addLinkForm.link_sub_category.value=subCatValue;
}


function edit_audio_form_validation(channelID, spID, itemID) {
				 /* validate data */
				 var thisform = document.editAudioForm;
				 if (validate_entered(thisform.user_radio_title,"Please input a valid audio feed name.",thisform.user_radio_title.length,1)==false){ 
				 		thisform.user_radio_title.focus(); 
						thisform.user_radio_title.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.user_radio_url,"Please input a valid audio feed URL.",thisform.user_radio_url.value.length,1)==false){ 
				 		thisform.user_radio_url.focus(); 
						thisform.user_radio_url.select(); 
						return false;
  			 }
				 if (thisform.user_radio_url.value=='http://'){ 
				 		alert("Please input a valid audio feed URL.");
						thisform.user_radio_url.focus(); 
						thisform.user_radio_url.select(); 
						return false;
  			 }
				 document.getElementById('editAudioButton').innerHTML='&nbsp;';
				 
				 /* Send data */
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
				 poststr = poststr + "&itemid=" + encodeURIComponent( itemID );
		 		 poststr = poststr + "&user_radio_title=" + encodeURIComponent( thisform.user_radio_title.value );
		 		 poststr = poststr + "&user_radio_url=" + encodeURIComponent( thisform.user_radio_url.value );
		 		 poststr = poststr + "&user_radio_website_url=" + encodeURIComponent( thisform.user_radio_website_url.value );
		 		 poststr = poststr + "&user_radio_category=" + encodeURIComponent( thisform.user_radio_category.value );
				 content_edit_validate(channelID, spID, poststr,'editAudioButton', '<input type="button" name="submit" id="submit" value="Edit Audio Feed" onclick="edit_audio_form_validation(\''+channelID+'\',\''+spID+'\',\''+itemID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}

/* Add form elements Feed */


function displayAudioTopCategory(topCatValue) {
				 document.addAudioForm.user_radio_category.value=topCatValue;
}



function audio_form_validation(channelID, spID) {
				 /* validate data */
				 var thisform = document.addAudioForm;
				 if (validate_entered(thisform.user_radio_title,"Please input a valid audio feed name.",thisform.user_radio_title.length,1)==false){ 
				 		thisform.user_radio_title.focus(); 
						thisform.user_radio_title.select(); 
						return false;
  			 }
				 if (validate_entered(thisform.user_radio_url,"Please input a valid audio feed URL.",thisform.user_radio_url.value.length,1)==false){ 
				 		thisform.user_radio_url.focus(); 
						thisform.user_radio_url.select(); 
						return false;
  			 }
				 if (thisform.user_radio_url.value=='http://'){ 
				 		alert("Please input a valid audio feed URL.");
						thisform.user_radio_url.focus(); 
						thisform.user_radio_url.select(); 
						return false;
  			 }
				 document.getElementById('addAudioButton').innerHTML='&nbsp;';
				 
				 /* Send data */
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
		 		 poststr = poststr + "&user_radio_title=" + encodeURIComponent( thisform.user_radio_title.value );
		 		 poststr = poststr + "&user_radio_url=" + encodeURIComponent( thisform.user_radio_url.value );
		 		 poststr = poststr + "&user_radio_website_url=" + encodeURIComponent( thisform.user_radio_website_url.value );
		 		 poststr = poststr + "&user_radio_category=" + encodeURIComponent( thisform.user_radio_category.value );
				 content_add_validate(channelID, spID, poststr,'addAudioButton', '<input type="button" name="submit" id="submit" value="Add Audio Feed" onclick="audio_form_validation(\''+channelID+'\',\''+spID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}



/* Form validation */
/* Validates that the email address is in the proper format */
function validate_email(field,alerttxt) {
  with (field) {
      apos=value.indexOf("@")
      dotpos=value.lastIndexOf(".")
      if (apos<1||dotpos-apos<2) { 
		 		 alert(alerttxt);
		    return false;
    	} else {
    		 return true;
    	}
  }
}
			
/* Validates whether something has been entered for this field */
function validate_entered(field,alerttxt,act_length,min_length) {
  with (field) {
	  if (value==null||value==""||act_length<min_length) {
			 alert(alerttxt);
			 return false;
		} else {
			 return true
		}
  }
}

function displayWeatherOptions(channelID, spID) {
				 selectedItem="locationOptions";
				 
				 /* validate ajax capabilities */
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 /* form validation */
				 var thisform = document.locationOptionsForm;
				 if (thisform.where.value.length<2) {
				 		alert ("Please input a valid postcode, city, or country");
				 		thisform.where.focus(); 
						thisform.where.select(); 
						return false;
  			 }
				 
				 /* retrieve weather response */
				 var url="startpage/display/modules/ajax_weather_options_display.php";
			 	 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="Loading options list..." title="Loading options list..." />';
			 
				 var poststr = "cid=" + encodeURIComponent ( channelID );
  			 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
  			 poststr = poststr + "&where=" + encodeURIComponent ( thisform.where.value )
  			 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
}

function addWeatherContent(channelID, spID) {
				 selectedItem="addContent";
				 
				 /* validate ajax capabilities */
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 /* form validation */
				 var thisform = document.getElementById('locationSelect');
				 var unitSelect = thisform.unit.options[thisform.unit.selectedIndex].value;
				 var locationSelect = thisform.location.options[thisform.location.selectedIndex].value;
				 /* retrieve weather response */
				 var url="startpage/display/modules/ajax_add_weather.php";
			 	 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="Adding location..." title="Adding location..." />';
			 
				 var poststr = "cid=" + encodeURIComponent ( channelID );
  			 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
				 poststr = poststr + "&unit=" + encodeURIComponent ( unitSelect );
  			 poststr = poststr + "&location=" + encodeURIComponent ( locationSelect );
				 
  			 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
				 
				 refreshChannel(channelID);
}

function updateWeatherUnits(channelID, spID, wlID, unit) {
				 selectedItem="unit_" + wlID;
				 
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 var url="startpage/display/modules/ajax_update_weather_units.php";
			 	 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="..." title="Updating settings..." />';
			 
				 var poststr = "cid=" + encodeURIComponent ( channelID );
  			 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
  			 poststr = poststr + "&wlid=" + encodeURIComponent ( wlID );
				 poststr = poststr + "&unit=" + encodeURIComponent ( unit );
  			 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
				 
				 refreshChannel(channelID);
}

function deleteWeatherLocation(channelID, spID, wlID) {
				 if (confirm("Are you sure you want to delete this location?")) {
				 
				 } else {
				 	  return false;
				 }
				 
				 selectedItem="deleteButton" + wlID;
				 
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 var url="startpage/display/modules/ajax_delete_weather_location.php";
				 var temp = "locid" + wlID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
			 	 temp = "dnam" + wlID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 temp = "unitSelectArea" + wlID;
				 document.getElementById(temp).innerHTML = '&nbsp;';
				 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="..." title="Deleting location..." />';
			 
				 var poststr = "cid=" + encodeURIComponent ( channelID );
  			 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
  			 poststr = poststr + "&wlid=" + encodeURIComponent ( wlID );
  			 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
				 
				 refreshChannel(channelID);
}

function ebay_form_validation(channelID, spID) {
				 /* validate data */
				 var thisform = document.addebayForm;
				 
				 if ((thisform.QueryKeywords.length==0) && (thisform.SellerID.length==0)) {
				 		alert("Please input either a search query or a list of seller IDs.");
						return;
				 }
				 
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 selectedItem="messages";
				 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="..." title="Saving data..." />';
				 document.getElementById('addebayButton').innerHTML='&nbsp;';
				 
				 /* Send data */
				 var url="startpage/display/modules/ajax_add_ebay_search.php";
				 
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
		 		 poststr = poststr + "&siteid=" + encodeURIComponent( thisform.siteid.options[thisform.siteid.selectedIndex].value );
				 poststr = poststr + "&QueryKeywords=" + encodeURIComponent( thisform.QueryKeywords.value );
		 		 poststr = poststr + "&SellerID=" + encodeURIComponent( thisform.SellerID.value );
		 		 poststr = poststr + "&ItemSort=" + encodeURIComponent( thisform.ItemSort.options[thisform.ItemSort.selectedIndex].value );
		 		 poststr = poststr + "&SortOrder=" + encodeURIComponent( thisform.SortOrder.options[thisform.SortOrder.selectedIndex].value );
				 poststr = poststr + "&HideDuplicateItems=" + encodeURIComponent( thisform.HideDuplicateItems.options[thisform.HideDuplicateItems.selectedIndex].value );
				 
				 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
				 
				 document.getElementById("addebayButton").innerHTML = '<input type="button" name="submit" id="submit" value="Add eBay Search" onclick="ebay_form_validation(\''+channelID+'\',\''+spID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />';
     		 refreshChannel(channelID);
}



function deleteebaySearch(channelID, spID, esID) {
				 if (confirm("Are you sure you want to delete this eBay search?")) {
				 
				 } else {
				 	  return;
				 }
				 
				 selectedItem="deleteebayButton" + esID;
				 
				 xmlHttp=GetXmlHttpObject();
				 if (xmlHttp==null) {
           		alert("Your browser does not support AJAX. Please update your browser.");
          		return;
         }
				 
				 var url="startpage/display/modules/ajax_delete_ebay_search.php";
				 var temp = "name" + esID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
			 	 temp = "QueryKeywords" + esID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 temp = "SellerID" + esID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 temp = "HideDuplicateItems" + esID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 temp = "ItemSort" + esID;
				 document.getElementById(temp).innerHTML = '<span style="text-decoration: line-through;">' + document.getElementById(temp).innerHTML + '</span>';
				 				 
				 temp = "editButton" + esID;
				 document.getElementById(temp).innerHTML = '&nbsp;';
				 
				 
				 document.getElementById(selectedItem).innerHTML = '<img src="images/icon_animated_progress.gif" alt="..." title="Deleting location..." />';
			 
				 var poststr = "cid=" + encodeURIComponent ( channelID );
  			 poststr = poststr + "&spid=" + encodeURIComponent ( spID );
  			 poststr = poststr + "&esid=" + encodeURIComponent ( esID );
  			 xmlHttp.onreadystatechange=stateChanged;
  			 
  			 xmlHttp.open('POST', url, true);
  			 xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  			 xmlHttp.setRequestHeader("Content-length", poststr.length);
  			 xmlHttp.setRequestHeader("Connection", "close");
  			 xmlHttp.send(poststr);
				 
				 refreshChannel(channelID);
}

function edit_ebay_form_validation(channelID, spID, itemID) {
				 /* validate data */
				 var thisform = document.editebayForm;
				 
				 if ((thisform.QueryKeywords.length==0) && (thisform.SellerID.length==0)) {
				 		alert("Please input either a search query or a list of seller IDs.");
						return;
				 }
				 document.getElementById('editebayButton').innerHTML='<img src="images/icon_animated_progress.gif" alt="..." title="Saving data..." />';
				 
				 /* Send data */
				 var poststr = "cid=" + encodeURIComponent( channelID );
		 		 poststr = poststr + "&spid=" + encodeURIComponent( spID );
				 poststr = poststr + "&itemid=" + encodeURIComponent( itemID );
		 		 poststr = poststr + "&siteid=" + encodeURIComponent( thisform.siteid.options[thisform.siteid.selectedIndex].value );
				 poststr = poststr + "&QueryKeywords=" + encodeURIComponent( thisform.QueryKeywords.value );
		 		 poststr = poststr + "&SellerID=" + encodeURIComponent( thisform.SellerID.value );
		 		 poststr = poststr + "&ItemSort=" + encodeURIComponent( thisform.ItemSort.options[thisform.ItemSort.selectedIndex].value );
		 		 poststr = poststr + "&SortOrder=" + encodeURIComponent( thisform.SortOrder.options[thisform.SortOrder.selectedIndex].value );
				 poststr = poststr + "&HideDuplicateItems=" + encodeURIComponent( thisform.HideDuplicateItems.options[thisform.HideDuplicateItems.selectedIndex].value );
				 
				 content_edit_validate(channelID, spID, poststr,'editebayButton', '<input type="button" name="submit" id="submit" value="Edit eBay Search" onclick="edit_ebay_form_validation(\''+channelID+'\',\''+spID+'\',\''+itemID+'\');" />&nbsp;&nbsp;<input type="reset" value="Reset" />');
}
