function fillyUrl(file) {

	var handset;
	var lang = "";
	var country = "";
	
	var allcookies = document.cookie;
	
	var handset_pos = allcookies.indexOf("handset=");
	var lang_pos = allcookies.indexOf("lang=");
	var country_pos = allcookies.indexOf("country=");
	
	
	if (handset_pos != -1) {
	
		handset = _findCookieValue(handset_pos,8);
		
		}
	if (lang_pos != -1) {
	
		lang = _findCookieValue(lang_pos,5);
		
		}
	if (country_pos != -1) {
	
		country = _findCookieValue(country_pos,8);
		
		}
		
	var text = handset+"/"+country+"/"+lang;
	text = text.replace(/\/{2,}/,"/");
	var append = text.replace(/\/+$/,"");
	
	window.location.href = "http://filly.local.com/"+append+"/"+file;
}

function submitVoucher(type)
{
	var myForm;
	if ("voucherForm" == type)
	{
		if (! document.getElementById("allMobile2").value)
		{
			return false;
		}
		myForm = document.getElementById("voucherForm");
		var mobile = (document.getElementById("allMobile2").value).replace(/\s+/,"");
		mobile = mobile.replace(/^[\+0]+/,"");
		document.getElementById("voucherMobile").value = mobile;
		myForm.submit();
		return true;
	}
}

function electronicTransaction(type) {
	
	var myForm;
	if ("voucherForm" == type) {
		if (! document.getElementById("allMobile2").value) {
			return false;
		}
		myForm = document.getElementById("voucherForm");
		var mobile = (document.getElementById("allMobile2").value).replace(/\s+/,"");
		mobile = mobile.replace(/^[\+0]+/,"");
		document.getElementById("voucherMobile").value = mobile;

		window.open("", "formTarget","width=350,height=300,scrollbars=yes,resizable=yes,status=yes");
		myForm.submit();
		document.location = "/index.html";
		return true;
		
		}
	else if ("worldpayForm" == type) {
		if (! document.getElementById("allMobile").value) {
			return false;
		}
		myForm = document.getElementById("worldpayForm");
		var mobile = (document.getElementById("allMobile").value).replace(/\s+/,"");
		mobile = mobile.replace(/^[\+0]+/,"");
		
		document.getElementById("worldpayMobile").value = mobile;
		
		}
	else if ("paypalForm" == type) {
		if (! document.getElementById("allMobile").value ) {
			return false;
		}
		myForm = document.getElementById("paypalForm");
		
		document.getElementById("paypalMobile").value = document.getElementById("allMobile").value;

		var mobile  = (document.getElementById("paypalMobile").value).replace(/\s+/,"");
		mobile = mobile.replace(/^[\+0]+/,"");

		// compile urlencoded string for form
		var str = "system=fonepark&intDialingCode=" + escape(document.getElementById("paypalIntDialingCode").value) + "&mobile=" + 
		escape(mobile) + "&email=" + "&ref=" + escape(document.getElementById("paypalTransRef").value);
		document.getElementById("paypalData").value = str;
		}
	else if ("paypalFormEmail" == type) {
		if (! document.getElementById("email").value ) {
			return false;
		}
		myForm = document.getElementById("paypalForm");

		document.getElementById("paypalMobile").value = document.getElementById("email").value;

		var email  = (document.getElementById("paypalMobile").value).replace(/\s+/,"");
		// compile urlencoded string for form
		var str = "system=fonepark&intDialingCode=" + "&mobile=" + 
		 "&email=" + escape(email) + "&ref=" + escape(document.getElementById("paypalTransRef").value);
		document.getElementById("paypalData").value = str;
		}
	else {
		return false;
		}
		
	
	window.open("", "formTarget","width=700,height=600,scrollbars=yes,resizable=yes,status=yes");
	myForm.submit();
	document.location = "/index.html";
	return true;
			


}


//deprecated
function createTarget(t,inputField){

	if(creditCardOrderCheck(inputField)) {
	
		if ( 'ppMobile' == inputField ) {
			var str = "system=fonepark&intDialingCode=" + escape(document.getElementById("ppIntDialingCode").value) + "&mobile=" + 
			escape(document.getElementById("ppMobile").value) + "&ref=" + escape(document.getElementById("ppTransRef").value);
			document.getElementById("ppData").value = str;
			
			}
		window.open("", t, "width=700,height=600,scrollbars=yes,resizable=yes,status=yes");
		document.location = "/index.html";
		return true;
		}
	else {
		return false;
		}
}

function doSearch() {

	var searchData = escape(document.getElementById("searchData").value);
	var searchProduct = escape(document.getElementById("searchProduct").value);
	
	if (searchData && searchProduct != '0') {
		
		window.location.href = "searchcontent_"+searchProduct+"_"+searchData+"_1.html";
		
		}

}

