var xmlhttp = false;
var xmlPath = 'http://calendar.yamahapubs.com/xml_http/';
var returnText;

/* detect browser type */
var browser = '';
var version = '';
var entrance = '';
var cond = '';

if (browser == '')
{
	if (navigator.appName.indexOf('Microsoft') != -1) browser = 'IE'
	else if (navigator.appName.indexOf('Netscape') != -1) browser = 'Netscape'
	else browser = 'IE';
}
if (version == '')
{
	version= navigator.appVersion;
	paren = version.indexOf('(');
	whole_version = navigator.appVersion.substring(0,paren-1);
	version = parseInt(whole_version);
}
if(!xmlhttp)
{
	if (browser == 'IE')
	{
		if (typeof ActiveXObject!='undefined') 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	else if(browser == 'Netscape')
	{
		if (typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
	}
}

function getPhoto(photo_image_id,form_id)
{ 
	uri = xmlPath + "xml_http.php?cmd=getPhoto&photo_image_id=" + photo_image_id;
	xmlhttp.open("GET", uri ,true);
	xmlhttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4) 
		{
			returnText = xmlhttp.responseText;
			changeImage(returnText,form_id);
		}
	}
	xmlhttp.send(null);  
}
function changeImage(img_src,form_id) 
{
	document.getElementById(form_id).src="images/thumbs/" + img_src;
}
function getPhotoList(photo_category_id,photo_list_form_id,photo_form_id)
{
	uri = xmlPath + "xml_http.php?cmd=getPhotoList&photo_category_id=" + photo_category_id;
	xmlhttp.open("GET", uri ,true);
	xmlhttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4) 
		{
			returnText = xmlhttp.responseText;
			insertPhotoList("[Choose a photo]",photo_list_form_id,photo_form_id);
		}
	}
	xmlhttp.send(null);
}
function insertPhotoList(first_element,photo_list_form_id,photo_form_id)
{
	dataSet = returnText.split("&____&");
	valueSet = dataSet[0].split("____");
	textSet = dataSet[1].split("____");

	total = valueSet.length;
	document.getElementById(photo_list_form_id).length=total+1;
	document.getElementById(photo_list_form_id).options[0].value = "";
	document.getElementById(photo_list_form_id).options[0].text = first_element;
						
	for(i=0; i<total; i++)
	{
		document.getElementById(photo_list_form_id).options[i+1].value = valueSet[i];
		document.getElementById(photo_list_form_id).options[i+1].text = textSet[i];
	}
	document.getElementById(photo_list_form_id).options[0].selected=true;
	changeImage('nothumb.jpg',photo_form_id) 
}
function getProgramList(program_category_id,start_date,end_date)
{
	if(program_category_id=='')
	{
		var myTbody = document.getElementById('program_tbody');
		while (myTbody.childNodes[0]) 
		{
			myTbody.removeChild(myTbody.childNodes[0]);
		}
	}
	else
	{
		uri = xmlPath + "xml_http.php?cmd=getProgramList&program_category_id=" + program_category_id + "&s=" + start_date + "&e=" + end_date;
		xmlhttp.open("GET", uri ,true);
		xmlhttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
		xmlhttp.onreadystatechange=function() 
		{
			if(xmlhttp.readyState==4)
			{
				returnText = xmlhttp.responseText;
				insertProgramList();
			}
		}
		xmlhttp.send(null);
	}
}
function insertProgramList()
{
	var myTbody = document.getElementById("program_tbody");
	var myTr;
	var myTd0;
	var myTd1;
	var myTd2;
	var myText0 = document.createTextNode("Following events will be added to your calendar");
	var myText1 = document.createTextNode("Date");
	var myText2 = document.createTextNode("Event");
	var font0 = document.createElement("font");
	font0.style.fontWeight = "bold";
	var font1 = document.createElement("font");
	font1.style.fontWeight = "bold";
	var font2 = document.createElement("font");
	font2.style.fontWeight = "bold";
	font0.appendChild(myText0);
	font1.appendChild(myText1);
	font2.appendChild(myText2);
	
	myTbody.childNodes[0];
	while (myTbody.childNodes[0]) 
	{
		myTbody.removeChild(myTbody.childNodes[0]);
	}
	myTr0 = document.createElement("tr");
	myTr1 = document.createElement("tr");
	myTd0 = document.createElement("td");
	myTd1 = document.createElement("td");
	myTd2 = document.createElement("td");
	myTd0.appendChild(font0);
	myTd0.setAttribute("colSpan","2");
	myTd1.appendChild(font1);
	myTd1.setAttribute("width","100");
	
	myTd2.appendChild(font2);
	myTr0.appendChild(myTd0);
	myTr1.appendChild(myTd1);
	myTr1.appendChild(myTd2);
	myTbody.appendChild(myTr0);
	myTbody.appendChild(myTr1);
	
	dataSet = returnText.split("&____&");
	textSet1 = dataSet[0].split("____");
	textSet2 = dataSet[1].split("____");

	total = textSet1.length;
						
	for(i=0; i<total; i++)
	{
		myTr = document.createElement("tr");
		myTd1 = document.createElement("td");
		myTd2 = document.createElement("td");
		myTd1.appendChild(document.createTextNode(textSet1[i]));
		myTd2.appendChild(document.createTextNode(textSet2[i]));
		myTr.appendChild(myTd1);
		myTr.appendChild(myTd2);
		myTbody.appendChild(myTr);
	}
	
	document.getElementById("program_list").style.display="block";
}
function isFloat (s)
{  
	var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
	if (isEmpty(s)) 
	if (isFloat.arguments.length == 1) return defaultEmptyOK;
	else return (isFloat.arguments[1] == true);
	return reFloat.test(s)
}
function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function isInteger(s)
{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else
	{
		window.onload = function()
		{
			if(oldonload) { oldonload();}
			func();
		}
	}
}