var isIE=false;
var currencyCode	= 'GBP'	
var countryCode		= 'UK';
var countryIndex	= 0;
var curr			= '&pound;'
var curr2			= 'p'
var curr3			= '£'
var extraHour		= 0
var langs			= 'en,fr,du'
var selectedLanguage= 'en'
var egpost = 'NW3 5AS'
var thisPage = (document.location + '').toLowerCase();

isIE=('abc'.substr(-1)!='c')?true:false;

var s_=String.fromCharCode(172);
var ccDom;
//var page2Loaded=false;
//var page3Loaded=false;

var locContent0=new Array('e.g. EC2 1AB');
var locContent1=new Array('(e.g. DUBLIN 2)');
var locContent2=new Array('(e.g. 60308)');
var loc=new Array(locContent0,locContent1,locContent2);
var langLoaded=false;
var dist=0;

var menucount=0;
var sourceid = '';
var thisStep = 1;
var clogon = ''
var locationID = -1;
var entryTime=''


//variables for the menu
var todayTimes='';
var sod=0;


lc = (top.document.location+'').toUpperCase()
i  = lc.indexOf('SOURCEID=')

if (i > -1)
{
    lc1 = lc.substring(i+1,lc.length)
    i1  = lc1.indexOf('=')
    i2  = lc1.indexOf('&')
    if (i2<0) i2 = lc1.length
    sourceid = lc1.substring(i1+1,i2)
}

var sMsg	     = ''
var Im1_             = new Image
var Im2_             = new Image
var Im3_             = new Image
var Im4_             = new Image
var Im5_             = new Image
var Im6_             = new Image
var Im7_             = new Image
var cuisineSelection = ''
var curr             = '&pound;'
var curr2            = 'p'
var conver           = 0.4545
var curSel           = 1
var dec              = '.'
var path             = top.location.href;
var pod              = 0
// new for the expected delay
var delayMins	     	= 0
var delayMsg	     	= ''
var delayRemainingSecs 	= 0	
var selectedCuisine = ''
var entryPoint = 'UB'


// these are for the corporate accounts
var anyLocation
var memberID            // the individual within the corporate account
var corporateTimes,cTimes1,cTimes2
var corporateType=''
var jobTitle
var staffNumber
var subAccount
var validWebnames
var individualBudget, budget, budgetWeekend, indBudget;
var account
var memberEmail
var enforceBudget
var accountType
var loyaltyAccount
var loyaltyRule
var deptID
var cardMissing = "1"
var groupBudget
var groupString; var G=','; 
var groupMemberNames;
var allowGroup=false  
var groups   
var pDirect
var GS_info
var cCentre
var groupID=-1
var groupOrderTime=''
var groupDeliveryTime=''
var timeOffset=0;
var paymentID=-1;
var payByCreditCard=0;
var perSur=0;
var diet='';

p    = path.substring(0,path.lastIndexOf('/')+1)
path = ((p!='http://')?p:path+'/')+'UBpages/'


function myString(s){
			this.value=s;
		}
// support functions
function wri(dest,sT)
{
			/*
			for (m=0;m<sT.length;m+=100)
				dest.write(sT.substring(m,m+100))
			*/
		    
			dest.value+=sT;	
} 

function getName(){
	if (logonString==undefined || logonString=='')
		return ''
	//'Thomson-Reuters~test~test~1¬2 Finsbury Avenue¬EC2M-2PP¬2 Finsbury Avenue, Sun Street 
	pars=(logonString+'~~~~~~~').split('~')
	return pars[1]+' '+pars[2];
}

function home(){

	var link='../homepage4.asp'
	if(selectedLanguage!='en')
		link='../homepage'+((selectedLanguage!='')?'_'+selectedLanguage:'')+'.htm'
	link+='?cc='+countryCode
	if (entryPoint=='lmn')
		link='http://www.lastminute.com/site/entertainment/restaurants/'
	if (entryPoint=='sticky')
		link='http://www.stickyfingers.co.uk/'
    if (entryPoint == 'gostosa')
        link = 'http://www.eatgostosa.com/index.html'
	parent.document.location=link;

}
function infPage(n)
{

    if (n == 0)
    {
        if (!document.orderConfirmed && parent.lastPageCalled >= 4 && parent.Main.total != 0)
        {
            if (confirm('If you go back to the home page, all your order details will be lost. Do you really want to go to the home page?') == true)
                document.location='/ub.htm'
        }
        else
            document.location='/ub.htm'
    }
    else
    {
        pageName=''
        if (n==11) pageName='information_customerservice.htm#feedback'
        if (n==1) pageName='information_customerservice.htm'
        if (n==2) pageName='information_aboutus.htm'
        if (n==3) pageName='information_help.htm'
        if (n==4) pageName='information_howitworks.htm'
        if (n==5) pageName='AboutUB.htm'
        if (n==6) pageName='information_tnc.htm'
        if (n==7) pageName='UBreferRestaurant.asp'
        if (n==8) pageName='beenzSplash.htm'
        if (n==9) pageName='UBemailFriend.asp'
        if (n==10) pageName='http://www.lastminute.com/affiliates'
        

        if (pageName.indexOf('http')>=0) path=""
        window.open (path+pageName,'infoPage','scrollbars=yes,width=800,height=550')
    }
}



