<?php
include_once( SAXUE_ROOT_PATH . "/lib/form/form.php" );
class saxuethemeform extends saxueform {
		function insertbreak( $_extra = null ) {
				if ( !isset( $_extra ) ) {
						$_extra = "<tr><td colspan=\"2\"></td></tr>";
						$this -> addelement( $_extra );
				} else {
						$_extra = "<tr><td colspan=\"2\">" . $_extra . "</td></tr>";
						$this -> addelement( $_extra );
				} 
		} 

		function render( $_width = "100%" ) {
				$_required = $this -> getrequired();
				$_ret = "\n<form name=\"" . $this -> getname() . "\" id=\"" . $this -> getname() . "\" action=\"" . $this -> getaction() . "\" method=\"" . $this -> getmethod() . "\" onsubmit=\"return saxueFormValidate_" . $this -> getname() . "();\"" . $this -> getextra() . ">\n<table width=\"" . $_width . "\" class=\"grid\" cellspacing=\"1\" align=\"center\">\n";
				foreach ( $this -> getelements() as $_ele ) {
						if ( !is_object( $_ele ) ) {
								$_ret .= $_ele;
						} else if ( !$_ele -> ishidden() ) {
								$_caption = $_ele -> getcaption();
								if ( empty( $_caption ) ) {
										$_ret .= "<tr><td colspan=\"2\" class=\"head\">" . $_ele -> render() . "</td></tr>\n";
								} elseif ( $_caption == "colspan" ) {
										$_ret .= "<tr><td colspan=\"2\" class=\"c_colspan\">" . $_ele -> render() . "</td></tr>\n";
								} elseif ( $_caption == "&nbsp;" ) {
										$_ret .= "<tr><td colspan=\"2\" class=\"c_button\">" . $_ele -> render() . "</td></tr>\n";
								} else {
										$_ret .= "<tr><td colspan=\"2\" class=\"c_title\">" . $_caption . ":</td></tr>\n<tr class=\"c_row\">\n  <td class=\"c_content\">" . $_ele -> render() . "</td>\n  <td class=\"c_description\" valign=\"top\">" . $_ele -> getdescription();
										if ( $_ele -> getintro() != "" ) {
												$_ret .= "<br /><span class=\"c_intro\">" . $_ele -> getintro() . "</span>";
										} 
										$_ret .= "</td>\n</tr>\n";
								} 
						} else {
								$_ret .= $_ele -> render();
						} 
				} 
				$_js = "\r\n<script language=\"javascript\" type=\"text/javascript\">\r\n<!--\r\nfunction saxueFormValidate_" . $this -> getname() . "(){\r\n";
				$_required = $this -> getrequired();
				$_requirenum = count( $_required );
				if ( !defined( "LANG_PLEASE_ENTER" ) ) {
						$_tips = "请输入%s";
				} else {
						$_tips = LANG_PLEASE_ENTER;
				} 
				$_i = 0;
				for ( ; $_i < $_requirenum; ++$_i ) {
						$_js .= "  if(document." . $this -> getname() . "." . $_required[$_i] -> getname() . ".value == \"\"){\r\n    alert(\"" . sprintf( $_tips, preg_replace( array( "/\\<span[^\\<\\>]*\\>[^\\<\\>]*\\<\\/span\\>/is", "/\\<div[^\\<\\>]*\\>[^\\<\\>]*\\<\\/div\\>/is", "/\\<font[^\\<\\>]*\\>[^\\<\\>]*\\<\\/font\\>/is" ), "", str_replace( array( "\\", "\"" ), array( "\\\\", "\\\"" ), $_required[$_i] -> getcaption() ) ) ) . "\");\r\n    document." . $this -> getname() . "." . $_required[$_i] -> getname() . ".focus();\r\n    return false;\r\n  }\r\n";
				} 
				$_js .= "}\r\n//-->\r\n</script>\n";
				$_ret .= "</table>\n</form>\n";
				$_ret .= $_js;
				return $_ret;
		} 
} 
