﻿var agt=navigator.userAgent.toLowerCase();
var brws;    
if (agt.indexOf("firefox") != -1) brws = 'ff';
if (agt.indexOf("msie") != -1) brws = 'ie';
if (agt.indexOf("safari")!=-1) brws = 'sf';
    
  
//function scrollToCoordinates(scrollx, scrolly) {
//    parent.window.scrollTo(scrollx, scrolly);
//} 

//function resetWindowScrol(){
//    scrollToCoordinates(0,0);
//}
    
function CurrencyFormatted(amount, ignoreDecimals)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { 	    
	    s += (ignoreDecimals?'':'.00'); 
	}
	if(s.indexOf('.') == (s.length - 2)) { 
	    s += (ignoreDecimals?'':'0'); 
	}
	s = minus + s;
	return s;
}



       
       function replace(string,text,by) {// Replaces text with by in string
     //  alert('cp1');
            var strLength = string.length
            var txtLength = text.length;           
            if ((strLength == 0) || (txtLength == 0)) 
                return string;
            var i = string.indexOf(text);
            if ((!i) && (text != string.substring(0,txtLength))) 
                return string;
            if (i == -1) 
                return string;           
            var newstr = string.substring(0,i) + by;
            if (i+txtLength < strLength)
                newstr += replace(string.substring(i+txtLength,strLength),text,by);            
            return newstr;
        }

function trim(inputString)
        {
         if (typeof inputString != "string") { return inputString; }
         var retValue = inputString;
         var ch = retValue.substring(0, 1);
         while (ch == " ")
          { // Check for spaces at the beginning of the string
          retValue = retValue.substring(1, retValue.length);
          ch = retValue.substring(0, 1);
         }
         ch = retValue.substring(retValue.length-1, retValue.length);
         while (ch == " ")
         { // Check for spaces at the end of the string
          retValue = retValue.substring(0, retValue.length-1);
          ch = retValue.substring(retValue.length-1, retValue.length);
         }
         while (retValue.indexOf("  ") != -1)
         { 
         // Note that there are two spaces in the string
         // - look for multiple spaces within the string
          retValue = retValue.substring(0, 
            retValue.indexOf("  ")) + 
            retValue.substring(retValue.indexOf("  ")+1, 

         retValue.length);
         // Again, there are two spaces in each of the strings
         }
         
         return retValue; // Return the trimmed string back to the user
        }
        
//function checkformgeneral(empties, empmessages, positives, posmesages, shouldResize)
//{
//    var errormessage = "";
//    var errorno = 0;
//    document.getElementById('divErrorContent').innerHTML = "";
//        document.getElementById('divError').style.display = "none";
//    
//        for (i=0; i<empties.length;i++)
//        {
//            
//            if (trim(document.getElementById(empties[i]).value) == '')
//            {
//                errormessage += "- "+empmessages[i]+".<br>";
//                errorno++;
//            }
//        }
//        
//         for (i=0; i<positives.length;i++)
//        {
//            if (parseFloat(document.getElementById(positives[i]).value) <= 0)
//            {
//                errormessage += "- "+posmesages[i]+".<br>";
//                errorno++;
//            }
//        }
//   
//    
//    if (errorno==0)
//        return true;
//    else
//    {
//        document.getElementById('divErrorContent').innerHTML = "<b>"+errorno+" error(s) prohibited this form from being saved</b><br><br>There were problems with the following fields:<br>"+errormessage;
//        if(brws == 'ie')
//            document.getElementById('divError').style.display = "inline";
//        else
//            document.getElementById('divError').style.display = "block";
//        
//        if (shouldResize)
//         resizeIframe('frmMain');
//        
//        return false;
//    }
//    return false;
//}

function isNumberKey(evt, hideDots)
{

 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode !=46 || hideDots))
    return false;

 return true;
}

function isAlphanumeric(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
 if ((charCode >= 48 && charCode <=57) || (charCode >= 65 && charCode<=90) || (charCode >=97 && charCode<=122) || charCode==95)
    return true;

 return false;
}

function isDigit(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode >= 48 && charCode <=57)
    return true;

 return false;
}

function showMessage(message)
{
    document.getElementById('divMessage').innerHTML = message;
    window.scrollTo(0,0);
    $('#divMessage').slideToggle("slow").animate({opacity: 1.0}, 2000).slideToggle("slow");
}

