var overlay_path="https://uniservices1.uobgroup.com/";
var overlay_path_secure="https://uniservices1.uobgroup.com/";
var podcast_srcfiles="http://www.uobgroup.com/investor/podcast/mp3/"
var tpid_src="http://www.uobgroup.com/"
var atm_search_link="http://www3.uobgroup.com/locator/uob_search.html";

// Current Page Reference
function getURL(uri) {
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir;
	if (uri.dom.substr(0,7) == 'http:\/\/') 
		uri.dom = uri.dom.substr(7);
	uri.path = ''; 
	var pos = uri.dom.indexOf('\/'); 
	if (pos > -1) {
		uri.path = uri.dom.substr(pos+1); 
		uri.dom = uri.dom.substr(0,pos);
	}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');
	if (pos > -1) {
		uri.page = uri.page.substring(0, pos);
	}
	pos = uri.page.indexOf('#');if (pos > -1){
		uri.page = uri.page.substring(0, pos);
	}
	uri.ext = ''; pos = uri.page.indexOf('.');
	if (pos > -1) {
		uri.ext =uri.page.substring(pos+1); 
		uri.page = uri.page.substr(0,pos);
	}
	uri.file = uri.page;
	if (uri.ext != '') 
		uri.file += '.' + uri.ext;
	if (uri.file == '') 
		uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	return uri;
}

var uri = new Object();
getURL(uri);
                  

function show_contactus_personal(type1, type2)
{
	var addr=overlay_path_secure+"secure/forms/emailusp_pweb.jsp?s1="+escape(type1)+"&s2="+escape(type2)+"&keepThis=true&TB_iframe=true&height=480&width=560";
	tb_show("Contact Us", addr, false);
}

function show_contactus_corporate(type1, type2)
{
	var addr=overlay_path_secure+"secure/forms/emailusb_pweb.jsp?s1="+escape(type1)+"&s2="+escape(type2)+"&keepThis=true&TB_iframe=true&height=540&width=560";
	tb_show("Contact Us", addr, false);
}

function show_contactus_corporatecards(title)
{
	var addr=overlay_path_secure+"secure/forms/corp_cards_contactus.jsp?keepThis=true&TB_iframe=true&height=470&width=540";
	tb_show(title, addr, false);
}

function show_business_inclusion(title){
	var addr=overlay_path_secure+"secure/forms/corp_merchants_inclusion.jsp?keepThis=true&TB_iframe=true&height=470&width=520";
	tb_show(title, addr, false);
}

function show_personal_cards_pa(url,title){
	var addr=overlay_path_secure+url+"?keepThis=true&TB_iframe=true&height=470&width=520";
	tb_show(title, addr, false);
}

function show_application_form(url,type)
{
	var addr="";
	if(type=="secure"){
		addr=overlay_path_secure+url;
	}else{
		addr=overlay_path_secure+url;
	}
	window.open (addr,"appln_form");
}

function show_secure_form(add, title){
	var addr=overlay_path_secure+add;
	tb_show(title, addr, false);
}

function show_taf_form(){
	var referlink=location.href;
	var addr=overlay_path_secure+"secure/forms/taf_form.jsp?link="+encodeURIComponent(referlink)+"&keepThis=true&TB_iframe=true&height=490&width=500";
	tb_show("Share this page with your friends!", addr, false);
}

function share_with_friends()
{
	var referlink=location.href;
	var addr=overlay_path_secure+"secure/forms/share_with_friends_form.jsp?link="+encodeURIComponent(referlink)+"&keepThis=true&TB_iframe=true&height=490&width=500";
	tb_show("Share this page with your friends!", addr, false);
}

function share_with_friends_iacct(lh)
{
	var s=s_gi('uobcomprd');
	s.tl(lh,'o','i-Account Promotion : Tell a Friend');

	var referlink=location.href;
	var addr=overlay_path_secure+"secure/forms/share_with_friends_form.jsp?link="+encodeURIComponent(referlink)+"&keepThis=true&TB_iframe=true&height=490&width=500";
	tb_show("Share this page with your friends!", addr, false);
}

