var trgo;
var brname=navigator.appName;

var x1,y1;

if(brname=="Netscape"){
  document.captureEvents(Event.MOUSEMOVE);
  document.onmouseover=ujemi1;
 }
else{
document.onmouseover=ujemi;
}

function check_feng()
{
	var mess="";
	if(document.feng.ime_priimek.value=="" ||document.feng.ime_priimek.value=='Ime in priimek' )
			mess="Ime in priimek??\n";
	var email=document.feng.email.value;
	if(email=="" || valEmail(email)!="OK")
		mess+="Nepravilen e-mail!\n";

	if(mess==""){
		document.feng.action='../feng.php';
		document.feng.submit();
	}
	else
		alert(mess);
}

function check_p_n()
{
	var mess="";
	if(document.p_n.n_priimek.value=="" ||document.p_n.n_priimek.value=='Ime in priimek' )
			mess="Ime in priimek??\n";
	var email=document.p_n.n_email.value;
	if(email=="" || valEmail(email)!="OK")
		mess+="Nepravilen e-mail!\n";

	if(mess==""){
		document.p_n.action='index.php?action=message&typ=21';
		document.p_n.submit();
	}
	else
		alert(mess);
}

function checkFriends()
{

	var a=0;
	var b=0;
	var c=0;
	var d=0;
	var e=0;
	var ms="";
	if(document.friends.em1.value=="email @ prijatelja" || document.friends.em1.value=="")
			a=0;
	else{
			if(valEmail(document.friends.em1.value)=='OK')
					a=1;
	}
	if(document.friends.em2.value=="email @ prijatelja" || document.friends.em2.value=="")
			b=0;
	else{
			if(valEmail(document.friends.em2.value)=='OK')
					b=1;
	}
	if(document.friends.em3.value=="email @ prijatelja" || document.friends.em3.value=="")
			c=0;
	else{
			if(valEmail(document.friends.em3.value)=='OK')
					c=1;
	}
	if(document.friends.em4.value=="")
			d=0;
	else{
			if(valEmail(document.friends.em4.value)=='OK')
					d=1;
	}
	if(document.friends.ime_priimek.value=="")
			e=0;
	else
		e=1;

		if((a+b+c)==0)
				ms=mess[11];
		if(d==0){
				if(ms.length>0)
					ms=ms+"\n"+mess[12]		;
				else
						ms=mess[12];
		}
		if(e==0){
				if(ms.length>0)
					ms=ms+"\n"+mess[13]		;
			else
					ms=mess[13];
		}
		if(ms.length>0)
				alert(ms);
		else
		  document.friends.submit();


}

function checkPrijava()
{
var mess="";
if(document.prijava.Username.value=="")
	mess="E-mail?\n";
if(document.prijava.Password.value=="")
	mess+="Geslo?";

if(mess!="")
	alert(mess);
else{
	document.prijava.action="index.php?action=login&what=submit";
	document.prijava.submit();
}

}


function checkrmFriend()
{
var mess="";
if(document.rmFriend.reg.value=='ne'){
	if(document.rmFriend.Surname.value=="")
		mess="Ime??\n";
	if(document.rmFriend.Name.value=="")
		mess+="Priimek??\n";
	var nas=document.rmFriend.email.value;
	var nas1=document.rmFriend.email1.value;
	if(nas=="" || nas1=="")
		mess+="Email??\n";
	else{
		if(nas!=nas1)
			mess+="E-mail naslova nista enaka!\n";
		else{
			mail=valEmail(nas1);
			if(mail!=="OK")
				mess+="E-mail je nepravilen\n";
		}
	}
}

if(document.rmFriend.name_surname.value=="")
		mess+="Priimek in ime slavljenca??\n";

if(document.rmFriend.Event.options[document.rmFriend.Event.selectedIndex].value=="" && document.rmFriend.OtherEvent.value=="ali vpi?ite svojega")
		mess+="Dogodek??\n";

if(document.rmFriend.EventDay.options[document.rmFriend.EventDay.selectedIndex].value=="")
		mess+="Dan dogodka??\n";

if(document.rmFriend.EventMonth.options[document.rmFriend.EventMonth.selectedIndex].value=="")
		mess+="Mesec dogodka??\n";

if(document.rmFriend.Alarm.options[document.rmFriend.Alarm.selectedIndex].value=="")
		mess+="Alarm??\n";

if(mess.length>0){
		alert(mess);
		return false;
	}
	else{
		document.rmFriend.submit();
		return true;
	}

}