// NOT USED ANYMORE ??
function selectFlag() {

	// document.location is depreceated
	var text = window.location.pathname;
	
	// define a regular expression for matching the country code
	var pattern = new RegExp("/.*([A-Z]{2})/");
	
	var result = text.match(pattern);
	
	if( result != null) {
		var country = result[1];
		
		if ( (typeof (document[country]) == "object") && (document[country].constructor == HTMLImageElement) ) {
			document[country].src = "images/flag_icons_over/flag_"+country+".gif";
			
			if ( ( typeof (document.selectedFlagDownload) == "object") && (document.selectedFlagDownload.constructor == HTMLImageElement) )  {
				
				document.selectedFlagDownload.src = "images/flag_icons_over/flag_"+country+".gif";
				}
			document[country].style.border = "1px solid #000000";
			}
		}
	

}
function changeLang() {
		
	
	var lang = document.getElementById("lang").value;

	lang = lang.replace(/\.[a-z]{3}[0-9]{1}$/,"");
	// The user has selected a new language as their preference
	// makes sense to try and store it as a cookie if we can
	
	setCookie('lang',lang);
	
	var text = new String(window.location.pathname);
	var pattern = /(^\/.+\/.+\/)(.+)(\/.*$)/;
	text = text.replace(pattern,"$1"+lang+"$3");
	//alert(window.location.protocol+"//"+window.location.hostname+text);
	window.location.href = window.location.protocol+"//"+window.location.hostname+text;
	

}

function changeCategory(shortname,elemId) {


	if (!elemId) {
		var elemId = "category";
		}
	var new_category = document.getElementById(elemId).value;
	
	var text = new String(window.location.pathname);
	//alert (text);
	
	if (shortname) {
		var pattern = /(^\/.+\/.+\/.+)\/.*$/;
		text = text.replace(pattern,"$1"+"/content_"+shortname+"_"+encodeURIComponent(new_category)+"_1.html");
		}
	else {
		var pattern = /(^\/.+\/.+\/.+\/content_([a-z]+)_)(.+)_([0-9]+)(\.html)$/;

		text = text.replace(pattern,"$1"+encodeURIComponent(new_category)+"_1$5");

		}
	window.location.href = window.location.protocol+"//"+window.location.hostname+text;
	

}

function changeMobileHandset(id,redirect,page) {

	var mobile;
	if(id) {
		mobile = id;
		}
	else {
		mobile = document.getElementById("changeHandset").value;
		}
		
	if (!mobile) {
		mobile = '0';
		}
	setCookie('handset',mobile);
	
	var text = new String(window.location.pathname);
	var pattern = /^\/.+\/(.+\/.+\/)(.*$)/;
	
	
	if (redirect) {
		if (page) {
			text = new String(page);
			text = text.replace(pattern,"/"+mobile+"/$1$2");
		} else {
			text = text.replace(pattern,"/"+mobile+"/$1index.html");
		}
	} else {
		text = text.replace(pattern,"/"+mobile+"/$1$2");

		}

	
	window.location.href = window.location.protocol+"//"+window.location.hostname+text;
	
}

function changeCountry(country) {
	
	setCookie('country',country);
	var text = new String(window.location.pathname);
	var pattern = /(^\/.+\/)(.+)(\/.+\/.*$)/;
	text = text.replace(pattern,"$1"+country+"$3");
	//alert(window.location.protocol+"//"+window.location.hostname+text);
	window.location.href = window.location.protocol+"//"+window.location.hostname+text;

}

function getBannerImage() {

	var pattern = new RegExp("([^.]+)\.{1}.*");
	var text = new String(window.location.hostname);
	var result = text.match(pattern);
	if (!result[1]) {
		sub_domain = 'www';
		}
	else {
		sub_domain = result[1];
		}
		
	return sub_domain+"_banner.gif";
}
function setCookie(name,value) {
	// make sure only recognised cookies can be set
	// values must be checked at server side
	
	switch(name) {
		case 'country':
		break;
		case 'lang':
		break;
		case 'handset':
		break;
		default:
		return false;
		}
	// cookie expires in one month
	nextmonth = new Date();
	nextmonth.setMonth(nextmonth.getMonth() + 1);
	path = "/";
	var allcookies = document.cookie;
	var handset_pos = allcookies.indexOf("handset=");
	var lang_pos = allcookies.indexOf("lang=");
	var country_pos = allcookies.indexOf("country=");
	value=escape(value)
	//alert (name +" "+value + " " + nextmonth.toGMTString());
	document.cookie = name+"="+value+"; expires=" + nextmonth.toGMTString() + "; path=/;";


}
function _findCookieValue(pos,count) {

	var start = pos + count;
	var end = document.cookie.indexOf(";",start);
	if (end == -1) end = document.cookie.length;
	var value = document.cookie.substring(start,end);
	value = unescape(value);
	return value;

}

function creditCardOrderCheck(inputField) {

	var mobile = document.getElementById(inputField).value;
	if (!mobile) {
		return false;
		}
	return true;
	

}

    
   
function numericOnly(e) {
		code = e.keyCode?e.keyCode:e.which;
		if (code == null || code == 0 || code == 37 || code == 39 || code == 8 || code == 46) return true;
		key = String.fromCharCode(code);
		myRegExp = /[0-9]/;
		if (myRegExp.test(key)) return true;
		return false;
	}

function popRussianPrices(shortcode) {
	window.open("http://www.qrelax.ru/" + shortcode + ".html", "","width=350,height=300,scrollbars=yes,resizable=yes,status=no");
	return false;
}