﻿/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* http://dynamicdrive.com/dynamicindex16/showhint.htm
***********************************************/
var ie=document.all
var ns6=document.getElementById&&!document.all

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
positionit(tipwidth)
setInterval("positionit(" + tipwidth + ")",100)
dropmenuobj.style.visibility="visible"
}
}

function positionit(tipwidth)
{
var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
dropmenuobj.style.left = ((document.body.clientWidth - tipwidth)/2 + scrollx) + "px";
dropmenuobj.style.top = ((window.screen.height - 100)/2 - 280 + scrolly) + "px";
dropmenuobj.x=((document.body.clientWidth - tipwidth)/2)
dropmenuobj.y=((window.screen.height - 100)/2 - 280)
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")        
document.body.appendChild(divblock)
}

function ShowWaitMessage()
{    
    showhint('<IMG SRC="../Images/indicator.gif" /> <b>Please wait... </b> ', this, null, '200');            
    //document.style.cursor = 'wait';
}

function HideWaitMessage()
{
    hidetip(null);
}

/**********************************************************************************************/

// JScript File

function OpenWindow(strURL, intHeight, intWidth)
{	
window.open(strURL + "","","resizable=no,scrollbars=yes,toolbar=no,status=no,left=" + (window.screen.width - intWidth)/2 + ",top=" + (window.screen.height - intHeight)/2 + ",width=" + intWidth + ",height=" + intHeight);

}
function OpenWindowAndCloseParent(strURL, intHeight, intWidth)
{
	window.open(strURL + "?OpenInNewWindow=True", "", "resizable=yes,scrollbars=yes,toolbar = no,status=no,left=" + (window.screen.width - intWidth)/2 + ",top=" + (window.screen.height - intHeight)/2 + ",width=" + intWidth + ",height=" + intHeight);
	
	window.parent.close();
	
}

function ClientValidate(source, arguments)
{  
        
    val= ConvertCurrToNumber(document.getElementById(source.controltovalidate).value); 
    if(val>0)
        arguments.IsValid=true
    else
        arguments.IsValid=false     
    return;
 }
 
function HasFormContentsChanged()
{	
	var bFlag = false;	
	objForm = document.forms[0];
    for (var i=0;i < objForm.elements.length;i++)
    {
		oElem = objForm.elements[i];
		sType = oElem.type.toLowerCase();						
		if(sType == "checkbox" || sType == "radio")
		{
			if(oElem.checked != oElem.defaultChecked)
				bFlag = true;
		}
		else if(sType == "select-one")			
		{
			for(nOptIdx = 1; nOptIdx < oElem.options.length; nOptIdx++)
            {
                oOpt = oElem.options[nOptIdx];                    
                if(oOpt.selected != oOpt.defaultSelected)
                {
					bFlag = true;
                    break;
                }
            }                                			
        }
		else if(sType == "text" || sType == "textarea")
		{			
			if(oElem.value != oElem.defaultValue)
				bFlag = true;
		}
    }    
    return (bFlag);            
}

function validate()
{
   if (document.getElementById("Username").value=="")
      {
                 alert("Name Feild can not be blank");
                 document.getElementById("txtUserName").focus();
                 return false;
      }

}


function ResizeDiv()
{

      var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
      
        var intHeight;
        objWorkArea = document.getElementById("WorkArea")	
        objBottomPanel = document.getElementById("trBottomPanel")	
        if(objWorkArea)
        {
            if(objBottomPanel)
	            pnlHeight = objBottomPanel.offsetHeight + 105;	
            else
	            pnlHeight = 40;							     

            intHeight = myHeight - objWorkArea.offsetTop - pnlHeight;
            if (intHeight < 100) intHeight = 100;		
            //objWorkArea.height = intHeight;
            objWorkArea.setAttribute('height', intHeight);
        }
}
function window_onload()
{    
	ResizeDiv();
    objForm = document.forms[0];
    if(window.top)
    {
        window.top.document.title = window.document.title;        
    }
    createhintbox();
    //ShowWaitMessage();    
}
function window_onresize()
{	
    ResizeDiv();
}
window.onload = window_onload;
window.onresize = window_onresize;

function ConvertCurrToNumber(strCurr)
{
    if(strCurr == "" || strCurr == undefined)
        strCurr = "0";
    else
        strCurr = strCurr + "";
    return parseFloat(strCurr.replace('$', '').replace('(', '').replace(')', '').replace(',', ''))
} 

function IncreaseAmount(ctl, stepValue)
{    
    dblValue = ConvertCurrToNumber(ctl.value);    
    dblValue = dblValue + stepValue;    
    dblValue = dblValue - ( dblValue % stepValue);
    ctl.value = formatCurrency(dblValue);
}

