function resizeWin()
{
    browser = navigator.appName;
    os = navigator.platform;
    ie = "Microsoft Internet Explorer";
    netscape = "Netscape";
    mac = 'MacPPC'
	if (os != mac) {
	  if (browser != ie) {
		noScroll();
		window.location.reload();
		return true;
	  }
	}
	else
	{
		noScroll();
		window.location.reload();
		return true;
	}
}
function Trim(str)
{
	while(str.charAt(0)==' ')
		str=str.substring(1,str.length);
	while(str.charAt(str.length-1)==' ')
		str=str.substring(0,str.length-1);
	
	return str;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
// Open a modal dialog object
function OpenModalDialog(strURL, intWidth ,intHeight)
{
    var value = window.showModalDialog(strURL, 'window', 'dialogwidth:' + intWidth + 'px; dialogheight:' +  intHeight + 'px;center:yes;help:no;status:yes;edge:sunken;scroll:no');
    if (value != 'cancel')
    {
        // window.location.reload();
    }
}   

// Open a modal dialog object
var vPrintWindow = null;
function OpenPrintDialog(strURL, width ,height)
{
    
    if (vPrintWindow != null) vPrintWindow.close();
    var topY = (window.screen.height - height)/2;
    var leftX = (window.screen.width - width)/2;    
    vPrintWindow = window.open(strURL,"PrintWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,statusbar=1,scrollbars=1,resizable=1,left=' + leftX + ',top=' + topY  + ',width=' + width + ',height=' + height);
}  

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function PopUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=80,left = 390,top = 472');");
}

function OpenLink(URL) {
       window.open(URL);
}
function CheckInFrame(mainURL){
    if(parent == null || parent.MainFrame == null)
        location.href = mainURL;
}


function CheckInput(obj, evt)
{
	var  k = -1;
	if (document.all)
	{
	    k = window.event.keyCode;
	} else {
	    k = evt.which;
	}
	
	var kStr = String.fromCharCode(k);
	if(obj.value.length >= 1)
	{
			var str  = obj.value.substring(obj.value.length - 1);
			
			if(str == "." && kStr == "."){
					return false;
			}
			
			if(kStr == "." && (obj.value.substring(1,obj.value.length-1)).indexOf(".") > -1)
				return false;
			
	}else{
		
		if(kStr == ".")
			return false;
		
	}
	if ((k<=57) && (k>=48) ||(k==46))
		{
			return true;
	}else{
			return false;
		}
}
function CheckDigit(obj,evt){
    var key,keychar;
	if (window.event)
	     key=evt.keyCode;
	else 
	      key=evt.which;
		
	keychar=String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
        return true;
    else if (("0123456789-").indexOf(keychar) >-1)
		return true;
    else
		return false;

}

// Open a modal dialog object
var vOpopupWindow = null;
function OpenActionModalDialog(btnObjID, strURL, width ,height)
{
    // add the browser type, e.g: appName=Netscape
    var index = strURL.indexOf(".aspx?");
    if (index > 0)
    {
        strURL = strURL + "&appName=" + navigator.appName;  
    } else {
        strURL = strURL + "?appName=" + navigator.appName;  
    }
    
    var isShowScroll = 0;
    if (window.screen.availHeight <= height)
    {
        isShowScroll = 1;
        height = window.screen.availHeight;
    }
    
    if (navigator.appName != "Netscape") 
    {
        var value = null;
        if (height >= window.screen.availHeight) height = window.screen.availHeight;
        
        value = window.showModalDialog(strURL, 'window', 'dialogwidth:' + width + 'px; dialogheight:' +  height + 'px;center:1;help:0;status:0;edge:sunken;scroll:' + isShowScroll);
        if (value!= null && value.toLowerCase() == 'update')
        {
           var btnObj = window.document.getElementById(btnObjID);
          
           if (btnObj != null) btnObj.click();
        }
    } else {
        
        if (vOpopupWindow != null) vOpopupWindow.close();
        var topY = (window.screen.height - height)/2;
        var leftX = (window.screen.width - width)/2;
        vOpopupWindow = window.open(strURL,"OpopupWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,statusbar=1,scrollbars=' + isShowScroll + ',resizable=0,left=' + leftX + ',top=' + topY  + ',width=' + width + ',height=' + height);
    }    
}

// Open a modal dialog object and return the modal dialog value in IE
function OpenActionModalDialogValue(strURL, width ,height)
{
 
    // add the browser type, e.g: appName=Netscape
    var index = strURL.indexOf(".aspx?");
    if (index > 0)
    {
        strURL = strURL + "&appName=" + navigator.appName;  
    } else {
        strURL = strURL + "?appName=" + navigator.appName;  
    }
    
    var isShowScroll = 0;
    if (window.screen.availHeight <= height)
    {
        isShowScroll = 1;
        height = window.screen.availHeight;
    }
    
    if (navigator.appName != "Netscape") 
    {
        if (height >= window.screen.availHeight) height = window.screen.availHeight;
        return window.showModalDialog(strURL, 'window', 'dialogwidth:' + width + 'px; dialogheight:' +  height + 'px;center:1;help:0;status:0;edge:sunken;scroll:' + isShowScroll);
    } else {        
        if (vOpopupWindow != null) vOpopupWindow.close();
        var topY = (window.screen.height - height)/2;
        var leftX = (window.screen.width - width)/2;
        vOpopupWindow = window.open(strURL,"OpopupWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,statusbar=1,scrollbars=' + isShowScroll + ',resizable=0,left=' + leftX + ',top=' + topY  + ',width=' + width + ',height=' + height);
    }    
}

// Open a modal dialog object and return the modal dialog value in IE
function OpenDialog(strURL, width ,height)
{
    // add the browser type, e.g: appName=Netscape
    var index = strURL.indexOf(".aspx?");
    if (index > 0)
    {
        strURL = strURL + "&appName=" + navigator.appName;  
    } else {
        strURL = strURL + "?appName=" + navigator.appName;  
    }
    
    var isShowScroll = 0;
    if (window.screen.availHeight <= height)
    {
        isShowScroll = 1;
        height = window.screen.availHeight;
    }
    
    if (vOpopupWindow != null) vOpopupWindow.close();
    var topY = (window.screen.availHeight - height)/2;
    var leftX = (window.screen.availWidth - width)/2;
    vOpopupWindow = window.open(strURL,"OpopupWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,statusbar=1,scrollbars=' + isShowScroll + ',resizable=0,left=' + leftX + ',top=' + topY  + ',width=' + width + ',height=' + height);
}

// Clear the object's value
function ClearTextValue(vClientID, vType)
{
    if (vType == 'txt')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.value = '';
    } else 
    if (vType == 'date')
    {
        var vObj = igedit_getById(vClientID);
        if (vObj != null) vObj.setText('');
    } else 
    if (vType == 'checkbox')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.checked = false;
    } else 
    if (vType == 'ddl')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.selectedIndex = 0;
    }
}    
// Set the object's value
function SetTextValue(vClientID, vType,value)
{
    if (vType == 'txt')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.value = value;
    } else 
    if (vType == 'date')
    {
        var vObj = igedit_getById(vClientID);
        if (vObj != null) vObj.setText(value);
    } else 
    if (vType == 'checkbox')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.checked = value;
    } else 
    if (vType == 'ddl')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) vObj.value = value;
    }
}    