function findArea(pos)
{

    if (countryCode=='IR') return findAreaIR(pos)
    if (countryCode=='DE') return findAreaDE(pos)	
    if (countryCode=='NL') return findAreaNL(pos)
    if (countryCode=='BE') return findAreaBE(pos)
    if (countryCode=='IT') return findAreaIT(pos)
    /*
    returns the postal area in the format:
    NW3-2PA
    NW3-2
    EC1R-4
    EC1R-4AB
    */

    newPos = '';
    part1  = '';
    part2  = '';
    
    if (pos.indexOf('%')>=0)
		return 'none';
    for (t=0;t<pos.length;t++)
    {
        c = pos.substring(t, t+1)
        if (c != ' ' && c != '-') newPos += c
    }

    l=newPos.length;
    if (l < 2) return 'none'

    if (l <= 4)
        part1 = newPos
    else
    {
        part1 = newPos.substring(0, l-3)
        part2 = newPos.substring(l-3, l)
    }

    newPos = part1
    if (part2 != '') newPos += '-' + part2

    return newPos.toUpperCase()
}

function findAreaNL(pos){
 /*
 returns the postal area in the format:
 1032-12
 */

 newPos=''
 for (t=0;t<pos.length;t++){
  c=pos.substring(t,t+1)
  if (c!=' ' && c!='-') newPos+=c
 } 
 

 if (newPos.length!=4&&newPos.length!=6&&!(newPos.length==7&&newPos.charAt(4)==' ')) return 'none';
 
 for (i=0;i<4;i++){
   ch2=newPos.charAt(i)
   if (ch2<"0" || ch2>"9") return 'none';
   if (i==3 && ch2=='0' && newPos!='1060') return 'none'
 }

 part1='';part2=''
 l=newPos.length;
 if (l==4)part1=newPos
 if (l>4){
   part1 = newPos.substring(0,4)
   part2 = newPos.substring(4,l)
 }
 newPos = part1
 if (part2!='')newPos+='-'+part2  
 
 return (newPos.toUpperCase())
}


function findAreaIR(pos){
		
		//converts from dublin2 or dublin 2 to dublin-2
		pos=trim(pos);
		pos=pos.replace(' ','');
		// look for the numerical, and insert a dash just before it
		for(i=0;i<pos.length;i++){
			c=pos.substring(i,i+1);
			if ('0123456789'.indexOf(c)>=0)
				return pos.substring(0,i)+'-'+pos.substring(i);
			
		}
		return 'none'
}
function findAreaDE(pos){
		
		//converts to 203456
		pos=trim(pos);
		pos=pos.replace(' ','');
		if (pos.length!=5)
			return 'none'
		return pos;
}
function findAreaBE(pos){
		
		//converts to 1040
		pos=trim(pos);
		pos=pos.replace(' ','');
		pos=pos.replace('-','');
		if (pos.length>=4)
			return pos.substring(0,4);
		return pos;
}
function trim(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    return value;
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}


function deliveryExplain(delF,disL,minO,disF,tD,sty,del_)
{
p1='';
p2='';
p3='';
p4='';

  
try{
     if (del_==0) return transl('No delivery. Collection only!',58);
     p1 = curr + parseFloat(delF).toFixed(2) + ' '+transl('delivery',59)+'. ';
     if (delF==0) p1 = transl('Free delivery',60)+'. '
}catch(err)
{
	return ''
}
   
 
   

try{
    if (minO > 0) p2 = ' ' + transl('Minimum order',61) + ' '+curr+parseFloat(minO).toFixed(2) + '. '

    if (disL > 0)
    {
        if (disF > 0)
            p3 = sty + curr + parseFloat(disF).toFixed(2) + ' '+transl('delivery on orders over',62)+' '+curr + parseFloat(disL).toFixed(2) + '. '
        else
            p3 = sty + transl('Free delivery on orders over',63)+' '+curr + parseFloat(disL).toFixed(2) + '. '
    }

    if (tD != 0) p4 = sty + ' '+transl('Discount for pick-up',64) +': '+ tD + '%'
}catch(err){
   
}
 return   p1+ p3 + p4 + sty + p2
}



function matchZone(delarea,pC){
    if (delarea == undefined)
        return 1;
	
	matchtype=-1; // absolutely no match, 0=partial match, 1=match
	
	//zS='NW1-2 NW2-3 NW3-1 NW3-2'
	//pC='NW1 1AB'
	// make a list of the available postcodes

	pC=findArea(pC).toUpperCase();
	postcodes=delarea.toUpperCase().split(' ')
	for(var p=0;p<postcodes.length;p++){
		theMatch=matchPostcode(postcodes[p],pC)
		if(theMatch>matchtype)matchtype=theMatch	
	}
return matchtype;
}


