var SELECTED='1';
var UNSELECTED='0';
var NOTAVAILABLE='2'

function getCookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) 
    	return null;
    if (start == -1) 
    	return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) 
    	end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function setCookieDataToForm(hitBetList,data) {
	var filter=data.substring(0,data.indexOf('|'));
	if(document.filterform!=null && document.filterform.select != null){
		for(a=0;a<document.filterform.select.length;a++) {
			if(document.filterform.select[a] && document.filterform.select[a].value==filter)
				document.filterform.select[a].checked=true;
		}
	}
	data=data.substring(data.indexOf('|')+1);	
	while(data.charAt(0)=='N') {
		var betnumber=data.substring(0,data.indexOf('|'));			
		var bNum=betnumber.substring(1);
		openedBetId=bNum;
		data=data.substring(data.indexOf('|')+1);
		var tippBoxString=data.substring(0,data.indexOf('|'));	
		data=data.substring(data.indexOf('|')+1);
		var betAmount=data.substring(0,data.indexOf('|'));	
		data=data.substring(data.indexOf('|')+1);
		var thisBet=hitBetList.getHitBetByNumber(bNum);
		if((thisBet!=null)&&(thisBet.betStatus=='0')) {			
			for(b=0;b<tippBoxString.length;b++) {
				if(BETSTATUS!='1') {
					if(thisBet.getTippBox((b+1))!=tippBoxString.charAt(b)) {
						thisBet.setTippBoxByNumber((b+1),tippBoxString.charAt(b));
					}
				}
			}
			if(BETSTATUS=='') {
				thisBet.betAmount=betAmount;	
			}
			hitBetTicket.addBet(thisBet);
		}
	}	
	var bettype=data.substring(0,data.indexOf('|'));	
	data=data.substring(data.indexOf('|')+1);
}

//----------------------------------------------
// set a cookie
//----------------------------------------------
function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

//----------------------------------------------
// Prepares the value string for the cookie.
// fills the value part of the cookie with the
// datas of the betround and betticket
//----------------------------------------------
function setCookieValueString(bets) {
	var valueString="";
        if(document.filterform!=null && document.filterform.select != null) {
		for(a=0;a<=document.filterform.select.length;a++) {
			if(document.filterform.select[a] && document.filterform.select[a].checked == true)
				valueString=valueString+document.filterform.select[a].value+'|';
	        }
        }

	//---------------------------
	// get all selected bets
	//---------------------------
	var actBet=hitBetTicket.bets;
	while(actBet!=null) {
		//------------------------------------------
		// add a bet if something is set
		//------------------------------------------
		if(actBet.checkSelectedBets()>0) {
			//----------------------------------
			// add the tippbox string:
			// returns smth. like 00101110.....
			// 0...not selected, 1...selected
			//----------------------------------
			valueString=valueString+"N"+actBet.getGameNumber()+"|"+actBet.getTippBoxString()+"|"+actBet.betAmount+"|";
		}
		actBet=actBet.getNextHitBet();
	}	
	//---------------------------------
	// now add the bet amount
	//---------------------------------
	var money=2;
	if(document.getElementById('BETMONEYTICKET')!=null)
		money=document.getElementById('BETMONEYTICKET').value;
	valueString=valueString+money+"|";
	return valueString;	
}

//----------------------------------------------
// delete a cookie
//----------------------------------------------
function deleteCookie(name,path,domain) {
    if (getCookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

//----------------------------------------------
// renew information of a cookie
//----------------------------------------------
function renewCookie(name,value,expires,path,domain,secure) {
	deleteCookie(name,path,domain);
	setCookie(name,value,expires,path,domain,secure);
}



//----------------------------------------------
// The replace() function simply replaces any 
// occurences of the text string within the 
// string string with the by string. 
//----------------------------------------------
function replace(string,text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    var newstr = '';
    if ((!i) || (i == -1)) return string;
    newstr += string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    
    return newstr;
}


var src_loaded = true;

