//----------------------------------------------------------------------------------------------------------------------
//
// ACP Version	: 1.5
// Script 			: jscript/functions.js
// Last Edit 		: October 16, 2008 03:37:01 PM 
//
//----------------------------------------------------------------------------------------------------------------------

function checkImageWidth( a, b )
{
   return a > b;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function windowOpen( page )
{
	
		var width 	= 700;
		var height 	= 550;
	
		var top = (screen.height / 2) - (height / 2);
		var left = (screen.width / 2) - (width / 2);

		window.open( page,'','top='+top+',left='+left+',width='+width+',height='+height+',scrollbars=1,status=1')

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPcheckEmail( the_email )
{
		var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		if( regex.test( the_email ) )
		{
			return true;
		}
		else
		{
			return false;
		}
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPcheckSingleBox( the_form, the_value )
{
	  for ( var i = 0; i < document.forms[the_form].elements.length; i++ )
	  {
		    if( document.forms[the_form].elements[i].type == 'checkbox' && document.forms[the_form].elements[i].value == the_value )
		    {
			      if( document.forms[the_form].elements[i].checked == false )
			      {
				      	document.forms[the_form].elements[i].checked = true;
			      }
			      else
			      {
				      	document.forms[the_form].elements[i].checked = false;
			      }
		    }
	  }
	  // end for(i)
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPcheckUrl( url )
{
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(url);
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPchangeBgTo( highlightcolor )
{
	source=event.srcElement
	if (source.tagName=="TR"||source.tagName=="TABLE")
	return
	while(source.tagName!="TR")
	source=source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
	source.style.backgroundColor=highlightcolor
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPchangeBgBack( originalcolor )
{
	if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
	return
	if (event.toElement!=source)
	source.style.backgroundColor=originalcolor
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPhtmlPreview( width,height,title,text,close )
{
		var w 		= screen.availWidth;
		var h 		= screen.availHeight;
		var left 	= (w-width)/2;
		var top 	= (h-height)/2;
    var prevWnd=window.open("", "prvw", "left="+left+",top="+top+",width="+width+",height="+height+",scrollbars=1,resizable=1,status=0");
    prevWnd.document.open();
    prevWnd.document.writeln('<html>');
    prevWnd.document.writeln('<head>');
    prevWnd.document.writeln('<title>'+title+'</title>');
    prevWnd.document.writeln('<meta http-equiv="content-type" content="text/html; charset=Big5">');
    prevWnd.document.writeln('</head>');
    prevWnd.document.writeln('<body topmargin="5" leftmargin="5" onblur="self.focus()">');
		prevWnd.document.writeln('<div align="right"><input type="button" value=" [X] '+close+' " style="background-color: whitesmoke; color: blue;" onClick="window.close();"></div><hr size="1">');
    prevWnd.document.writeln(text);
    prevWnd.document.writeln('</body></html>');
    prevWnd.document.close();							
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPcheckDigit( the_object )
{
	  var regex 	= new RegExp(/^\d+$/);
	  var result 	= regex.test(the_object.value);
	  
	  if( the_object.value.length == 0 )
	  {
		  return true;
	  }
	  else if( ! result )
	  {
		  return false;
	  }
	  else
	  {
		  return true;
	  }
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPautoSelectAll( the_form, the_select, the_choice )
{
    var selects = document.forms[the_form].elements[the_select];
    var count  = selects.length;

    for( var i = 0; i < count; i++ )
    {
        selects.options[i].selected = the_choice;
    }
    // end for

    return true;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPradioButtonCheck( the_form, the_object )
{
		var check = false;
		
		for ( var i = 0; i < document.forms[the_form].elements[the_object].length; i++ )
		{
			if( document.forms[the_form].elements[the_object][i].checked )
			{
				check = true;
			}
		}
		// end for(i)
		
		if( i==0 )
		{
			check = true;
		}
		
		return check;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//---------------------------------------------------------------------------
// Check or uncheck all 'checkbox', use with buttons
//---------------------------------------------------------------------------

function ACPcheckUncheckAll( the_form )
{
	  var t = 1;
	  
	  for ( var i = 0; i < document.forms[the_form].elements.length; i++ )
	  {
		    if( document.forms[the_form].elements[i].type == 'checkbox' )
		    {
						if( t )
						{
								t = 0;
								chk =! document.forms[the_form].elements[i].checked;
						}
			      document.forms[the_form].elements[i].checked = chk;
		    }
	  }
	  // end for(i)
}
// end of function

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPautoCheckAll( the_form, the_choice )
{
	  for ( var i = 0; i < document.forms[the_form].elements.length; i++ )
	  {
		    if( document.forms[the_form].elements[i].type == 'checkbox' )
		    {
			      document.forms[the_form].elements[i].checked = the_choice;
		    }
	  }
	  // end for(i)
}
// end of function

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ACPcountCheckedItems( the_form )
{
		j = 0;
		f = document.forms[the_form];
		
		for( i = 0; i < f.length; i++ )
		{
				e = f.elements[i];
				
				if( e.type == 'checkbox' && e.checked )
				{
						j++;
				}
		}
	
		return j;
}
// end of function

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------------------------
// Select or unselect the whole select field, use with checkbox or single button
//-------------------------------------------------------------------------------------

function ACPselectUnselectAll( the_form, the_select, all )
{
    var selects = document.forms[the_form].elements[the_select];
    var count  = selects.length;

    for( var i = 0; i < count; i++ )
    {
	    	if( document.forms[the_form].elements[all].checked )
	    	{
        	selects.options[i].selected = true;
      	}
      	else
      	{
	      	selects.options[i].selected = false;
      	}
    }
    // end for

    return true;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//---------------------------------------------------------------------------
// Verify and display error messages for backup page
//---------------------------------------------------------------------------

function ACPcheckSelectedItems( the_form, the_select, msg_1, msg_2, format )
{
		var j = 0;
    var selects = document.forms[the_form].elements[the_select];
    var count  = selects.length;

    for( var i = 0; i < count; i++ )
    {
			if( selects.options[i].selected == true ) j++;
    }
    // end for
    
    if( j < 1 )
    {
	    alert( msg_1 );
	    return false;
    }
    
    if( document.forms[the_form].elements[format][1].checked && j > 1 )
    {
	    alert( msg_2 );
	    return false;
    }
    
   	return true;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//---------------------------------------------------------------------------
// Select or unselect the whole select field, use with buttons
//---------------------------------------------------------------------------

function ACPselectUnselectAll2( the_form, the_select, the_choice )
{
    var selects = document.forms[the_form].elements[the_select];
    var count  = selects.length;

    for( var i = 0; i < count; i++ )
    {
        selects.options[i].selected = the_choice;
    }
    // end for

    return true;
}
// end func

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////