function matchPostcode(p1,p2){
    // p1='NW3-1' , p2='NW3-1ab'
    if (p1 == '') return -1; 
	var p1_=(p1+'-').split('-')
	var p2_=(p2+'-').split('-')

	// first condition - the left parts must match:
	if(p1_[0]!=p2_[0] && p1_[0]!=leftPart(p2_[0]))
		return -1;
	
	// second condition - no right part on the base postcode means a complete match:
	if(p1_[1]=='')
		return 1;
	// now for the last part of the matching process
	for(var c=0;c<p1_[1].length;c++){
		
		theChar=p1_[1].substring(c,c+1);
		//alert(p1+'\n'+p2+'\n\nchar='+theChar+' '+p2_[1].substring(c,c+1))
		if(p2_[1].length<c+1)
			return 0;
		if(theChar!=p2_[1].substring(c,c+1))
			return 0;
	}
	return 1;
}

function leftPart(txt_){
    var txt=txt_
	if (txt=='')return ''
	// cleans up the left hand side for the UK
	if (countryCode=='UK'){
		if('0123456789'.indexOf( txt.substring(txt.length-1,txt.length) )<0)
			return(txt.substring(0,txt.length-1))
	}
	
	return txt;
}

/*
function matchZone_(zS,pC)
{
    

pC=findArea(pC);
alert(zS+'\n'+pC+'\n'+countryCode)
	
//temp:
    if (countryCode!='UK')
		return true;	
		
    // this function returns true if the postcode is within the zones available
    var sE = new Array();
    var c  = -1                 //will contain the different postcodes to search on

    pA = pC.toUpperCase().split('-')

    if (pA.length > 1)
    {
        for (var t=0;t<pA[1].length;t++)
        {
            c++;
            sE[c] = pA[0] + '-' + pA[1].substring(0,t+1)
        }
    }

    c++;
    sE[c] = pA[0]

    //exception for UK EC1r etc.
    if ('0123456789'.indexOf(pA[0].charAt(pA[0].length - 1)) < 0)
    {
        c++;
        sE[c] = pA[0].substring(0,pA[0].length - 1)
    }

    // now check to see whether one of these matches
    for (var t = 0; t < c + 1; t++)
        if (' '+zS.toUpperCase().indexOf(' '+sE[t]+' ') >= 0) return true

    return false
}
*/



function findZone(pC)
{
    // this function to return the number of the matching zone: global array (zones)
 
    for (var t=1; t<zones.length; t++)
    {
        zA=zones[t].split(',')
        pS=zA[5]
        if(matchZone(pS, pC) == true) return zones[t]
    }
    return 'none'
}


function corporateLogon(st)
{
    clogon=st;
    if (st==undefined||st=='')
        // st='¬09:00-23:55¬¬¬-1¬-1¬¬¬1¬¬¬0¬1¬¬'  // return
        st = '' + s_ + '09:00-23:55' + s_ + s_ + s_ + '-1' + s_ + '-1' + s_ + s_ + s_ + '1' + s_ + s_ + s_ + '0' + s_ + '0' + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ + s_ +  s_ + s_ + ''   // return
    
    ret=st.split(s_)
    if (ret.length > 0)
    {
        txt = ''

        for (t=0; t<ret.length; t++)
            txt += '\n' + t + '  ' + ret[t]

        anyLocation      = parseInt(ret[8])
        jobTitle         = ret[2]
        staffNumber      = ret[3]
        subAccount       = ret[0]
        corporateTimes   = ret[1]
        corporateType    = ret[7]
        validWebnames    = ret[6]
        individualBudget = ret[4];indBudget = individualBudget;
        budget           = ret[5]
        account          = ret[9]
        memberEmail      = ret[10]
        enforceBudget    = ret[11]
        accountType      = parseInt(ret[12])
        loyaltyAccount   = ret[13]
        loyaltyRule      = ret[14]
        deptID           = ret[15]
        cardMissing 	 = ret[16] 
		allowGroup       = ret[17]
        pDirect          = ret[18]
        cCentre = ret[19]
        //ret[20] = 'a';
		perSur			 = (isNaN(ret[20]) || ret[20]==undefined || ret[20]==null || ret[20]=='')?0:parseFloat(ret[20])
		diet			 = ret[21]
		cTimes1			 = ret[22]
		cTimes2          = ret[23]
		budgetWeekend    = ret[24]
        if (accountType>1)enforceBudget='True' 
       
    }
}




function displayCorpPopup()
{
    corpPop = window.open('corpPopup.asp?at=' + accountType + '&iB=' + escape(individualBudget), 'cP', 'scrollbars=no,width=280,height=330')
    corpPop.moveTo((screen.availWidth / 2) - 160, (screen.availHeight / 2) - 160)
}

function viewMap(wN){
   window.open('/UBpages/showMap.asp?wN='+wN,'map','scrollbars=no,width=600,height=400');
}


function bookmark()
{
    if(navigator.appName == "Netscape")
        alert('Please click CTRL-D to bookmark this page.')
    else
        window.external.AddFavorite('http://www.urbanbite.com', 'Order TAKE-AWAY online with Urbanbite');
}

function openRest(webname){
 Right.document.location='http://www.urbanbite.com/UBorder.asp?origin=1&webname='+webname
}
function sMessage(){
a='<table width="354" border="0" align="center" cellpadding="0" cellspacing="0" class="serviceMessage">'
a+='<tr><td width="15">&nbsp;</td><td valign="top"><br><br>'+sMsg+'</td><td width="15">&nbsp;</td></tr></table>'
if (sMsg=='') return ''
return a;
}

