var ie4 = document.all ? 1 : 0;
var ns4 = document.layers ? 1 : 0;
var ns6 = window.netscape ? 1 : 0;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value) thefield.value = "";
}

function MM_showHideLayers() 
{ //v6.0
 	var i,p,v,obj,args=MM_showHideLayers.arguments;
  	for (i=0; i<(args.length-2); i+=3)
	{
		if ((obj=MM_findObj(args[i]))!=null) 
		{
			v=args[i+2];

			if (obj.style) 
			{ 
				obj=obj.style; 
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			obj.visibility=v; 
		}
	}
}


function toggleLayer(name, price)
{
	//ccobj = (ie4) ? document.all[name] : (ns6 ? document.getElementById(name) : (ns4 ? document.layers[name] : ''));
	
	//if (document.getElementById(name).style.visibility == "visible") 
	//{
		/*document.getElementById(name).style.visibility = "hidden";
	}
	else
	{*/
		if (document.documentElement && document.documentElement.scrollTop)
			theTop = document.documentElement.scrollTop;
		else if (document.body)
			theTop = document.body.scrollTop
		else
			theTop = document.body.scrollTop
		
		theTop = 250 + theTop;
		
		document.getElementById(name).style.top = theTop + "px";
		document.getElementById(name).style.visibility = "visible";
		
		
		//ccobj.style.top = theTop + "px";
		//ccobj.style.visibility = "visible";
		
		document.calcForm.inV.value = price;
		document.calcForm.outV.value = "";
		
		CvalueFF();
	//}
}

function closeCC()
{
	ccobj = (ie4) ? document.all[name] : (ns6 ? document.getElementById(name) : (ns4 ? document.layers[name] : ''));
	
	document.getElementById("currencyConverter").style.visibility = "hidden";
	//ccobj.style.visibility = "hidden";
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}



function int_only(value) {
	value = parseInt(value);
	if(value<0) value = value * -1;
	return (value) ? value+"" : "";
}




function BookMark_Page(alerttext) {
	/*
	if(document.all) {
		window.external.AddFavorite(this.location,document.title);
	} else {
		alert("To bookmark page use (Ctrl+D)");
	}
	*/
	var title = document.title;
	var url = this.location;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	//} else if(window.opera && window.print) { // Opera Hotlist
	//	return true;
	} else {
		if(!alerttext) alerttext = "To bookmark this page use [Ctrl+D]";
		alert(alerttext);	
	}
}


function addText(id,text) {
	
	menuobj = (ie4) ? document.all[id] : (ns6 ? document.getElementById(id) : (ns4 ? document.layers[id] : ''));
	
	if(ie4 || ns6) {
		menuobj.innerHTML=text;
	} else {
		menuobj.document.open();
		menuobj.document.write(text);
		menuobj.document.close();
	}
	
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

var clickZoomImage;
function clickZoom(url,imgname,windowstatus) {
	clickZoomImage=window.open(url,imgname,windowstatus);
	if (window.focus) {
		clickZoomImage.focus();
	}
}
function checkClickZoom() {
	if (clickZoomImage) {
		clickZoomImage.close();
	}
}

var layerDisplayStatus = new Array;
// switch layer visibility
function toggleLayerDisplay(whichLayer, status) {
	// store current layer status
	layerDisplayStatus[whichLayer] = status;
	// status: 'none', 'block'	
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = status;
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichLayer].style.display = status;
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = status;
	}
}
function nospam(recip,domain){
	var mail = "mailto:" + recip + "@" + domain;
	window.location.href = mail;
}




function CvalueFF()
{
  // missing relevant digits
  var fromR, toR, resultV, nVal;
  fromR = rate[0];
  toR = rate[document.calcForm.to.selectedIndex];
  nVal = document.calcForm.inV.value;
  if ( IsNumericFF(nVal) == false ) {
    alert("amount to multiply is not a number\n\nyou can only use\n\n1234567890 and . (dot)");
  }
  
  nVal = nVal.replace( ",", "." )
  
  resultV = nVal * ( toR / fromR );
  // 6 relevant digits only, or integer 
  if ( (resultV == parseInt(resultV)) || (resultV > 99999) )
  {
    // mostly integer
    resultV = parseInt( resultV );
  }
  else
  {
    if (resultV > 1)
    {
	resultV = resultV.toString();
	resultV = resultV.substring(0,7);
    } else {
	resultV = resultV.toString();
	resultV = resultV.substring(0,8);
    }
  }
  document.calcForm.outV.value = comma(resultV) + " " + currency[document.calcForm.to.selectedIndex];
  document.getElementById("rateText").innerHTML = "Call 1-877-627-4817 for Intl Wires, Drafts, Currencies. Rate as of " + ratedt[document.calcForm.to.selectedIndex];
;
}
function invertCurrFF()
{
  var i;
  i = document.calcForm.from.selectedIndex;
  document.calcForm.from.selectedIndex = document.calcForm.to.selectedIndex;
  document.calcForm.to.selectedIndex = i;
   Cvalue();
}
function commaFF(num)
{
 var n = Math.floor(num);
 var myNum = num + "";
 var myDec = ""
 if (myNum.indexOf('.',0) > -1){
  myDec = myNum.substring(myNum.indexOf('.',0),myNum.length);
 }
 var arr=new Array('0'), i=0; 
 while (n>0) 
   {arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
 arr=arr.reverse();
 for (var i in arr) if (i>0) //padding zeros
   while (arr[i].length<3) arr[i]='0'+arr[i];
 return arr.join() + myDec;
}
function IsNumericFF(strString)
{
   var strValidChars = "0123456789.,";
   var strChar;
   var blnResult = true;

   for (i = 0; i < strString.length && blnResult == true; i++)
   {
      strChar = strString.charAt(i);
	  
      if (strValidChars.indexOf(strChar) == -1)
      {
         blnResult = false;
      }
   }
   return blnResult;
}

