// this animate function reloads the animated gif on the search holding pages
function animate() {
	if (!document.getElementById("moveingpic")) return true;
	var animatePic = document.getElementById("moveingpic");
	animatePic.setAttribute("src","/en/opodo/images/holding/hld_ani.gif");
}

function resetAni(){	
	setTimeout('document.images["moveingpic"].src = "/gen/opodo/images/pres/hld_ani.gif"', 200); 
}

function popUp(url,w,h,name,resizable,scrollbar,menu,tool,status,directories,x,y){

	this.strUrl = url;
	//x and y for window screen position not required at the moment
	this.intX = x;
	this.intY = y;

	this.strName = "win_"+name;
	this.strResizable = (resizable=="yes" || resizable==1) ? "resizable=yes" : "";
	this.strScroll = (scrollbar=="yes" || scrollbar==1) ? "scrollbars=yes" : "";
	this.strMenu = (menu=="yes" || menu==1) ? "menubar=yes" : "";
	this.strTool = (tool=="yes" || tool==1) ? "toolbar=yes" : "";
	this.strStatus = (status=="yes" || status==1) ? "status=yes" : "";
	this.strDirectories = (directories=="yes" || directories==1) ? "directories=yes" : "";
	this.intW = (!isNaN(w)) ? "width="+w: "";
	this.intH = (!isNaN(h)) ? "height="+h: "";
	
	this.arrOptions = new Array(this.strResizable,this.strScroll,this.strMenu,this.strTool,this.strStatus,this.strDirectories,this.intW,this.intH);
	this.strOptions = "";
	
	//build the options
	for(var i=0;i<this.arrOptions.length;i++){
		if(this.arrOptions[i].length>0){
			this.strOptions+=this.arrOptions[i]+",";
		}
	}
	//remove any trailing ","
	if(this.strOptions.length>0){
		this.strOptions=this.strOptions.substring(0,this.strOptions.length-1);
	}
	
	this.win=window.open(this.strUrl,this.strName,this.strOptions);
	this.win.focus();
}

function genPopUp(url,w,h,name,resizable,scrollbar,menu,tool,status,directories,x,y){
	//no requirement to hold popups in global references at the moment
	new popUp(url,w,h,name,resizable,scrollbar,menu,tool,status,directories,x,y)
	return false;
}


function hideError(){
	document.getElementById("error").style.display="none";
}
function showError(){
	document.getElementById("errorMessage").innerHTML = "<ul><li class=\"errMsg\">"+hiErr+"</li></ul>";
	document.getElementById("error").style.display="";
	window.scrollTo(0,0);
}
function showDest(num){
if(num<11){
	document.getElementById('dest').value=destArr[num-1];
	document.getElementById('hotel').value='';
	}
}
var errorBorder = "#CCCCCC";
function errorCheck(nam,err){
	var check = document.getElementById(nam);
	check.style.borderColor = errorBorder;
	var errorMsg = "";
	if(check.value==""){
		check.focus();
		check.style.borderColor="#FF0000";
		errorMsg +='<li class="mlneg9v11">'+err+'</li>\n';
		}
	if(errorMsg != ""){
		document.getElementById("errorMessage").innerHTML = "<ul>"+errorMsg+"</ul>";
		document.getElementById("error").style.display="";
		window.scrollTo(0,0);
		return false;
	}else{
		//dispHolding();
		setTimeout("dispHolding()",50);
		return true;
		}
	}

function blankIfNotNumeric( obj ){
	//determine if the field contains a numeric value
	var numericPattern	= /(\d)/;
	var objValue 		= obj.value;
	var checkReg 		= objValue.match( numericPattern );
	
	if( checkReg == null ){
		//no, lets blank out the field
		obj.value = "";
		obj.select();
	}

}



function generateInfantRoomAllocation(){
	var searchForm = document.forms['tripPackageHotelFlightSearchForm'];
	if (searchForm == null){
		searchForm = document.forms['ComtecForm'];
	}
	var inputName = 'roomAllocations[0].adultQuantity';
	var infantRoomAllocation = 'roomAllocations[0].infantQuantity';
	var totalTravellers=parseInt(searchForm[inputName].value);
	generateOption(searchForm[infantRoomAllocation], parseInt(searchForm[inputName].value));
}

function generateOption(elem, num){
	var prevSelectedVal = elem.value;

	elem.length = 0;
	for (var i=0; i<=num; i++){
		var option = document.createElement('option');
		option.value = i;
		option.innerHTML = i;
		if (i==prevSelectedVal){
			option.selected = "true";
		}
		elem.appendChild(option);
		if (prevSelectedVal < elem.length){
			elem.selectedIndex = prevSelectedVal;
		} else {
			elem.selectedIndex = elem.length - 1;
		}
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

