<!-- Common JavaScript Functions -->

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "13";
  else
    return results[1];
}
function file_get_contents( url ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Legaev Andrey
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes. 
    // %        note 1: To avoid browser blocking issues's consider using jQuery's: $('#divId').load('http://url') instead.
    // *     example 1: file_get_contents('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
 
    var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) throw new Error('XMLHttpRequest not supported');
    
    req.open("GET", url, false);
    req.send(null);
    
    return req.responseText;
}
function createDOM(url){
	var doc = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLDOM") : document.implementation.createDocument(ns, root-element, null);
	doc.load(url);
	return doc;
}
function changeMethod(method)
{	document.getElementById('methodHidden').value=method;
	document.forms[0].submit();
}
function submitWithoutCookie(){
	document.getElementById('isCookieEnabled').value=false;
	document.forms[0].submit();
}

function changeLocation(){
	var data = document.getElementById('remitCountryId').value;
	setCookie('remitCountryId',data,365);
	document.forms[0].submit();
}
function getCountry(data){
	var country;
	if (data == '32') {
		country = 'brunei';
	}
	else if (data == '95'){
		country = 'hongkong';
	}
	else if (data == '99'){
		country = 'indonesia';
	}
	else if (data == '128'){
		country = 'malaysia';
	}
	else if (data == '148'){
		country = 'nepal';
	}
	else if (data == '152'){
		country = 'newzealand';
	}
	else if (data == '167'){
		country = 'philippine';
	}
	else if (data == '228'){
		country = 'vietnam';
	}
	else if (data == '236'){
		country = 'vietnam';
	}
	else if (data == '189'){
		country = 'singapore';
	}
	else if (data == '208'){
		country = 'thailand';
	}
	else if (data == '221'){
		country = 'unitedkingdom';
	}
	else if (data == '237'){
		country = 'cambodia';
	}
	else if (data == '238'){
		country = 'eu';
	}
	else {
		country = 'australia';
	}
	return country;
}
function changeLocation2(){
	var data = document.getElementById('remitCountryId').value;
	var country;
	setCookie('remitCountryId',data,365);
	country = getCountry(data);
	generateContent(country);
}
function ucfirst(string){
	var result = '';
	var words = string.split(' ');
	for (i = 0; i < words.length; i++){
		if (i!=0){
			result = result + ' ';
		}
		result = result + words[i].substring(0,1).toUpperCase();
		result = result + words[i].substring(1,words[i].length);
	}
	return result;
}
function generateContent(country){
	var content = file_get_contents('remitcontent/'+country+'.xml');
	var tag = file_get_contents('remitcontent/'+country+'tag.txt');
	var upcountry = country;
	
	remitManager.getBaseCurrencyCodeFX(getCookie('remitCountryId'),setBaseCurrencyCode);
 	remitManager.getCurrencyCodeFX(getCookie('remitCountryId'),setCurrencyCode);
 	remitManager.getExchangeRate(getCookie('remitCountryId'),setExchangeRate);
 	remitManager.getComment(getCookie('remitCountryId'),setComment);
 		
	document.getElementById('countryContent').innerHTML = content;
	document.getElementById('tagline').innerHTML = tag;
	
	if (country == 'newzealand')
		upcountry = 'new zealand';
	else if (country == 'hongkong')
		upcountry = 'hong kong';
	else if (country == 'unitedkingdom')
		upcountry = 'united kingdom';
	else if (country == 'philippine')
		upcountry = 'the philippines';
	else if (country == 'eu')
		upcountry = 'European Union (EU)';
	document.getElementById('countryPic').innerHTML = '<img src="images/'+country+
		'.jpg" width="150" height="100" alt="Send Money To ' + ucfirst(upcountry) + '" title=""/>';
	document.title = 'Pay2Home - Send Money To '+ucfirst(upcountry);
	
}
function getCookie(c_name){
	if (document.cookie.length>0){
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1){ 
			    c_start=c_start + c_name.length+1; 
			    c_end=document.cookie.indexOf(";",c_start);
			    if (c_end==-1) c_end=document.cookie.length;
			    return unescape(document.cookie.substring(c_start,c_end));
		  } 
 	}
	if (document.getElementById('remitCountryId') != null)
		return document.getElementById('remitCountryId').value;
	else
		return 13;
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+";"+
	((expiredays==null) ? "" : "expires="+exdate.toGMTString());
}

function checkCookie(c_name){
	c_value=getCookie(c_name);
	if (c_value!=null && c_value!=""){
		setCookie(c_name,"",365);
  		window.location.href='remit.do?'+c_name+'='+c_value;
  		
	}else{
		
	}
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

 function addbookmark(url, title) {

	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { 
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { 
		return true; }
 }

 function hover(btn){
	btn.src = "images/" + btn.id+ "over.png";
}
function mout(btn){
	btn.src = "images/" + btn.id + ".png";
}
function hoverPng(btn){
	btn.src = "images/" + btn.id+ "over.png";
}
function moutPng(btn){
	btn.src = "images/" + btn.id + ".png";
}