function setEntryTime(tim){
 entryTime=tim
 sMinutes=timeToMinutes(entryTime)
 nowDate=new Date();
 lMinutes=nowDate.getMinutes()+nowDate.getHours()*60;
 timeOffset=sMinutes-lMinutes;
}

function timeToMinutes(tim){
	sp=tim.split(':')
	res= parseInt(sp[0]) * 60 + parseInt(sp[1])
	if (res<360)res+=1440;
	return res
	
}
function minutesToTime(mins){
	hours=Math.floor(mins/60)
    minutes=mins-(hours*60)
    if (hours<10) hours='0'+hours;
    if (minutes<10) minutes='0'+minutes;
    return hours+':'+minutes
}

// returns the amount of time that a restaurant is open during the day
function openMinutes(tim){
	
}

// takes 2 time strings and creates a single one
function mergeTimes(time1,time2){
// time1 is the original time, i.e. 12:00-15:00,18:00-22:00

//12:00-15:00,18:00-22:00  and //11:00-23:00
// should become 12:00-15:00, 18:00-22:00

newTimeString=''
times1=time1.split(',')
times2=time2.split(',')

for (t1=0;t1<times1.length;t1++){
	for (t2=0;t2<times2.length;t2++){
		
		mergedPair=mergeTimePair(times1[t1],times2[t2])
		//alert(times1[t1]+'\n'+times2[t2]+'\n\n'+mergedPair);
		if(mergedPair!='')
			newTimeString+=','+mergedPair
				 			
	}
}

return (newTimeString+'').substring(1);
}


function mergeTimePair(pair1,pair2){

    //alert('pair1: ' + pair1 + '\npair2: ' + pair2);
    
//pair1 is the original pair, i.e. 12:00-14:30
//pair2 is the contender, i.e. 11:00-14:00
//result should be 12:00-14:00

	newPair=''
	pars1=pair1.split('-')
	pars2=pair2.split('-')
	if(timeToMinutes(pars1[0])>timeToMinutes(pars2[0]))
		newPairF=pars1[0]
	else
		newPairF=pars2[0]
	
		
	if(timeToMinutes(pars1[1])<timeToMinutes(pars2[1]))
		newPairT=pars1[1]
	else 
		newPairT=pars2[1]

	if (timeToMinutes(newPairF)<timeToMinutes(newPairT))
		newPair=newPairF+'-'+newPairT;


return newPair;

}



function serverTime(){
    // returns in format '10:20'
    myDate=new Date();
    mins=myDate.getMinutes()+myDate.getHours()*60+timeOffset
    return minutesToTime(mins)
}
function setTopStep(thePath,aStep){
	
	tFrame=topLeft.document;
	thisStep=aStep;
	
	if ((tFrame.location+'').indexOf('page1_top')<0){
		if (Cbrand=='')
			tFrame.location=((thePath.indexOf('http')>=0)?'':'/')+thePath+'UBpages/'+Cbrand+'page1_top.htm';
		else
			tFrame.location=((thePath.indexOf('http')>=0)?'':'/')+thePath+'LMimages/'+Cbrand+'page1_top.htm';	
	}
	
	else{
		try
			{
				topLeft.setStep(-1);
			}
		catch(err)
			{
			}
		}
		
}

function dishSearch(dish){
alert(dish)
}



/*

RATINGS

*/
function displayScores(scores,layout, headings){


	s=scores.split(',')
	score1=getRatingDisplay(s,1,'',headings[1])
	score2=getRatingDisplay(s,2,'',headings[2])
	score3=getRatingDisplay(s,3,'',headings[3])
	score4=getRatingDisplay(s,0,'g',headings[0])
	
	if (layout==2){
		htm=score1+score2+score3+'<td>&nbsp;&nbsp;</td>'+score4
	}
	else{
		htm='<table width="130" border="0" align="center" cellpadding="0" cellspacing="0">'
		htm+='<tr>'+score1+'</tr></tr>'+score2+'</tr></tr>'+score3+'</tr><tr><td colspan="2">&nbsp;</td></tr><tr>'+score4+'</tr>'
		htm+='</table>'
	}
	return htm;
}

function viewRatings(wn){
	window.open('/UBpages/feedbackDisplay.asp?webname='+wn,'Customerfeedback','width=700,height=600,scrollbars=yes',true)
	//Customerfeedback.setFocus()
}

function getRatingDisplay(s,x,g,theHeading){

	theScore=0
	if (x==0)
		theScore=(parseFloat(s[0])+parseFloat(s[1])+parseFloat(s[2]))/3  
	else 
		theScore=parseFloat(s[x-1])
		
		

	if (theHeading!='')theHeading+=':&nbsp;';
	htm='<td valign="middle" align="left" width="10" class="feedbackHeading">'+theHeading+'</td>'
    htm+='<td width="50" valign="middle" class="feedbackStarBack1">'
    if (theScore==0)
		return htm+'</td>'
    
    thePath='/LMimages'
    if(entryPoint.toLowerCase()=='lmn')thePath='/partners/LMN'
	for (i=1;i<theScore;i++)
		htm+='<img src="'+thePath+'/feedback_star2_2'+g+'.gif" width="11" height="11" alt="Score: '+theScore.toFixed(2)+' out of 5."/>'
	remainder=theScore-(i-1);
	theNum='2'
	//if (remainder>0.1 && remainder<0.6)	theNum='1'
	if (remainder>=0.3 && remainder<0.9)	theNum='1'
	if (theNum!='')
				htm+='<img src="'+thePath+'/feedback_star2_'+theNum+g+'.gif" width="11" height="11" />' 
	
	htm+='</td>'	
	return htm;
}










