﻿
function popup_win( loc, wd, hg ) {
   var remote = null;
   var xpos = screen.availWidth/2 - wd/2; 
   var ypos = screen.availHeight/2 - hg/2; 
   remote = window.open('','','width=' + wd + ',height=' + hg + ',resizable=1,scrollbars=1,screenX=0,screenY=0,top='+ypos+',left='+xpos);
   if (remote != null) {
      if (remote.opener == null) {
         remote.opener = self;
      }
      remote.location.href = loc;
      remote.focus();
   } 
//   else { 
//      self.close(); 
//   }
}

function popup_win1( loc, wd, hg ) {
   var remote = null;
   var xpos = screen.availWidth/2 - wd/2; 
   var ypos = screen.availHeight/2 - hg/2; 
   remote = window.open('','','width=' + wd + ',height=' + hg + ',location=1,toolbar=1,statusbar=1,resizable=1,scrollbars=1,screenX=0,screenY=0,top='+ypos+',left='+xpos);
   if (remote != null) {
      if (remote.opener == null) {
         remote.opener = self;
      }
      remote.location.href = loc;
      remote.focus();
   } 
//   else { 
//      self.close(); 
//   }
}


 





function disableControl(DisableObject)
{
    if (typeof(Page_ClientValidate) == 'function') 
    { 
        if (Page_ClientValidate() == false) { return false; }
    } 
    this.disabled = true;
    Page.ClientScript.GetPostBackEventReference(DisableObject, null);
}
	
function ValidateEmail(ctl)
{
    var vl =ctl.value;
	var validErr = true;
	
	// scan for typo errors for the following domains:
	//	 - hotmail.com
	//   - yahoo.com, yahoo.co.uk, yahoo.co.in
	//   - rediffmail.com
	//   - tm.net.my
	validErr=valid(vl,"Invalid email. Please enter a valid email address.","[\\w-_]+((\\.|')[\\w-_]+)*\\@[\\w-_]+(\\.[\\w-_]+){1,5}");

	if (!validErr) {
	      ctl.focus();
	    }
	else{
		return validErr;
	}
}	




//string function

function CheckMaxLength(f, len)
{
  if (f.value.length > len)
  {
    if (confirm('The data in this field exceeds the ' + len + ' character maximum.\n\nDo you wish to shorten the data to match?') == true)
    {
      f.value = f.value.substring(0,len);
      f.focus();
      return true;
    }
    else
    {
      f.focus();
      return false;
    }
  }
  else
  {
    return true;
  }
}

function charCounter(field,cntfield,maxlimit) 
{
    if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.value = maxlimit - field.value.length;
}

function characters(e)
{

    var keycode;
    if (window.event)

    keycode = e.keyCode;
    else if (e.which)

    keycode = e.which;  
    if(keycode >= 48 && keycode <= 57)

    {
        return true;
    }
    else
    {
        alert('Enter Numbers only');
        return false;
    }

}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//end String Function

function getRadioButtonListValue(elementId)
{
    var checkedItem = "";

    var listItemArray = document.getElementsByName(elementId);

    for (var i=0; i<listItemArray.length; i++)
    {
        var listItem = listItemArray[i];

        if (listItem.checked )
        {
            checkedItem = listItem.value;
            break;
        }
    }

    return checkedItem;
}

function getRadioButtonListIndex(elementId)
{
    var checkedItem = -1;

    var listItemArray = document.getElementsByName(elementId);

    for (var i=0; i<listItemArray.length; i++)
    {
         var listItem = listItemArray[i];

        if (listItem.checked )
        {
            checkedItem = i;
            break;
        }
    }

    return checkedItem;
}

function doPostBackAsync( eventName, eventArgs )
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if( !Array.contains( prm._asyncPostBackControlIDs, eventName) )
    {
        prm._asyncPostBackControlIDs.push(eventName);
    }
 
    if( !Array.contains( prm._asyncPostBackControlClientIDs, eventName) )
    {
        prm._asyncPostBackControlClientIDs.push(eventName);
    }
 
    __doPostBack( eventName, eventArgs );
}

 function SendValueBack(value, ctrlId, doPostback, doCallBack) 
 {
      if(this.opener.document.getElementById(ctrlId) != null)
      {
        this.opener.document.getElementById(ctrlId).value = value;
      
        if (doCallBack)
        {
            this.opener.document.getElementById(ctrlId).onchange();
        }
        
        if (doPostback)
        {
           //kst@2009/09/10 this.opener.__doPostBack("'"+ctrlId+"'", '')
            this.opener.doPostBackAsync("'"+ctrlId+"'", '')
        }  
        //this.opener.document.getElementById(ctrlId).Focus();    
      }
      this.close();
 }

   //kst@2009/10/07 add 
    function CloseAndReloadParentPage() 
    {
      opener.location.href = opener.location.href;
      this.close();
    }

   //kst@2009/10/07 add 
    function CloseAndTriggerParentCtrlClick(ctrlId) 
    {
      if(this.opener.document.getElementById(ctrlId) != null)
      {
        this.opener.document.getElementById(ctrlId).click();
      }
      this.close();
    }

//Numeric
function checkNumeric()
{
    var iKeyCode;

    ikeyCode = event.keyCode;

    if( iKeyCode < 48 || iKeyCode > 57 )
        event.keyCode = null;

    var strnumber;
    strnumber = window.event.srcElement.value;
    
    //negative is only allowed at the first character
    if (ikeyCode == 45 && strnumber.length > 0 ) 
        window.event.returnValue = null;    

    //only allow one occurance of dot
    if (ikeyCode == 46 && strnumber.indexOf(".") > 0) 
        window.event.returnValue = null;

    if ((ikeyCode > 47 && ikeyCode < 58) || (ikeyCode == 13) || (ikeyCode == 45) || (ikeyCode == 46)) 
    {
        if ((ikeyCode == 13) && (strnumber.length > 0)) 
        {
          //translate();
        }
    }    
    else
        window.event.returnValue = null;
}

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);
        }

function RoundNumber(num, dec) 
{
    var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
    return result;
}

function checkIsNumber()
{
    var iKeyCode;

	iKeyCode = event.keyCode;

    //
    //  If key pressed is not 0 - 9, don't allow it through.
    //
    if( iKeyCode < 48 || iKeyCode > 57 )
        event.keyCode = null;
}

function currencyFormat(fld, milSep, decSep, e)
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 8) return true;  // Delete (Bug fixed)
	
	key = String.fromCharCode(whichCode);  // Get key value from key code
	
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	
	len = fld.value.length;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) 
	{
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) 
		{
			if (j == 3) 
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) 
{
    var x = Math.round(num * Math.pow(10,dec));
    if (x >= 0) n1=n2='';
    var y = (''+Math.abs(x)).split('');
    var z = y.length - dec;y.splice(z, 0, pnt);

    while (z > 3) {z-=3; y.splice(z,0,thou);}

    var r = curr1+n1+y.join('')+n2+curr2;
    return r;
}
	
//end numeric function
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();