function SetVisible(vClientID,visible)
{
   var obj = $(vClientID);
   if(obj != null)
   {
        if(visible){
            obj.style.display = "inline";
            obj.style.visibility = "visible";
            
        }else{
            obj.style.display = "none";
            obj.style.visibility = "hidden";
        }
   }
   
}   
function IsVisible(vClientID)
{
   var obj = $(vClientID);
   if(obj != null){
        if(obj.style.display == "none" || obj.style.visibility == "hidden")
            return false;
        else
            return true;
   }
   return false;
 
}   

// Set the component status
function SetComponentStatus(vClientID, vDisable, vType)
{
    if (vType == 'txt')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) 
        {
            if (vDisable) 
            {
                vObj.readOnly = 'readonly';
            } else {
                vObj.readOnly = '';
            }
            vObj.value = Trim(vObj.value);
        }
    } else 
    if (vType == 'itxt')
    {
        var vObj = igedit_getById(vClientID);
        if (vObj != null) vObj.setReadOnly(vDisable);
    } else
    if (vType == 'checkbox' || vType == 'button' || vType == 'ddl' )
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) 
        {
            if (vDisable) 
            {
                vObj.disabled = 'disabled';
            } else {
                vObj.disabled = '';
            }
        }
    }
}

// Set the component status
function SetFocus(vClientID, vType)
{
    if (vType == 'txt')
    {
        var vObj = document.getElementById(vClientID);
        if (vObj != null) 
        {
            vObj.focus();
        }
    } else 
    if (vType == 'itxt')
    {
        var vObj = igedit_getById(vClientID);
        vObj.focus();
    } else
    if (vType == 'checkbox' || vType == 'button' || vType == 'ddl' )
    {
        var vObj = document.getElementById(vClientID);
        vObj.focus();
    }
}