function paymentMethods(cclist){
	newccList='';cclist=cclist.toLowerCase();
	if (cclist.indexOf('cash')>=0)
		newccList='Cash'
	if (cclist.indexOf('ubdebit')>=0)
		newccList+=', Credit Cards' // <%=application("UBcards")%>'
	if (cclist.indexOf('redebit')>=0 || cclist.indexOf('visa')>=0)
		newccList+=', Credit Cards';
	if ((newccList+' ').substring(0,1)==",")
		newccList=newccList.substring(1);
	return newccList			
}
/*
function paymentMethods(restPay,mode){

	rP=restPay.toLowerCase().replace('ubdebit',(mode==2)?'<img src="/LMimages/ccCards.gif">':'<img src="/LMimages/ccCards.gif" width="180" height="30">')
	rP=rP.replace('redebit','Credit cards')
	rP=rP.replace('cash','<img src="/LMimages/trans.gif" class="cash">')
	rP=rP.replace('account','');
	while(rP.indexOf(',')>=0)
		rP=rP.replace(',','')
	return rP;
}
*/
function changeImage(im){

startPos=0
for(i=im.length;i>0;i--){
	
	if (im.substring(i-1,i)=='/'){
		alert(im.substring(i-1));
		startPos=i;
		break;
	}
}
return im.substring(0,startPos-1)+'/'+countryCode+'_'+im.substring(startPos);
}

function langText(n){
	
	return loc[countryIndex][n];	
}



function transl(eng,textIndex){
	if (selectedLanguage=='en')
		return eng
	try{
	comp=langPages[textIndex].split('¬');
		return comp[2];
	}catch(err){return eng}
}


function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url+'?rand=k98'+Math.random()+'';
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}






function gup( name ){  
	name = name.toLowerCase().replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href.toLowerCase() );  
	if( results == null )   
	return "";  
		else   
	return results[1];
}




function sLext(){
	
	if (selectedLanguage=='en')
		return ''
	else
		return selectedLanguage
}

function genBubble(tit,txt,backClass){

    return '<div style="width:98%;background-color:white;border:solid 1px grey;font-size:11px;"><div style="position:relative;left:3%;width:96%;padding-top:3px;padding-bottom:3px;"><div class="genTitleText">' + tit + '</div><div class="genTitle">&nbsp;</div>' + txt + '</div></div>'
	return genBubble2(tit, txt, '');
	return ab;
}


function genBubble2(tit, txt, backImg, bottomClass) {

    if (backImg == undefined || backImg == '')
        backImg = '' // 'generic_05.gif'
    var ab = '<div style="background-image: url(/LMimages/genBubbleTopNew.gif);width:268px;top:0px;">'
    
    if (backImg != '')
        ab = '<div style="background-image: url(/LMimages/cuisines/menu/' + backImg + '.gif);width:268px;padding-top:90px;top:0px;position:relative;">'

    ab += '<div style="position:relative;left:8px;width:242px;font-size:12px;">' 
    ab += '<div class="genTitleText">' + tit + '</div><div class="genTitle">&nbsp;</div>'

    ab += txt+'</div>'
    ab += '</div>'
    ab += '<div class="genBubbleBottomNew">&nbsp;</div>'
    return ab;
}

function format_number(pnumber,decimals){
	if (isNaN(pnumber)) { return '0.00'};
	if (pnumber=='') { return '0.00'};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}

/*
Handling of promotional vouchers here
*/


