var mapIntervalId = 0;

function clearItold(strElement, strDefault){
	if(strElement.value == strDefault){
		strElement.value='';
		if(strElement.id == 'pwd'){
		   strElement.type = 'password';
		}
	}else if(strElement.value.length == 0){
		if(strElement.id == 'pwd'){
		   strElement.type = 'text';
		}
		strElement.value=strDefault;
	}
		
}

function imageSwap(strEle){
	if(document.getElementById(strEle)){
		document.getElementById(strEle).innerHTML='';
	}
}

function clearIt(strElement, strDefault){
	if(strElement.value == strDefault){
		strElement.value='';
		if(strElement.id == 'pwd'){
			document.getElementById('pwddiv').innerHTML='';
			document.getElementById('pwddiv').innerHTML='<input name="pwd" type="password" id="pwd" value="" onclick="clearIt(this,\'Password\')" onblur="clearIt(this,\'Password\')" />'
			document.getElementById(strElement.id).focus();
			document.getElementById(strElement.id).select();
		}
	}else if(strElement.value.length == 0){
		if(strElement.id == 'pwd'){
		   document.getElementById('pwddiv').innerHTML='';
			document.getElementById('pwddiv').innerHTML='<input name="pwd" type="text" id="pwd" value="Password" onclick="clearIt(this,\'Password\')" onblur="clearIt(this,\'Password\')" />'
		}
		strElement.value=strDefault;
	}
}

function textboxImage(strElement, strClass, intType, strWidth){
	
	switch (intType){
		case 0: 
			if(strElement.value.length == 0)strElement.className = strClass;
		break
		case 1: 
			strElement.className = 'txtbx-title-none';
			if(strWidth){
				if(strWidth.length>0){
					strElement.style.width=strWidth;
				}
			}
		break
		default: 
			strElement.className = 'txtbx-title-none';
		break
	}
}

function clearTxtBoxes(){
	if(document.getElementById('search_name')){
		if(document.getElementById('search_name').value.length>0){textboxImage(document.getElementById('search_name'),'txtbx-title-none',1)}
	}
	if(document.getElementById('search_type')){
		if(document.getElementById('search_type').value.length>0){textboxImage(document.getElementById('search_type'),'txtbx-title-none',1)}
	}
	if(document.getElementById('search_town')){
		if(document.getElementById('search_town').value.length>0){textboxImage(document.getElementById('search_town'),'txtbx-title-none',1)}
	}
	if(document.getElementById('usr')){
		if(document.getElementById('usr').value.length>0){textboxImage(document.getElementById('usr'),'txtbx-title-none',1)}
	}
	if(document.getElementById('pwd')){
		if(document.getElementById('pwd').value.length>0){textboxImage(document.getElementById('pwd'),'txtbx-title-none',1)}
	}
}

function astriskFields(strVal){
	if(strVal==1){
		document.getElementById('bus_add1').innerHTML='Business address for membership:';
		document.getElementById('bus_town').innerHTML='Town:';
		document.getElementById('bus_county').innerHTML='County:';
		document.getElementById('bus_pc').innerHTML='Post Code:';
		document.getElementById('bus_web').innerHTML='Website Address:*';
		
	}else{
		document.getElementById('bus_add1').innerHTML='Business address for membership:*';
		document.getElementById('bus_town').innerHTML='Town:*';
		document.getElementById('bus_county').innerHTML='County:*';
		document.getElementById('bus_pc').innerHTML='Post Code:*';
		document.getElementById('bus_web').innerHTML='Website Address:';
	}
}

