function changeFrames(contentURL, paramURL, to) {	
    //for netvigation on the same page    
    if(top.document.getElementById("mainFrame")!=null){	
        if(contentURL.indexOf(top.mainFrame.location.pathname) > -1) {
            top.mainFrame.location.href = contentURL;
            return;
        }
    }
    if(to == 0){
        if(contentURL.indexOf("#") > -1) {
            var url = contentURL.split("#");
            contentURL = url[0] + "&anchor=" + url[1];
        } //if
        top.location.href = "/its/account/productService.do?content="+contentURL+"&index="+paramURL;
    }else{
        top.leftFrame.location.href = "/its/account/productService/menu.do?index="+paramURL;
        top.mainFrame.location.href = contentURL;
    }
}

function openPopupWindow(url, windowName, width, height) {
   return openPopupWindow(url, windowName, width, height, "yes");
}

function openPopupWindow(url, windowName, width, height, fixed) {
   popupwin = window.open(url,windowName,'scrollbars=yes,resizable=' + fixed + ',toolbar=no,width='+width+', height='+height+',left=0,top=0');
   popupwin.focus();
   return popupwin;
}

function popupFAQ(name, height) {
   var s = "/its/help/faq/content.do" + "#" + name;
   var win = openPopupWindow(s,'FAQ',780,height, "yes");
   win.resizeTo(780, height);
   win.focus();
}

function popupNoScrollBar(path, height, width) {
	var popWin = window.open(path, 'popupNoScroll', 'dependent=yes, menubar=no, toolbar=no, width='+width+', height='+height+', resizable=yes, top=50, scrollbars=0 ' ); 
    popWin.focus();
}

function openRemoteWindow(url, name, width, height,sroll) {
    var s;
    if (scroll==null || scroll=="") {
      s="no";
    } else {
      s="yes";
    }

   var feature = "scrollbars=" +s+ ",resizable=yes,width=" + width + ",height=" + height
               + ",alwaysRaised=yes,left=0,top=0,screenX=0,screenY=0;";

   promotionWin = window.open(url, name, feature);
   if (promotionWin.opener == null) promotionWin.opener = window;
   // window.focus();
}

function openerToURL(url) {
   if (opener == null) {
      window.location=url;
   } else if (opener.closed) {
      var win = window.open(url,'new_win','');
      win.focus();
   } else {
         opener.top.location=url;
         opener.top.focus();
   }
}

function openWinStat(theURL,winName,features)  {
    if (!features || features=="")  {
     features = 'scrollbars=yes, resizable=yes, toolbar=no,width=780, height=580,alwaysRaised=yes,left=0,top=0,screenX=0,screenY=0';
    }
    orderWin = window.open(theURL,winName,features);
    //if (orderWin.opener == null) orderWin.opener = window;
    orderWin.focus();
}

function openPopup(url, windowName, width, height, left, top) {
    return window.open(url,windowName,'scrollbars=no,resizable=no,toolbar=no,width='+width+', height='+height+',left='+left+',top='+top);
}

function getParamFromURL(name) {
   var l_href = location.href;
   var l_href = l_href.split("?");
   var subMenu = "0";
   if(l_href.length>1){
      for (var i = 1; i<= l_href.length-1; i++) {
         var l_param = l_href[i].split("=");
         if(l_param.length>1){
            if (l_param[0] == name) {
               return l_param[1];
            }
         }
      }
   }
}

function isValidCharacterOrNumeric(str) {
   //search the string to see if it only contains characters or numbers
   var i;
   for (i=0; i < str.length; i ++) {
      var c = str.charAt(i);
      //alert("check char " + c);
         //if a non-character found
         if (  !(((c>= "a") && (c <= "z")) || (( c >= "A") && (c <= "Z"))) && ((c < '0') || ( c > '9'))) {
            return false;
         }//if
   }//for
   return true;
}//isCharacter

function isValidCharacterOrNumeric(str) {
   //search the string to see if it only contains characters or numbers
   var i;
   for (i=0; i < str.length; i ++) {
      var c = str.charAt(i);
      //alert("check char " + c);
         //if a non-character found
         if (  !(((c>= "a") && (c <= "z")) || (( c >= "A") && (c <= "Z"))) && ((c < '0') || ( c > '9'))) {
            return false;
         }//if
   }//for
   return true;
}//isCharacter

function enOpenAcrobat()
{
	var screenWidth = screen.width;
	var screenHeight = screen.height;
	var sWidth = 640;
	var sHeight = 480;
	var sLeft = (screenWidth-sWidth)/2;
	var sTop = (screenHeight-sHeight)/2;
	
  	orderWin = window.open("http://www.adobe.com/products/acrobat/readstep2_allversions.html", "popup", "scrollbars=yes, resizable=yes, toolbar=yes, location=yes, menubar=yes, status=yes, width="+sWidth+", height="+sHeight+",alwaysRaised=yes,left="+sLeft+",top="+sTop+",screenX="+sLeft+",screenY="+sTop);
	if (orderWin.opener == null) orderWin.opener = window;
	orderWin.focus();
}

