
function chkMemberId(code)
{   var strangCode = "abcdefghijklmnopqrstuvwxyz0123456789_";
    var temp;
    for (var i = 0; i<code.length; i++ )
    {
        temp = code.substring(i,i+1);
        if (strangCode.indexOf(temp) ==-1)
        {
            return (false);
        }
    }
}

function chksafe(a)
{
	fibdn = new Array ("'",'\\',"/");
	i=fibdn.length;
	j=a.length;
	for (ii=0;ii<i;ii++)
	{
		for (jj=0;jj<j;jj++)
		{	
			temp1=a.charAt(jj);
			temp2=fibdn[ii];
			if (temp1==temp2)
			{
				//alert("You have entered invalid char!");
				return 0;
			}
		}
	}
	return 1;
}



function chkspc(a)
{

	var i=a.length;
	for (j=0;(j<i) && (a.charAt(j)==' ');j++)
	{
	
	}
	if (i==j)
	{
		//alert("You have enter enough space!")
		return 0;
	}
	else
	{
		return 1;
	}
	if (i==0)
	{
		return 0;
	}

}

function chkemail(a){ 
	if(!a.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
		return false;
		}
	return true;
		
} 
/*
function chkemail(a)
{

	var i=a.length;

	var temp = a.indexOf('@');
	//var tempd = a.indexOf('.');
	var tempd = a.indexOf('.');

	if (tempd > 0) {
		tempd = (a.substring(temp)).indexOf('.');
		
		if (temp > 1) {
		
			if ((i-temp) > 7){
				if (tempd > 2){
				
					if ((i-temp-tempd)>2){
						return 1;
					}
				}
			}
		}

	}
	
	return 0;
	
}
*/

function chknbr(num,opt1,opt2)
{
	var i=num.length;
	var status;
	status=0;
	if ((opt2!=1) && (num.charAt(0)=='-'))
	{
		//alert("You have enter a invalid number.");
		return 0;
	
	}
	if (num.charAt(i-1)=='.')
	{
		//alert("You have enter a invalid number.");
		return 0;
	}

	for (j=0;j<i;j++)
	{
		if (num.charAt(j)=='.')
		{
			status++;
		}

		if (status>1) 
		{
		//alert("You have enter a invalid number.");
		return 0;		
		}
		if (num.charAt(j)<'0' || num.charAt(j)>'9' )
		{
			if (((opt1==0) || (num.charAt(j)!='.')) && (j!=0)) 
			{
				//alert("You have enter a invalid number.");
				return 0;
			}
		}
	}
	return 1;
}


function chkdate(datestr)
{
	var lthdatestr=datestr.length;
	var tmpy="";
	var tmpm="";
	var tmpd="";
	var datestr;
	var status;
	status=0;
	for (i=0;i<lthdatestr;i++)
	{	if (datestr.charAt(i)== '-')
		{
			status++;
		}
		if (status>2)
		{
			//alert("Invalid format of date!");
			return 0;
		}
		if ((status==0) && (datestr.charAt(i)!='-'))
		{
			tmpy=tmpy+datestr.charAt(i)
		}
		if ((status==1) && (datestr.charAt(i)!='-'))
		{
			tmpm=tmpm+datestr.charAt(i)
		}
		if ((status==2) && (datestr.charAt(i)!='-'))
		{
			tmpd=tmpd+datestr.charAt(i)
		}

	}
	year=new String (tmpy);
	month=new String (tmpm);
	day=new String (tmpd)
	//tempdate= new String (year+month+day);
	//alert(tempdate);
	if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
	{
		//alert("Invalid format of date!");
		return 0;
	}
	if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
	{
		//alert ("Invalid month or day!");
		return 0;
	}
	if (!((year % 4)==0) && (month==2) && (day==29))
	{
		//alert ("This is not a leap year!");
		return 0;
	}
	if ((month<=7) && ((month % 2)==0) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	
	}
	if ((month>=8) && ((month % 2)==1) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	}
	if ((month==2) && (day==30))
	{
		//alert("The Febryary never has this day!");
		return 0;
	}
	return 1;
}


function fucPWDchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()_-+=|\}{[]:;'?/>.,<";
  var ch;
  var i;
  var temp;
  
  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  } 
}


function fucStrchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var ch;
  var i;
  var temp;
  
  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  } 
}

function jtrim(str)
{     while ((str.charAt(0)==" ")||(str.charAt(0)=="¡¡"))
          {str=str.substr(1);}      
     while (str.charAt(str.length-1)==" ")
         {str=str.substr(0,str.length-1);}
     return(str);
}


function fucCheckNUM(NUM)
{
	var i,j,strTemp;
	strTemp="0123456789";
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1)
		{
			return 0;
		}
	}
	return 1;
}


function fucCheckTel(Tel)
{
	var i,j,strTemp;
	strTemp="0123456789-#()";
	if (Tel.length < 7 )
	{
	 return 0;
	 }
	for (i=0;i<Tel.length;i++)
	{
		j=strTemp.indexOf(Tel.charAt(i));	
		if (j==-1)
		{
			return 0;
		}
	}
	return 1;
}


function fucCheckLength(strTemp)
{
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}

function jreplace(str)
{
	var strTemp=str;
	var i=0;
	while (i!=-1)
	{
		i=strTemp.indexOf("'");
		if (i!=-1)
		{
			strTemp=strTemp.substring(0,i)+"¡¯"+strTemp.substring(i+1,strTemp.length);
		}
	}
	return strTemp;
}


function fucChkFileName(filename, filenarr)
{
	var intfarrlen = filenarr.length;
	var intflen = filename.length;
	var strfilen = filename.toLowerCase();
	for (i=0;i<intflen;i++)
	{
			temp=filenarr[i];
			if ( temp==strfilen )
			{
				//You upload a image
				return 1;
			}

	}
	return 0;
}


function datechange(strDate)
{
	var tempy="";
	var tempm="";
	var tempd="";
	var tempDate;
	var status;
	status=0;
	for (i=0;i<strDate.length;i++)
	{	if (strDate.charAt(i)== '-')
		{
			status++;
		}
		if ((status==0) && (strDate.charAt(i)!='-'))
		{
			tempy=tempy+strDate.charAt(i);
		}
		if ((status==1) && (strDate.charAt(i)!='-'))
		{
			tempm=tempm+strDate.charAt(i);
		}
		if ((status==2) && (strDate.charAt(i)!='-'))
		{
			tempd=tempd+strDate.charAt(i);
		}

	}
	tempy="0000"+tempy;tempy=tempy.substring(tempy.length-4,tempy.length);
	tempm="00"+tempm;tempm=tempm.substring(tempm.length-2,tempm.length);
	tempd="00"+tempd;tempd=tempd.substring(tempd.length-2,tempd.length);
	tempDate=tempy+"-"+tempm+"-"+tempd;
	return tempDate;

}


function fucDateLimit(strDate)
{
	var strTempYear;
	strTempYear=strDate.substring(0,4);
	if ((strTempYear<"1900") ||(strTempYear>"2999"))
	{
		return false;
	}
	return true;
}


function fucCheckNumeric(NUM)
{
	var i,j,strTemp;
	var PointNum;
	PointNum=0
	strTemp="0123456789.";
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));	
		if (j==-1)
		{
			return 0;
		}
		if(j==10)
		{
			PointNum=PointNum+1;
		}
		
	}
	if(PointNum>1)
	{
		return 0;
	}
	return 1;
}


var flag=false;
function DrawImage(ImgD,x,y){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= x/y){
     if(image.width>x){  
     ImgD.width=x;
     ImgD.height=(image.height*x)/image.width;
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"x"+image.height;
     }
    else{
     if(image.height>y){  
     ImgD.height=y;
     ImgD.width=(image.width*y)/image.height;     
     }else{
     ImgD.width=image.width;  
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"x"+image.height;
     }
    }
} 

function doZoom(size){ 
		document.getElementById('zoom').style.fontSize=size+'px'
	setTailPosition()
	}
	