function checkrmFriend1()
{
var mess="";
if(document.rmFriend.reg.value=='ne'){
	if(document.rmFriend.Surname.value=="")
		mess="Ime??\n";
	if(document.rmFriend.Name.value=="")
		mess+="Priimek??\n";
	var nas=document.rmFriend.email.value;
	var nas1=document.rmFriend.email1.value;
	if(nas=="" || nas1=="")
		mess+="Email??\n";
	else{
		if(nas!=nas1)
			mess+="E-mail naslova nista enaka!\n";
		else{
			mail=valEmail(nas1);
			if(mail!=="OK")
				mess+="E-mail je nepravilen\n";
		}
	}
}

if(document.rmFriend.name_surname.value=="")
		mess+="Priimek in ime slavljenca??\n";

if(document.rmFriend.Event.options[document.rmFriend.Event.selectedIndex].value=="" && document.rmFriend.OtherEvent.value=="ali vpi?ite svojega")
		mess+="Dogodek??\n";

if(document.rmFriend.EventDay.options[document.rmFriend.EventDay.selectedIndex].value=="")
		mess+="Dan dogodka??\n";

if(document.rmFriend.EventMonth.options[document.rmFriend.EventMonth.selectedIndex].value=="")
		mess+="Mesec dogodka??\n";



if(mess.length>0){
		alert(mess);
		return false;
	}
	else{
		document.rmFriend.submit();
		return true;
	}

}

function spremeniEmail()
{
	var	novi=window.open("nov_mail.php","mail","width=300,height=220,left=300,top=300");

}

function checkNewMail()
{
	var mess="";

	var nas=document.nov_mail.email.value;
	var nas1=document.nov_mail.email1.value;
	if(nas=="" || nas1=="")
		mess="Email??\n";
	else{
		if(nas!=nas1)
			mess="E-mail naslova nista enaka!\n";
		else{
			mail=valEmail(nas1);
			if(mail!=="OK")
				mess+="E-mail je nepravilen\n";
		}
	}

	if(mess.length>0){
		alert(mess);
		return false;
	}
	else{
		document.nov_mail.submit();
		return true;
	}

}

function checkVoscilo()
{

var mess="";
if(document.skupinsko4.ime.value=="" || document.skupinsko4.ime.value=="Ime in priimek")
	mess="Ime in priimek??\n";

if(document.skupinsko4.nick.value=="")
		mess+="E-mail??\n";
	else{
		var nas1=document.skupinsko4.nick.value;
		mail=valEmail(nas1);
		if(mail!=="OK")
			mess+="E-mail je nepravilen\n";
	}

if(mess.length>0){
		alert(mess);
		return false;
	}
else{
	SwitchMode();
	document.skupinsko4.submit();
	return true;
}

}


function prenos(n,a)
{
	window.opener.skupinsko4.slika.value=a;

	var el=window.opener.document.getElementById("obvestilo");
	el.style.display="";

	window.close();
}

function odpriOkno(link,ime,w,h,sc)
{
	var	novi=window.open(link,ime,"width="+w+",height="+h+",left=300,top=100,scrollbars="+sc);
}

function odpriUpload(n)
{
	var	novi=window.open("upload.php?n="+n,"Upload","width=400,height=180,left=300,top=100");
}

function checkSkupinsko3()
{

	var mess="";
	var mail="";
	if(document.skupinsko3.ime.value=="")
		mess="Ime??\n";
	if(document.skupinsko3.priimek.value=="")
		mess="Priimek??\n";
	if(document.skupinsko3.email.value=="")
		mess+="Mail??\n";
	else{
		var nas1=document.skupinsko3.email.value;
		mail=valEmail(nas1);
		if(mail!=="OK")
			mess+="E-mail je nepravilen\n";
	}
	if(document.skupinsko3.dan.options[document.skupinsko3.dan.selectedIndex].value=="")
		mess+="Dan dogodka??\n";
	if(document.skupinsko3.mesec.options[document.skupinsko3.mesec.selectedIndex].value=="")
		mess+="Dan dogodka??\n";
	if(document.skupinsko3.vrsta.options[document.skupinsko3.vrsta.selectedIndex].value=="" && document.skupinsko3.drugo_dogodek.value=="")
		mess+="Vrsta??\n";
	if(document.skupinsko3.ddan.options[document.skupinsko3.ddan.selectedIndex].value=="")
		mess+="Dan prejema??\n";
	if(document.skupinsko3.dmesec.options[document.skupinsko3.dmesec.selectedIndex].value=="")
		mess+="Mesec prejema??\n";
	if(document.skupinsko3.sex.checked==false)
		mess+="Spol??\n";

	if(mess.length>0){
		alert(mess);
		return false;
	}
	else
		document.skupinsko3.submit();
		return true;


}

