parseCurrency = function (amount) {
  //amount = amount.gsub("[^0-9"+decimal_sep+"]", "");
  amount = amount.gsub("[^0-9,.]", "");
  amount = amount.gsub(",", ".");
  amount = amount.split('.');

  return parseFloat(amount[0]+"."+amount[1]);
}

function poptastic(url) {
	var newwindow;
	newwindow=window.open(url,'name','height=400,width=600,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function updateStrength(pw) {
	var strength = getStrength(pw);
	var width = (100/32)*strength;
	new Effect.Morph('psStrength', {style:'width:'+width+'px', duration:'0.4'}); 
}

function getStrength(passwd) {
	intScore = 0;
	if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
			{
			intScore = (intScore+1)
			} if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
			{
			intScore = (intScore+5)
			} // NUMBERS
			if (passwd.match(/\d+/)) // [verified] at least one number
			{
			intScore = (intScore+5)
			} if (passwd.match(/(\d.*\d.*\d)/)) // [verified] at least three numbers
			{
			intScore = (intScore+5)
			} // SPECIAL CHAR
			if (passwd.match(/[!,@#$%^&*?_~]/)) // [verified] at least one special character
			{
			intScore = (intScore+5)
			} if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) // [verified] at least two special characters
			{
			intScore = (intScore+5)
			} // COMBOS
			if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // [verified] both upper and lower case
			{
			intScore = (intScore+2)
			} if (passwd.match(/\d/) && passwd.match(/\D/)) // [verified] both letters and numbers
			{
			intScore = (intScore+2)
			} // [Verified] Upper Letters, Lower Letters, numbers and special characters
			if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/))
			{
			intScore = (intScore+2)
			}
			return intScore;
}

// verifies only a number was typed into the form element
function numbersonly(e, value, maxLength) {
    var c=e.charCode? e.charCode : e.keyCode;

    if (c == 13)
        return false;

    var is_max_len = (String(parseInt(value)).length >= maxLength) ? true : false;

    // decimal separator check
    if (c == 46 || c == 44) {
      var s = (!e.target?event.srcElement.value:e.target.value);
      if ( (s.indexOf('.') > -1) || (s.indexOf(',') > -1) || s == "") {
        return false;
      } else {
        return true;
      }
    }
    
    // if a control key
    if (c == 9 || c == 35 || c == 36 || c == 37 || c == 39 || c == 13 || c == 8 || c == 46) {
        return true;
    }

    // if not a number
    if (c < 48 || c > 57) {
        return false; //disable key press
    }
    return !is_max_len;
}

function emailIsValid(email) {
    var pat = /^([.0-9a-zA-Z_-]+)@(([0-9a-zA-Z_-]+)\.)*([0-9a-zA-Z_-]+)$/;
    return pat.test(email);
}

//switch login inputs - only ES
function switch_input(id1, id2, op){
	if(op){	$(id1).style.display="none";$(id2).style.display="block";$(id2).focus();}
	else{	
		if($(id1).value==''){$(id1).style.display="none";$(id2).style.display="block";}}
};