function show_map(postalcode)
{ 
	//http://www3.uobgroup.com/googlemap/search.cgi?search=yes&start=1&searchType=BRANCH&searchBy=postal_code&searchString=738344
	var addr="http://www3.uobgroup.com/googlemap/search.cgi?search=yes&start=1&searchType=BRANCH&searchBy=postal_code&searchString="+postalcode+"&keepThis=true&TB_iframe=true&height=490&width=560";
	tb_show("Location Map", addr, false);
}

function search_merchants(title){
	var myDEPCategory=document.getElementById("category").value;
	var myDEPZone=document.getElementById("zone").value;
	var myDEPInfoType=document.getElementById("itype").value;
	var myDEPMerchantType=document.getElementById("mtype").value;
	var addr= "http://www3.uobgroup.com/merchant_search/business_merchant_search_results.cgi?category=" + myDEPCategory + "&zone=" + myDEPZone + "&itype=" + myDEPInfoType + "&mtype=" + myDEPMerchantType + "&keepThis=true&TB_iframe=true&height=490&width=560";
	tb_show(title, addr, false);
}

function search_dining(title,searchtype,catname,locationname){
	var Category="";
	var location="";
	var addr="";
	if(searchtype=="form"){
		Category=document.getElementById("Category").value;
		location=document.getElementById("location").value;
	}else if(searchtype=="mylink"){
		Category=catname;
		location=locationname;
	}
	addr= "http://www3.uobgroup.com/personal/promotions/cards/dining.cgi?Category=" + Category + "&location=" + location + "&keepThis=true&TB_iframe=true&height=490&width=570";
	
	tb_show(title, addr, false);
}


function openinvestmentpopup()
{
	window.open('https://uniservices1.uobgroup.com/secure/investing/home.html','Bodyframe','toolbar=no,directories=no,scrollbars=no,resizable=no, menubar=no,location=no,width=1024,height=768,maximize=no,minimize=no');
}

function openinvestmentpopupbanner(lh)
{
var s=s_gi('uobcomprd');
s.tl(lh,'o','Investing Microsite');
window.open('https://uniservices1.uobgroup.com/secure/investing/home.html','Bodyframe','toolbar=no,directories=no,scrollbars=no,resizable=no, menubar=no,location=no,width=1024,height=768,maximize=no,minimize=no');
}

function show_appln_form(url,params,formname)
{
	var addr="";
	var address="";
	if(params==""){
		addr=overlay_path_secure+url+"?";
	}else{
		addr=overlay_path_secure+url+params+"&";
	}
	var address=addr+"keepThis=true&TB_iframe=true&height=540&width=800";
	tb_show(formname, address, false);
}

