function RemoveComma(amount)
{
    //alert(amount);
    while(1)
    {
        if(amount.indexOf(',') > -1)
        {
            amount = amount.replace(',', '');
            //alert(amount);
        }
        else
            return amount;
    }
    return amount;    
}

function CurrencyFormatted(amount)
{
	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 += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function CommaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return '$' + amount;
}

function cellMouseOver(theCell,theClass) {
	    eval(theCell).className=theClass;
}

function cellMouseOut(theCell,theClass) {
	    eval(theCell).className=theClass;
}

//This function will check allowed files for upload
function CheckFile(source,args)
{
    objFile = eval("theForm." + source.controltovalidate);
    if(!objFile.value)
    {
        args.IsValid = true;
        return;
    }
	
    dots = objFile.value.split(".");
    fileType = "." + dots[dots.length-1];
    if(!fileType)
    {
        args.IsValid = false; //not selected valid file
        return;
    }
	
    allowedTypes = objFile.allowed;
    if(allowedTypes.indexOf(fileType) != -1)
    {
        args.IsValid = true;
    }
    else
    {
        args.IsValid = false;
    }
}

//This function will check Length of textarea
function maxLen(source,args) 
{
    intMax =  parseInt(eval("theForm." + source.controltovalidate + ".maxlen"));		
    intTextLen =  parseInt(eval("theForm." + source.controltovalidate + ".value.length"));
    if (intTextLen > intMax)
	    args.IsValid = false;
    else
	    args.IsValid = true;
}

//This function will check max selection allowed in Listbox
function maxSel(source,args)
{
    intMax =  parseInt(eval("theForm." + source.controltovalidate + ".maxSel"));		
    intTotSel = 0;
    objListBox = eval("theForm." + source.controltovalidate);
    for(i = 0; i < objListBox.length; i++)
    {
	    //Check : if selected then Add.
	    if(objListBox.options[i].selected)
	    {
		    intTotSel += 1;
	    }
    }
    if (intTotSel > intMax)
	    args.IsValid = false;
    else
	    args.IsValid = true;
}

//This function will check min selection allowed in Listbox
function minSel(source,args)
{
    intMin =  parseInt(eval("theForm." + source.controltovalidate + ".minSel"));		
    intTotSel = 0;
    objListBox = eval("theForm." + source.controltovalidate);
	
    for(i = 0; i < objListBox.length; i++)
    {
	    //Check : if selected then Add.
	    if(objListBox.options[i].selected)
	    {
		    intTotSel += 1;
	    }
    }
	
    if (intTotSel < intMin)
	    args.IsValid = false;
    else
	    args.IsValid = true;
}
    
function ShowAlert(msg)
{
    alert(msg);
}
// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
function hookEvent(element, eventName, callback)
{
  if(typeof(element) == "string")
    element = document.getElementById(element);
  if(element == null)
    return;
  if(element.addEventListener)
    element.addEventListener(eventName, callback, false);
  else if(element.attachEvent)
    element.attachEvent("on" + eventName, callback);
}
hookEvent(window,"load",correctPNG);
//End Png




/* For */

function pageWidth()
{
    return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() 
{
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

function posLeft() 
{
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

function posTop() 
{
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

function $(x)
{
    return document.getElementById(x);
}

function scrollFix()
{
    var obol=$('ol');obol.style.top=posTop()+'px';
    obol.style.left=posLeft()+'px'
}

function sizeFix()
{
    var obol=$('ol');
    obol.style.height=pageHeight()+'px';
    obol.style.width=pageWidth()+'px';
}

function kp(e)
{
    ky=e?e.which:event.keyCode;
    if(ky==88||ky==120)hm();
    return false
}

function inf(h)
{
    tag=document.getElementsByTagName('select');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
    tag=document.getElementsByTagName('iframe');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
    tag=document.getElementsByTagName('object');
    for(i=tag.length-1;i>=0;i--)
        tag[i].style.visibility=h;
}

function sm(obl, wd, ht)
{
    var h='hidden';
    var b='block';
    var p='px';
    var obol=$('ol'); 
    var obbxd = $('mbd');
    obbxd.innerHTML = $(obl).innerHTML;
    obol.style.height=pageHeight()+p;
    obol.style.width=pageWidth()+p;
    obol.style.top=posTop()+p;
    obol.style.left=posLeft()+p;
    obol.style.display=b;
    var tp=posTop()+((pageHeight()-ht)/2)-12;
    var lt=posLeft()+((pageWidth()-wd)/2)-12;
    var obbx=$('mbox');
    obbx.style.top=(tp<0?0:tp)+p;
    obbx.style.left=(lt<0?0:lt)+p;
    obbx.style.width=wd+p;
    obbx.style.height=ht+p;
    inf(h);
    obbx.style.display=b;
    return false;
}
    
function hm()
{
    if($('ol'))
    {
        var v='visible';var n='none';
        $('ol').style.display=n;
        $('mbox').style.display=n;
        inf(v);
        document.onkeypress=''
    }
}

function initmb()
{
    var ab='absolute';var n='none';
    var obody=document.getElementsByTagName('body')[0];
    var frag=document.createDocumentFragment();
    var obol=document.createElement('div');
    obol.setAttribute('id','ol');
    obol.style.display=n;
    obol.style.position=ab;
    obol.style.top=0;
    obol.style.left=0;
    obol.style.zIndex=998;
    obol.style.width='100%';
    frag.appendChild(obol);
    var obbx=document.createElement('div');
    obbx.setAttribute('id','mbox');
    obbx.style.display=n;
    obbx.style.position=ab;
    obbx.style.zIndex=999;
    var obl=document.createElement('span');
    obbx.appendChild(obl);
    var obbxd=document.createElement('div');
    obbxd.setAttribute('id','mbd');
    obl.appendChild(obbxd);
    frag.insertBefore(obbx,obol.nextSibling);
    obody.insertBefore(frag,obody.firstChild);
    window.onscroll = scrollFix; window.onresize = sizeFix;
}
window.onload = initmb;



function cshowDialog()
{
    if (typeof(ValidatorOnSubmit) == "function")
    {
        if(Page_IsValid==true)
            sm('box',20,20);
        else
            return false;
    }
    else
    {
        sm('box',20,20);
        return true;
    }
}

function hookAjax()
{
    try
    {
        var orq = Sys.WebForms.PageRequestManager.getInstance();
        if(orq)
            orq.add_endRequest(EndRequestHandler);
    }
    catch(obj)
    {}
}

function EndRequestHandler(sender,args)
{
    hideDialog();
}
    
function hideDialog()
{
    hm('box');
}

function AjaxEndRequestHandler(sender,args)
{
//    var ref =  $get('adminBar_reqRef').value;
//    if(ref=='true')
//        refreshRVPage();
alert('123');
    window.setTimeout(hideDialog,500);
}