function DecreaseAmount(ctl, stepValue)
{
    dblValue = ConvertCurrToNumber(ctl.value);    
    if((dblValue - stepValue) >= 0)
    {
        if(( dblValue % stepValue) > 0)
            dblValue = dblValue - ( dblValue % stepValue);
        else
            dblValue = dblValue - stepValue;    
        
        ctl.value = formatCurrency(dblValue);
     }
     else
        ctl.value = formatCurrency(0);
}

function FormatCurrency(obj)
{    
    obj.value = formatCurrency(obj.value)
}

function formatCurrency(num) {         
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    /*return (((sign)?'':'-') + '$' + num + '.' + cents);
    return (((sign)?'':'-') + num + '.' + cents);*/
    return (((sign)?'':'-') + '$' + num);    
}

function conDec(tmp)
{
    var alertbox=false;
    var tmp;
    tmp = tmp*100;
    tmp = Math.round(tmp);
    if(isNaN(tmp)) {tmp = 0.00;}
    if(tmp>99999999999)alert("trillion is not supported - only millions.");
    /* converts tmp to decimal cents and adds a 0 to .1 to .9 or adds .00 to 0 */
    cen = tmp%100;
    if(cen < 0){cen = ".00"}
    else if(cen <10) {cen = ".0"+cen}
    else if(cen < 100){cen = "."+cen}
    else {cen = cen}
    if(alertbox)alert("Cents "+cen);  /* Cents alert dialog box */

    tmp = parseInt(tmp/100);
    hun = tmp - ((parseInt(tmp/1000)) *1000 );
    if(hun > 0 && hun <1000) {hun = hun}
    else {hun = ''}
    if(alertbox)alert("Hundreds "+hun); /* Hundreds alert dialog box */

    tmp = parseInt(tmp/1000)
    tho = tmp -((parseInt(tmp/1000)) *1000);
    if(tho > 0 && tho < 1000) {tho = tho +","}
    else {tho = ''}
    if(alertbox)alert("Thousands "+tho);  /* Thousands dialog box */


    tmp = parseInt(tmp/1000);
    mil = tmp -((parseInt(tmp/1000)) *1000);
    if(mil > 0 && mil < 1000) {mil = mil + ","}
    else {mil = ''}
    if(alertbox)alert("Millions "+mil); /* Millions dialog box */
    if(alertbox)alert("$"+mil+tho+hun+cen); /* Convert tmp to Currency */
}

function KeyHook(e)
{
    var key = (window.event) ? event.keyCode : e.which;
    if (window.event)
        key = event.keyCode
    else
        key = e.which   
    
    if (key == 13)
        return false;    
}

function CheckFloat(e)
{
//    var key; if (e.keyCode) key = e.keyCode; else if (e.which) key = e.which; 	
//	ret_val = (( key > 47 && key < 58 ) || key == 46 || key == 44 );    
//    return (ret_val);
    
	 var key = (window.event) ? event.keyCode : e.which;
  if (window.event)
    key = event.keyCode
  else
    key = e.which
    
    // Allow special characters: BACKSPACE, TAB, RETURN, LEFT ARROW,
  // RIGHT ARROW to go through
  if ((key == 8) || (key == 9) 
     || (key == 0)) {
    return;
   }

    
  /* Changed code to disallow decimal numbers */
  //if (( key > 47 && key < 58 ) || key == 46 || key == 44 )
  
  // Was key that was pressed a numeric character (0-9) or backspace (8)?
  if (( key > 47 && key < 58 ) || key == 44 )
    return; // if so, do nothing
  else // otherwise, discard character

    if (window.event) //IE
      window.event.returnValue = null;     else //Firefox
      e.preventDefault();
}

function maximizeWindow() {
 if (parseInt(navigator.appVersion)>3) {
  if (navigator.appName=="Netscape") {
   if (top.screenX>0 || top.screenY>0) top.moveTo(0,0);
   if (top.outerWidth < screen.availWidth)
      top.outerWidth=screen.availWidth;
   if (top.outerHeight < screen.availHeight) 
      top.outerHeight=screen.availHeight;
  }
  else {
   top.moveTo(-4,-4);
   top.resizeTo(screen.availWidth+8,screen.availHeight+8);
  }
 }
}


function AllowOnlyNumeric(cntrlID)
{
var objCtl = window.event.srcElement;    
    var sNewString = window.clipboardData.getData("Text"); 
    if (sNewString.length == 0)
     return false;
    var strValidChars = "0123456789.,";
    var strChar;
    var blnResult = true;  
    //  test strString consists of valid characters listed above
    for (i = 0; i < sNewString.length && blnResult == true; i++)
    {
     strChar = sNewString.charAt(i);
     if (strValidChars.indexOf(strChar) == -1)
     {
     document.getElementById(cntrlID).value='';
     
      blnResult = false;
      
     }
    }  
    return blnResult; 
}