function getParams()
{
	var idx = window.document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1)
	{
		var pairs = window.document.URL.substring(idx+1, window.document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++)
		{
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}

	
function show_appln_form_with_s_cid(url,params,formname)
{

var myParams;
var uobqsp1="";

myParams = getParams();

if (myParams["s_cid"] != null)
	uobqsp1 = unescape(myParams["s_cid"]);

	var addr="";
	var address="";
	if(params==""){
		addr=overlay_path_secure+url+"?";
	}else{
		addr=overlay_path_secure+url+params+"&";
	}
	if (uobqsp1!="")
	{
		uobqsp1.replace(/#tab2/g, "");
		address = addr + "s_cid=" + uobqsp1 + "&keepThis=true&TB_iframe=true&height=540&width=800";
	}
	else
		address = addr + "keepThis=true&TB_iframe=true&height=540&width=800";
	tb_show(formname, address, false);
}

function show_atm_search_form(url,params,formname)
{
	
	var address=url+"?"+params+"&keepThis=true&TB_iframe=true&height=540&width=600";
	tb_show(formname, address, false);
}


function show_uobtp_resources(formname,width,height){
	var address=tpid_src + "uobtravel/resources/" + formname +"?keepThis=true&TB_iframe=true&height=" + height + "&width=" + width;
	tb_show(" ", address, false);	
}

function rightnav_usefulinfo_goto(url, formname,width,height,selectname){
	if(url!=""){
		
/*
		if(formname=='Rates'){
			document.getElementById("SGD_Money").style.display="none";
			document.getElementById("Uniplus").style.display="none";
			document.getElementById("gold_silver").style.display="none";
		}
*/
		
		if(url.substr(0,8)=="rates - "){
			//var divName=document.getElementById("menu1").value;
			document.getElementById(url.substr(8)).style.display="block";
		}else if(url.substr(0,19)=="overlay - atmsearch"){
			var address = 'http://www3.uobgroup.com/locator/uob_search.html?TB_iframe=true&height=' + height + "&width=" + width;
			tb_show(formname, address, false);
		}else if(url.substr(0,9)=="_blank - "){
			//alert(url.substr(9));
			var myURL=url.substr(9);
			window.open (myURL,"mypdfs");
		}else if(url.substr(0,10)=="overlay - "){
			var addr = {url:url.substr(10), hash:'', query:''};
			var pos = -1;
			if ((pos = addr.url.indexOf('#')) != -1)
			{
				addr.hash = addr.url.substr(pos + 1); 
				addr.url = addr.url.substr(0, pos);  
			}
			if ((pos = addr.url.indexOf('?')) != -1)
			{
				addr.query = addr.url.substr(pos + 1); 
				addr.url = addr.url.substr(0, pos);  
			}
			var address = addr.url + '?' + addr.query + '&TB_iframe=true&height=' + height + "&width=" + width + '#' + addr.hash;
			if ($('#TB_window').css('display') != 'block') tb_show(formname, address, false);
		}else{
			document.location.href=url;
		}
		
		//set the value to default value;
		document.getElementById(selectname).value="";
		
	}
		
}

function playPodcast(xmlname){
	var servername=tpid_src;
	var realPath = servername+"/investor/podcast/detectitunes.html?id="+xmlname;
	var myWidth = 500; 
	var myHeight = 400;  
	var myLeft = (screen.width - myWidth) / 2;
	var myTop = (screen.height - myHeight - 15) / 2;
	myFeatures = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,width=' + myWidth + ',height=' + myHeight + ',left=' + myLeft +',top='+ myTop +',scrollbars=yes';
	var TheNewWindow = window.open(realPath,'PodcastXML',myFeatures);
}

function playPodcast1(xmlname){
	var servername=tpid_src;
	var realPath = servername+"/investor/podcast/detectitunes.html?id="+xmlname;
	var addr=realPath+"&keepThis=true&TB_iframe=true&height=450&width=450";

	tb_show("Play Podcast", addr, false);
}

// JavaScript Document
function clearFields()
{
	document.getElementById("amount").value="";
	document.getElementById("from").value="SGD";
	document.getElementById("to").value="SGD";
	
}

function isNumberDup(string)
{
    if (!string) return false;
    var Chars = "0123456789.,";

    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
}

function toTruncateDup(string)
{
	var lstring = string;
	var dotpos = lstring.indexOf('.');
        if (dotpos == -1) return lstring;
	var moneystr = lstring.substring(0,dotpos);
    	return moneystr;
} 


function mnycalc()
{
	var amount = document.getElementById("amount_CurConv").value;
	
	// if not numeric, set to zero
	if (!isNumberDup(amount))
		document.getElementById("amount_CurConv").value = "0";
	
	// if numeric, mask out comma character
	document.getElementById("amount_CurConv").value = document.getElementById("amount_CurConv").value.replace(/,/g, "");
	
	// remove cents
	document.getElementById("amount_CurConv").value = toTruncateDup(document.getElementById("amount_CurConv").value);
	
	var address    =  overlay_path_secure + "secure/forms/calculators/moneyChangingResults.jsp?";
	var addr = address + "amount=" + document.getElementById("amount_CurConv").value
			   + "&from="  + document.getElementById("menu_from_CurConv").options[document.getElementById("menu_from_CurConv").selectedIndex].value
			   + "&to=" + document.getElementById("menu_to_CurConv").options[document.getElementById("menu_to_CurConv").selectedIndex].value + "&keepThis=true&TB_iframe=true&height=430&width=555";
	tb_remove();
	tb_show("Money Changing Calculator", addr, false);
}

function selectRates(){
	var divName = document.getElementById("menu_Rates").value;
	document.getElementById("SGD_Money").style.display="none";
	document.getElementById("Uniplus").style.display="none";
	document.getElementById("gold_silver").style.display="none";
	if(divName!=""){
		document.getElementById(divName).style.display="block";
	}

}

function open_overlay(url,title, width){
	var addr=url+"?keepThis=true&TB_iframe=true&height=470&width="+width;
	tb_show(title, addr, false);	
}

function OpenNewWindow(myurl)
{
	window.open(myurl);
}