function IsFireFox()
{
    if (navigator.appName == "Netscape")
    {
        return true;
    }
    return false;
}

//Cal Event Postion
function mouseCoords(ev){
    
    if(ev.pageX || ev.pageY){
         return {x:ev.pageX, y:ev.pageY};
    } return {
       x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
       y:ev.clientY + document.body.scrollTop  - document.body.clientTop     
     };
} 

function OnError(result)
{
    alert(result.get_message());
}

function OnTimeOut(result)
{
    alert(result);
}

function getElementPos(elementId) {
	 var ua = navigator.userAgent.toLowerCase();
	 var isOpera = (ua.indexOf('opera') != -1);
	 var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
	 var el = document.getElementById(elementId);
	 
	 if(el.parentNode === null || el.style.display == 'none') {
	    return false;
	 }      
	 var parent = null;
	 var pos = [];     
	 var box;     
	 if(el.getBoundingClientRect)    //IE
	 {         
	      box = el.getBoundingClientRect();
	      var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
	      var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
	      return {x:box.left + scrollLeft, y:box.top + scrollTop};
	 }else if(document.getBoxObjectFor)    // gecko    
	 {
	      box = document.getBoxObjectFor(el); 
	      var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0; 
	      var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0; 
	      pos = [box.x - borderLeft, box.y  - borderTop];
	 } else    // safari & opera    
	 {
	      pos = [el.offsetLeft, el.offsetTop];  
	      parent = el.offsetParent;     
	      if (parent != el) { 
	           while (parent) {  
		            pos[0] += parent.offsetLeft; 
		            pos[1] += parent.offsetTop; 
		            parent = parent.offsetParent;
	           }  
	      }
	      
	      if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) { 
	           pos[0] -= document.body.offsetLeft;
	           pos[1] -= document.body.offsetTop;         
	      }    
	 }              
	 if (el.parentNode) { 
		parent = el.parentNode;
	 }else{
		parent = null;
	 }
	 while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors
	      pos[0] -= parent.scrollLeft;
	      pos[1] -= parent.scrollTop;
	      if (parent.parentNode) {
	       parent = parent.parentNode;
	      } else {
	        parent = null;
	      }
	}

	 return {x:pos[0], y:pos[1]};
}     
function disableSelect()
{   
    if(document.all != null){
        for(i=0;i<document.all.length;i++)  
              if(document.all(i).tagName=="SELECT")
                document.all(i).disabled = true;
    }
 } 

function enableSelect()
{
    if(document.all != null){
        for(i=0;i<document.all.length;i++){   
                  if(document.all(i).tagName=="SELECT")
                  {
                    document.all(i).disabled = false;
                  }
            }   
    }    
}  
// JScript File
        function dyniframesize(iframename) {
            var pTar = null;
            if (document.getElementById){ 
                pTar =document.getElementById(iframename);
            } 
            else{ 
                eval('pTar = ' + iframename + ';'); 
            }
            if (pTar && !window.opera){ 
                //begin resizing iframe 
                pTar.style.display="block" 
                if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){ 
                    //ns6 syntax
                    if(pTar.contentDocument.body.offsetHeight+FFextraHeight<600){
                        pTar.height = 600;
                    }else{
                        pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight;
                    }
                } 
                else if (pTar.Document && pTar.Document.body.scrollHeight){ 
                    //ie5+ syntax
                    if(pTar.Document.body.scrollHeight<600){
                        pTar.height = 600;
                    }else{
                        pTar.height = pTar.Document.body.scrollHeight;
                    }
                }
            }
        }
        function link(lintext,leftdis){
            try{
                alert(MainFrame);
                //var obj=document.getElementById("leftdis");
                //if (leftdis=='1'){
                //    obj.style.cssText="display:block;";
                //}else{
                //    obj.style.cssText="display:none;";
                //}
                MainFrame.location=lintext;
                dyniframesize('MainFrame');
            }catch(e){}
        }        