function phone(phone)
{
    var phoneNum = " 1234567890()-+";
    var temp;
    if (phone.length < 7)
    {
         return (false);
    }
    for (var i = 0; i < phone.length; i++)
    {
        temp = phone.substring(i,i+1);
        if (phoneNum.indexOf(temp) == -1)
        {
            return (false);
        }
    }
}

function strangecode(code)
{   var strangCode = "~`!@#$%^&*()_+=-|\'/£¿,£¬¡£.<>";
    var temp;
    for (var i = 0; i<code.length; i++ )
    {
        temp = code.substring(i,i+1);
        if (strangCode.indexOf(temp) !=-1)
        {
            return (false);
        }
    }
}


function isNumber(input)
{   var number = "1234567890";
    var temp;
    var j=0;
    for (var i = 0; i < input.length; i++ )
    {
        temp = input.substring(i,i+1);
        if (number.indexOf(temp) == -1)
        {
            return (false);
        }
    }
}

				function editTable(sid,hid)
                    {
                      whichEl = eval(sid);
                      if (whichEl.style.display == "none")
                         {
                           eval(sid + ".style.display=\"\";");
                          }
                          else
                           {
                           eval(sid + ".style.display=\"none\";");
                          }
						  if(hid!="")
						    {
							 whichHl = eval(hid);
                             if (whichHl.style.display == "none")
                             {
                              eval(hid + ".style.display=\"\";");
                              }
                              else
                             {
                              eval(hid + ".style.display=\"none\";");
                              }
							}
						  
                        }
						
function TableBgLock(Obj){
	if(!Obj.checked){
		Obj.style.backgroundColor='';
	}else{
		Obj.style.backgroundColor='orange';
	}
	if(checkSub(document.all['list'],'chkId')>0)
	{
	  document.all['list'].bsel[0].disabled=false;	
	  document.all['list'].bsel[1].disabled=false;	
    }
	else
	{
	  document.all['list'].bsel[0].disabled=true;	
	  document.all['list'].bsel[1].disabled=true;	
    }
}

function check(checked,id,theform)
{
  for(var i=0;i<theform.elements.length;i++)
  {  
     var e = theform.elements[i];
     if (e.name == id) {
        e.checked = checked;
		TableBgLock(e);
     }
  }
}


function checkSub(theform,theid)
{
  var k=0;
  for(var i=0;i<theform.elements.length;i++)
  {  
     var e = theform.elements[i];
	 //alert(e.name+"|"+theid);
     if (e.name == theid) {
     if(e.checked==true)
	    {
		  k++;
		}
     }
  }
	
	//}
  //}
 return k;
}


function checkAdd(theform,theid)
  {
    if(checkSub(theform,theid)>=1)
	  {
		  theform.submit();
	  }
	  else
	  {
	   alert("Please select an information.");
	   return false;
	  }
  }


//register select category
function selectCatalog()
 {
 if(document.all) //IE 
 {
 showModalDialog('catalog.asp',window,'dialogWidth:590px;dialogHeight:260px;help:no;scroll:no;status:no');
 }
 else
 {
 window.open('catalog.asp','xwindow','width=590,height=260,modal=yes')
	 }
 }	

function showDialog(url)
{
	 if(document.all) //IE 
	   {
		 showModalDialog(url,window,'dialogWidth:777px;dialogHeight:400px;help:no;scroll:no;status:no');
 //window.open(url,'xwindow','')
	   }
	 else
	   {
		 window.open(url,'wwindow','width=777,height=400,modal=yes')
	   }
}

function previewObj(type,url)
{
 if(url=="")
   {alert("Sorry,no information.\nPlease click 'Upload' button to upload file.");}
 else
 {
	 if( document.all) //IE 
	   {
	 showModalDialog('/Upload/Preview.asp?type='+type+'&url='+url,window,'dialogWidth:500px;dialogHeight:400px;help:no;scroll:no;status:no');
	   }
 	else
 	  {
 window.open('/Upload/Preview.asp?type='+type+'&url='+url,'swindow','width=500,height=400,modal=yes')
	  }
	 
 }
}