function zhOpenAcrobat()
{
	var screenWidth = screen.width;
	var screenHeight = screen.height;
	var sWidth = 640;
	var sHeight = 480;
	var sLeft = (screenWidth-sWidth)/2;
	var sTop = (screenHeight-sHeight)/2;
	
  	orderWin = window.open("http://www.chinese-t.adobe.com/products/acrobat/readstep2_allversions.html", "popup", "scrollbars=yes, resizable=yes, toolbar=yes, location=yes, menubar=yes, status=yes, width="+sWidth+", height="+sHeight+",alwaysRaised=yes,left="+sLeft+",top="+sTop+",screenX="+sLeft+",screenY="+sTop);
	if (orderWin.opener == null) orderWin.opener = window;
	orderWin.focus();
}

function firstSubmit(cnt) {
    // cnt is the SubmitCount object inside the form. Default value is 1.
    var num = parseInt(cnt.value);
    num = num - 1;
    cnt.value = num;
    if (num == 0) {
        return true;
    }
    return false;
}

function tradingDetails() {
  openPopupWindow("/its/market/bullionFaq.do",'tradingDetails',770,500);
}

function changeColour(elementId) {
	var interval = 700;
	var red = "#ff0000", defaultColour = "#ffffff";
	if (document.getElementById) {
		var element = document.getElementById(elementId);
		element.style.color = (element.style.color == red) ? defaultColour : red;
		setTimeout("changeColour('" + elementId + "')", interval);
	}
}

// Login/Trading password cannot be null and the length must between 6-10
function checkPasswordLength(password, lower, upper) {
  var lBound = 8;
  var uBound = 10;
  if (lower) lBound = lower;
  if (uBound) uBound = upper;
  if (password.length < lBound || password.length >uBound) {
    return false;
  }
  return true;
}

//**********************************************************
//Function	: isNumeric
//Input		: String
//Output	: True if the word contains only numbers
//**********************************************************
function isNumeric(str) {
	//search the string to see if it only contains numbers
	var i;
	for (i=0; i < str.length; i ++) {
		var c = str.charAt(i);
			//if a non-number found
            if (((c < '0') || ( c > '9')) &&  ( c!='.')) {
		//	if (!((c >= '0') && (c <= '9'))) {
				return false;
			}//if
	}//for
	return true;
}//isNumeric

// If pw is numeric, it cannot be in all sequencial ascending or descending order
// check isNumeric() first!

function checkNumPasswordSeq(password) {

  var ind1 = 1;
  var ind2 = 1;


  for (i=0; i < password.length-1; i++) {
  	var followNum = i+1;
    if (password.substring(i, followNum) != (password.substring(followNum, followNum +1) - 1)) {
      ind1 = 0;
    }

    if ((password.substring(i, followNum)-1) != password.substring(followNum, followNum +1)) {
      ind2 = 0;
    }

  }

  if (ind1 == 0 && ind2 ==0) {
    return true;
  } else {

    return false;
  }

}

// The password cannot be  all of the same number or letter
function checkPasswordCharacter(password) {

  var ind = 1;
  for (i=0; i < password.length; i++) {
  	  var followINum = i+1;

      for (j=0; j < password.length; j++) {
      	var followJNum = j+1;

        if (password.substring(i, followINum) != password.substring(j, followJNum)) {
          ind = 0;
        }
      }

  }

  if (ind == 0) {
    return true;
  } else {

    return false;
  }
}


function addThousandSeparator(n,sep) {
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	sValue=n + '';
	if (sep == undefined) {
		sep=',';
	}
	while(sRegExp.test(sValue)) {
		sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
	}
	return sValue;
}

function removeThousandSeparator(n, sep){
	return (n + '').replace(/,/g, '');
	/*
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
	sValue=n + '';
	if (sep == undefined) {
		sep=',';
	}
	while(sRegExp.test(sValue)) {
		sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
	}
	return sValue;
	*/
}


//**********************************************************
// Function : isEmpty
// Input	: String
// Output	: True if only whitespace enters; otherwise, returns false
//**********************************************************
function isEmpty(str) {
var whitespace = " \t\n\r";
var i;
	//if no input
	if (( str==null) || (str.length==0)) return true;

	//search the string to see if non-whitespace characters enters
	for (i=0; i < str.length; i++) {
		var c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
			return false;
	}
	//all characters are whitespace
	return true;
}//isEmpty


