function cookieFound() {
	return (document.cookie.length!=0); 
}

function cookiesAreEnabled() {
	document.cookie = "test=test";
	return cookieFound(); 
}

function warnIfNotEnabled(warningText) {
	if (!cookiesAreEnabled()) {
		alert(warningText);
	}
}

function submitSearch() {
	if (document.getElementById('search_eventname').value != null) { 
		Set_Cookie("search_eventname", document.getElementById('search_eventname').value);
	}
	if (document.getElementById('search_arena').value != null) { 
		Set_Cookie("search_arena", document.getElementById('search_arena').value);
	}
	if (document.getElementById('search_category').value != null) { 

		Set_Cookie("search_category", document.getElementById('search_category').value);
	}
	if (document.getElementById('search_city').value != null) { 
		Set_Cookie("search_city", document.getElementById('search_city').value);
	}
	if (document.getElementById('search_day').value != null) { 
		Set_Cookie("search_day", document.getElementById('search_day').value);
	}
	if (document.getElementById('search_yearmonth').value != null) { 
		Set_Cookie("search_yearmonth", document.getElementById('search_yearmonth').value);
	}
	if (document.getElementById('search_datetype').value != null) { 
		Set_Cookie("search_datetype", document.getElementById('search_datetype').value);
	}
	if (document.getElementById('search_rowsPerPage').value != null) { 
		Set_Cookie("search_rowsPerPage", document.getElementById('search_rowsPerPage').value);
	}
	return true;
}

function initStart() {
	clearCookies();
	setStartBgColor();
}

function setStartBgColor() {
	document.getElementById('searchandbook').style.backgroundColor='#DCEBED';
}

function initSearch() {
	initSearchBox();
}

function initSearchBox() {
	if (Get_Cookie('search_eventname')) {
		document.getElementById('search_eventname').value=Get_Cookie('search_eventname');
	}
	if (Get_Cookie('search_arena')) {
		document.getElementById('search_arena').value=Get_Cookie('search_arena');
	}
	if (Get_Cookie('search_category')) {
		document.getElementById('search_category').value=Get_Cookie('search_category');
	}
	if (Get_Cookie('search_city')) {
		document.getElementById('search_city').value=Get_Cookie('search_city');
	}
	if (Get_Cookie('search_day')) {
		document.getElementById('search_day').value=Get_Cookie('search_day');
	}
	if (Get_Cookie('search_yearmonth')) {
		document.getElementById('search_yearmonth').value=Get_Cookie('search_yearmonth');
	}
	if (Get_Cookie('search_datetype')) {
		document.getElementById('search_datetype').value=Get_Cookie('search_datetype');
	}
	if (Get_Cookie('search_rowsPerPage')) {
		document.getElementById('search_rowsPerPage').value=Get_Cookie('search_rowsPerPage');
	}
	clearCookies();
}

function clearCookies() {
	Delete_Cookie('search_eventname');
	Delete_Cookie('search_arena');
	Delete_Cookie('search_category');
	Delete_Cookie('search_city');
	Delete_Cookie('search_day');
	Delete_Cookie('search_yearmonth');
	Delete_Cookie('search_datetype');
	Delete_Cookie('search_rowsPerPage');
}

function Delete_Cookie(name, path, domain) {
	if (Get_Cookie(name)) {
		document.cookie = name + "=" +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}
			
function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
  //  document.cookie = name + "=" +escape(value) +  
    document.cookie = name + "=" +value +  
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function updateForm(formName) {
	var searchValues = Get_Cookie(formName);
	if(searchValues)
	{
		var searchForm=eval("document."+formName);
		for(var i=0;i<searchForm.elements.length;i++)
		{
			var field=eval("document."+formName+"."+searchForm.elements[i].name);
			// sets value of elementName from string and populates object of elementType
			setValue(searchValues,field.name,field,field.type);
		}
	}
}

function saveSearchValues(formName) {
    
	var searchForm=eval("document."+formName);
	var searchString="";
	for(var i=0;i<searchForm.elements.length;i++)
	{
		// gets value of elementName from string and populates object of elementType
		if(searchForm.elements[i].type=="checkbox")
			searchString+=searchForm.elements[i].name+"="+searchForm.elements[i].checked+"&";
		else
			searchString+=searchForm.elements[i].name+"="+searchForm.elements[i].value+"&";
	}
	Set_Cookie(formName,searchString);
}
function onCheck(string) { if (string == "true") return true; return false; }
function setValue(string,elementName,object,elementType) {
// sets value of elementName from string and populates object of elementType

    var startPos = string.indexOf(elementName + "=")
    
    if (startPos > -1) {
        startPos = startPos + elementName.length + 1;
        var endPos = string.indexOf("&",startPos);
        if (endPos == -1) endPos = string.length;

        var elementValue = unescape(string.substring(startPos,endPos));
        
        if (elementType == "text")     object.value = elementValue;
        if (elementType == "password") object.value = elementValue;
        if (elementType == "select")  object.selectedIndex=getCheckedIndex(object,elementValue);
		if (elementType == "select-one") object.selectedIndex=getCheckedIndex(object,elementValue);
        if (elementType == "checkbox") object.checked = onCheck(elementValue);
        //if (elementType == "radio")    object[elementValue].checked = true;
		//if (elementType == "hidden")   object.value = elementValue;
    }
}

function getCheckedIndex(object,elementValue){
	for(var i=0;i<object.length;i++){
		if(elementValue==object[i].value)
		{
			return i;
		}
	}
	return 0;
}