function checkBonEmail()
{
	var mess="";
	var mail="";
	var i,z;

	if(document.darilni1.ToSurname.value=="")
		mess="Komu - ime??\n";
	if(document.darilni1.ToName.value=="")
		mess+="Komu - priimek??\n";

	if(document.darilni1.FromSurname.value=="")
		mess+="Kdo - ime??\n";
	if(document.darilni1.FromName.value=="")
		mess+="Kdo - priimek??\n";


	if(document.darilni1.email.value=="")
		mess+="Mail naslovnika??\n";
	else{
		var nas1=document.darilni1.email.value;
		mail=valEmail(nas1);
		if(mail!=="OK")
			mess+="Nepravilen e-mail po?iljatelja\n";

	}

	if(mess.length>0){
		alert(mess);
		return false;
	}
	else
		document.darilni1.submit();
}

function checkBonPost()
{
	var mess="";
	var mail="";
	var i,z;

	if(document.darilni1.ToSurname.value=="")
		mess="Komu - ime??\n";
	if(document.darilni1.ToName.value=="")
		mess+="Komu - priimek??\n";

	if(document.darilni1.FromSurname.value=="")
		mess+="Kdo - ime??\n";
	if(document.darilni1.FromName.value=="")
		mess+="Kdo - priimek??\n";
	if(document.darilni1.street.value=="")
		mess+="Kdo - ulica??\n";
	if(document.darilni1.zip.value=="")
		mess+="Kdo - po?tna ?tevilka ??\n";
	if(document.darilni1.city.value=="")
		mess+="Kdo - kraj??\n";


	if(mess.length>0){
		alert(mess);
		return false;
	}
	else
		document.darilni1.submit();
}


function ecards_back(i)
{
	switch(i){
		case 1:
			document.voscilo.action="index.php?action=ecard1";
			document.voscilo.submit();
		break;
		case 2:
			document.voscilo.action="index.php?action=ecard2";
			document.voscilo.submit();
		break;
		case 3:
			document.voscilo.action="index.php?action=ecard3";
			document.voscilo.submit();
		break;
	}

}


function check_ecard1()
{
var ele=document.voscilo.izbor;
for(var i=0;i<ele.length;i++){
	if (ele[i].checked){
		document.voscilo.submit();
		return true;
	}
 }
 alert("Izberite sliko");
}

function checkFriends1()
{

	var a=0;
	var b=0;
	var c=0;

	var ms="";
	if(document.friends.em1.value=="")
			a=0;
	else{
			if(valEmail(document.friends.em1.value)=='OK')
					a=1;
	}
	if(document.friends.em2.value=="")
			b=0;
	else{
			if(valEmail(document.friends.em2.value)=='OK')
					b=1;
	}
	if(document.friends.em3.value=="")
			c=0;
	else{
			if(valEmail(document.friends.em3.value)=='OK')
					c=1;
	}

		if((a+b+c)==0)
				ms=mess[11];
		if(ms.length>0)
				alert(ms);
		else
		  document.friends.submit();


}



function checkQty(id){

 var f=document.getElementById(id);
 var mess1="Nepravilna količina";
 var z=f.Qty.value;
var nap=0;
 
	if(isNaN(z)){
			alert(mess1);
	 nap=1;
	}
	if (z==0){
		 alert(mess1);
		nap=1;
	}
	if (z<0){
		 alert(mess1);
		nap=1;
	}
 
	
	if(nap==0)f.submit();
}
function odpri_znamenje(id)
{
	window.open("znak.php?subID="+id,'_blank',"left=100,top=5,width=570,height=600;scrollbars=yes");
}

function misli_skupina(id)
{
	SwitchMode();
	document.voscilo.action="index.php?action=ecard3&gid="+id;
	document.voscilo.submit();
}

function dodaj_misel(id){
	var el1 = document.getElementById("misel"+id);
	insertHtml(id);
	//document.voscilo.massage.value+=el1.innerHTML;

}

function checkEcard1()
{
	var mess="";
	var mail="";
	var i,z;

	if(document.voscilo.FromName.value=="")
		mess="Ime po?iljatelja??\n";
	if(document.voscilo.ToName.value=="")
		mess+="Ime naslovnika??\n";
	if(document.voscilo.FromEmail.value=="")
		mess+="Va? mail??\n";
	else{
		var nas1=document.voscilo.FromEmail.value;
		mail=valEmail(nas1);
		if(mail!=="OK")
			mess+="Nepravilen e-mail po?iljatelja\n";

	}
	mail="";
	if(document.voscilo.ToEmail.value=="")
		mess+="Mail naslovnika??\n";
	else{
		var tekst=document.voscilo.ToEmail.value;

		if(tekst.indexOf(",")==-1){
			mail=valEmail(tekst);
			if(mail!=="OK")
				mess+=mail+"\n";
		}
		else{
			var naslovi=tekst.split(",");
			for(i in naslovi){
				z=i+1;
				mail="";
				mail=valEmail(naslovi[i]);
				if(mail!=="OK")
				mess+=mail+"\n";
			}

		}
	}
	if(mess.length>0){
		alert(mess);
		return false;
	}
	else
		document.voscilo.submit();
}