function BusRate(img_no, ele_id) {
	for (i = 1; i <= 5; i++){
		document.getElementById(i).src='images/star-rate-off-small.gif';
	}

	for (i = 1; i <= img_no; i++){
		document.getElementById(i).src='images/star-rate-on-small.gif';
		document.getElementById(ele_id).value=img_no;
	}
}
function BusStandardsRate(img_no, line_no, ele_id, color) {
	for (i = 1; i <= 5; i++){
		//alert(line_no+'_'+i);
		if(color==1){
			document.getElementById(i+'_'+line_no).src='images/star-rate-off-white-small.gif';
		}else{
			document.getElementById(i+'_'+line_no).src='images/star-rate-off-small.gif';
		}
			
	}

	for (i = 1; i <= img_no; i++){
		if(color==1){
			document.getElementById(i+'_'+line_no).src='images/star-rate-on-white-small.gif';
		}else{
			document.getElementById(i+'_'+line_no).src='images/star-rate-on-small.gif';
		}
		
		document.getElementById(ele_id).value=img_no;
	}
	
	document.getElementById('frm_rate_na_'+line_no).checked=false;
}

function BusStandardsReset(line_no,color) {
	for (i = 1; i <= 5; i++){
		if(color==1){
			document.getElementById(i+'_'+line_no).src='images/star-rate-off-white-small.gif';
		}else{
			document.getElementById(i+'_'+line_no).src='images/star-rate-off-small.gif';
		}
		document.getElementById('frm_rate_'+line_no).value='0';
	}
}

function BusStandardsReload(element, value, line, color){
	//for (j = 0; j <=8; j++){
		if(value > 0){
			BusStandardsRate(value,line,element,color);
			//alert(element+'='+value+'and'+j);
			//BusStandardsRate(img_no, line_no, ele_id, color)
		}else{
			//BusStandardsReset(line+'_'+value,1);
			document.getElementById('frm_rate_na_'+line).checked=true;
		}
	//}
}
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

function loadMap(strAddress){
	if (geocoder) {
		
		clearInterval(mapIntervalId);
		//alert(strAddress);
		showAddress(strAddress, 'GB');
	}
}

function CreateBookmarkLink(strTitle, strLink) {

	if(strTitle != undefined){
		title = strTitle; 
	}else{
		title = document.title; 
	}
	
	if(strLink != undefined){
		url = strLink;
	}else{
		url = window.location.href;
	}
	
	if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
	return true; }
}

function busAlert() {
	alert('You need to be a full member to access this area.');
}

function calcDist(lat1, lon1, lat2, lon2, targDiv){
var R = 3963; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
        Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
document.getElementById(targDiv).innerHTML=(((d* 0.621)).toFixed(1)+' Miles')

}

Number.prototype.toRad = function() {  // convert degrees to radians
  return this * Math.PI / 180;
}

function checkSearchForm(strBusName, strBusType, strPlace){
	var flag = true

	if(strBusName.length==0&&strPlace.length==0||strBusType.length==0&&strPlace.length==0||strBusName=='Search for business name'&&strPlace=='Postcode or Town'||strBusType=='Search for type of business'&&strPlace=='Postcode or Town'){
		alert ("Please complete both step 1 and step 2")
		flag = false
	}
	if (flag) {
		 document.form3.submit()
	}
}

function showButtonOpt(objSelected){
	document.getElementById('next_button').style.visibility = 'visible';
	strType = document.getElementById('page').value
	
	if(objSelected.length != 0){
		if(strType == "cust_review"){
			document.form3.submit();
			//document.getElementById('next_button').innerHTML = '<input type="submit" name="Submit" value="Next &gt;" class="buttons" />'
		}else{
			document.getElementById('next_button').innerHTML = 'The business you have nominated is already a business member. <a href="business-review.asp?id='+document.getElementById('frm_business_hidden').value+'">Click here to review them.</a>'
		}
	}else{
		if(strType == "cust_review"){		
			document.getElementById('next_button').innerHTML = 'The business you’re looking for is not a member of FGCS - <a href="customer-recommend-details.asp">click here to nominate them.</a>'
		}else{
			document.getElementById('next_button').innerHTML = 'The business is not a member of FGCS - <a href="customer-recommend-details.asp">click here to nominate them.</a>'
		}
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

