function popWindow(url, name, width, height){
	newWin = window.open(url, name,  'height='+height+',width='+width+',fullscreen=no,location=no,menubar=no,status=no,toolbar=no,scrollbars=auto,resizable=no');
	if (newWin.opener == null){ newWin.opener = self; }
	newWin.focus();
	return newWin;
}

function checkCouponCode(fVal,gameCode){
	if (fVal.length > 3){
		xmlhttpPost('/ajax/ajaxserv_checkcoupon.php?coupon_code='+fVal+'&game_code='+gameCode,'updateCoupon')
	}else{
		updateCoupon('0');
		document.getElementById('checkout_coupon').src= '/images/checkout_cross.gif';
	}
	
}

function roll(elemID){


	if (document.getElementById(elemID).src.indexOf('_on') > 0 ){
		document.getElementById(elemID).src = document.getElementById(elemID).src.replace('_on','_off');
	}else{
		document.getElementById(elemID).src = document.getElementById(elemID).src.replace('_off','_on');	
	}
	/*
	if (fState == 'on'){
		document.getElementById(elemID).src = document.getElementById(elemID).src.replace('_off','_on');
	}else{
		document.getElementById(elemID).src = document.getElementById(elemID).src.replace('_on','_off');
	}
	*/
}

function updateCoupon(fdata){

	if (fdata != "0"){
		discount_percen = getInnerStr(fdata,'<discount_percen>','</discount_percen>');
		discount_abs = getInnerStr(fdata,'<discount_abs>','</discount_abs>');

		if (discount_abs != '0'){
			newAmount = originalAmount - discount_abs;
		}else if (discount_percen != '0'){
			newPercen = discount_percen / 100;
			discount = originalAmount * newPercen;
			newAmount = originalAmount - discount;
		}
		if (newAmount < 0 ) newAmount = 0;
		
		document.getElementById('checkout_coupon').src= '/images/checkout_tick.gif';
	}else{
		newAmount = originalAmount;
		document.getElementById('checkout_coupon').src= '/images/checkout_cross.gif';
	}
	document.getElementById('priceUSD').innerHTML = '$'+roundDec(newAmount);

	document.getElementById('item_price').value = roundDec(newAmount);
	
	amnt = convert_currency(newAmount,'USD','GBP',rates)
	document.getElementById('priceGBP').innerHTML = '&pound;' + roundDec(amnt) + ' GBP';
	
	amnt = convert_currency(newAmount,'USD','EUR',rates)
	document.getElementById('priceEUR').innerHTML = '&euro;' + roundDec(amnt) + ' EUR';
	
	amnt = convert_currency(newAmount,'USD','AUD',rates)
	document.getElementById('priceAUD').innerHTML = '$' + roundDec(amnt) + ' AUD';
	
	amnt = convert_currency(newAmount,'USD','NZD',rates)
	document.getElementById('priceNZD').innerHTML = '$' + roundDec(amnt) + ' NZD';
	
}

function roundDec(original){
	var s = new String(Math.round(original*100)/100);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	return s;
}
function jsDebug(str){
  document.getElementById("jsdebug").value = document.getElementById("jsdebug").value +str;
}

function convert_currency(amount,from,to,rates) {
	 fRes = (amount/rates[from]) * rates[to];
	 return fRes;
}

function reloadTo(fUrl){
	window.location = fUrl;
}

function getInnerStr(str,startTag,endTag){
	var res = "";

	fstart = str.indexOf(startTag)+startTag.length;
	fend = str.indexOf(endTag);

	res = str.substr(fstart,fend-fstart);
	return res;
}