function ujemi(){
	x1=event.clientX-60;
	y1=event.clientY;

}
function ujemi1(e){
	x1=e.pageX-50;
	y1=e.pageY;

}

function show_oblak(i)
{

	var el1 = document.getElementById("oblak"+i);
	if(el1.style.display=="none"){
		if(i==1)x1+=30;
		x1+="px";

		el1.style.left=x1;


		el1.style.display="block";

	}


	if(i==1)
		skrij_oblak(2);
	if(i==2)
		skrij_oblak(1);



}


function skrij_oblak(z)
{

var el1 = document.getElementById("oblak"+z);

if(el1.style.display=="block")
	el1.style.display="none";

}





function okno(windowURL,sirina,visina,cs)
{
  //visina += 40;
  visina+=100;
  if(cs>0)
  	sirina+=100+(sirina/3);
  else
  	sirina+=100;
  var leftpos = (screen.width - sirina-10)/2;
  var toppos  = (screen.height - visina-60)/2;
  var nWindow = window;

  nWindow = window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos);
}

function okno_sound(windowURL,sirina,visina)
{

  var leftpos = (screen.width - sirina-10)/2;
  var toppos  = (screen.height - visina-60)/2;
  var nWindow = window;

  nWindow = window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos);
}

function trim(str)
{
  var start = 0;
  var end = str.length;

  for(i = 0; i < str.length; i++)
  {
    if(str.charAt(i) == " ")
      start++;
    else
      break;
  }
  for(i = str.length-1; i >= 0; i--)
  {
    if(str.charAt(i) == " ")
      end--;
    else
      break;
  }

  if(end == 0)
    start = 0;
  str = str.substring(start,end);

  return str;
}

function valEmail(emailStr)
{
  /* The following variable tells the rest of the function whether or not
  to verify that the address ends in a two-letter country or well-known
  TLD.  1 means check it, 0 means don't. */
  var checkTLD=1;

  /* The following is the list of known TLDs that an e-mail address must end with. */
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address
  fits the user@domain format.  It also is used to separate the username
  from the domain. */
  var emailPat=/^(.+)@(.+)$/;

  /* The following string represents the pattern for matching all special
  characters.  We don't want to allow special characters in the address.
  These characters include ( ) < > @ , ; : \ " . [ ] */
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a
  username or domainname.  It really states which chars aren't allowed.*/
  var validChars="\[^\\s" + specialChars + "\]";

  /* The following pattern applies if the "user" is a quoted string (in
  which case, there are no rules about which characters are allowed
  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
  is a legal e-mail address. */
  var quotedUser="(\"[^\"]*\")";

  /* The following pattern applies for domains that are IP addresses,
  rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  e-mail address. NOTE: The square brackets are required. */
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  /* The following string represents an atom (basically a series of non-special characters.) */
  var atom=validChars + '+';

  /* The following string represents one word in the typical username.
  For example, in john.doe@somewhere.com, john and doe are words.
  Basically, a word is either an atom or quoted string. */
  var word="(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

  /* The following pattern describes the structure of a normal symbolic
  domain, as opposed to ipDomainPat, shown above. */
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


  /* Finally, let's start trying to figure out if the supplied address is valid. */


  /* Begin with the coarse pattern to simply break up user@domain into
  different pieces that are easy to analyze. */
  var matchArray=emailStr.match(emailPat);
  if (matchArray == null)
  {
    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */
    error = "Napa?en E-mail (preverite @ in pike)";
    return error;
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).
  for (i=0; i < user.length; i++)
  {
    if (user.charCodeAt(i) > 127)
    {
      error = mess[3];
      return error;
    }
  }
  for (i=0; i < domain.length; i++)
  {
    if (domain.charCodeAt(i)>127)
    {
      error = mess[4];
      return error;
    }
  }

  // See if "user" is valid
  if (user.match(userPat)==null)
  {
    // user is not valid
    error = mess[3];
    return error;
  }

  /* if the e-mail address is at an IP address (as opposed to a symbolic
  host name) make sure the IP address is valid. */
  var IPArray=domain.match(ipDomainPat);
  if (IPArray != null)
  {
    // this is an IP address
    for (var i=1;i <= 4;i++)
    {
      if (IPArray[i]>255)
      {
        error = mess[5];
        return error;
      }
    }
    return true;
  }

  // Domain is symbolic name.  Check if it's valid.
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++)
  {
    if (domArr[i].search(atomPat)==-1)
    {
      error = mess[4];
      return error;
    }
  }

  /* domain name seems valid, but now make sure that it ends in a
  known top-level domain (like com, edu, gov) or a two-letter word,
  representing country (uk, nl), and that there's a hostname preceding
  the domain or country. */
  if (checkTLD && (domArr[domArr.length-1].length != 2) && (domArr[domArr.length-1].search(knownDomsPat) == -1))
  {
    error = mess[6];
    return error;
  }

  // Make sure there's a host name preceding the domain.
  if (len < 2)
  {
    error = mess[4];
    return error;
  }

  // If we've gotten this far, everything's valid!
  return "OK";
}



