function $(id){return document.getElementById(id);}

/*Fn to toggle maps and directions view*/
function MQShow(e){
	aElms=e.parentNode.getElementsByTagName('span');
	for(i=0;i<aElms.length;i++){
		aElms[i].className="";
		sHide=aElms[i].getAttribute('rel');
		$(sHide).className="hide-data";
	}
	$(e.getAttribute('rel')).className="show-data";
	e.className="active";
}

/*Fn to count the PV's*/
gnSearchCount=1;
function PageRefresh(){
	sURL=window.location.href;
	aURL=sURL.split("#");
	if(aURL.length > 1){
		sURL=aURL[0];
	}
	sTitle=document.title;
	document.getElementById('pvcount').src = sURL+'/kerefresh.adp?title='+sTitle+'&count='+gnSearchCount;
	gnSearchCount++;
}

/*Fn to render map and directions*/
function RenderData(_type){
	PageRefresh();
	if(_type=="map"){
		sObj=CreateObjectData('http://info.aol.co.uk/mapquest-api/FindMap.swf',_type);
		$('show-maps-map').innerHTML=sObj;
		$('show-maps').style.display="";
	}else if(_type=="directions"){
		sObj=CreateObjectData('http://info.aol.co.uk/mapquest-api/DirectionsData.swf',_type);
		$('show-directions-data').innerHTML=sObj;
		sObj=CreateObjectData('http://info.aol.co.uk/mapquest-api/DirectionsMap.swf',_type);
		$('show-directions-map').innerHTML=sObj;
		$('show-directions').style.display="";
	}else{
		alert('Please check the search type');
	}
}

/*Fn to directions form values*/
function GenerateParameters(_type){
	if(_type=="map"){
		sMapCountry=$("mapCountry").value;
		sMapStreet=$("mapStreet").value;
		sMapCity=$("mapCity").value;
		sMapPin=$("mapPostCode").value;
		sGeoLanguage=$("GeoLanguage").value;
		sParamString='sCountry='+sMapCountry+'&sCity='+sMapCity+'&sStreet='+sMapStreet+'&sPin='+sMapPin+'&lang='+sGeoLanguage;
		return sParamString;
	}else if(_type=="directions"){
		sStartCountry=$("startCountry").value;
		sStartStreet=$("startStreet").value;
		sStartCity=$("startCity").value;
		sStartPin=$("startPostCode").value;
		sToCountry=$("toCountry").value;
		sToStreet=$("toStreet").value;
		sToCity=$("toCity").value;
		sToPin=$("toPostCode").value;
		sGeoLanguage=$("GeoLanguage").value;
		sParamString='sCountry='+sStartCountry+'&sCity='+sStartCity+'&sStreet='+sStartStreet+'&sPin='+sStartPin+'&tCountry='+sToCountry+'&tCity='+sToCity+'&tStreet='+sToStreet+'&tPin='+sToPin+'&lang='+sGeoLanguage;
		return sParamString;		
	}
}

/*Fn to create the flash object using the parameters*/
function CreateObjectData(_path,_type){
	sObject='<object width="600" height="424" id="flobj"><param name="AllowScriptAccess" value="always"/> <param name="movie" value="'+_path+'?'+GenerateParameters(_type)+'">	<embed id="flobj" src="'+_path+'?'+GenerateParameters(_type)+'" width="600" height="424" AllowScriptAccess="always"></embed></object>';
	sObject=FixEmbeddedObject(sObject);
	return sObject;
}

/*Fn to fix object in IE*/
function FixEmbeddedObject(embedCode) {
	if(embedCode && embedCode.toLowerCase().indexOf('classid') == -1) {
		var objPos = embedCode.toLowerCase().indexOf('object ') + 'object '.length;
		return embedCode.substr(0, objPos) + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + embedCode.substr(objPos);
	} else {
		return embedCode;
	}
}

/*Fn to print the map data retrieved from flash object*/

function printMapData(oData){
	if($('dd-print')){	$('outer_wrapper').removeChild($('dd-print'))};
	var nDiv  = document.createElement('div');
	nDiv.id="dd-print";
	$('outer_wrapper').appendChild(nDiv);
	oTxt=new Array();
	oTxt.push('<h1>'+document.title+'</h1>');
	oTxt.push(oData);
	nDiv.innerHTML=oTxt.join('');
	window.print();
}
