<!--

var checkflag = "false";
function check(FormName,FieldName) {
	//field = document.getElementById(elemid);
	//do not use
	var field = document.forms[FormName].elements[FieldName];
	
	if (checkflag == "false") {
	  for (i = 0; i < field.length; i++) {
		field[i].checked = true;
	  }
	  checkflag = "true";
	  return "Uncheck all"; }
	else {
	  for (i = 0; i < field.length; i++) {
	  field[i].checked = "false"; }
	  checkflag = "false";
	  return "Check all"; 
	}
}

function change_value(target,newvalue) {
	var obx = document.getElementById(target);
	obx.value = newvalue;
}

function $(id) {
	return document.getElementById(id);
}

function show_email(name,emailHost) {
	document.write("<a href=" + "mailto:" + name + "@" + emailHost+ ">" + name + "@" + emailHost + "</a>");
}

function get_if_exists(idElem) {
	if (document.getElementById("opt_title")) {
		var val = document.getElementById("opt_title").value;
	} else val = "";
	return val;
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');

	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function refresh_image(img_id,target_id,filename,alignimg,ht,wt) {
	var targetnode = document.getElementById(target_id);
	if ( targetnode.hasChildNodes() ) {
		while ( targetnode.childNodes.length >= 1 ) {
			targetnode.removeChild( targetnode.firstChild );
		}
	}	
	var images = document.createElement('img');
	images.src = filename;
	images.align = alignimg;
	images.border = 0;
	images.height = ht;
	images.width = wt;
	targetnode.appendChild(images);
}

function detect_optional() {
	//for inserting custom lines in the itinerary
	var val = document.getElementById("endday").value;
	var spannode = document.getElementById("opttitle");
	var spaninput = document.getElementById("opttitle_text");
	if (val > 899) {
		//spaninput.removeChild(document.getElementById("opttitle_text").firstChild);
		
		var spantxt = document.createTextNode(" Enter optional title: ");
		spannode.removeChild(document.getElementById("opttitle").firstChild);
		spannode.appendChild(spantxt);
		
		spaninput.removeChild(document.getElementById("opttitle_text").firstChild);
		
		newfield = document.createElement("input");
		spaninput.appendChild(newfield);
		newfield.name = "opt_title";
		newfield.id = "opt_title";
		newfield.type = "text";
		newfield.value = "(Optional)";
	} else {
		if (document.getElementById("opt_title")) {

			spaninput.removeChild(document.getElementById("opttitle_text").firstChild);			
			spannode.removeChild(document.getElementById("opttitle").firstChild);	
	
			var spantxt = document.createTextNode(" ");
			var spantxst = document.createTextNode(" ");			
			spannode.appendChild(spantxt);
			spaninput.appendChild(spantxst);
		}
	}
}

function getHint(str,idname,idrefs,userid,owner,tagonly,tagonlytarget) {
	var extra = idname;
	var pos = idname.indexOf("?");
	var tags_qry = "";
	var extra_start = "";
	var extra_end = "";
	
	finalElem = idrefs;

	if (pos > -1) {
		extra = idname.substring(pos+1);
		idname = idname.substring(0,pos);  
	}
	var url = "js/get"+idname;
	
	if (tagonly == 'y') {
		var pos_tags = extra.indexOf('&tags=');
		
		//change tags to include value in target field if tagonly=y
		var t = extra.substring(pos_tags+6);
		var pos_next_ampersand = t.indexOf("&");
		if (pos_next_ampersand > -1) {
			extra_start = extra.substring(0,pos_tags);
			extra_end = extra.substring(pos_next_ampersand+1);
		} else {
			extra_start = extra.substring(0,pos_tags); 
		}
		current_tags = document.getElementById(tagonlytarget).value;
		if ( current_tags.length > 0 ) {
			tags_qry = "&tags="+current_tags;
		}
		extra = extra_start+extra_end;	
	}
	
	url = url+".php";
	
    if (str.length==0) { 
      document.getElementById(finalElem).innerHTML="";
      return;
    }
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    url=url+"?l="+str+extra+"&user_id="+userid+"&owner="+owner+"&ex="+idname+"&idrefs="+idrefs+"&tagonly="+tagonly+"&tagonlytarget="+tagonlytarget+tags_qry;
    url=url+"&xxx="+Math.random();
    
	//alert(" "+finalElem+" "+url+" "+str);

    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function check_date_format(dateval) {
	var bool = true;
	var dateval = dateval.replace('/','-');
		//dateval.replace(/\//gi,'-');
	var arr = new Array();
	var numdigits;
	var numdays;
	
	arr = dateval.split('-');
	if (arr.length != 3) {
		bool = false;
		alert(dateval+" Enter your dates as YYYY-MM-DD.");
		return bool;
	}
	var i = 0;
	for (i=0; i<arr.length; i++) {
		numdigits = 2;
		switch (i) {
			case 0:
				numdigits = 4;
				minnumdays = 1000;
				numdays = 9999;		
			break;
			case 1:
				numdigits = 2;
				numdays = 12;		
				minnumdays = 0;	
				if (parseInt(arr[1]) > numdays) {
					alert(dateval+" There are only 12 months in a year.");
					bool = false;
					return bool;
				}
			break;
			case 2:
				numdigits = 2;
				minnumdays = 0;							
				if ((parseInt(arr[1]) < 12) && (parseInt(arr[1]) > 1)) {
					var tempmth = parseInt(arr[1]) + 1;
					var tempdate = new Date();
					tempdate.setDate(1);
					tempdate.setMonth(tempmth-1);
					tempdate.setFullYear(arr[0]);
					tempdate.setHours(0,0,0,0);
					var d = Date.parse(tempdate) - (1000*60*60*24);
					tempdate.setTime(d);
					numdays = parseInt(tempdate.getDate());
				} else { 
					numdays = 31;
				}
				if (parseInt(arr[2]) > numdays) {
					bool = false;
					alert(dateval+" You entered more days than there are in a month.");
					return bool;
				}
			break;
		}
		if ( (arr[i].length == numdigits) && (arr[i] == parseInt(arr[i])) && (arr[i] <= numdays) && (arr[i] > minnumdays) ) {
			//true
			var d = new Date();
			d.setDate(parseInt(arr[2]));
			d.setMonth(parseInt(arr[1])-1);
			d.setFullYear(parseInt(arr[0]));
			d.setHours(0,0,0,0);
		} else {
			bool = false;
			alert(dateval+" Date must be entered as YYYY-MM-DD");
			return bool;
		}
	}
	if (bool == false) return bool;
	else return d;
}

function get_tag_by_name_js(ell,divtarget) {
	followLink('../js/get_tag_by_name.php?l='+ell,divtarget);
	
}

function confirmbox(url,ref,message) {
	var r=confirm(message)
	if (r==true) {
		followLink(url,ref);
	}
}

function add_new_items(item,title) {
	
}

function show_or_hide(check_element,display_id) {
	if (document.getElementById(check_element)) {
		var spanTxt = document.createTextNode("Hide");
	} else {
		var spanTxt = document.createTextNode("Show");
	}
	var newSpan = document.getElementById(display_id);
	newSpan.removeChild(document.getElementById(display_id).firstChild);
	newSpan.appendChild(spanTxt);
}



function setCheckFlag(itemid) {
	var flag = document.getElementByID(itemid).checked.value;
	alert(itemid + "  "+flag);
	if (flag == "false") {
		document.getElementByID(itemid).checked = true;
	}
	else {
		document.getElementByID(itemid).checked = false;
	}
	
}


function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	//USE THIS FUNCTION ALWAYS
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function setAttributes (object, attributeName, attributeValue)
{
	var attributeNode = document.createAttribute (attributeName);
	attributeNode.value = attributeValue;
	object.setAttributeNode (attributeNode);
} // end setAttribute method

function createNewElements (type,newID) {
	var newE = document.createElement(type);
	newE.id = newID;
}



function insertTableObj(gTableId,position,spans,newrowname,currentrow,whereto,queryargs) {
	//gTableId: tbody id
	//position: direction to place new row (-1 or +1)
	//spans - columns to span; newrowname: id for new row; currentrow: currentrow id; whereto: pathname of target; queryargs: queries.
	var nSpanId = currentrow+newrowname+position;
	
	rindx = document.getElementById(currentrow);
	//alert(rindx.rowIndex);
	lineno = rindx.rowIndex+1;
	createTableX(gTableId,lineno,spans,nSpanId,newrowname);
	//whereto in case we want to use this script for another destination url
//	alert(whereto+queryargs);
	followLink(whereto+queryargs,nSpanId);	
}

function createTableX (gTableId,lineNo,spans,nSpanId,temprow) {
	
	if (document.getElementById(temprow)) {
		tempChild = document.getElementById(temprow);
		TableObj = document.getElementById(gTableId);
		TableObj.removeChild(tempChild);
		return;
	}
   	
   	var gCell = document.createElement("td");
   	gCell.colSpan=spans;
	gCell.id = temprow+nSpanId;
	   	
	var newSpan = document.createElement("span");
	newSpan.id=nSpanId;
   	var spanTxt = document.createTextNode("   ");
	newSpan.appendChild(spanTxt);
	
   	gCell.appendChild(newSpan);
   	
	var gTableB = document.getElementById(gTableId);
   	var gRow = gTableB.insertRow(lineNo);
   	
   	gRow.id = temprow;
   	gRow.appendChild(gCell);

/*
When adding rows to a table:

1. Don"t ever user innerHTML (OK, you didn"t do that)

2. Don"t append rows to the table, append them to a
    tableSection element (tbody, thead or tfoot)

3. Consider using insertRow(-1) on the table or tableSection
    so the row is created and appended in one statement.
*/
}
-->