function redeemvoucher(){
	uL=document.getElementById('utilityLayer')
	uL.innerHTML='<iframe src="/checkVoucher.asp?voucherCode='+document.getElementById('promotionalCode').value+'">'
}
function redeemVoucherResult(result,theValue,expires){
	// we have a result:
	if (result=='notmatched'){
		alert(transl('Sorry, this promotional code has not been recognised',376))
		return;
	}

	if (result=='expired'){
		alert(transl('Sorry, this promotional code has now expired (valid until '+expires+').',377));
		return;
	}

	// we have a valid promotional code: update the price
	document.forms[0].promCode.value=result;
	document.forms[0].promotionalValue.value=theValue;
	promCode=result;
	promotionalValue=theValue;
	
	updateVoucherDisplay(1)
}
function updateVoucherDisplay(md){
	
	if (document.forms[0].promCode.value==''){
	    document.getElementById('promInfo').innerHTML = ''
		document.getElementById('promInfo').style.display='none';
	}else{
		pars=document.forms[0].promotionalValue.value.split(',')
		msgMin='No minimum order value'
		if (eval(pars[2])!=0)
			msgMin='<strong>'+transl('The minimum spend to qualify for this reduction is ',390)+curr+eval(pars[2]).toFixed(2)+'</strong>.'


		msg1='<div class="promotionDisplay">'+transl('Promotional code',386)+' <b>'+document.forms[0].promCode.value+'</b>:<br>'+transl('Reduction of XXX on the final total',387).replace('XXX',(pars[1]!='true'?curr:'')+eval(pars[0]).toFixed(2)+(pars[1]=='true'?'%':''))+'.<br>- '+msgMin+((isRestaurantPromotion())?'':'<br>- '+transl('payment by card only',388))+'</div>'
		msg2=transl('This promotional code / voucher (<b>YYY</b>) entitles you to a reduction of <b>XXX</b> on the final total.',389).replace('YYY',document.forms[0].promCode.value).replace('XXX',(pars[1]!='true'?curr:'')+eval(pars[0]).toFixed(2)+(pars[1]=='true'?'%':''))+' '+msgMin+((isRestaurantPromotion())?'':'<br><br>'+transl('Please note: this reduction is only valid if paying by credit card. The discounted total will be updated when you select to pay by credit card.',392))
		ele=document.getElementById('promInfo')
		ele.style.display = '';
		
		if(thisPage.indexOf('checkout')>=0){
			ele.innerHTML=msg1;
			updateDisplayPage();
        }
        if(thisPage.indexOf('order')>=0)
            displayOrder();
			
		this.modalTitle=transl('Urbanbite promotional voucher',391)
		if(md==1)displayModal3(parent,this,'',msg2,true,'#0000F',-100,true,'menu,right','top5.gif','bottom5.gif');
	}
}
/*
	returns the amount to be deducted from the final total
*/
function voucherReduction(tot){

	if(document.forms[0].promCode==null || document.forms[0].promCode.value=='')return 0;
	pars=document.forms[0].promotionalValue.value.split(',');
	//alert(document.forms[0].promotionalValue.value+'\n'+tot+'\n'+eval(pars[2]))
	
	if(tot>eval(pars[2])|| eval(pars[2])<=0 || tot<eval(pars[0]) ){
		return ((pars[1]=='false')?eval(pars[0]):tot*eval(pars[0])/100).toFixed(2)
	}else
		return 0
}
function isRestaurantPromotion(){
	if(document.forms[0].promotionalValue==null || document.forms[0].promotionalValue.value=='')return false;
	pars = document.forms[0].promotionalValue.value.split(',');
	return (pars[4]=='False')?true:false;
}



function setQueryStringParameters(ep,cc){

	if (ep!='')	
		entryPoint=ep;
	
	if (ccDom!='' && ccDom!=undefined)	
		cc=ccDom;
	
	if (cc!=''){
		if (cc=='ir'){
			currencyCode= 'EUR'
			countryCode = 'IR'
			countryIndex = 1
			curr		= '&euro;'
			curr2		= 'c'	
			curr3		= 'EUR'
			extraHour	= 0
			langs='en,fr'
			selectedLanguage='en'
			egpost='DUBLIN 2'
			GoogleMapsKey='ABQIAAAA5k-tOMKT9rn2xUXSxe1NmRTh5ADzjdvVRnRs3L84QGLFqcOo-BRNGHaFCKZcHwL88q0UetG5rgRQXQ'
		}	
		if (cc=='de'){
			currencyCode= 'EUR'
			countryCode = 'DE'
			countryIndex = 2
			curr		= '&euro;'
			curr2		= 'c'	
			curr3		= 'EUR'
			extraHour	= 1
			langs='de,en'
			selectedLanguage='en'
			egpost='1928345'
		}	
		if (cc=='be'){
			currencyCode= 'EUR'
			countryCode = 'BE'
			countryIndex = 3
			curr		= '&euro;'
			curr2		= 'c'	
			curr3		= 'EUR'
			extraHour	= 1
			langs='en,fr,du'
			selectedLanguage='en'
			egpost='1040'
			GoogleMapsKey='ABQIAAAAWk0M2WtUGqf-Q6KE4VL2mhRcNXVDxlYn4ybayc8X0uSdG1S7HhRInsLd7lpZaAR_FGiToYy2oiMTPA'
		}
		if (cc=='nl'){
			currencyCode= 'EUR'
			countryCode = 'NL'
			countryIndex = 4
			curr		= '&euro;'
			curr2		= 'c'	
			curr3		= 'EUR'
			extraHour	= 1
			langs='en,fr,du'
			selectedLanguage='du'
			egpost='1017ax'
			GoogleMapsKey='ABQIAAAAWk0M2WtUGqf-Q6KE4VL2mhR7gw2ViAb6sdU5ifWTRSifjrz9yBQd7TJ2-1ZaSB6lcLqTT5Tr6en20w'
		}
		if (cc=='po'){
			currencyCode= 'EUR'
			countryCode = 'PO'
			countryIndex = 5
			curr		= '&euro;'
			curr2		= 'c'	
			curr3		= 'EUR'
			extraHour	= 0
			langs='en,po'
			selectedLanguage='po'
			GoogleMapsKey='ABQIAAAAWk0M2WtUGqf-Q6KE4VL2mhR7gw2ViAb6sdU5ifWTRSifjrz9yBQd7TJ2-1ZaSB6lcLqTT5Tr6en20w'
		}
		if (cc == 'it') {
		    currencyCode = 'EUR'
		    countryCode = 'IT'
		    countryIndex = 6
		    curr = '&euro;'
		    curr2 = 'c'
		    curr3 = 'EUR'
		    extraHour = 0
		    langs = 'en,it'
		    selectedLanguage = 'it'
		    GoogleMapsKey = 'ABQIAAAAWk0M2WtUGqf-Q6KE4VL2mhR7gw2ViAb6sdU5ifWTRSifjrz9yBQd7TJ2-1ZaSB6lcLqTT5Tr6en20w'
		}		
	}	
}



