﻿
function winOpen(page, winName, w, h, scrollbars, resizable)
{
	if( !scrollbars ) scrollbars = 0;
	if( scrollbars==1) scrollbars= 'yes';
	if( scrollbars==0) scrollbars= 'no';
	
	if( !resizable ) resizable = 0;
	if( resizable==1) resizable= 'yes';
	if( resizable==0) resizable= 'no';
	
	str = 'width=' + w + ', height=' + h + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',toolbar=no,location=no,directories=no,status=no,menubar=no';
	window.open(page, winName, str);
	return false;
}

function checkEmail(email){ 
	
  if(email.length==0) return false; 
  email = email.toLowerCase();
  var myReg = /^[_a-z0-9.-]+@([-_a-z0-9]+\.)+[a-z0-9]{2,3}$/; 
  return myReg.test(email);
}

function getDim(el)
{
	for(var lx=0,ly=0; el!=null; lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly};
}

function getParentNodeById(cobj, id)
{
	while(cobj)
	{
		if(cobj.id==id) return cobj;
		cobj = cobj.parentNode;
	}
	return null;
}
		
function getChildNodeById(cobj, id)
{
	while(cobj)
	{
		if(cobj.id==id)
			return cobj;
		if(cobj.childNodes.length==0) 
			return null;
		for(var i=0; i<cobj.childNodes.length; i++)
		{
			temp = getChildNodeById(cobj.childNodes[i], id);
			if(temp) 
				return temp;
			else
			{
				if(i==cobj.childNodes.length-1)
					return null;
			}
		}
	}
	return null;
}

function ReadSign(strSign,strContent)
{
   var r, re;
   re = new RegExp('<!--' + strSign + '-->.*<!--/' + strSign + '-->','i');
   r = strContent.match(re);
   if(r==null) return null;
   return(r.toString());
}

function ReadScript(strContent)
{
   var script;
   script = ReadSign('script', strContent);
   
   if(script==null) return null;
   script = script.replace('<!--script-->','');
   script = script.replace('<!--/script-->','');
   script = script.replace('<script language="javascript">','');
   script = script.replace('</script>','');
   return(script);
}

Number.prototype.rate=function()
{  
    var oStr=this.toString(); 
    if(oStr.indexOf(".")==-1)  
        return 1; 
    else 
        return Math.pow(10,parseInt(oStr.length-oStr.indexOf(".")-1)); 
}

String.prototype.rate = function()
{
    var oStr=this.toString(); 
    if(oStr.indexOf(".")==-1)  
        return 1; 
    else 
        return Math.pow(10,parseInt(oStr.length-oStr.indexOf(".")-1)); 
}


function multi()
{ 
    args=multi.arguments;
    var temp=1;
    for(i=0;i<args.length;i++) 
        temp*=args[i]*args[i].rate(); 
    for(i=0;i<args.length;i++)  
        temp/=args[i].rate(); 
    return temp;
}

function add()
{
    args=add.arguments;
    var temp=0;
    var rate = 1;
    for(i=0;i<args.length;i++)
    {
        if(args[i].rate()>rate)
            rate = args[i].rate();
    } 
    for(i=0;i<args.length;i++) 
        temp+=args[i]*rate;
    temp/=rate; 
    return temp;
}

function ImgAuto(i,MaxW,MaxH)
{
    if(!navigator.B+navigator.V=='IE6')
        return;
    if(!MaxW)
    {
        MaxW = i.style.maxWidth.replace('px','');
        MaxH = i.style.maxHeight.replace('px','');
        alert(MaxH+' '+MaxW+' '+i.src);
    }
    var o=new Image();
    o.src=i.src;
    var w=o.width;
    var h=o.height;
    var t;
    if (w>MaxW){t=MaxW;}else{t=w;}
    if ((h*t/w)>MaxH){i.style.height=MaxH+'px';i.style.width=MaxH/h*w+'px';}else{i.style.width=t+'px';i.style.height=t/w*h+'px';}
    
}