function checkBuyStep1(form)
{
  var empty = false;

  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "radio")
    {
      if(form.elements[i].name == "UserData[IsCompany]")
      {
        if((form.elements[i].checked == true) && (form.elements[i].value == "yes"))
          comp = true;
        else
          comp = false;
      }
    }
  }
  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "text")
    {
      form.elements[i].value = trim(form.elements[i].value);
      if(form.elements[i].value == "")
      {
        if(form.elements[i].disabled == false)
        {
          if(comp == true)
          {
            if((form.elements[i].name != "Recipient[Phone]") && (form.elements[i].name != "Recipient[Email]"))
            {
              message = "Izpolniti morate vsa polja ozna?ena z *!";
              empty = true;
            }
          }
          else
          {
            if((form.elements[i].name != "UserData[Company]") && (form.elements[i].name != "UserData[TaxID]") && (form.elements[i].name != "Recipient[Phone]") && (form.elements[i].name != "Recipient[Email]"))
            {
              message = "Izpolniti morate vsa polja ozna?ena z *!";
              empty = true;
            }
          }
        }
      }
    }
  }
  if(empty == true)
  {
    alert(message);
    return false;
  }
  else
  {
    email = valEmail(form["UserData[Email]"].value);

    if(email != "OK")
    {
      alert(email);
      return false;
    }
    else
      return true;
  }
}

function checkRegister1()
{
	if(checkRegister()==true) {
		document.personalData.action="index.php?action=register&what=submit";
     
       document.personalData.submit();
    }  
}

function checkRegister()
{
  var form=document.personalData;
  var empty = false;
  var passErr = false;
  var comp=false;
  
  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "radio")
    {
      if(form.elements[i].name == "UserData[IsCompany]")
      {
        if((form.elements[i].checked == true) && (form.elements[i].value == "yes"))
          comp = true;
        else
          comp = false;
      }
    }
  }
  
  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "text")
    {
      form.elements[i].value = trim(form.elements[i].value);
      if(form.elements[i].value == "" && form.elements[i].name!="UserData[drugo]")
      {
        if(comp == true)
        {
          message = "Izpolniti morate vsa polja označena z *!";
          empty = true;
        }
        else
        {
          if((form.elements[i].name != "UserData[Company]") && (form.elements[i].name != "UserData[TaxID]"))
          {
            message = "Izpolniti morate vsa polja označena z *!";
            empty = true;
          }
        }
      }
    }
  }
  
  if(empty == true)
  {
    alert(message);
    return false;
  }
  else
  {
    email = valEmail(form["UserData[Email]"].value);

    if(email != "OK")
    {
      alert(email);
      return false;
    }
    else
    {
      if(form["UserData[Password]"].value != form["UserData[rPassword]"].value)
      {
        message = "Gesli se ne ujemata!";
        passErr = true;
      }
      else if(form["UserData[Password]"].value.length < 4)
      {
        message = "Geslo mora biti dolgo najmanj 4 znake!";
        passErr = true;
      }
	  
      if(passErr == true)
      {
        alert(message);
        return false;
      }
      else
        return true;
    }
  }
}
// mredkj.com
function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.NO_ROUNDING = -1 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.roundToPlaces; 
this.truncate; 
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal); 
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(false); 
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal); 
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal) {
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING); 
this.truncate = (tr != null && tr); 
this.places = (p < 0) ? 0 : p; 
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{    
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
} else {
nStr = this.expandExponential(Math.abs(nNum)); 
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + ''; 
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc); 
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
} 
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val; 
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');        
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal); 
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length); 
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, ''); 
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val); 
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true; 
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');    
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal); 
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length); 
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, ''); 
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}