function getY( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function getX( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

/*
function hideShow(div){

    obj = document.getElementById(div)
    obj2 = document.getElementById('img' + div);
   
    obj.style.display = (obj.style.display == 'none') ? '' : 'none'
    if (obj2 != null)
           obj2.style.backgroundImage = (obj.style.display == 'none') ? 'url(/LMimages/hideshowplus.gif)' : 'url(/LMimages/hideshowminus.gif)'
       
}
*/


//window.onload=function(){

setQueryStringParameters(gup('partnerID'),gup('cc').toLowerCase());
if(gup('sL')!='')
	selectedLanguage=gup('sL')
//}
langLoaded=true;


function forgotUN(){
	msg='<iframe src="/UBpages/detailsReminder.asp"  height="200" width="100%"  frameborder="no"></iframe>'
	displayModal3(parent,this,'',msg,true,'#CCCCCC',50,false,'menu,right','top5.gif','bottom5.gif','Login details Reminder:',-1,200);
}








/*
 CODE to get the X and Y coordinates
*/
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
			if (tempY < 0){tempY = 0;}  
			
		
}

function getAnchorCoords(ele){
    var obj = document.getElementById(ele);
    if(obj==null)return-1;
   	var curleft = curtop = 0;
	if ('string' == typeof obj)
	obj = document.getElementById(ele);
	var curtop = 0;
	while (obj != null)
	{
		curtop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return curtop;
}	

function aButton(txt,func,style,id,idText){
 idText=(idText==undefined)?'':idText;
 btn= '<div id="'+id+'" class="btnButton" onclick="'+func+'">'
 btn+='<div class="btnLeft'+style+'"></div>'
 btn+='<div class="btnBody'+style+'"><div class="btnText'+style+'" id="'+idText+'">'+txt+'</div></div>'
 btn+='<div class="btnRight'+style+'"></div>'
 btn+='</div>'
 return btn;

}	
function serviceMessage(){
	
	return;
	msg='Dear customer, due to the festive season, there is a small possibility that some restaurants could have closed without informing us. <br><br>Please place your order as usual and we will confirm it within minutes. Regular service will resume from 1st January 2010. Merry Christmas! <br><br>the Urbanbite team.'
	msg='Wednesday 6 Jan: Britain is experiencing some extreme weather conditions. Customers in some areas may experience slower deliveries or sudden restaurant closures.<br>We apologise for any inconvenience this may cause. '
	
	displayModal3(parent,this,'',msg,true,'#CCCCCC',50,false,'menu,right','top5.gif','bottom5.gif','Service notification',-1,200);
}

function voucherOffer() {

    if (entryPoint != 'AS08') {
        msg='<iframe src="footballGame.html" width="100%"  height="260px" frameborder=0></iframe>'
        displayModal3(parent, this, '', msg, false, '#CCCCCC', 50, false, 'menu,right', 'top5.gif', 'bottom5.gif', 'World Cup Promotion', -1, 200);
    }
    
    var voucher = '';var voucherPoint=''
	if(entryPoint=='bing'){
		voucherPoint='BING'
		voucher='EASTER10'
	}
	if(entryPoint=='google'){
		voucherPoint='Google'
		voucher='NY2010'
    }
    if (entryPoint == 'easter') {
        voucherPoint = 'Google'
        voucher='EASTER'
    }

    if (voucher == '')
        return;
	
	msg='Dear customer, thank you for choosing Urbanbite. It is our pleasure to offer you an introductory gift of <strong>£2.50</strong>. Please make a note of voucher <span class="voucherCode">'+voucher+'</span> and simply type this in when composing your order on the menu page:<img src="/LMimages/voucherExplain4.gif">'

	displayModal3(parent,this,'',msg,true,'#CCCCCC',50,false,'menu,right','top5.gif','bottom5.gif','Discount voucher',-1,200);

}
function floatingMessage(lay,msg){
	mil=document.getElementById(lay)
	mil.style.left=(tempX+5)+'px';
	mil.style.top=tempY+'px';
	mil.style.visibility='visible'
	mil.innerHTML=msg; 
}
function hideFloatingMess(lay){
	document.getElementById(lay).style.visibility='hidden'
}

// returns an array of zone objects
function getZones(zonesString) {

    zones_ = zonesString.split('||');
    var zones = new Array(); zones.length = 0;
    for (var i = 0; i < zones_.length; i++) {
        pars = zones_[i].split(',');
        zones[zones.length] = new aZone(pars[0], pars[1], pars[2], pars[3], pars[4], pars[5]);
    }

    return zones;
    //12,0,0,3,60, E14 ||12,0,0,5,60, e3    
    //zones[1]='7.50,0,0,0,45, E1 EC2 EC3 EC4 SE1 SE16 ';
    //zones[2]='10.00,2.50,0,0,60, E2 E14 SE8 ';
}
function toValue(v) {
    if (isNaN(v))
        v = 0;
    else
        v = parseFloat(v);
    return v;
}
function aZone(minOrder, delFee, disLimit, disFee, restLead, delArea) {
    this.minOrder =toValue(minOrder);
    this.delFee = toValue(delFee);
    this.disLimit = toValue(disLimit);
    this.disFee = toValue(disFee);
    this.delArea = delArea;
    this.restLead = toValue(restLead);
    this.matchType = -1;          // default, no match with the current postcode.
}

function matchZonesNew(postcode, zones) {
    // zones is an array of zone objects, i.e. zone.delArea
    // add the match type on each zone item
    for (var i = 0; i < zones.length; i++)
        zones[i].matchType = matchZone(zones[i].delArea, postcode);

    // now check for the best match
    idZone = 0; matchType = -1;
    for (var i = 0; i < zones.length; i++) {
        // alert(i+'\ndelarea:' + zones[i].delArea + ', ' + zones[i].matchType)
        if (zones[i].matchType > matchType) {
            matchType = zones[i].matchType;
            idZone = i;

        }
    }
    return idZone;
}


function getNumerical(txt) {
    var n = txt.match(/\d/g)
    if (n == '' || n == null) return 0;
    result = ''
    for (var i = 0; i < n.length; i++)
        result += n[i] + '';
    return eval(result);
}


function resizeDiv(id, maxSize) {
    var div = document.getElementById('divC' + id);
    if (div.offsetHeight > maxSize) {
        div.style.height = maxSize + 'px'
        div.style.overflow = 'auto';
    }
    try {
        div.scrollTop = orderItem.selections[id].scrol;
    } catch (err) { }
}
function hideshow(id, maxSize, disp) {

    
    var img = document.getElementById('img' + id);
    var div = document.getElementById('div' + id);
    var pre = document.getElementById('pr' + id);
    var sha = document.getElementById('sa' + id);
    var divC = document.getElementById('divC' + id);



    if (pre != null) {
        preHtm = pre.innerHTML;
        divHtm = div.innerHTML;
        pre.innerHTML = '';
        div.innerHTML = '';
        div.innerHTML = preHtm + divHtm;
        if (sha != null)
            sha.style.display = 'none';
               
    }

    resizeDiv(id, maxSize);
    
    if (div.style.display == '' && disp!=true) {
        div.style.display = 'none';
        img.className = 'sectionHide'
    } else {
        div.style.display = '';
        img.className = 'sectionShow'
    }
}
function hideshowSection(id, content, preview, title, titleClass, display, infoMsg, maxSize, scrol) {

    if (scrol == undefined)
        scrol = 0;
    
    var htm = '<span style="cursor:pointer;text-transform:capitalize;" class="' + titleClass + '"  onclick="hideshow(' + id + ','+maxSize+')"><img id="img' + id + '" src="/LMimages/trans.gif" class="' + (display ? 'sectionShow' : 'sectionHide') + '">' + title + '</span>'
   
    if (infoMsg != undefined && infoMsg!='')
        htm += infoMsg
    htm+='<div id="divC'+id+'">'    
    if (preview != '')
        htm += '<div id="pr' + id + '">' + preview + '</div>' + ((content != '' && !display) ? '<div style="text-align:right;font-size:11px;font-weight:bold;" id="sa' + id + '"><a href="javascript:hideshow(' + id + ',' + maxSize + ',true)">show all</a></div>' : '');
    
    htm += '<div id="div' + id + '" style="display:' + (display ? '' : 'none') + '">' + content + '</div>'
    htm +='</div>'
    
    return htm + '<div style="clear:both;"></div>';

}




function displayPrice(dP, style) {

    if (style == undefined) style = 1;
    if (isNaN(dP)) 
        dP = 0;

    if (dP == '' && dP != 0) return '-'
    if (dP == 0 && style==3) return ''
    
    sign = '';
    free = transl('Free', 99)
    dP += ''
    zeroP = (style == 1) ? free : (curr + '0' + dec + '00')
    if (style == 2) zeroP = ''

    p = parseFloat(dP)
    if (p < 0) {
        p *= -1;
        sign = '-'
    }
    if (p == 0) return zeroP
    if (p == 0.01) return 'various'
    if (p < 1 && curr2 != '')
        return sign + parseInt((p * 100) + .002) + curr2
    else
        return sign + curr + conc(p)
}
function conc(nu) {
    if (isNaN(nu))
        nu = 0;
    return eval(nu).toFixed(2);
}
function orderLine(left,right,style){
	bg='grey'
	if (style==undefined)
		style=''
	isStyle=false;isClass=false;
	if(style.indexOf(':')>=0)
		isStyle=true;
	else if (style!='')
		isClass=true;
	var h='<div style="'+((isStyle)?style:'')+'" '+((isClass)?'class="'+style+'"':'')+'><div style="padding:2px;">';
	h+='<div style="float:left;width:170px;">'+left+'</div>'
	h+='<div style="float:right;text-align:right;">'+right+'</div>'
	h+='<br style="clear: both;"></div></div>'
	return h;
}
function concat(str,l) {
    if(str.length>l)
        return str.substring(0, l - 3) + '...'
    return str;
}
