fbpx

Just put [php_everywhere] where you want the code to be executed.
validator_array = array();
$this->show_all_errors_together=true;
$this->error_hash = array();
$this->custom_validators=array();
}

function SetFileUploader(&$uploader)
{
$this->file_uploader = &$uploader;
$uploads = $this->file_uploader->getUploadFields();
foreach($this->validator_array as $val_obj)
{
if(false !== array_search($val_obj->variable_name,$uploads))
{
$command = ”;
$command_value = ”;
$this->parse_validator_string($val_obj->validator_string,
$command,$command_value);

$this->file_uploader->setFieldValidations($val_obj->variable_name,
$command,$command_value,$val_obj->error_string);
}
}
}
function SetDatabase(&$db)
{
$this->database = &$db;
}
function AddCustomValidator(&$customv)
{
array_push_ref($this->custom_validators,$customv);
}

function addValidation($variable,$validator,$error,$condition=””)
{
$validator_obj = new ValidatorObj();
$validator_obj->variable_name = $variable;
$validator_obj->validator_string = $validator;
$validator_obj->error_string = $error;
$validator_obj->condition = $condition;
array_push($this->validator_array,$validator_obj);
}

function Process(&$continue)
{
$bResult = true;

if(!$this->common_objs->security_monitor->Validate($this->formvars))
{
$this->error_handler->ShowError(“Form Security Check: Access Denied”,/*show form*/false);
$continue = false;
return false;
}

if(false == $this->ValidateForm($this->formvars))
{
$bResult = false;
}

if(count($this->custom_validators) > 0)
{
foreach( $this->custom_validators as $custom_val)
{
if(false == $custom_val->DoValidate($this->formvars,$this->error_hash))
{
$bResult = false;
}
}
}

if(false === $this->ext_module->DoValidate($this->formvars,$this->error_hash))
{
$bResult = false;
}

if(!$bResult)
{
$continue=false;
$this->error_handler->ShowInputError($this->error_hash,$this->formname);
return false;
}
else
{
$continue=true;
return true;
}
}

function ValidateCurrentPage($form_variables)
{
if(!$this->common_objs->formpage_renderer->IsPageNumSet())
{
return true;
}

$cur_page_num =
$this->common_objs->formpage_renderer->GetCurrentPageNum();

$bResult = $this->ValidatePage($cur_page_num,$form_variables);

if(false === $this->ext_module->DoValidatePage($this->formvars,$this->error_hash,$cur_page_num))
{
$bResult = false;
}

if(!$bResult)
{
$this->logger->LogInfo(“Page Validations $cur_page_num: Errors “.var_export($this->error_hash,TRUE));
$this->error_handler->ShowInputError($this->error_hash,$this->formname);
}
else
{
$this->logger->LogInfo(“Page Validations $cur_page_num: succeeded”);
}
return $bResult;
}

function IsThisElementInCurrentPage($varname)
{
$cur_page_num =
$this->common_objs->formpage_renderer->GetCurrentPageNum();

$elmnt_page =
$this->config->element_info->GetPageNum($varname);

return ($cur_page_num == $elmnt_page) ? true:false;
}
function ValidateForm($form_variables)
{
$bret = true;

$vcount = count($this->validator_array);
$this->logger->LogInfo(“Validating form data: number of validations: $vcount” );

foreach($this->validator_array as $val_obj)
{
$page_num =
$this->config->element_info->GetPageNum($val_obj->variable_name);

//See if the page is shown
if(!$this->common_objs->formpage_renderer->TestPageCondition($page_num,$form_variables))
{
continue;
}

if(!$this->ValidateOneObject($val_obj,$form_variables))
{
$bret = false;
if(false == $this->show_all_errors_together)
{
break;
}
}
}
return $bret;
}

function ValidateOneObject($val_obj,&$form_variables)
{
$error_string=””;
$bret = $this->ValidateObject($val_obj,$form_variables,$error_string);
if(!$bret)
{
$this->error_hash[$val_obj->variable_name] = $error_string;
}
return $bret;
}

function ValidatePage($page_num,$form_variables)
{
$bret = true;

$vcount = count($this->validator_array);

foreach($this->validator_array as $val_obj)
{
$elmnt_page =
$this->config->element_info->GetPageNum($val_obj->variable_name);

if($elmnt_page != $page_num)
{
continue;
}

if(!$this->ValidateOneObject($val_obj,$form_variables))
{
$this->logger->LogInfo(“Validating variable “.$val_obj->variable_name.” returns false” );
$bret = false;
if(false == $this->show_all_errors_together)
{
break;
}
}
}
return $bret;
}

function getErrors()
{
return $this->errors;
}
function parse_validator_string($validator_string,&$command,&$command_value)
{
$matches=”;
preg_match(‘/^([\w]+)(\=\s*(.*?))?\s*$/’, $validator_string, $matches);

$command = $matches[1];
$command_value = empty($matches[3]) ? ” : $matches[3];
}

function ValidateObject($validatorobj,$formvariables,&$error_string)
{
$bret = true;

//validation condition
if(isset($validatorobj->condition) &&
strlen($validatorobj->condition)>0)
{
if(false == $this->ValidateCondition(
$validatorobj->condition,$formvariables))
{
return true;
}
}

/*$splitted = explode(“=”,$validatorobj->validator_string);
$command = $splitted[0];
$command_value = ”;

if(isset($splitted[1]) && strlen($splitted[1])>0)
{
$command_value = $splitted[1];
}*/

$command = ”;
$command_value = ”;
$this->parse_validator_string($validatorobj->validator_string,$command,$command_value);

$default_error_message=””;

$input_value =””;

if(isset($formvariables[$validatorobj->variable_name]))
{
$input_value = $formvariables[$validatorobj->variable_name];
}

$extra_info=””;

$bret = $this->ValidateCommand($command,$command_value,$input_value,
$default_error_message,
$validatorobj->variable_name,
$extra_info,
$formvariables);

if(false == $bret)
{
if(isset($validatorobj->error_string) &&
strlen($validatorobj->error_string)>0)
{
$error_string = $validatorobj->error_string;
}
else
{
$error_string = $default_error_message;
}
if(strlen($extra_info)>0)
{
$error_string .= “\n”.$extra_info;
}

}//if
return $bret;
}

function ValidateCondition($condn,$formvariables)
{
return sfm_validate_multi_conditions($condn,$formvariables);
}

function validate_req($input_value, &$default_error_message,$variable_name)
{
$bret = true;
if(!isset($input_value))
{
$bret=false;
}
else
{
$input_value = trim($input_value);

if(strlen($input_value) <=0)
{
$bret=false;
}

$type = $this->config->element_info->GetType($variable_name);
if(“datepicker” == $type)
{
$date_obj = new FM_DateObj($this->formvars,$this->config,$this->logger);
if(!$date_obj->GetDateFieldInStdForm($variable_name))
{
$bret=false;
}
}
}
if(!$bret)
{
$default_error_message = sprintf(“Please enter the value for %s”,$variable_name);
}

return $bret;
}

function validate_maxlen($input_value,$max_len,$variable_name,&$extra_info,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length > $max_len)
{
$bret=false;
$default_error_message = sprintf(“Maximum length exceeded for %s.”,$variable_name);
}
}
return $bret;
}

function validate_minlen($input_value,$min_len,$variable_name,&$extra_info,&$default_error_message)
{
$bret = true;
if(isset($input_value) )
{
$input_length = strlen($input_value);
if($input_length < $min_len)
{
$bret=false;
//$extra_info = sprintf(E_VAL_MINLEN_EXTRA_INFO,$min_len,$input_length);
$default_error_message = sprintf(“Please enter input with length more than %d for %s”,$min_len,$variable_name);
}
}
return $bret;
}

function test_datatype($input_value,$reg_exp)
{
if(preg_match($reg_exp,$input_value))
{
return true;
}
return false;
}
/**
Source: http://www.linuxjournal.com/article/9585?page=0,3
*/
function validate_email($email)
{
$isValid = true;
$atIndex = strrpos($email, “@”);
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == ‘.’ || $local[$localLen-1] == ‘.’)
{
// local part starts or ends with ‘.’
$isValid = false;
}
else if (preg_match(‘/\\.\\./’, $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match(‘/^[A-Za-z0-9\\-\\.]+$/’, $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match(‘/\\.\\./’, $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if(!preg_match(‘/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\’*+?^{}|~.-])+$/’,
str_replace(“\\\\”,””,$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match(‘/^”(\\\\”|[^”])+”$/’,
str_replace(“\\\\”,””,$local)))
{
$isValid = false;
}
}
}
return $isValid;
}

//function validate_email($email)
//{
// return preg_match(“/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i”, $email);
//return preg_match(‘/^((([a-z]|\d|[!#\$%&\’\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&\’\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i’,$email);
//}

function make_number($input_value)
{
return str_replace(“,”,””,$input_value);
}

function validate_for_numeric_input($input_value,&$validation_success,&$extra_info)
{

$more_validations=true;
$validation_success = true;
if(strlen($input_value)>0)
{

if(false == is_numeric($input_value))
{
$extra_info = “Numeric value required.”;
$validation_success = false;
$more_validations=false;
}
}
else
{
$more_validations=false;
}
return $more_validations;
}

function validate_lessthan($command_value,$input_value,
$variable_name,&$default_error_message,&$extra_info )
{
$bret = true;
$input_value = $this->make_number($input_value);
if(false == $this->validate_for_numeric_input($input_value,
$bret,$extra_info))
{
return $bret;
}
if($bret)
{
$lessthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval >= $lessthan)
{
$default_error_message = sprintf(“Enter a value less than %f for %s”,
$lessthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}
function validate_greaterthan($command_value,$input_value,$variable_name,&$default_error_message,&$extra_info )
{
$bret = true;
$input_value = $this->make_number($input_value);
if(false == $this->validate_for_numeric_input($input_value,$bret,$extra_info))
{
return $bret;
}
if($bret)
{
$greaterthan = doubleval($command_value);
$float_inputval = doubleval($input_value);
if($float_inputval <= $greaterthan)
{
$default_error_message = sprintf(“Enter a value greater than %f for %s”,
$greaterthan,
$variable_name);
$bret = false;
}//if
}
return $bret ;
}

function validate_select($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=false;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=true;
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=true;
}
}
if(false == $bret)
{
$default_error_message = sprintf(“You should select option %s for %s”,
$command_value,$variable_name);
}
return $bret;
}

function validate_dontselect($input_value,$command_value,&$default_error_message,$variable_name)
{
$bret=true;
if(is_array($input_value))
{
foreach($input_value as $value)
{
if($value == $command_value)
{
$bret=false;
$default_error_message = sprintf(“Wrong option selected for %s”,$variable_name);
break;
}
}
}
else
{
if($command_value == $input_value)
{
$bret=false;
$default_error_message = sprintf(“Wrong option selected for %s”,$variable_name);
}
}
return $bret;
}

function ValidateComparison($input_value,$formvariables,
$command_value,&$extra_info,&$default_error_message,$variable_name,$command)
{
$bret = true;
if(isset($input_value) &&
isset($formvariables[$command_value]))
{
$input_value = $this->make_number($input_value);
$valueOther = $this->make_number($formvariables[$command_value]);

if(true == $this->validate_for_numeric_input($input_value,$bret,$extra_info) &&
true == $this->validate_for_numeric_input($valueOther,$bret,$extra_info))
{
$valueThis = doubleval($input_value);
$valueOther = doubleval($valueOther);
switch($command)
{
case “ltelmnt”:
{
if($valueThis >= $valueOther)
{
$bret = false;
$default_error_message = sprintf(“Value of %s should be less than that of %s”,$variable_name,$command_value);
}
break;
}
case “leelmnt”:
{
if($valueThis > $valueOther)
{
$bret = false;
$default_error_message = sprintf(“Value of %s should be less than or equal to that of %s”,$variable_name,$command_value);
}
break;
}
case “gtelmnt”:
{
if($valueThis <= $valueOther)
{
$bret = false;
$default_error_message = sprintf(“Value of %s should be greater that of %s”,$variable_name,$command_value);
}
break;
}
case “geelmnt”:
{
if($valueThis < $valueOther)
{
$bret = false;
$default_error_message = sprintf(“Value of %s should be greater or equal to that of %s”,$variable_name,$command_value);
}
break;
}

}//switch
}
}
return $bret;
}

function ValidateCommand($command,$command_value,$input_value,&$default_error_message,$variable_name,&$extra_info,$formvariables)
{
$bret=true;
switch($command)
{
case ‘required’:
{
$bret = $this->validate_req($input_value, $default_error_message,$variable_name);
break;
}

case ‘maxlen’:
{
$max_len = intval($command_value);
$bret = $this->validate_maxlen($input_value,$max_len,$variable_name,
$extra_info,$default_error_message);
break;
}

case ‘minlen’:
{
$min_len = intval($command_value);
$bret = $this->validate_minlen($input_value,$min_len,$variable_name,
$extra_info,$default_error_message);
break;
}

case ‘alnum’:
{
$bret= $this->test_datatype($input_value,”/^[A-Za-z0-9]*$/”);
if(false == $bret)
{
$default_error_message = sprintf(“Please provide an alpha-numeric input for %s”,$variable_name);
}
break;
}

case ‘alnum_s’:
{
$bret= $this->test_datatype($input_value,”/^[A-Za-z0-9\s]*$/”);
if(false == $bret)
{
$default_error_message = sprintf(“Please provide an alpha-numeric input for %s”,$variable_name);
}
break;
}

case ‘num’:
case ‘numeric’:
{
if(isset($input_value) && strlen($input_value)>0)
{
if(!preg_match(“/^[\-\+]?[\d\,]*\.?[\d]*$/”,$input_value))
{
$bret=false;
$default_error_message = sprintf(“Please provide numeric input for %s”,$variable_name);
}
}
break;
}

case ‘alpha’:
{
$bret= $this->test_datatype($input_value,”/^[A-Za-z]*$/”);
if(false == $bret)
{
$default_error_message = sprintf(“Please provide alphabetic input for %s”,$variable_name);
}
break;
}
case ‘alpha_s’:
{
$bret= $this->test_datatype($input_value,”/^[A-Za-z\s]*$/”);
if(false == $bret)
{
$default_error_message = sprintf(“Please provide alphabetic input for %s”,$variable_name);
}
break;
}
case ’email’:
{
if(isset($input_value) && strlen($input_value)>0)
{
$bret= $this->validate_email($input_value);
if(false == $bret)
{
$default_error_message = “Please provide a valid email address”;
}
}
break;
}
case “lt”:
case “lessthan”:
{
$bret = $this->validate_lessthan($command_value,
$input_value,
$variable_name,
$default_error_message,
$extra_info );
break;
}
case “gt”:
case “greaterthan”:
{
$bret = $this->validate_greaterthan($command_value,
$input_value,
$variable_name,
$default_error_message,
$extra_info );
break;
}

case “regexp”:
{
if(isset($input_value) && strlen($input_value)>0)
{
if(!preg_match(“$command_value”,$input_value))
{
$bret=false;
$default_error_message = sprintf(“Please provide a valid input for %s”,$variable_name);
}
}
break;
}
case “dontselect”:
case “dontselectchk”:
case “dontselectradio”:
{
$bret = $this->validate_dontselect($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case

case “shouldselchk”:
case “selectradio”:
{
$bret = $this->validate_select($input_value,
$command_value,
$default_error_message,
$variable_name);
break;
}//case

case “selmin”:
{
$min_count = intval($command_value);
$bret = false;

if(is_array($input_value))
{
$bret = (count($input_value) >= $min_count )?true:false;
}
else
{
if(isset($input_value) && !empty($input_value) && $min_count == 1)
{
$bret = true;
}
}
if(!$bret)
{
$default_error_message = sprintf(“Please select minimum %d options for %s”,
$min_count,$variable_name);

}

break;
}//case
case “selmax”:
{
$max_count = intval($command_value);

if(isset($input_value))
{
$bret = (count($input_value) > $max_count )?false:true;
}

break;
}//case
case “selone”:
{
if(false == isset($input_value)||
strlen($input_value)<=0)
{
$bret= false;
$default_error_message = sprintf(“Please select an option for %s”,$variable_name);
}
break;
}
case “eqelmnt”:
{
if(isset($formvariables[$command_value]) &&
strcmp($input_value,$formvariables[$command_value])==0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(“Value of %s should be same as that of %s”,$variable_name,$command_value);
}
break;
}
case “ltelmnt”:
case “leelmnt”:
case “gtelmnt”:
case “geelmnt”:
{
$bret= $this->ValidateComparison($input_value,$formvariables,
$command_value,$extra_info,$default_error_message,
$variable_name,
$command);
break;
}
case “neelmnt”:
{
if(!empty($input_value))
{
if(strcmp($input_value,$formvariables[$command_value]) !=0 )
{
$bret=true;
}
else
{
$bret= false;
$default_error_message = sprintf(“Value of %s should not be same as that of %s”,$variable_name,$command_value);
}
}
break;
}
case “req_file”:
case “max_filesize”:
case “file_extn”:
{
$bret= $this->ValidateFileUpload($variable_name,
$command,
$command_value,
$default_error_message);
break;
}

case “after_date”:
{
$bret = $this->ValidateDate($command_value,$variable_name,false,$formvariables);
}
break;

case “before_date”:
{
$bret = $this->ValidateDate($command_value,$variable_name,true,$formvariables);
}
break;
case “unique”:
{
//$input_value, $default_error_message,$variable_name
if($this->database)
{
$bret = $this->database->IsFieldUnique($variable_name,$input_value);
if(!$bret)
{
$default_error_message = “This value is already submitted”;
}
}
}
break;
}//switch
return $bret;
}//validdate command

function ValidateDate($command_value,$variable_name,$before,$formvariables)
{
$bret = true;
$date_obj = new FM_DateObj($formvariables,$this->config,$this->logger);

$date_other = $date_obj->GetOtherDate($command_value);

$date_this = $date_obj->GetDateFieldInStdForm($variable_name);

if(empty($formvariables[$variable_name]))
{
$bret=true;
}
else
if(!$date_other || !$date_this)
{
$this->logger->LogError(“Invalid date received. “.$formvariables[$variable_name]);
$bret=false;
}
else
{
$bret = $before ? strcmp($date_this,$date_other) < 0: strcmp($date_this,$date_other)>0;
}
if(!$bret)
{
$this->logger->LogError(“$variable_name: Date validation failed”);
}
return $bret;
}

function ValidateFileUpload($variable_name,$command,$command_value,&$default_error_message)
{
$bret=true;

if($command != ‘req_file’ && !$this->IsThisElementInCurrentPage($variable_name))
{
return true;
}

$bret = $this->file_uploader->ValidateFileUpload($variable_name,$command,
$command_value,$default_error_message,/*form_submitted*/true);
return $bret;
}//function
}//FM_FormValidator

class FM_DateObj
{
private $formvars;
private $config;
private $logger;

public function __construct(&$formvars,&$config,&$logger)
{
$this->formvars = &$formvars;
$this->config = &$config;
$this->logger = &$logger;
}

function GetDateFieldInStdForm($var_name)
{
if(!isset($this->formvars[$var_name]))
{
$this->logger->LogError(“date field $var_name is not set. returning false…”.@print_r($this->formvars,true));
return false;
}

$date_value = $this->formvars[$var_name];

//Note 14 July 2012:
//Date format is always YYYY-MM-DD at server side

return $this->GetDateFieldInStdFormInternal($date_value,’YYYY-MM-DD’);
}

function GetDateFieldInStdFormInternal($date_value,$date_format)
{
$day=0;
$mon =0;
$year=0;

if(empty($date_value))
{
return false;
}

$this->logger->LogInfo(“GetDateFieldInStdFormInternal:$date_value format:$date_format”);
$date_parts=array();

if(preg_match(‘#^(\d*)[\-\\\/\.](\d*)[\-\\\/\.](\d*)$#’,$date_value,$date_parts))
{
switch($date_format)
{
case “DD-MM-YYYY”:
$day = $date_parts[1];
$mon = $date_parts[2];
$year = $date_parts[3];
break;

case “MM-DD-YYYY”:
$mon = $date_parts[1];
$day = $date_parts[2];
$year = $date_parts[3];
break;

case “YYYY-MM-DD”:
$year = $date_parts[1];
$mon = $date_parts[2];
$day = $date_parts[3];
break;
}//switch
}
else
{
$monthnames=array(“jan”=>1,”feb”=>2,”mar”=>3,”apr”=>4,”may”=>5,”jun”=>6,”jul”=>7,”aug”=>8,
“sep”=>9,”oct”=>10,”nov”=>11,”dec”=>12);

switch($date_format)
{
case “DD-MON-YYYY”:
$date_parts=array();
preg_match(‘#(\d*)[\-\\\/\.](\w*)[\-\\\/\.](\d*)#’,$date_value,$date_parts);
$day = $date_parts[1];
$mon = $monthnames[strtolower($date_parts[2])];
$year = $date_parts[3];
break;

case “MON-DD-YYYY”:
$date_parts=array();
preg_match(‘#(\w*)[\-\\\/\.](\d*)[\-\\\/\.](\d*)#’,$date_value,$date_parts);
$mon = $monthnames[strtolower($date_parts[1])];
$day = $date_parts[2];
$year = $date_parts[3];
break;
}
}//else

if($year<=100 || $year > 3000 || $mon < 1 || $mon>12 || $day<1 || $day > 31 )
{
$this->logger->LogInfo(“Received bad date: $date_value”);
return false;
}
else
{
$ret_date = sprintf(“%04d-%02d-%02d”, $year, $mon, $day);
}

$this->logger->LogInfo(“return date in std form: $ret_date”);

return $ret_date;
}

function GetOtherDate($command_value)
{
$date_ret=”;
if(strcmp($command_value,”SameDay”)==0)
{
$date_ret = date(“Y-m-d”);
}
else
{
$cmd_parts=array();
preg_match(‘#^(\w+)\(([\d\w\-]+)\)$#’,$command_value,$cmd_parts);

if(‘FixedDate’ == $cmd_parts[1])
{
$date_ret = $this->GetDateFieldInStdFormInternal($cmd_parts[2],’YYYY-MM-DD’);
}
else
if(‘Field’ == $cmd_parts[1])
{
$date_ret = $this->GetDateFieldInStdForm($cmd_parts[2]);
}
}
return $date_ret;
}

}

/**
* PEAR, the PHP Extension and Application Repository
*
* PEAR class and PEAR_Error class
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Sterling Hughes
* @author Stig Bakken
* @author Tomas V.V.Cox
* @author Greg Beaver
* @copyright 1997-2010 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/

/**#@+
* ERROR constants
*/
define(‘PEAR_ERROR_RETURN’, 1);
define(‘PEAR_ERROR_PRINT’, 2);
define(‘PEAR_ERROR_TRIGGER’, 4);
define(‘PEAR_ERROR_DIE’, 8);
define(‘PEAR_ERROR_CALLBACK’, 16);
/**
* WARNING: obsolete
* @deprecated
*/
define(‘PEAR_ERROR_EXCEPTION’, 32);
/**#@-*/

if (substr(PHP_OS, 0, 3) == ‘WIN’) {
define(‘OS_WINDOWS’, true);
define(‘OS_UNIX’, false);
define(‘PEAR_OS’, ‘Windows’);
} else {
define(‘OS_WINDOWS’, false);
define(‘OS_UNIX’, true);
define(‘PEAR_OS’, ‘Unix’); // blatant assumption
}

$GLOBALS[‘_PEAR_default_error_mode’] = PEAR_ERROR_RETURN;
$GLOBALS[‘_PEAR_default_error_options’] = E_USER_NOTICE;
$GLOBALS[‘_PEAR_destructor_object_list’] = array();
$GLOBALS[‘_PEAR_shutdown_funcs’] = array();
$GLOBALS[‘_PEAR_error_handler_stack’] = array();

@ini_set(‘track_errors’, true);

/**
* Base class for other PEAR classes. Provides rudimentary
* emulation of destructors.
*
* If you want a destructor in your class, inherit PEAR and make a
* destructor method called _yourclassname (same name as the
* constructor, but with a “_” prefix). Also, in your constructor you
* have to call the PEAR constructor: $this->PEAR();.
* The destructor method will be called without parameters. Note that
* at in some SAPI implementations (such as Apache), any output during
* the request shutdown (in which destructors are called) seems to be
* discarded. If you need to get any debug information from your
* destructor, use error_log(), syslog() or something similar.
*
* IMPORTANT! To use the emulated destructors you need to create the
* objects by reference: $obj =& new PEAR_child;
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V.V. Cox
* @author Greg Beaver
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @see PEAR_Error
* @since Class available since PHP 4.0.2
* @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
*/
class PEAR
{
/**
* Whether to enable internal debug messages.
*
* @var bool
* @access private
*/
var $_debug = false;

/**
* Default error mode for this object.
*
* @var int
* @access private
*/
var $_default_error_mode = null;

/**
* Default error options used for this object when error mode
* is PEAR_ERROR_TRIGGER.
*
* @var int
* @access private
*/
var $_default_error_options = null;

/**
* Default error handler (callback) for this object, if error mode is
* PEAR_ERROR_CALLBACK.
*
* @var string
* @access private
*/
var $_default_error_handler = ”;

/**
* Which class to use for error objects.
*
* @var string
* @access private
*/
var $_error_class = ‘PEAR_Error’;

/**
* An array of expected errors.
*
* @var array
* @access private
*/
var $_expected_errors = array();

/**
* List of methods that can be called both statically and non-statically.
* @var array
*/
protected static $bivalentMethods = array(
‘setErrorHandling’ => true,
‘raiseError’ => true,
‘throwError’ => true,
‘pushErrorHandling’ => true,
‘popErrorHandling’ => true,
);

/**
* Constructor. Registers this object in
* $_PEAR_destructor_object_list for destructor emulation if a
* destructor object exists.
*
* @param string $error_class (optional) which class to use for
* error objects, defaults to PEAR_Error.
* @access public
* @return void
*/
function __construct($error_class = null)
{
$classname = strtolower(get_class($this));
if ($this->_debug) {
print “PEAR constructor called, class=$classname\n”;
}

if ($error_class !== null) {
$this->_error_class = $error_class;
}

while ($classname && strcasecmp($classname, “pear”)) {
$destructor = “_$classname”;
if (method_exists($this, $destructor)) {
global $_PEAR_destructor_object_list;
$_PEAR_destructor_object_list[] = &$this;
if (!isset($GLOBALS[‘_PEAR_SHUTDOWN_REGISTERED’])) {
register_shutdown_function(“_PEAR_call_destructors”);
$GLOBALS[‘_PEAR_SHUTDOWN_REGISTERED’] = true;
}
break;
} else {
$classname = get_parent_class($classname);
}
}
}

/**
* Only here for backwards compatibility.
* E.g. Archive_Tar calls $this->PEAR() in its constructor.
*
* @param string $error_class Which class to use for error objects,
* defaults to PEAR_Error.
*/
public function PEAR($error_class = null)
{
self::__construct($error_class);
}

/**
* Destructor (the emulated type of…). Does nothing right now,
* but is included for forward compatibility, so subclass
* destructors should always call it.
*
* See the note in the class desciption about output from
* destructors.
*
* @access public
* @return void
*/
function _PEAR() {
if ($this->_debug) {
printf(“PEAR destructor called, class=%s\n”, strtolower(get_class($this)));
}
}

public function __call($method, $arguments)
{
if (!isset(self::$bivalentMethods[$method])) {
trigger_error(
‘Call to undefined method PEAR::’ . $method . ‘()’, E_USER_ERROR
);
}
return call_user_func_array(
array(get_class(), ‘_’ . $method),
array_merge(array($this), $arguments)
);
}

public static function __callStatic($method, $arguments)
{
if (!isset(self::$bivalentMethods[$method])) {
trigger_error(
‘Call to undefined method PEAR::’ . $method . ‘()’, E_USER_ERROR
);
}
return call_user_func_array(
array(get_class(), ‘_’ . $method),
array_merge(array(null), $arguments)
);
}

/**
* If you have a class that’s mostly/entirely static, and you need static
* properties, you can use this method to simulate them. Eg. in your method(s)
* do this: $myVar = &PEAR::getStaticProperty(‘myclass’, ‘myVar’);
* You MUST use a reference, or they will not persist!
*
* @param string $class The calling classname, to prevent clashes
* @param string $var The variable to retrieve.
* @return mixed A reference to the variable. If not set it will be
* auto initialised to NULL.
*/
public static function &getStaticProperty($class, $var)
{
static $properties;
if (!isset($properties[$class])) {
$properties[$class] = array();
}

if (!array_key_exists($var, $properties[$class])) {
$properties[$class][$var] = null;
}

return $properties[$class][$var];
}

/**
* Use this function to register a shutdown method for static
* classes.
*
* @param mixed $func The function name (or array of class/method) to call
* @param mixed $args The arguments to pass to the function
*
* @return void
*/
public static function registerShutdownFunc($func, $args = array())
{
// if we are called statically, there is a potential
// that no shutdown func is registered. Bug #6445
if (!isset($GLOBALS[‘_PEAR_SHUTDOWN_REGISTERED’])) {
register_shutdown_function(“_PEAR_call_destructors”);
$GLOBALS[‘_PEAR_SHUTDOWN_REGISTERED’] = true;
}
$GLOBALS[‘_PEAR_shutdown_funcs’][] = array($func, $args);
}

/**
* Tell whether a value is a PEAR error.
*
* @param mixed $data the value to test
* @param int $code if $data is an error object, return true
* only if $code is a string and
* $obj->getMessage() == $code or
* $code is an integer and $obj->getCode() == $code
*
* @return bool true if parameter is an error
*/
public static function isError($data, $code = null)
{
if (!is_a($data, ‘PEAR_Error’)) {
return false;
}

if (is_null($code)) {
return true;
} elseif (is_string($code)) {
return $data->getMessage() == $code;
}

return $data->getCode() == $code;
}

/**
* Sets how errors generated by this object should be handled.
* Can be invoked both in objects and statically. If called
* statically, setErrorHandling sets the default behaviour for all
* PEAR objects. If called in an object, setErrorHandling sets
* the default behaviour for that object.
*
* @param object $object
* Object the method was called on (non-static mode)
*
* @param int $mode
* One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
*
* @param mixed $options
* When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
* of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
*
* When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
* to be the callback function or method. A callback
* function is a string with the name of the function, a
* callback method is an array of two elements: the element
* at index 0 is the object, and the element at index 1 is
* the name of the method to call in the object.
*
* When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
* a printf format string used when printing the error
* message.
*
* @access public
* @return void
* @see PEAR_ERROR_RETURN
* @see PEAR_ERROR_PRINT
* @see PEAR_ERROR_TRIGGER
* @see PEAR_ERROR_DIE
* @see PEAR_ERROR_CALLBACK
* @see PEAR_ERROR_EXCEPTION
*
* @since PHP 4.0.5
*/
protected static function _setErrorHandling(
$object, $mode = null, $options = null
) {
if ($object !== null) {
$setmode = &$object->_default_error_mode;
$setoptions = &$object->_default_error_options;
} else {
$setmode = &$GLOBALS[‘_PEAR_default_error_mode’];
$setoptions = &$GLOBALS[‘_PEAR_default_error_options’];
}

switch ($mode) {
case PEAR_ERROR_EXCEPTION:
case PEAR_ERROR_RETURN:
case PEAR_ERROR_PRINT:
case PEAR_ERROR_TRIGGER:
case PEAR_ERROR_DIE:
case null:
$setmode = $mode;
$setoptions = $options;
break;

case PEAR_ERROR_CALLBACK:
$setmode = $mode;
// class/object method callback
if (is_callable($options)) {
$setoptions = $options;
} else {
trigger_error(“invalid error callback”, E_USER_WARNING);
}
break;

default:
trigger_error(“invalid error mode”, E_USER_WARNING);
break;
}
}

/**
* This method is used to tell which errors you expect to get.
* Expected errors are always returned with error mode
* PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
* and this method pushes a new element onto it. The list of
* expected errors are in effect until they are popped off the
* stack with the popExpect() method.
*
* Note that this method can not be called statically
*
* @param mixed $code a single error code or an array of error codes to expect
*
* @return int the new depth of the “expected errors” stack
* @access public
*/
function expectError($code = ‘*’)
{
if (is_array($code)) {
array_push($this->_expected_errors, $code);
} else {
array_push($this->_expected_errors, array($code));
}
return count($this->_expected_errors);
}

/**
* This method pops one element off the expected error codes
* stack.
*
* @return array the list of error codes that were popped
*/
function popExpect()
{
return array_pop($this->_expected_errors);
}

/**
* This method checks unsets an error code if available
*
* @param mixed error code
* @return bool true if the error code was unset, false otherwise
* @access private
* @since PHP 4.3.0
*/
function _checkDelExpect($error_code)
{
$deleted = false;
foreach ($this->_expected_errors as $key => $error_array) {
if (in_array($error_code, $error_array)) {
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
$deleted = true;
}

// clean up empty arrays
if (0 == count($this->_expected_errors[$key])) {
unset($this->_expected_errors[$key]);
}
}

return $deleted;
}

/**
* This method deletes all occurences of the specified element from
* the expected error codes stack.
*
* @param mixed $error_code error code that should be deleted
* @return mixed list of error codes that were deleted or error
* @access public
* @since PHP 4.3.0
*/
function delExpect($error_code)
{
$deleted = false;
if ((is_array($error_code) && (0 != count($error_code)))) {
// $error_code is a non-empty array here; we walk through it trying
// to unset all values
foreach ($error_code as $key => $error) {
$deleted = $this->_checkDelExpect($error) ? true : false;
}

return $deleted ? true : PEAR::raiseError(“The expected error you submitted does not exist”); // IMPROVE ME
} elseif (!empty($error_code)) {
// $error_code comes alone, trying to unset it
if ($this->_checkDelExpect($error_code)) {
return true;
}

return PEAR::raiseError(“The expected error you submitted does not exist”); // IMPROVE ME
}

// $error_code is empty
return PEAR::raiseError(“The expected error you submitted is empty”); // IMPROVE ME
}

/**
* This method is a wrapper that returns an instance of the
* configured error class with this object’s default error
* handling applied. If the $mode and $options parameters are not
* specified, the object’s defaults are used.
*
* @param mixed $message a text error message or a PEAR error object
*
* @param int $code a numeric error code (it is up to your class
* to define these if you want to use codes)
*
* @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
* PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
*
* @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
* specifies the PHP-internal error level (one of
* E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
* If $mode is PEAR_ERROR_CALLBACK, this
* parameter specifies the callback function or
* method. In other error modes this parameter
* is ignored.
*
* @param string $userinfo If you need to pass along for example debug
* information, this parameter is meant for that.
*
* @param string $error_class The returned error object will be
* instantiated from this class, if specified.
*
* @param bool $skipmsg If true, raiseError will only pass error codes,
* the error message parameter will be dropped.
*
* @return object a PEAR error object
* @see PEAR::setErrorHandling
* @since PHP 4.0.5
*/
protected static function _raiseError($object,
$message = null,
$code = null,
$mode = null,
$options = null,
$userinfo = null,
$error_class = null,
$skipmsg = false)
{
// The error is yet a PEAR error object
if (is_object($message)) {
$code = $message->getCode();
$userinfo = $message->getUserInfo();
$error_class = $message->getType();
$message->error_message_prefix = ”;
$message = $message->getMessage();
}

if (
$object !== null &&
isset($object->_expected_errors) &&
count($object->_expected_errors) > 0 &&
count($exp = end($object->_expected_errors))
) {
if ($exp[0] == “*” ||
(is_int(reset($exp)) && in_array($code, $exp)) ||
(is_string(reset($exp)) && in_array($message, $exp))
) {
$mode = PEAR_ERROR_RETURN;
}
}

// No mode given, try global ones
if ($mode === null) {
// Class error handler
if ($object !== null && isset($object->_default_error_mode)) {
$mode = $object->_default_error_mode;
$options = $object->_default_error_options;
// Global error handler
} elseif (isset($GLOBALS[‘_PEAR_default_error_mode’])) {
$mode = $GLOBALS[‘_PEAR_default_error_mode’];
$options = $GLOBALS[‘_PEAR_default_error_options’];
}
}

if ($error_class !== null) {
$ec = $error_class;
} elseif ($object !== null && isset($object->_error_class)) {
$ec = $object->_error_class;
} else {
$ec = ‘PEAR_Error’;
}

if ($skipmsg) {
$a = new $ec($code, $mode, $options, $userinfo);
} else {
$a = new $ec($message, $code, $mode, $options, $userinfo);
}

return $a;
}

/**
* Simpler form of raiseError with fewer options. In most cases
* message, code and userinfo are enough.
*
* @param mixed $message a text error message or a PEAR error object
*
* @param int $code a numeric error code (it is up to your class
* to define these if you want to use codes)
*
* @param string $userinfo If you need to pass along for example debug
* information, this parameter is meant for that.
*
* @return object a PEAR error object
* @see PEAR::raiseError
*/
protected static function _throwError($object, $message = null, $code = null, $userinfo = null)
{
if ($object !== null) {
$a = &$object->raiseError($message, $code, null, null, $userinfo);
return $a;
}

$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
return $a;
}

public static function staticPushErrorHandling($mode, $options = null)
{
$stack = &$GLOBALS[‘_PEAR_error_handler_stack’];
$def_mode = &$GLOBALS[‘_PEAR_default_error_mode’];
$def_options = &$GLOBALS[‘_PEAR_default_error_options’];
$stack[] = array($def_mode, $def_options);
switch ($mode) {
case PEAR_ERROR_EXCEPTION:
case PEAR_ERROR_RETURN:
case PEAR_ERROR_PRINT:
case PEAR_ERROR_TRIGGER:
case PEAR_ERROR_DIE:
case null:
$def_mode = $mode;
$def_options = $options;
break;

case PEAR_ERROR_CALLBACK:
$def_mode = $mode;
// class/object method callback
if (is_callable($options)) {
$def_options = $options;
} else {
trigger_error(“invalid error callback”, E_USER_WARNING);
}
break;

default:
trigger_error(“invalid error mode”, E_USER_WARNING);
break;
}
$stack[] = array($mode, $options);
return true;
}

public static function staticPopErrorHandling()
{
$stack = &$GLOBALS[‘_PEAR_error_handler_stack’];
$setmode = &$GLOBALS[‘_PEAR_default_error_mode’];
$setoptions = &$GLOBALS[‘_PEAR_default_error_options’];
array_pop($stack);
list($mode, $options) = $stack[sizeof($stack) – 1];
array_pop($stack);
switch ($mode) {
case PEAR_ERROR_EXCEPTION:
case PEAR_ERROR_RETURN:
case PEAR_ERROR_PRINT:
case PEAR_ERROR_TRIGGER:
case PEAR_ERROR_DIE:
case null:
$setmode = $mode;
$setoptions = $options;
break;

case PEAR_ERROR_CALLBACK:
$setmode = $mode;
// class/object method callback
if (is_callable($options)) {
$setoptions = $options;
} else {
trigger_error(“invalid error callback”, E_USER_WARNING);
}
break;

default:
trigger_error(“invalid error mode”, E_USER_WARNING);
break;
}
return true;
}

/**
* Push a new error handler on top of the error handler options stack. With this
* you can easily override the actual error handler for some code and restore
* it later with popErrorHandling.
*
* @param mixed $mode (same as setErrorHandling)
* @param mixed $options (same as setErrorHandling)
*
* @return bool Always true
*
* @see PEAR::setErrorHandling
*/
protected static function _pushErrorHandling($object, $mode, $options = null)
{
$stack = &$GLOBALS[‘_PEAR_error_handler_stack’];
if ($object !== null) {
$def_mode = &$object->_default_error_mode;
$def_options = &$object->_default_error_options;
} else {
$def_mode = &$GLOBALS[‘_PEAR_default_error_mode’];
$def_options = &$GLOBALS[‘_PEAR_default_error_options’];
}
$stack[] = array($def_mode, $def_options);

if ($object !== null) {
$object->setErrorHandling($mode, $options);
} else {
PEAR::setErrorHandling($mode, $options);
}
$stack[] = array($mode, $options);
return true;
}

/**
* Pop the last error handler used
*
* @return bool Always true
*
* @see PEAR::pushErrorHandling
*/
protected static function _popErrorHandling($object)
{
$stack = &$GLOBALS[‘_PEAR_error_handler_stack’];
array_pop($stack);
list($mode, $options) = $stack[sizeof($stack) – 1];
array_pop($stack);
if ($object !== null) {
$object->setErrorHandling($mode, $options);
} else {
PEAR::setErrorHandling($mode, $options);
}
return true;
}

/**
* OS independent PHP extension load. Remember to take care
* on the correct extension name for case sensitive OSes.
*
* @param string $ext The extension name
* @return bool Success or not on the dl() call
*/
public static function loadExtension($ext)
{
if (extension_loaded($ext)) {
return true;
}

// if either returns true dl() will produce a FATAL error, stop that
if (
function_exists(‘dl’) === false ||
ini_get(‘enable_dl’) != 1
) {
return false;
}

if (OS_WINDOWS) {
$suffix = ‘.dll’;
} elseif (PHP_OS == ‘HP-UX’) {
$suffix = ‘.sl’;
} elseif (PHP_OS == ‘AIX’) {
$suffix = ‘.a’;
} elseif (PHP_OS == ‘OSX’) {
$suffix = ‘.bundle’;
} else {
$suffix = ‘.so’;
}

return @dl(‘php_’.$ext.$suffix) || @dl($ext.$suffix);
}
}

function _PEAR_call_destructors()
{
global $_PEAR_destructor_object_list;
if (is_array($_PEAR_destructor_object_list) &&
sizeof($_PEAR_destructor_object_list))
{
reset($_PEAR_destructor_object_list);

$destructLifoExists = PEAR::getStaticProperty(‘PEAR’, ‘destructlifo’);

if ($destructLifoExists) {
$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
}

while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
$classname = get_class($objref);
while ($classname) {
$destructor = “_$classname”;
if (method_exists($objref, $destructor)) {
$objref->$destructor();
break;
} else {
$classname = get_parent_class($classname);
}
}
}
// Empty the object list to ensure that destructors are
// not called more than once.
$_PEAR_destructor_object_list = array();
}

// Now call the shutdown functions
if (
isset($GLOBALS[‘_PEAR_shutdown_funcs’]) &&
is_array($GLOBALS[‘_PEAR_shutdown_funcs’]) &&
!empty($GLOBALS[‘_PEAR_shutdown_funcs’])
) {
foreach ($GLOBALS[‘_PEAR_shutdown_funcs’] as $value) {
call_user_func_array($value[0], $value[1]);
}
}
}

/**
* Standard PEAR error class for PHP 4
*
* This class is supserseded by {@link PEAR_Exception} in PHP 5
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V.V. Cox
* @author Gregory Beaver
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/manual/en/core.pear.pear-error.php
* @see PEAR::raiseError(), PEAR::throwError()
* @since Class available since PHP 4.0.2
*/
class PEAR_Error
{
var $error_message_prefix = ”;
var $mode = PEAR_ERROR_RETURN;
var $level = E_USER_NOTICE;
var $code = -1;
var $message = ”;
var $userinfo = ”;
var $backtrace = null;

/**
* PEAR_Error constructor
*
* @param string $message message
*
* @param int $code (optional) error code
*
* @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
* PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
*
* @param mixed $options (optional) error level, _OR_ in the case of
* PEAR_ERROR_CALLBACK, the callback function or object/method
* tuple.
*
* @param string $userinfo (optional) additional user/debug info
*
* @access public
*
*/
function __construct($message = ‘unknown error’, $code = null,
$mode = null, $options = null, $userinfo = null)
{
if ($mode === null) {
$mode = PEAR_ERROR_RETURN;
}
$this->message = $message;
$this->code = $code;
$this->mode = $mode;
$this->userinfo = $userinfo;

$skiptrace = PEAR::getStaticProperty(‘PEAR_Error’, ‘skiptrace’);

if (!$skiptrace) {
$this->backtrace = debug_backtrace();
if (isset($this->backtrace[0]) && isset($this->backtrace[0][‘object’])) {
unset($this->backtrace[0][‘object’]);
}
}

if ($mode & PEAR_ERROR_CALLBACK) {
$this->level = E_USER_NOTICE;
$this->callback = $options;
} else {
if ($options === null) {
$options = E_USER_NOTICE;
}

$this->level = $options;
$this->callback = null;
}

if ($this->mode & PEAR_ERROR_PRINT) {
if (is_null($options) || is_int($options)) {
$format = “%s”;
} else {
$format = $options;
}

printf($format, $this->getMessage());
}

if ($this->mode & PEAR_ERROR_TRIGGER) {
trigger_error($this->getMessage(), $this->level);
}

if ($this->mode & PEAR_ERROR_DIE) {
$msg = $this->getMessage();
if (is_null($options) || is_int($options)) {
$format = “%s”;
if (substr($msg, -1) != “\n”) {
$msg .= “\n”;
}
} else {
$format = $options;
}
die(sprintf($format, $msg));
}

if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
call_user_func($this->callback, $this);
}

if ($this->mode & PEAR_ERROR_EXCEPTION) {
trigger_error(“PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions”, E_USER_WARNING);
eval(‘$e = new Exception($this->message, $this->code);throw($e);’);
}
}

/**
* Only here for backwards compatibility.
*
* Class “Cache_Error” still uses it, among others.
*
* @param string $message Message
* @param int $code Error code
* @param int $mode Error mode
* @param mixed $options See __construct()
* @param string $userinfo Additional user/debug info
*/
public function PEAR_Error(
$message = ‘unknown error’, $code = null, $mode = null,
$options = null, $userinfo = null
) {
self::__construct($message, $code, $mode, $options, $userinfo);
}

/**
* Get the error mode from an error object.
*
* @return int error mode
* @access public
*/
function getMode()
{
return $this->mode;
}

/**
* Get the callback function/method from an error object.
*
* @return mixed callback function or object/method array
* @access public
*/
function getCallback()
{
return $this->callback;
}

/**
* Get the error message from an error object.
*
* @return string full error message
* @access public
*/
function getMessage()
{
return ($this->error_message_prefix . $this->message);
}

/**
* Get error code from an error object
*
* @return int error code
* @access public
*/
function getCode()
{
return $this->code;
}

/**
* Get the name of this error/exception.
*
* @return string error/exception name (type)
* @access public
*/
function getType()
{
return get_class($this);
}

/**
* Get additional user-supplied information.
*
* @return string user-supplied information
* @access public
*/
function getUserInfo()
{
return $this->userinfo;
}

/**
* Get additional debug information supplied by the application.
*
* @return string debug information
* @access public
*/
function getDebugInfo()
{
return $this->getUserInfo();
}

/**
* Get the call backtrace from where the error was generated.
* Supported with PHP 4.3.0 or newer.
*
* @param int $frame (optional) what frame to fetch
* @return array Backtrace, or NULL if not available.
* @access public
*/
function getBacktrace($frame = null)
{
if (defined(‘PEAR_IGNORE_BACKTRACE’)) {
return null;
}
if ($frame === null) {
return $this->backtrace;
}
return $this->backtrace[$frame];
}

function addUserInfo($info)
{
if (empty($this->userinfo)) {
$this->userinfo = $info;
} else {
$this->userinfo .= ” ** $info”;
}
}

function __toString()
{
return $this->getMessage();
}

/**
* Make a string representation of this object.
*
* @return string a string with an object summary
* @access public
*/
function toString()
{
$modes = array();
$levels = array(E_USER_NOTICE => ‘notice’,
E_USER_WARNING => ‘warning’,
E_USER_ERROR => ‘error’);
if ($this->mode & PEAR_ERROR_CALLBACK) {
if (is_array($this->callback)) {
$callback = (is_object($this->callback[0]) ?
strtolower(get_class($this->callback[0])) :
$this->callback[0]) . ‘::’ .
$this->callback[1];
} else {
$callback = $this->callback;
}
return sprintf(‘[%s: message=”%s” code=%d mode=callback ‘.
‘callback=%s prefix=”%s” info=”%s”]’,
strtolower(get_class($this)), $this->message, $this->code,
$callback, $this->error_message_prefix,
$this->userinfo);
}
if ($this->mode & PEAR_ERROR_PRINT) {
$modes[] = ‘print’;
}
if ($this->mode & PEAR_ERROR_TRIGGER) {
$modes[] = ‘trigger’;
}
if ($this->mode & PEAR_ERROR_DIE) {
$modes[] = ‘die’;
}
if ($this->mode & PEAR_ERROR_RETURN) {
$modes[] = ‘return’;
}
return sprintf(‘[%s: message=”%s” code=%d mode=%s level=%s ‘.
‘prefix=”%s” info=”%s”]’,
strtolower(get_class($this)), $this->message, $this->code,
implode(“|”, $modes), $levels[$this->level],
$this->error_message_prefix,
$this->userinfo);
}
}

/*
* Local Variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* End:
*/
/**
* PHPMailer – PHP email creation and transport class.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag)
* @author Andy Prevost (codeworxtech)
* @author Brent R. Matzelle (original founder)
* @copyright 2012 – 2014 Marcus Bointon
* @copyright 2010 – 2012 Jim Jagielski
* @copyright 2004 – 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful – WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/

/**
* PHPMailer – PHP email creation and transport class.
* @package PHPMailer
* @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag)
* @author Andy Prevost (codeworxtech)
* @author Brent R. Matzelle (original founder)
*/
class PHPMailer
{
/**
* The PHPMailer Version number.
* @var string
*/
public $Version = ‘5.2.16’;

/**
* Email priority.
* Options: null (default), 1 = High, 3 = Normal, 5 = low.
* When null, the header is not set at all.
* @var integer
*/
public $Priority = null;

/**
* The character set of the message.
* @var string
*/
public $CharSet = ‘iso-8859-1’;

/**
* The MIME Content-type of the message.
* @var string
*/
public $ContentType = ‘text/plain’;

/**
* The message encoding.
* Options: “8bit”, “7bit”, “binary”, “base64”, and “quoted-printable”.
* @var string
*/
public $Encoding = ‘8bit’;

/**
* Holds the most recent mailer error message.
* @var string
*/
public $ErrorInfo = ”;

/**
* The From email address for the message.
* @var string
*/
public $From = ‘root@localhost’;

/**
* The From name of the message.
* @var string
*/
public $FromName = ‘Root User’;

/**
* The Sender email (Return-Path) of the message.
* If not empty, will be sent via -f to sendmail or as ‘MAIL FROM’ in smtp mode.
* @var string
*/
public $Sender = ”;

/**
* The Return-Path of the message.
* If empty, it will be set to either From or Sender.
* @var string
* @deprecated Email senders should never set a return-path header;
* it’s the receiver’s job (RFC5321 section 4.4), so this no longer does anything.
* @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
*/
public $ReturnPath = ”;

/**
* The Subject of the message.
* @var string
*/
public $Subject = ”;

/**
* An HTML or plain text message body.
* If HTML then call isHTML(true).
* @var string
*/
public $Body = ”;

/**
* The plain-text message body.
* This body can be read by mail clients that do not have HTML email
* capability such as mutt & Eudora.
* Clients that can read HTML will view the normal Body.
* @var string
*/
public $AltBody = ”;

/**
* An iCal message part body.
* Only supported in simple alt or alt_inline message types
* To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
* @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
* @link http://kigkonsult.se/iCalcreator/
* @var string
*/
public $Ical = ”;

/**
* The complete compiled MIME message body.
* @access protected
* @var string
*/
protected $MIMEBody = ”;

/**
* The complete compiled MIME message headers.
* @var string
* @access protected
*/
protected $MIMEHeader = ”;

/**
* Extra headers that createHeader() doesn’t fold in.
* @var string
* @access protected
*/
protected $mailHeader = ”;

/**
* Word-wrap the message body to this number of chars.
* Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
* @var integer
*/
public $WordWrap = 0;

/**
* Which method to use to send mail.
* Options: “mail”, “sendmail”, or “smtp”.
* @var string
*/
public $Mailer = ‘mail’;

/**
* The path to the sendmail program.
* @var string
*/
public $Sendmail = ‘/usr/sbin/sendmail’;

/**
* Whether mail() uses a fully sendmail-compatible MTA.
* One which supports sendmail’s “-oi -f” options.
* @var boolean
*/
public $UseSendmailOptions = true;

/**
* Path to PHPMailer plugins.
* Useful if the SMTP class is not in the PHP include path.
* @var string
* @deprecated Should not be needed now there is an autoloader.
*/
public $PluginDir = ”;

/**
* The email address that a reading confirmation should be sent to, also known as read receipt.
* @var string
*/
public $ConfirmReadingTo = ”;

/**
* The hostname to use in the Message-ID header and as default HELO string.
* If empty, PHPMailer attempts to find one with, in order,
* $_SERVER[‘SERVER_NAME’], gethostname(), php_uname(‘n’), or the value
* ‘localhost.localdomain’.
* @var string
*/
public $Hostname = ”;

/**
* An ID to be used in the Message-ID header.
* If empty, a unique id will be generated.
* @var string
*/
public $MessageID = ”;

/**
* The message Date to be used in the Date header.
* If empty, the current date will be added.
* @var string
*/
public $MessageDate = ”;

/**
* SMTP hosts.
* Either a single hostname or multiple semicolon-delimited hostnames.
* You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. “smtp1.example.com:25;smtp2.example.com”).
* You can also specify encryption type, for example:
* (e.g. “tls://smtp1.example.com:587;ssl://smtp2.example.com:465″).
* Hosts will be tried in order.
* @var string
*/
public $Host = ‘localhost’;

/**
* The default SMTP server port.
* @var integer
* @TODO Why is this needed when the SMTP class takes care of it?
*/
public $Port = 25;

/**
* The SMTP HELO of the message.
* Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
* one with the same method described above for $Hostname.
* @var string
* @see PHPMailer::$Hostname
*/
public $Helo = ”;

/**
* What kind of encryption to use on the SMTP connection.
* Options: ”, ‘ssl’ or ‘tls’
* @var string
*/
public $SMTPSecure = ”;

/**
* Whether to enable TLS encryption automatically if a server supports it,
* even if `SMTPSecure` is not set to ‘tls’.
* Be aware that in PHP >= 5.6 this requires that the server’s certificates are valid.
* @var boolean
*/
public $SMTPAutoTLS = true;

/**
* Whether to use SMTP authentication.
* Uses the Username and Password properties.
* @var boolean
* @see PHPMailer::$Username
* @see PHPMailer::$Password
*/
public $SMTPAuth = false;

/**
* Options array passed to stream_context_create when connecting via SMTP.
* @var array
*/
public $SMTPOptions = array();

/**
* SMTP username.
* @var string
*/
public $Username = ”;

/**
* SMTP password.
* @var string
*/
public $Password = ”;

/**
* SMTP auth type.
* Options are CRAM-MD5, LOGIN, PLAIN, NTLM, XOAUTH2, attempted in that order if not specified
* @var string
*/
public $AuthType = ”;

/**
* SMTP realm.
* Used for NTLM auth
* @var string
*/
public $Realm = ”;

/**
* SMTP workstation.
* Used for NTLM auth
* @var string
*/
public $Workstation = ”;

/**
* The SMTP server timeout in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* @var integer
*/
public $Timeout = 300;

/**
* SMTP class debug output mode.
* Debug output level.
* Options:
* * `0` No output
* * `1` Commands
* * `2` Data and commands
* * `3` As 2 plus connection status
* * `4` Low-level data output
* @var integer
* @see SMTP::$do_debug
*/
public $SMTPDebug = 0;

/**
* How to handle debug output.
* Options:
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to `
`, appropriate for browser output
* * `error_log` Output to error log as configured in php.ini
*
* Alternatively, you can provide a callable expecting two params: a message string and the debug level:
*
* $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
*

* @var string|callable
* @see SMTP::$Debugoutput
*/
public $Debugoutput = ‘echo’;

/**
* Whether to keep SMTP connection open after each message.
* If this is set to true then to close the connection
* requires an explicit call to smtpClose().
* @var boolean
*/
public $SMTPKeepAlive = false;

/**
* Whether to split multiple to addresses into multiple messages
* or send them all in one message.
* Only supported in `mail` and `sendmail` transports, not in SMTP.
* @var boolean
*/
public $SingleTo = false;

/**
* Storage for addresses when SingleTo is enabled.
* @var array
* @TODO This should really not be public
*/
public $SingleToArray = array();

/**
* Whether to generate VERP addresses on send.
* Only applicable when sending via SMTP.
* @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
* @link http://www.postfix.org/VERP_README.html Postfix VERP info
* @var boolean
*/
public $do_verp = false;

/**
* Whether to allow sending messages with an empty body.
* @var boolean
*/
public $AllowEmpty = false;

/**
* The default line ending.
* @note The default remains “\n”. We force CRLF where we know
* it must be used via self::CRLF.
* @var string
*/
public $LE = “\n”;

/**
* DKIM selector.
* @var string
*/
public $DKIM_selector = ”;

/**
* DKIM Identity.
* Usually the email address used as the source of the email.
* @var string
*/
public $DKIM_identity = ”;

/**
* DKIM passphrase.
* Used if your key is encrypted.
* @var string
*/
public $DKIM_passphrase = ”;

/**
* DKIM signing domain name.
* @example ‘example.com’
* @var string
*/
public $DKIM_domain = ”;

/**
* DKIM private key file path.
* @var string
*/
public $DKIM_private = ”;

/**
* Callback Action function name.
*
* The function that handles the result of the send email action.
* It is called out by send() for each email sent.
*
* Value can be any php callable: http://www.php.net/is_callable
*
* Parameters:
* boolean $result result of the send action
* string $to email address of the recipient
* string $cc cc email addresses
* string $bcc bcc email addresses
* string $subject the subject
* string $body the email body
* string $from email address of sender
* @var string
*/
public $action_function = ”;

/**
* What to put in the X-Mailer header.
* Options: An empty string for PHPMailer default, whitespace for none, or a string to use
* @var string
*/
public $XMailer = ”;

/**
* Which validator to use by default when validating email addresses.
* May be a callable to inject your own validator, but there are several built-in validators.
* @see PHPMailer::validateAddress()
* @var string|callable
* @static
*/
public static $validator = ‘auto’;

/**
* An instance of the SMTP sender class.
* @var SMTP
* @access protected
*/
protected $smtp = null;

/**
* The array of ‘to’ names and addresses.
* @var array
* @access protected
*/
protected $to = array();

/**
* The array of ‘cc’ names and addresses.
* @var array
* @access protected
*/
protected $cc = array();

/**
* The array of ‘bcc’ names and addresses.
* @var array
* @access protected
*/
protected $bcc = array();

/**
* The array of reply-to names and addresses.
* @var array
* @access protected
*/
protected $ReplyTo = array();

/**
* An array of all kinds of addresses.
* Includes all of $to, $cc, $bcc
* @var array
* @access protected
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
*/
protected $all_recipients = array();

/**
* An array of names and addresses queued for validation.
* In send(), valid and non duplicate entries are moved to $all_recipients
* and one of $to, $cc, or $bcc.
* This array is used only for addresses with IDN.
* @var array
* @access protected
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
* @see PHPMailer::$all_recipients
*/
protected $RecipientsQueue = array();

/**
* An array of reply-to names and addresses queued for validation.
* In send(), valid and non duplicate entries are moved to $ReplyTo.
* This array is used only for addresses with IDN.
* @var array
* @access protected
* @see PHPMailer::$ReplyTo
*/
protected $ReplyToQueue = array();

/**
* The array of attachments.
* @var array
* @access protected
*/
protected $attachment = array();

/**
* The array of custom headers.
* @var array
* @access protected
*/
protected $CustomHeader = array();

/**
* The most recent Message-ID (including angular brackets).
* @var string
* @access protected
*/
protected $lastMessageID = ”;

/**
* The message’s MIME type.
* @var string
* @access protected
*/
protected $message_type = ”;

/**
* The array of MIME boundary strings.
* @var array
* @access protected
*/
protected $boundary = array();

/**
* The array of available languages.
* @var array
* @access protected
*/
protected $language = array();

/**
* The number of errors encountered.
* @var integer
* @access protected
*/
protected $error_count = 0;

/**
* The S/MIME certificate file path.
* @var string
* @access protected
*/
protected $sign_cert_file = ”;

/**
* The S/MIME key file path.
* @var string
* @access protected
*/
protected $sign_key_file = ”;

/**
* The optional S/MIME extra certificates (“CA Chain”) file path.
* @var string
* @access protected
*/
protected $sign_extracerts_file = ”;

/**
* The S/MIME password for the key.
* Used only if the key is encrypted.
* @var string
* @access protected
*/
protected $sign_key_pass = ”;

/**
* Whether to throw exceptions for errors.
* @var boolean
* @access protected
*/
protected $exceptions = false;

/**
* Unique ID used for message ID and boundaries.
* @var string
* @access protected
*/
protected $uniqueid = ”;

/**
* Error severity: message only, continue processing.
*/
const STOP_MESSAGE = 0;

/**
* Error severity: message, likely ok to continue processing.
*/
const STOP_CONTINUE = 1;

/**
* Error severity: message, plus full stop, critical error reached.
*/
const STOP_CRITICAL = 2;

/**
* SMTP RFC standard line ending.
*/
const CRLF = “\r\n”;

/**
* The maximum line length allowed by RFC 2822 section 2.1.1
* @var integer
*/
const MAX_LINE_LENGTH = 998;

/**
* Constructor.
* @param boolean $exceptions Should we throw external exceptions?
*/
public function __construct($exceptions = null)
{
if ($exceptions !== null) {
$this->exceptions = (boolean)$exceptions;
}
}

/**
* Destructor.
*/
public function __destruct()
{
//Close any open SMTP connection nicely
$this->smtpClose();
}

/**
* Call mail() in a safe_mode-aware fashion.
* Also, unless sendmail_path points to sendmail (or something that
* claims to be sendmail), don’t pass params (not a perfect fix,
* but it will do)
* @param string $to To
* @param string $subject Subject
* @param string $body Message Body
* @param string $header Additional Header(s)
* @param string $params Params
* @access private
* @return boolean
*/
private function mailPassthru($to, $subject, $body, $header, $params)
{
//Check overloading of mail function to avoid double-encoding
if (ini_get(‘mbstring.func_overload’) & 1) {
$subject = $this->secureHeader($subject);
} else {
$subject = $this->encodeHeader($this->secureHeader($subject));
}
//Can’t use additional_parameters in safe_mode
//@link http://php.net/manual/en/function.mail.php
if (ini_get(‘safe_mode’) or !$this->UseSendmailOptions) {
$result = @mail($to, $subject, $body, $header);
} else {
$result = @mail($to, $subject, $body, $header, $params);
}
return $result;
}

/**
* Output debugging info via user-defined method.
* Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
* @see PHPMailer::$Debugoutput
* @see PHPMailer::$SMTPDebug
* @param string $str
*/
protected function edebug($str)
{
if ($this->SMTPDebug <= 0) {
return;
}
//Avoid clash with built-in function names
if (!in_array($this->Debugoutput, array(‘error_log’, ‘html’, ‘echo’)) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
return;
}
switch ($this->Debugoutput) {
case ‘error_log’:
//Don’t output, just log
error_log($str);
break;
case ‘html’:
//Cleans up output a bit for a better looking, HTML-safe output
echo htmlentities(
preg_replace(‘/[\r\n]+/’, ”, $str),
ENT_QUOTES,
‘UTF-8’
)
. “
\n”;
break;
case ‘echo’:
default:
//Normalize line breaks
$str = preg_replace(‘/\r\n?/ms’, “\n”, $str);
echo gmdate(‘Y-m-d H:i:s’) . “\t” . str_replace(
“\n”,
“\n \t “,
trim($str)
) . “\n”;
}
}

/**
* Sets message type to HTML or plain.
* @param boolean $isHtml True for HTML mode.
* @return void
*/
public function isHTML($isHtml = true)
{
if ($isHtml) {
$this->ContentType = ‘text/html’;
} else {
$this->ContentType = ‘text/plain’;
}
}

/**
* Send messages using SMTP.
* @return void
*/
public function isSMTP()
{
$this->Mailer = ‘smtp’;
}

/**
* Send messages using PHP’s mail() function.
* @return void
*/
public function isMail()
{
$this->Mailer = ‘mail’;
}

/**
* Send messages using $Sendmail.
* @return void
*/
public function isSendmail()
{
$ini_sendmail_path = ini_get(‘sendmail_path’);

if (!stristr($ini_sendmail_path, ‘sendmail’)) {
$this->Sendmail = ‘/usr/sbin/sendmail’;
} else {
$this->Sendmail = $ini_sendmail_path;
}
$this->Mailer = ‘sendmail’;
}

/**
* Send messages using qmail.
* @return void
*/
public function isQmail()
{
$ini_sendmail_path = ini_get(‘sendmail_path’);

if (!stristr($ini_sendmail_path, ‘qmail’)) {
$this->Sendmail = ‘/var/qmail/bin/qmail-inject’;
} else {
$this->Sendmail = $ini_sendmail_path;
}
$this->Mailer = ‘qmail’;
}

/**
* Add a “To” address.
* @param string $address The email address to send to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
*/
public function addAddress($address, $name = ”)
{
return $this->addOrEnqueueAnAddress(‘to’, $address, $name);
}

/**
* Add a “CC” address.
* @note: This function works with the SMTP mailer on win32, not with the “mail” mailer.
* @param string $address The email address to send to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
*/
public function addCC($address, $name = ”)
{
return $this->addOrEnqueueAnAddress(‘cc’, $address, $name);
}

/**
* Add a “BCC” address.
* @note: This function works with the SMTP mailer on win32, not with the “mail” mailer.
* @param string $address The email address to send to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
*/
public function addBCC($address, $name = ”)
{
return $this->addOrEnqueueAnAddress(‘bcc’, $address, $name);
}

/**
* Add a “Reply-To” address.
* @param string $address The email address to reply to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
*/
public function addReplyTo($address, $name = ”)
{
return $this->addOrEnqueueAnAddress(‘Reply-To’, $address, $name);
}

/**
* Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
* can’t validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
* be modified after calling this function), addition of such addresses is delayed until send().
* Addresses that have been added already return false, but do not throw exceptions.
* @param string $kind One of ‘to’, ‘cc’, ‘bcc’, or ‘ReplyTo’
* @param string $address The email address to send, resp. to reply to
* @param string $name
* @throws phpmailerException
* @return boolean true on success, false if address already used or invalid in some way
* @access protected
*/
protected function addOrEnqueueAnAddress($kind, $address, $name)
{
$address = trim($address);
$name = trim(preg_replace(‘/[\r\n]+/’, ”, $name)); //Strip breaks and trim
if (($pos = strrpos($address, ‘@’)) === false) {
// At-sign is misssing.
$error_message = $this->lang(‘invalid_address’) . ” (addAnAddress $kind): $address”;
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
}
return false;
}
$params = array($kind, $address, $name);
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
if ($kind != ‘Reply-To’) {
if (!array_key_exists($address, $this->RecipientsQueue)) {
$this->RecipientsQueue[$address] = $params;
return true;
}
} else {
if (!array_key_exists($address, $this->ReplyToQueue)) {
$this->ReplyToQueue[$address] = $params;
return true;
}
}
return false;
}
// Immediately add standard addresses without IDN.
return call_user_func_array(array($this, ‘addAnAddress’), $params);
}

/**
* Add an address to one of the recipient arrays or to the ReplyTo array.
* Addresses that have been added already return false, but do not throw exceptions.
* @param string $kind One of ‘to’, ‘cc’, ‘bcc’, or ‘ReplyTo’
* @param string $address The email address to send, resp. to reply to
* @param string $name
* @throws phpmailerException
* @return boolean true on success, false if address already used or invalid in some way
* @access protected
*/
protected function addAnAddress($kind, $address, $name = ”)
{
if (!in_array($kind, array(‘to’, ‘cc’, ‘bcc’, ‘Reply-To’))) {
$error_message = $this->lang(‘Invalid recipient kind: ‘) . $kind;
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
}
return false;
}
if (!$this->validateAddress($address)) {
$error_message = $this->lang(‘invalid_address’) . ” (addAnAddress $kind): $address”;
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
}
return false;
}
if ($kind != ‘Reply-To’) {
if (!array_key_exists(strtolower($address), $this->all_recipients)) {
array_push($this->$kind, array($address, $name));
$this->all_recipients[strtolower($address)] = true;
return true;
}
} else {
if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
$this->ReplyTo[strtolower($address)] = array($address, $name);
return true;
}
}
return false;
}

/**
* Parse and validate a string containing one or more RFC822-style comma-separated email addresses
* of the form “display name

” into an array of name/address pairs.
* Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
* Note that quotes in the name part are removed.
* @param string $addrstr The address list string
* @param bool $useimap Whether to use the IMAP extension to parse the list
* @return array
* @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
*/
public function parseAddresses($addrstr, $useimap = true)
{
$addresses = array();
if ($useimap and function_exists(‘imap_rfc822_parse_adrlist’)) {
//Use this built-in parser if it’s available
$list = imap_rfc822_parse_adrlist($addrstr, ”);
foreach ($list as $address) {
if ($address->host != ‘.SYNTAX-ERROR.’) {
if ($this->validateAddress($address->mailbox . ‘@’ . $address->host)) {
$addresses[] = array(
‘name’ => (property_exists($address, ‘personal’) ? $address->personal : ”),
‘address’ => $address->mailbox . ‘@’ . $address->host
);
}
}
}
} else {
//Use this simpler parser
$list = explode(‘,’, $addrstr);
foreach ($list as $address) {
$address = trim($address);
//Is there a separate name part?
if (strpos($address, ‘<‘) === false) {
//No separate name, just use the whole thing
if ($this->validateAddress($address)) {
$addresses[] = array(
‘name’ => ”,
‘address’ => $address
);
}
} else {
list($name, $email) = explode(‘<‘, $address);
$email = trim(str_replace(‘>’, ”, $email));
if ($this->validateAddress($email)) {
$addresses[] = array(
‘name’ => trim(str_replace(array(‘”‘, “‘”), ”, $name)),
‘address’ => $email
);
}
}
}
}
return $addresses;
}

/**
* Set the From and FromName properties.
* @param string $address
* @param string $name
* @param boolean $auto Whether to also set the Sender address, defaults to true
* @throws phpmailerException
* @return boolean
*/
public function setFrom($address, $name = ”, $auto = true)
{
$address = trim($address);
$name = trim(preg_replace(‘/[\r\n]+/’, ”, $name)); //Strip breaks and trim
// Don’t validate now addresses with IDN. Will be done in send().
if (($pos = strrpos($address, ‘@’)) === false or
(!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
!$this->validateAddress($address)) {
$error_message = $this->lang(‘invalid_address’) . ” (setFrom) $address”;
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
}
return false;
}
$this->From = $address;
$this->FromName = $name;
if ($auto) {
if (empty($this->Sender)) {
$this->Sender = $address;
}
}
return true;
}

/**
* Return the Message-ID header of the last email.
* Technically this is the value from the last time the headers were created,
* but it’s also the message ID of the last sent message except in
* pathological cases.
* @return string
*/
public function getLastMessageID()
{
return $this->lastMessageID;
}

/**
* Check that a string looks like an email address.
* @param string $address The email address to check
* @param string|callable $patternselect A selector for the validation pattern to use :
* * `auto` Pick best pattern automatically;
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
* * `pcre` Use old PCRE implementation;
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
* * `html5` Use the pattern given by the HTML5 spec for ’email’ type form input elements.
* * `noregex` Don’t use a regex: super fast, really dumb.
* Alternatively you may pass in a callable to inject your own validator, for example:
* PHPMailer::validateAddress(‘user@example.com’, function($address) {
* return (strpos($address, ‘@’) !== false);
* });
* You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
* @return boolean
* @static
* @access public
*/
public static function validateAddress($address, $patternselect = null)
{
if (is_null($patternselect)) {
$patternselect = self::$validator;
}
if (is_callable($patternselect)) {
return call_user_func($patternselect, $address);
}
//Reject line breaks in addresses; it’s valid RFC5322, but not RFC5321
if (strpos($address, “\n”) !== false or strpos($address, “\r”) !== false) {
return false;
}
if (!$patternselect or $patternselect == ‘auto’) {
//Check this constant first so it works when extension_loaded() is disabled by safe mode
//Constant was added in PHP 5.2.4
if (defined(‘PCRE_VERSION’)) {
//This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
if (version_compare(PCRE_VERSION, ‘8.0.3’) >= 0) {
$patternselect = ‘pcre8’;
} else {
$patternselect = ‘pcre’;
}
} elseif (function_exists(‘extension_loaded’) and extension_loaded(‘pcre’)) {
//Fall back to older PCRE
$patternselect = ‘pcre’;
} else {
//Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
if (version_compare(PHP_VERSION, ‘5.2.0’) >= 0) {
$patternselect = ‘php’;
} else {
$patternselect = ‘noregex’;
}
}
}
switch ($patternselect) {
case ‘pcre8’:
/**
* Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
* @link http://squiloople.com/2009/12/20/email-address-validation/
* @copyright 2009-2010 Michael Rushton
* Feel free to use and redistribute this code. But please keep this copyright notice.
*/
return (boolean)preg_match(
‘/^(?!(?>(?1)”?(?>\\\[ -~]|[^”])”?(?1)){255,})(?!(?>(?1)”?(?>\\\[ -~]|[^”])”?(?1)){65,}@)’ .
‘((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)’ .
‘(?>[\x01-\x08\x0B\x0C\x0E-\’*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)’ .
‘([!#-\’*+\/-9=?^-~-]+|”(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*’ .
‘(?2)”)(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)’ .
‘(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}’ .
‘|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:’ .
‘|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}’ .
‘|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD’,
$address
);
case ‘pcre’:
//An older regex that doesn’t need a recent PCRE
return (boolean)preg_match(
‘/^(?!(?>”?(?>\\\[ -~]|[^”])”?){255,})(?!(?>”?(?>\\\[ -~]|[^”])”?){65,}@)(?>’ .
‘[!#-\’*+\/-9=?^-~-]+|”(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*”)’ .
‘(?>\.(?>[!#-\’*+\/-9=?^-~-]+|”(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*”))*’ .
‘@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})’ .
‘(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:’ .
‘[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?’ .
‘::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:’ .
‘[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?’ .
‘::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}’ .
‘|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD’,
$address
);
case ‘html5′:
/**
* This is the pattern used in the HTML5 spec for validation of ’email’ type form input elements.
* @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
*/
return (boolean)preg_match(
‘/^[a-zA-Z0-9.!#$%&\’*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}’ .
‘[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD’,
$address
);
case ‘noregex’:
//No PCRE! Do something _very_ approximate!
//Check the address is 3 chars or longer and contains an @ that’s not the first or last char
return (strlen($address) >= 3
and strpos($address, ‘@’) >= 1
and strpos($address, ‘@’) != strlen($address) – 1);
case ‘php’:
default:
return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
}
}

/**
* Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
* “intl” and “mbstring” PHP extensions.
* @return bool “true” if required functions for IDN support are present
*/
public function idnSupported()
{
// @TODO: Write our own “idn_to_ascii” function for PHP <= 5.2.
return function_exists(‘idn_to_ascii’) and function_exists(‘mb_convert_encoding’);
}

/**
* Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
* Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
* This function silently returns unmodified address if:
* – No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
* – Conversion to punycode is impossible (e.g. required PHP functions are not available)
* or fails for any reason (e.g. domain has characters not allowed in an IDN)
* @see PHPMailer::$CharSet
* @param string $address The email address to convert
* @return string The encoded address in ASCII form
*/
public function punyencodeAddress($address)
{
// Verify we have required functions, CharSet, and at-sign.
if ($this->idnSupported() and
!empty($this->CharSet) and
($pos = strrpos($address, ‘@’)) !== false) {
$domain = substr($address, ++$pos);
// Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
$domain = mb_convert_encoding($domain, ‘UTF-8’, $this->CharSet);
if (($punycode = defined(‘INTL_IDNA_VARIANT_UTS46’) ?
idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
idn_to_ascii($domain)) !== false) {
return substr($address, 0, $pos) . $punycode;
}
}
}
return $address;
}

/**
* Create a message and send it.
* Uses the sending method specified by $Mailer.
* @throws phpmailerException
* @return boolean false on error – See the ErrorInfo property for details of the error.
*/
public function send()
{
try {
if (!$this->preSend()) {
return false;
}
return $this->postSend();
} catch (phpmailerException $exc) {
$this->mailHeader = ”;
$this->setError($exc->getMessage());
if ($this->exceptions) {
throw $exc;
}
return false;
}
}

/**
* Prepare a message for sending.
* @throws phpmailerException
* @return boolean
*/
public function preSend()
{
try {
$this->error_count = 0; // Reset errors
$this->mailHeader = ”;

// Dequeue recipient and Reply-To addresses with IDN
foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
$params[1] = $this->punyencodeAddress($params[1]);
call_user_func_array(array($this, ‘addAnAddress’), $params);
}
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new phpmailerException($this->lang(‘provide_address’), self::STOP_CRITICAL);
}

// Validate From, Sender, and ConfirmReadingTo addresses
foreach (array(‘From’, ‘Sender’, ‘ConfirmReadingTo’) as $address_kind) {
$this->$address_kind = trim($this->$address_kind);
if (empty($this->$address_kind)) {
continue;
}
$this->$address_kind = $this->punyencodeAddress($this->$address_kind);
if (!$this->validateAddress($this->$address_kind)) {
$error_message = $this->lang(‘invalid_address’) . ‘ (punyEncode) ‘ . $this->$address_kind;
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
}
return false;
}
}

// Set whether the message is multipart/alternative
if ($this->alternativeExists()) {
$this->ContentType = ‘multipart/alternative’;
}

$this->setMessageType();
// Refuse to send an empty message unless we are specifically allowing it
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->lang(’empty_message’), self::STOP_CRITICAL);
}

// Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
$this->MIMEHeader = ”;
$this->MIMEBody = $this->createBody();
// createBody may have added some headers, so retain them
$tempheaders = $this->MIMEHeader;
$this->MIMEHeader = $this->createHeader();
$this->MIMEHeader .= $tempheaders;

// To capture the complete message when using mail(), create
// an extra header list which createHeader() doesn’t fold in
if ($this->Mailer == ‘mail’) {
if (count($this->to) > 0) {
$this->mailHeader .= $this->addrAppend(‘To’, $this->to);
} else {
$this->mailHeader .= $this->headerLine(‘To’, ‘undisclosed-recipients:;’);
}
$this->mailHeader .= $this->headerLine(
‘Subject’,
$this->encodeHeader($this->secureHeader(trim($this->Subject)))
);
}

// Sign with DKIM if enabled
if (!empty($this->DKIM_domain)
&& !empty($this->DKIM_private)
&& !empty($this->DKIM_selector)
&& file_exists($this->DKIM_private)) {
$header_dkim = $this->DKIM_Add(
$this->MIMEHeader . $this->mailHeader,
$this->encodeHeader($this->secureHeader($this->Subject)),
$this->MIMEBody
);
$this->MIMEHeader = rtrim($this->MIMEHeader, “\r\n “) . self::CRLF .
str_replace(“\r\n”, “\n”, $header_dkim) . self::CRLF;
}
return true;
} catch (phpmailerException $exc) {
$this->setError($exc->getMessage());
if ($this->exceptions) {
throw $exc;
}
return false;
}
}

/**
* Actually send a message.
* Send the email via the selected mechanism
* @throws phpmailerException
* @return boolean
*/
public function postSend()
{
try {
// Choose the mailer and send through it
switch ($this->Mailer) {
case ‘sendmail’:
case ‘qmail’:
return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
case ‘smtp’:
return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
case ‘mail’:
return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
default:
$sendMethod = $this->Mailer.’Send’;
if (method_exists($this, $sendMethod)) {
return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
}

return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
}
} catch (phpmailerException $exc) {
$this->setError($exc->getMessage());
$this->edebug($exc->getMessage());
if ($this->exceptions) {
throw $exc;
}
}
return false;
}

/**
* Send mail using the $Sendmail program.
* @param string $header The message headers
* @param string $body The message body
* @see PHPMailer::$Sendmail
* @throws phpmailerException
* @access protected
* @return boolean
*/
protected function sendmailSend($header, $body)
{
if ($this->Sender != ”) {
if ($this->Mailer == ‘qmail’) {
$sendmail = sprintf(‘%s -f%s’, escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
} else {
$sendmail = sprintf(‘%s -oi -f%s -t’, escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
}
} else {
if ($this->Mailer == ‘qmail’) {
$sendmail = sprintf(‘%s’, escapeshellcmd($this->Sendmail));
} else {
$sendmail = sprintf(‘%s -oi -t’, escapeshellcmd($this->Sendmail));
}
}
if ($this->SingleTo) {
foreach ($this->SingleToArray as $toAddr) {
if (!@$mail = popen($sendmail, ‘w’)) {
throw new phpmailerException($this->lang(‘execute’) . $this->Sendmail, self::STOP_CRITICAL);
}
fputs($mail, ‘To: ‘ . $toAddr . “\n”);
fputs($mail, $header);
fputs($mail, $body);
$result = pclose($mail);
$this->doCallback(
($result == 0),
array($toAddr),
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From
);
if ($result != 0) {
throw new phpmailerException($this->lang(‘execute’) . $this->Sendmail, self::STOP_CRITICAL);
}
}
} else {
if (!@$mail = popen($sendmail, ‘w’)) {
throw new phpmailerException($this->lang(‘execute’) . $this->Sendmail, self::STOP_CRITICAL);
}
fputs($mail, $header);
fputs($mail, $body);
$result = pclose($mail);
$this->doCallback(
($result == 0),
$this->to,
$this->cc,
$this->bcc,
$this->Subject,
$body,
$this->From
);
if ($result != 0) {
throw new phpmailerException($this->lang(‘execute’) . $this->Sendmail, self::STOP_CRITICAL);
}
}
return true;
}

/**
* Send mail using the PHP mail() function.
* @param string $header The message headers
* @param string $body The message body
* @link http://www.php.net/manual/en/book.mail.php
* @throws phpmailerException
* @access protected
* @return boolean
*/
protected function mailSend($header, $body)
{
$toArr = array();
foreach ($this->to as $toaddr) {
$toArr[] = $this->addrFormat($toaddr);
}
$to = implode(‘, ‘, $toArr);

$params = null;
//This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
if (!empty($this->Sender)) {
$params = sprintf(‘-f%s’, $this->Sender);
}
if ($this->Sender != ” and !ini_get(‘safe_mode’)) {
$old_from = ini_get(‘sendmail_from’);
ini_set(‘sendmail_from’, $this->Sender);
}
$result = false;
if ($this->SingleTo and count($toArr) > 1) {
foreach ($toArr as $toAddr) {
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
$this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
}
} else {
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
$this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
}
if (isset($old_from)) {
ini_set(‘sendmail_from’, $old_from);
}
if (!$result) {
throw new phpmailerException($this->lang(‘instantiate’), self::STOP_CRITICAL);
}
return true;
}

/**
* Get an instance to use for SMTP operations.
* Override this function to load your own SMTP implementation
* @return SMTP
*/
public function getSMTPInstance()
{
if (!is_object($this->smtp)) {
$this->smtp = new SMTP;
}
return $this->smtp;
}

/**
* Send mail via SMTP.
* Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
* Uses the PHPMailerSMTP class by default.
* @see PHPMailer::getSMTPInstance() to use a different class.
* @param string $header The message headers
* @param string $body The message body
* @throws phpmailerException
* @uses SMTP
* @access protected
* @return boolean
*/
protected function smtpSend($header, $body)
{
$bad_rcpt = array();
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new phpmailerException($this->lang(‘smtp_connect_failed’), self::STOP_CRITICAL);
}
if (” == $this->Sender) {
$smtp_from = $this->From;
} else {
$smtp_from = $this->Sender;
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang(‘from_failed’) . $smtp_from . ‘ : ‘ . implode(‘,’, $this->smtp->getError()));
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
}

// Attempt to send to all recipients
foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
foreach ($togroup as $to) {
if (!$this->smtp->recipient($to[0])) {
$error = $this->smtp->getError();
$bad_rcpt[] = array(‘to’ => $to[0], ‘error’ => $error[‘detail’]);
$isSent = false;
} else {
$isSent = true;
}
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
}
}

// Only send the DATA command if we have viable recipients
if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
throw new phpmailerException($this->lang(‘data_not_accepted’), self::STOP_CRITICAL);
}
if ($this->SMTPKeepAlive) {
$this->smtp->reset();
} else {
$this->smtp->quit();
$this->smtp->close();
}
//Create error message for any bad addresses
if (count($bad_rcpt) > 0) {
$errstr = ”;
foreach ($bad_rcpt as $bad) {
$errstr .= $bad[‘to’] . ‘: ‘ . $bad[‘error’];
}
throw new phpmailerException(
$this->lang(‘recipients_failed’) . $errstr,
self::STOP_CONTINUE
);
}
return true;
}

/**
* Initiate a connection to an SMTP server.
* Returns false if the operation failed.
* @param array $options An array of options compatible with stream_context_create()
* @uses SMTP
* @access public
* @throws phpmailerException
* @return boolean
*/
public function smtpConnect($options = null)
{
if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance();
}

//If no options are provided, use whatever is set in the instance
if (is_null($options)) {
$options = $this->SMTPOptions;
}

// Already connected?
if ($this->smtp->connected()) {
return true;
}

$this->smtp->setTimeout($this->Timeout);
$this->smtp->setDebugLevel($this->SMTPDebug);
$this->smtp->setDebugOutput($this->Debugoutput);
$this->smtp->setVerp($this->do_verp);
$hosts = explode(‘;’, $this->Host);
$lastexception = null;

foreach ($hosts as $hostentry) {
$hostinfo = array();
if (!preg_match(‘/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/’, trim($hostentry), $hostinfo)) {
// Not a valid host entry
continue;
}
// $hostinfo[2]: optional ssl or tls prefix
// $hostinfo[3]: the hostname
// $hostinfo[4]: optional port number
// The host string prefix can temporarily override the current setting for SMTPSecure
// If it’s not specified, the default value is used
$prefix = ”;
$secure = $this->SMTPSecure;
$tls = ($this->SMTPSecure == ‘tls’);
if (‘ssl’ == $hostinfo[2] or (” == $hostinfo[2] and ‘ssl’ == $this->SMTPSecure)) {
$prefix = ‘ssl://’;
$tls = false; // Can’t have SSL and TLS at the same time
$secure = ‘ssl’;
} elseif ($hostinfo[2] == ‘tls’) {
$tls = true;
// tls doesn’t use a prefix
$secure = ‘tls’;
}
//Do we need the OpenSSL extension?
$sslext = defined(‘OPENSSL_ALGO_SHA1’);
if (‘tls’ === $secure or ‘ssl’ === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new phpmailerException($this->lang(‘extension_missing’).’openssl’, self::STOP_CRITICAL);
}
}
$host = $hostinfo[3];
$port = $this->Port;
$tport = (integer)$hostinfo[4];
if ($tport > 0 and $tport < 65536) {
$port = $tport;
}
if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
try {
if ($this->Helo) {
$hello = $this->Helo;
} else {
$hello = $this->serverHostname();
}
$this->smtp->hello($hello);
//Automatically enable TLS encryption if:
// * it’s not disabled
// * we have openssl extension
// * we are not already using SSL
// * the server offers STARTTLS
if ($this->SMTPAutoTLS and $sslext and $secure != ‘ssl’ and $this->smtp->getServerExt(‘STARTTLS’)) {
$tls = true;
}
if ($tls) {
if (!$this->smtp->startTLS()) {
throw new phpmailerException($this->lang(‘connect_host’));
}
// We must resend EHLO after TLS negotiation
$this->smtp->hello($hello);
}
if ($this->SMTPAuth) {
if (!$this->smtp->authenticate(
$this->Username,
$this->Password,
$this->AuthType,
$this->Realm,
$this->Workstation
)
) {
throw new phpmailerException($this->lang(‘authenticate’));
}
}
return true;
} catch (phpmailerException $exc) {
$lastexception = $exc;
$this->edebug($exc->getMessage());
// We must have connected, but then failed TLS or Auth, so close connection nicely
$this->smtp->quit();
}
}
}
// If we get here, all connection attempts have failed, so close connection hard
$this->smtp->close();
// As we’ve caught all exceptions, just report whatever the last one was
if ($this->exceptions and !is_null($lastexception)) {
throw $lastexception;
}
return false;
}

/**
* Close the active SMTP session if one exists.
* @return void
*/
public function smtpClose()
{
if (is_a($this->smtp, ‘SMTP’)) {
if ($this->smtp->connected()) {
$this->smtp->quit();
$this->smtp->close();
}
}
}

/**
* Set the language for error messages.
* Returns false if it cannot load the language file.
* The default language is English.
* @param string $langcode ISO 639-1 2-character language code (e.g. French is “fr”)
* @param string $lang_path Path to the language file directory, with trailing separator (slash)
* @return boolean
* @access public
*/
public function setLanguage($langcode = ‘en’, $lang_path = ”)
{
// Define full set of translatable strings in English
$PHPMAILER_LANG = array(
‘authenticate’ => ‘SMTP Error: Could not authenticate.’,
‘connect_host’ => ‘SMTP Error: Could not connect to SMTP host.’,
‘data_not_accepted’ => ‘SMTP Error: data not accepted.’,
’empty_message’ => ‘Message body empty’,
‘encoding’ => ‘Unknown encoding: ‘,
‘execute’ => ‘Could not execute: ‘,
‘file_access’ => ‘Could not access file: ‘,
‘file_open’ => ‘File Error: Could not open file: ‘,
‘from_failed’ => ‘The following From address failed: ‘,
‘instantiate’ => ‘Could not instantiate mail function.’,
‘invalid_address’ => ‘Invalid address: ‘,
‘mailer_not_supported’ => ‘ mailer is not supported.’,
‘provide_address’ => ‘You must provide at least one recipient email address.’,
‘recipients_failed’ => ‘SMTP Error: The following recipients failed: ‘,
‘signing’ => ‘Signing Error: ‘,
‘smtp_connect_failed’ => ‘SMTP connect() failed.’,
‘smtp_error’ => ‘SMTP server error: ‘,
‘variable_set’ => ‘Cannot set or reset variable: ‘,
‘extension_missing’ => ‘Extension missing: ‘
);
if (empty($lang_path)) {
// Calculate an absolute path so it can work if CWD is not here
$lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . ‘language’. DIRECTORY_SEPARATOR;
}
$foundlang = true;
$lang_file = $lang_path . ‘phpmailer.lang-‘ . $langcode . ‘.php’;
// There is no English translation file
if ($langcode != ‘en’) {
// Make sure language file path is readable
if (!is_readable($lang_file)) {
$foundlang = false;
} else {
// Overwrite language-specific strings.
// This way we’ll never have missing translation keys.
$foundlang = include $lang_file;
}
}
$this->language = $PHPMAILER_LANG;
return (boolean)$foundlang; // Returns false if language not found
}

/**
* Get the array of strings for the current language.
* @return array
*/
public function getTranslations()
{
return $this->language;
}

/**
* Create recipient headers.
* @access public
* @param string $type
* @param array $addr An array of recipient,
* where each recipient is a 2-element indexed array with element 0 containing an address
* and element 1 containing a name, like:
* array(array(‘joe@example.com’, ‘Joe User’), array(‘zoe@example.com’, ‘Zoe User’))
* @return string
*/
public function addrAppend($type, $addr)
{
$addresses = array();
foreach ($addr as $address) {
$addresses[] = $this->addrFormat($address);
}
return $type . ‘: ‘ . implode(‘, ‘, $addresses) . $this->LE;
}

/**
* Format an address for use in a message header.
* @access public
* @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
* like array(‘joe@example.com’, ‘Joe User’)
* @return string
*/
public function addrFormat($addr)
{
if (empty($addr[1])) { // No name provided
return $this->secureHeader($addr[0]);
} else {
return $this->encodeHeader($this->secureHeader($addr[1]), ‘phrase’) . ‘ <‘ . $this->secureHeader(
$addr[0]
) . ‘>’;
}
}

/**
* Word-wrap message.
* For use with mailers that do not automatically perform wrapping
* and for quoted-printable encoded messages.
* Original written by philippe.
* @param string $message The message to wrap
* @param integer $length The line length to wrap to
* @param boolean $qp_mode Whether to run in Quoted-Printable mode
* @access public
* @return string
*/
public function wrapText($message, $length, $qp_mode = false)
{
if ($qp_mode) {
$soft_break = sprintf(‘ =%s’, $this->LE);
} else {
$soft_break = $this->LE;
}
// If utf-8 encoding is used, we will need to make sure we don’t
// split multibyte characters when we wrap
$is_utf8 = (strtolower($this->CharSet) == ‘utf-8’);
$lelen = strlen($this->LE);
$crlflen = strlen(self::CRLF);

$message = $this->fixEOL($message);
//Remove a trailing line break
if (substr($message, -$lelen) == $this->LE) {
$message = substr($message, 0, -$lelen);
}

//Split message into lines
$lines = explode($this->LE, $message);
//Message will be rebuilt in here
$message = ”;
foreach ($lines as $line) {
$words = explode(‘ ‘, $line);
$buf = ”;
$firstword = true;
foreach ($words as $word) {
if ($qp_mode and (strlen($word) > $length)) {
$space_left = $length – strlen($buf) – $crlflen;
if (!$firstword) {
if ($space_left > 20) {
$len = $space_left;
if ($is_utf8) {
$len = $this->utf8CharBoundary($word, $len);
} elseif (substr($word, $len – 1, 1) == ‘=’) {
$len–;
} elseif (substr($word, $len – 2, 1) == ‘=’) {
$len -= 2;
}
$part = substr($word, 0, $len);
$word = substr($word, $len);
$buf .= ‘ ‘ . $part;
$message .= $buf . sprintf(‘=%s’, self::CRLF);
} else {
$message .= $buf . $soft_break;
}
$buf = ”;
}
while (strlen($word) > 0) {
if ($length <= 0) {
break;
}
$len = $length;
if ($is_utf8) {
$len = $this->utf8CharBoundary($word, $len);
} elseif (substr($word, $len – 1, 1) == ‘=’) {
$len–;
} elseif (substr($word, $len – 2, 1) == ‘=’) {
$len -= 2;
}
$part = substr($word, 0, $len);
$word = substr($word, $len);

if (strlen($word) > 0) {
$message .= $part . sprintf(‘=%s’, self::CRLF);
} else {
$buf = $part;
}
}
} else {
$buf_o = $buf;
if (!$firstword) {
$buf .= ‘ ‘;
}
$buf .= $word;

if (strlen($buf) > $length and $buf_o != ”) {
$message .= $buf_o . $soft_break;
$buf = $word;
}
}
$firstword = false;
}
$message .= $buf . self::CRLF;
}

return $message;
}

/**
* Find the last character boundary prior to $maxLength in a utf-8
* quoted-printable encoded string.
* Original written by Colin Brown.
* @access public
* @param string $encodedText utf-8 QP text
* @param integer $maxLength Find the last character boundary prior to this length
* @return integer
*/
public function utf8CharBoundary($encodedText, $maxLength)
{
$foundSplitPos = false;
$lookBack = 3;
while (!$foundSplitPos) {
$lastChunk = substr($encodedText, $maxLength – $lookBack, $lookBack);
$encodedCharPos = strpos($lastChunk, ‘=’);
if (false !== $encodedCharPos) {
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the ‘=’)
$hex = substr($encodedText, $maxLength – $lookBack + $encodedCharPos + 1, 2);
$dec = hexdec($hex);
if ($dec < 128) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
if ($encodedCharPos > 0) {
$maxLength = $maxLength – ($lookBack – $encodedCharPos);
}
$foundSplitPos = true;
} elseif ($dec >= 192) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength = $maxLength – ($lookBack – $encodedCharPos);
$foundSplitPos = true;
} elseif ($dec < 192) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
} else {
// No encoded character found
$foundSplitPos = true;
}
}
return $maxLength;
}

/**
* Apply word wrapping to the message body.
* Wraps the message body to the number of chars set in the WordWrap property.
* You should only do this to plain-text bodies as wrapping HTML tags may break them.
* This is called automatically by createBody(), so you don’t need to call it yourself.
* @access public
* @return void
*/
public function setWordWrap()
{
if ($this->WordWrap < 1) {
return;
}

switch ($this->message_type) {
case ‘alt’:
case ‘alt_inline’:
case ‘alt_attach’:
case ‘alt_inline_attach’:
$this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
break;
default:
$this->Body = $this->wrapText($this->Body, $this->WordWrap);
break;
}
}

/**
* Assemble message headers.
* @access public
* @return string The assembled headers
*/
public function createHeader()
{
$result = ”;

if ($this->MessageDate == ”) {
$this->MessageDate = self::rfcDate();
}
$result .= $this->headerLine(‘Date’, $this->MessageDate);

// To be created automatically by mail()
if ($this->SingleTo) {
if ($this->Mailer != ‘mail’) {
foreach ($this->to as $toaddr) {
$this->SingleToArray[] = $this->addrFormat($toaddr);
}
}
} else {
if (count($this->to) > 0) {
if ($this->Mailer != ‘mail’) {
$result .= $this->addrAppend(‘To’, $this->to);
}
} elseif (count($this->cc) == 0) {
$result .= $this->headerLine(‘To’, ‘undisclosed-recipients:;’);
}
}

$result .= $this->addrAppend(‘From’, array(array(trim($this->From), $this->FromName)));

// sendmail and mail() extract Cc from the header before sending
if (count($this->cc) > 0) {
$result .= $this->addrAppend(‘Cc’, $this->cc);
}

// sendmail and mail() extract Bcc from the header before sending
if ((
$this->Mailer == ‘sendmail’ or $this->Mailer == ‘qmail’ or $this->Mailer == ‘mail’
)
and count($this->bcc) > 0
) {
$result .= $this->addrAppend(‘Bcc’, $this->bcc);
}

if (count($this->ReplyTo) > 0) {
$result .= $this->addrAppend(‘Reply-To’, $this->ReplyTo);
}

// mail() sets the subject itself
if ($this->Mailer != ‘mail’) {
$result .= $this->headerLine(‘Subject’, $this->encodeHeader($this->secureHeader($this->Subject)));
}

if (” != $this->MessageID and preg_match(‘/^<.*@.*>$/’, $this->MessageID)) {
$this->lastMessageID = $this->MessageID;
} else {
$this->lastMessageID = sprintf(‘<%s@%s>’, $this->uniqueid, $this->serverHostname());
}
$result .= $this->headerLine(‘Message-ID’, $this->lastMessageID);
if (!is_null($this->Priority)) {
$result .= $this->headerLine(‘X-Priority’, $this->Priority);
}
if ($this->XMailer == ”) {
$result .= $this->headerLine(
‘X-Mailer’,
‘PHPMailer ‘ . $this->Version . ‘ (https://github.com/PHPMailer/PHPMailer)’
);
} else {
$myXmailer = trim($this->XMailer);
if ($myXmailer) {
$result .= $this->headerLine(‘X-Mailer’, $myXmailer);
}
}

if ($this->ConfirmReadingTo != ”) {
$result .= $this->headerLine(‘Disposition-Notification-To’, ‘<‘ . $this->ConfirmReadingTo . ‘>’);
}

// Add custom headers
foreach ($this->CustomHeader as $header) {
$result .= $this->headerLine(
trim($header[0]),
$this->encodeHeader(trim($header[1]))
);
}
if (!$this->sign_key_file) {
$result .= $this->headerLine(‘MIME-Version’, ‘1.0’);
$result .= $this->getMailMIME();
}

return $result;
}

/**
* Get the message MIME type headers.
* @access public
* @return string
*/
public function getMailMIME()
{
$result = ”;
$ismultipart = true;
switch ($this->message_type) {
case ‘inline’:
$result .= $this->headerLine(‘Content-Type’, ‘multipart/related;’);
$result .= $this->textLine(“\tboundary=\”” . $this->boundary[1] . ‘”‘);
break;
case ‘attach’:
case ‘inline_attach’:
case ‘alt_attach’:
case ‘alt_inline_attach’:
$result .= $this->headerLine(‘Content-Type’, ‘multipart/mixed;’);
$result .= $this->textLine(“\tboundary=\”” . $this->boundary[1] . ‘”‘);
break;
case ‘alt’:
case ‘alt_inline’:
$result .= $this->headerLine(‘Content-Type’, ‘multipart/alternative;’);
$result .= $this->textLine(“\tboundary=\”” . $this->boundary[1] . ‘”‘);
break;
default:
// Catches case ‘plain’: and case ”:
$result .= $this->textLine(‘Content-Type: ‘ . $this->ContentType . ‘; charset=’ . $this->CharSet);
$ismultipart = false;
break;
}
// RFC1341 part 5 says 7bit is assumed if not specified
if ($this->Encoding != ‘7bit’) {
// RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
if ($ismultipart) {
if ($this->Encoding == ‘8bit’) {
$result .= $this->headerLine(‘Content-Transfer-Encoding’, ‘8bit’);
}
// The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
} else {
$result .= $this->headerLine(‘Content-Transfer-Encoding’, $this->Encoding);
}
}

if ($this->Mailer != ‘mail’) {
$result .= $this->LE;
}

return $result;
}

/**
* Returns the whole MIME message.
* Includes complete headers and body.
* Only valid post preSend().
* @see PHPMailer::preSend()
* @access public
* @return string
*/
public function getSentMIMEMessage()
{
return rtrim($this->MIMEHeader . $this->mailHeader, “\n\r”) . self::CRLF . self::CRLF . $this->MIMEBody;
}

/**
* Assemble the message body.
* Returns an empty string on failure.
* @access public
* @throws phpmailerException
* @return string The assembled message body
*/
public function createBody()
{
$body = ”;
//Create unique IDs and preset boundaries
$this->uniqueid = md5(uniqid(time()));
$this->boundary[1] = ‘b1_’ . $this->uniqueid;
$this->boundary[2] = ‘b2_’ . $this->uniqueid;
$this->boundary[3] = ‘b3_’ . $this->uniqueid;

if ($this->sign_key_file) {
$body .= $this->getMailMIME() . $this->LE;
}

$this->setWordWrap();

$bodyEncoding = $this->Encoding;
$bodyCharSet = $this->CharSet;
//Can we do a 7-bit downgrade?
if ($bodyEncoding == ‘8bit’ and !$this->has8bitChars($this->Body)) {
$bodyEncoding = ‘7bit’;
//All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
$bodyCharSet = ‘us-ascii’;
}
//If lines are too long, and we’re not already using an encoding that will shorten them,
//change to quoted-printable transfer encoding for the body part only
if (‘base64’ != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
$bodyEncoding = ‘quoted-printable’;
}

$altBodyEncoding = $this->Encoding;
$altBodyCharSet = $this->CharSet;
//Can we do a 7-bit downgrade?
if ($altBodyEncoding == ‘8bit’ and !$this->has8bitChars($this->AltBody)) {
$altBodyEncoding = ‘7bit’;
//All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit
$altBodyCharSet = ‘us-ascii’;
}
//If lines are too long, and we’re not already using an encoding that will shorten them,
//change to quoted-printable transfer encoding for the alt body part only
if (‘base64’ != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
$altBodyEncoding = ‘quoted-printable’;
}
//Use this as a preamble in all multipart message types
$mimepre = “This is a multi-part message in MIME format.” . $this->LE . $this->LE;
switch ($this->message_type) {
case ‘inline’:
$body .= $mimepre;
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, ”, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->attachAll(‘inline’, $this->boundary[1]);
break;
case ‘attach’:
$body .= $mimepre;
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, ”, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->attachAll(‘attachment’, $this->boundary[1]);
break;
case ‘inline_attach’:
$body .= $mimepre;
$body .= $this->textLine(‘–‘ . $this->boundary[1]);
$body .= $this->headerLine(‘Content-Type’, ‘multipart/related;’);
$body .= $this->textLine(“\tboundary=\”” . $this->boundary[2] . ‘”‘);
$body .= $this->LE;
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, ”, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->attachAll(‘inline’, $this->boundary[2]);
$body .= $this->LE;
$body .= $this->attachAll(‘attachment’, $this->boundary[1]);
break;
case ‘alt’:
$body .= $mimepre;
$body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, ‘text/plain’, $altBodyEncoding);
$body .= $this->encodeString($this->AltBody, $altBodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, ‘text/html’, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
if (!empty($this->Ical)) {
$body .= $this->getBoundary($this->boundary[1], ”, ‘text/calendar; method=REQUEST’, ”);
$body .= $this->encodeString($this->Ical, $this->Encoding);
$body .= $this->LE . $this->LE;
}
$body .= $this->endBoundary($this->boundary[1]);
break;
case ‘alt_inline’:
$body .= $mimepre;
$body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, ‘text/plain’, $altBodyEncoding);
$body .= $this->encodeString($this->AltBody, $altBodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->textLine(‘–‘ . $this->boundary[1]);
$body .= $this->headerLine(‘Content-Type’, ‘multipart/related;’);
$body .= $this->textLine(“\tboundary=\”” . $this->boundary[2] . ‘”‘);
$body .= $this->LE;
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, ‘text/html’, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->attachAll(‘inline’, $this->boundary[2]);
$body .= $this->LE;
$body .= $this->endBoundary($this->boundary[1]);
break;
case ‘alt_attach’:
$body .= $mimepre;
$body .= $this->textLine(‘–‘ . $this->boundary[1]);
$body .= $this->headerLine(‘Content-Type’, ‘multipart/alternative;’);
$body .= $this->textLine(“\tboundary=\”” . $this->boundary[2] . ‘”‘);
$body .= $this->LE;
$body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, ‘text/plain’, $altBodyEncoding);
$body .= $this->encodeString($this->AltBody, $altBodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, ‘text/html’, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->endBoundary($this->boundary[2]);
$body .= $this->LE;
$body .= $this->attachAll(‘attachment’, $this->boundary[1]);
break;
case ‘alt_inline_attach’:
$body .= $mimepre;
$body .= $this->textLine(‘–‘ . $this->boundary[1]);
$body .= $this->headerLine(‘Content-Type’, ‘multipart/alternative;’);
$body .= $this->textLine(“\tboundary=\”” . $this->boundary[2] . ‘”‘);
$body .= $this->LE;
$body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, ‘text/plain’, $altBodyEncoding);
$body .= $this->encodeString($this->AltBody, $altBodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->textLine(‘–‘ . $this->boundary[2]);
$body .= $this->headerLine(‘Content-Type’, ‘multipart/related;’);
$body .= $this->textLine(“\tboundary=\”” . $this->boundary[3] . ‘”‘);
$body .= $this->LE;
$body .= $this->getBoundary($this->boundary[3], $bodyCharSet, ‘text/html’, $bodyEncoding);
$body .= $this->encodeString($this->Body, $bodyEncoding);
$body .= $this->LE . $this->LE;
$body .= $this->attachAll(‘inline’, $this->boundary[3]);
$body .= $this->LE;
$body .= $this->endBoundary($this->boundary[2]);
$body .= $this->LE;
$body .= $this->attachAll(‘attachment’, $this->boundary[1]);
break;
default:
// Catch case ‘plain’ and case ”, applies to simple `text/plain` and `text/html` body content types
//Reset the `Encoding` property in case we changed it for line length reasons
$this->Encoding = $bodyEncoding;
$body .= $this->encodeString($this->Body, $this->Encoding);
break;
}

if ($this->isError()) {
$body = ”;
} elseif ($this->sign_key_file) {
try {
if (!defined(‘PKCS7_TEXT’)) {
throw new phpmailerException($this->lang(‘extension_missing’) . ‘openssl’);
}
// @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
$file = tempnam(sys_get_temp_dir(), ‘mail’);
if (false === file_put_contents($file, $body)) {
throw new phpmailerException($this->lang(‘signing’) . ‘ Could not write temp file’);
}
$signed = tempnam(sys_get_temp_dir(), ‘signed’);
//Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
if (empty($this->sign_extracerts_file)) {
$sign = @openssl_pkcs7_sign(
$file,
$signed,
‘file://’ . realpath($this->sign_cert_file),
array(‘file://’ . realpath($this->sign_key_file), $this->sign_key_pass),
null
);
} else {
$sign = @openssl_pkcs7_sign(
$file,
$signed,
‘file://’ . realpath($this->sign_cert_file),
array(‘file://’ . realpath($this->sign_key_file), $this->sign_key_pass),
null,
PKCS7_DETACHED,
$this->sign_extracerts_file
);
}
if ($sign) {
@unlink($file);
$body = file_get_contents($signed);
@unlink($signed);
//The message returned by openssl contains both headers and body, so need to split them up
$parts = explode(“\n\n”, $body, 2);
$this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
$body = $parts[1];
} else {
@unlink($file);
@unlink($signed);
throw new phpmailerException($this->lang(‘signing’) . openssl_error_string());
}
} catch (phpmailerException $exc) {
$body = ”;
if ($this->exceptions) {
throw $exc;
}
}
}
return $body;
}

/**
* Return the start of a message boundary.
* @access protected
* @param string $boundary
* @param string $charSet
* @param string $contentType
* @param string $encoding
* @return string
*/
protected function getBoundary($boundary, $charSet, $contentType, $encoding)
{
$result = ”;
if ($charSet == ”) {
$charSet = $this->CharSet;
}
if ($contentType == ”) {
$contentType = $this->ContentType;
}
if ($encoding == ”) {
$encoding = $this->Encoding;
}
$result .= $this->textLine(‘–‘ . $boundary);
$result .= sprintf(‘Content-Type: %s; charset=%s’, $contentType, $charSet);
$result .= $this->LE;
// RFC1341 part 5 says 7bit is assumed if not specified
if ($encoding != ‘7bit’) {
$result .= $this->headerLine(‘Content-Transfer-Encoding’, $encoding);
}
$result .= $this->LE;

return $result;
}

/**
* Return the end of a message boundary.
* @access protected
* @param string $boundary
* @return string
*/
protected function endBoundary($boundary)
{
return $this->LE . ‘–‘ . $boundary . ‘–‘ . $this->LE;
}

/**
* Set the message type.
* PHPMailer only supports some preset message types, not arbitrary MIME structures.
* @access protected
* @return void
*/
protected function setMessageType()
{
$type = array();
if ($this->alternativeExists()) {
$type[] = ‘alt’;
}
if ($this->inlineImageExists()) {
$type[] = ‘inline’;
}
if ($this->attachmentExists()) {
$type[] = ‘attach’;
}
$this->message_type = implode(‘_’, $type);
if ($this->message_type == ”) {
//The ‘plain’ message_type refers to the message having a single body element, not that it is plain-text
$this->message_type = ‘plain’;
}
}

/**
* Format a header line.
* @access public
* @param string $name
* @param string $value
* @return string
*/
public function headerLine($name, $value)
{
return $name . ‘: ‘ . $value . $this->LE;
}

/**
* Return a formatted mail line.
* @access public
* @param string $value
* @return string
*/
public function textLine($value)
{
return $value . $this->LE;
}

/**
* Add an attachment from a path on the filesystem.
* Returns false if the file could not be found or read.
* @param string $path Path to the attachment.
* @param string $name Overrides the attachment name.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @param string $disposition Disposition to use
* @throws phpmailerException
* @return boolean
*/
public function addAttachment($path, $name = ”, $encoding = ‘base64’, $type = ”, $disposition = ‘attachment’)
{
try {
if (!@is_file($path)) {
throw new phpmailerException($this->lang(‘file_access’) . $path, self::STOP_CONTINUE);
}

// If a MIME type is not specified, try to work it out from the file name
if ($type == ”) {
$type = self::filenameToType($path);
}

$filename = basename($path);
if ($name == ”) {
$name = $filename;
}

$this->attachment[] = array(
0 => $path,
1 => $filename,
2 => $name,
3 => $encoding,
4 => $type,
5 => false, // isStringAttachment
6 => $disposition,
7 => 0
);

} catch (phpmailerException $exc) {
$this->setError($exc->getMessage());
$this->edebug($exc->getMessage());
if ($this->exceptions) {
throw $exc;
}
return false;
}
return true;
}

/**
* Return the array of attachments.
* @return array
*/
public function getAttachments()
{
return $this->attachment;
}

/**
* Attach all file, string, and binary attachments to the message.
* Returns an empty string on failure.
* @access protected
* @param string $disposition_type
* @param string $boundary
* @return string
*/
protected function attachAll($disposition_type, $boundary)
{
// Return text of body
$mime = array();
$cidUniq = array();
$incl = array();

// Add all attachments
foreach ($this->attachment as $attachment) {
// Check if it is a valid disposition_filter
if ($attachment[6] == $disposition_type) {
// Check for string attachment
$string = ”;
$path = ”;
$bString = $attachment[5];
if ($bString) {
$string = $attachment[0];
} else {
$path = $attachment[0];
}

$inclhash = md5(serialize($attachment));
if (in_array($inclhash, $incl)) {
continue;
}
$incl[] = $inclhash;
$name = $attachment[2];
$encoding = $attachment[3];
$type = $attachment[4];
$disposition = $attachment[6];
$cid = $attachment[7];
if ($disposition == ‘inline’ && array_key_exists($cid, $cidUniq)) {
continue;
}
$cidUniq[$cid] = true;

$mime[] = sprintf(‘–%s%s’, $boundary, $this->LE);
//Only include a filename property if we have one
if (!empty($name)) {
$mime[] = sprintf(
‘Content-Type: %s; name=”%s”%s’,
$type,
$this->encodeHeader($this->secureHeader($name)),
$this->LE
);
} else {
$mime[] = sprintf(
‘Content-Type: %s%s’,
$type,
$this->LE
);
}
// RFC1341 part 5 says 7bit is assumed if not specified
if ($encoding != ‘7bit’) {
$mime[] = sprintf(‘Content-Transfer-Encoding: %s%s’, $encoding, $this->LE);
}

if ($disposition == ‘inline’) {
$mime[] = sprintf(‘Content-ID: <%s>%s’, $cid, $this->LE);
}

// If a filename contains any of these chars, it should be quoted,
// but not otherwise: RFC2183 & RFC2045 5.1
// Fixes a warning in IETF’s msglint MIME checker
// Allow for bypassing the Content-Disposition header totally
if (!(empty($disposition))) {
$encoded_name = $this->encodeHeader($this->secureHeader($name));
if (preg_match(‘/[ \(\)<>@,;:\\”\/\[\]\?=]/’, $encoded_name)) {
$mime[] = sprintf(
‘Content-Disposition: %s; filename=”%s”%s’,
$disposition,
$encoded_name,
$this->LE . $this->LE
);
} else {
if (!empty($encoded_name)) {
$mime[] = sprintf(
‘Content-Disposition: %s; filename=%s%s’,
$disposition,
$encoded_name,
$this->LE . $this->LE
);
} else {
$mime[] = sprintf(
‘Content-Disposition: %s%s’,
$disposition,
$this->LE . $this->LE
);
}
}
} else {
$mime[] = $this->LE;
}

// Encode as string attachment
if ($bString) {
$mime[] = $this->encodeString($string, $encoding);
if ($this->isError()) {
return ”;
}
$mime[] = $this->LE . $this->LE;
} else {
$mime[] = $this->encodeFile($path, $encoding);
if ($this->isError()) {
return ”;
}
$mime[] = $this->LE . $this->LE;
}
}
}

$mime[] = sprintf(‘–%s–%s’, $boundary, $this->LE);

return implode(”, $mime);
}

/**
* Encode a file attachment in requested format.
* Returns an empty string on failure.
* @param string $path The full path to the file
* @param string $encoding The encoding to use; one of ‘base64’, ‘7bit’, ‘8bit’, ‘binary’, ‘quoted-printable’
* @throws phpmailerException
* @access protected
* @return string
*/
protected function encodeFile($path, $encoding = ‘base64’)
{
try {
if (!is_readable($path)) {
throw new phpmailerException($this->lang(‘file_open’) . $path, self::STOP_CONTINUE);
}
$magic_quotes = get_magic_quotes_runtime();
if ($magic_quotes) {
if (version_compare(PHP_VERSION, ‘5.3.0’, ‘<‘)) {
set_magic_quotes_runtime(false);
} else {
//Doesn’t exist in PHP 5.4, but we don’t need to check because
//get_magic_quotes_runtime always returns false in 5.4+
//so it will never get here
ini_set(‘magic_quotes_runtime’, false);
}
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->encodeString($file_buffer, $encoding);
if ($magic_quotes) {
if (version_compare(PHP_VERSION, ‘5.3.0’, ‘<‘)) {
set_magic_quotes_runtime($magic_quotes);
} else {
ini_set(‘magic_quotes_runtime’, $magic_quotes);
}
}
return $file_buffer;
} catch (Exception $exc) {
$this->setError($exc->getMessage());
return ”;
}
}

/**
* Encode a string in requested format.
* Returns an empty string on failure.
* @param string $str The text to encode
* @param string $encoding The encoding to use; one of ‘base64’, ‘7bit’, ‘8bit’, ‘binary’, ‘quoted-printable’
* @access public
* @return string
*/
public function encodeString($str, $encoding = ‘base64’)
{
$encoded = ”;
switch (strtolower($encoding)) {
case ‘base64’:
$encoded = chunk_split(base64_encode($str), 76, $this->LE);
break;
case ‘7bit’:
case ‘8bit’:
$encoded = $this->fixEOL($str);
// Make sure it ends with a line break
if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
$encoded .= $this->LE;
}
break;
case ‘binary’:
$encoded = $str;
break;
case ‘quoted-printable’:
$encoded = $this->encodeQP($str);
break;
default:
$this->setError($this->lang(‘encoding’) . $encoding);
break;
}
return $encoded;
}

/**
* Encode a header string optimally.
* Picks shortest of Q, B, quoted-printable or none.
* @access public
* @param string $str
* @param string $position
* @return string
*/
public function encodeHeader($str, $position = ‘text’)
{
$matchcount = 0;
switch (strtolower($position)) {
case ‘phrase’:
if (!preg_match(‘/[\200-\377]/’, $str)) {
// Can’t use addslashes as we don’t know the value of magic_quotes_sybase
$encoded = addcslashes($str, “\0..\37\177\\\””);
if (($str == $encoded) && !preg_match(‘/[^A-Za-z0-9!#$%&\’*+\/=?^_`{|}~ -]/’, $str)) {
return ($encoded);
} else {
return (“\”$encoded\””);
}
}
$matchcount = preg_match_all(‘/[^\040\041\043-\133\135-\176]/’, $str, $matches);
break;
/** @noinspection PhpMissingBreakStatementInspection */
case ‘comment’:
$matchcount = preg_match_all(‘/[()”]/’, $str, $matches);
// Intentional fall-through
case ‘text’:
default:
$matchcount += preg_match_all(‘/[\000-\010\013\014\016-\037\177-\377]/’, $str, $matches);
break;
}

//There are no chars that need encoding
if ($matchcount == 0) {
return ($str);
}

$maxlen = 75 – 7 – strlen($this->CharSet);
// Try to select the encoding which should produce the shortest output
if ($matchcount > strlen($str) / 3) {
// More than a third of the content will need encoding, so B encoding will be most efficient
$encoding = ‘B’;
if (function_exists(‘mb_strlen’) && $this->hasMultiBytes($str)) {
// Use a custom function which correctly encodes and wraps long
// multibyte strings without breaking lines within a character
$encoded = $this->base64EncodeWrapMB($str, “\n”);
} else {
$encoded = base64_encode($str);
$maxlen -= $maxlen % 4;
$encoded = trim(chunk_split($encoded, $maxlen, “\n”));
}
} else {
$encoding = ‘Q’;
$encoded = $this->encodeQ($str, $position);
$encoded = $this->wrapText($encoded, $maxlen, true);
$encoded = str_replace(‘=’ . self::CRLF, “\n”, trim($encoded));
}

$encoded = preg_replace(‘/^(.*)$/m’, ‘ =?’ . $this->CharSet . “?$encoding?\\1?=”, $encoded);
$encoded = trim(str_replace(“\n”, $this->LE, $encoded));

return $encoded;
}

/**
* Check if a string contains multi-byte characters.
* @access public
* @param string $str multi-byte text to wrap encode
* @return boolean
*/
public function hasMultiBytes($str)
{
if (function_exists(‘mb_strlen’)) {
return (strlen($str) > mb_strlen($str, $this->CharSet));
} else { // Assume no multibytes (we can’t handle without mbstring functions anyway)
return false;
}
}

/**
* Does a string contain any 8-bit chars (in any charset)?
* @param string $text
* @return boolean
*/
public function has8bitChars($text)
{
return (boolean)preg_match(‘/[\x80-\xFF]/’, $text);
}

/**
* Encode and wrap long multibyte strings for mail headers
* without breaking lines within a character.
* Adapted from a function by paravoid
* @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
* @access public
* @param string $str multi-byte text to wrap encode
* @param string $linebreak string to use as linefeed/end-of-line
* @return string
*/
public function base64EncodeWrapMB($str, $linebreak = null)
{
$start = ‘=?’ . $this->CharSet . ‘?B?’;
$end = ‘?=’;
$encoded = ”;
if ($linebreak === null) {
$linebreak = $this->LE;
}

$mb_length = mb_strlen($str, $this->CharSet);
// Each line must have length <= 75, including $start and $end
$length = 75 – strlen($start) – strlen($end);
// Average multi-byte ratio
$ratio = $mb_length / strlen($str);
// Base64 has a 4:3 ratio
$avgLength = floor($length * $ratio * .75);

for ($i = 0; $i < $mb_length; $i += $offset) {
$lookBack = 0;
do {
$offset = $avgLength – $lookBack;
$chunk = mb_substr($str, $i, $offset, $this->CharSet);
$chunk = base64_encode($chunk);
$lookBack++;
} while (strlen($chunk) > $length);
$encoded .= $chunk . $linebreak;
}

// Chomp the last linefeed
$encoded = substr($encoded, 0, -strlen($linebreak));
return $encoded;
}

/**
* Encode a string in quoted-printable format.
* According to RFC2045 section 6.7.
* @access public
* @param string $string The text to encode
* @param integer $line_max Number of chars allowed on a line before wrapping
* @return string
* @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
*/
public function encodeQP($string, $line_max = 76)
{
// Use native function if it’s available (>= PHP5.3)
if (function_exists(‘quoted_printable_encode’)) {
return quoted_printable_encode($string);
}
// Fall back to a pure PHP implementation
$string = str_replace(
array(‘%20’, ‘%0D%0A.’, ‘%0D%0A’, ‘%’),
array(‘ ‘, “\r\n=2E”, “\r\n”, ‘=’),
rawurlencode($string)
);
return preg_replace(‘/[^\r\n]{‘ . ($line_max – 3) . ‘}[^=\r\n]{2}/’, “$0=\r\n”, $string);
}

/**
* Backward compatibility wrapper for an old QP encoding function that was removed.
* @see PHPMailer::encodeQP()
* @access public
* @param string $string
* @param integer $line_max
* @param boolean $space_conv
* @return string
* @deprecated Use encodeQP instead.
*/
public function encodeQPphp(
$string,
$line_max = 76,
/** @noinspection PhpUnusedParameterInspection */ $space_conv = false
) {
return $this->encodeQP($string, $line_max);
}

/**
* Encode a string using Q encoding.
* @link http://tools.ietf.org/html/rfc2047
* @param string $str the text to encode
* @param string $position Where the text is going to be used, see the RFC for what that means
* @access public
* @return string
*/
public function encodeQ($str, $position = ‘text’)
{
// There should not be any EOL in the string
$pattern = ”;
$encoded = str_replace(array(“\r”, “\n”), ”, $str);
switch (strtolower($position)) {
case ‘phrase’:
// RFC 2047 section 5.3
$pattern = ‘^A-Za-z0-9!*+\/ -‘;
break;
/** @noinspection PhpMissingBreakStatementInspection */
case ‘comment’:
// RFC 2047 section 5.2
$pattern = ‘\(\)”‘;
// intentional fall-through
// for this reason we build the $pattern without including delimiters and []
case ‘text’:
default:
// RFC 2047 section 5.1
// Replace every high ascii, control, =, ? and _ characters
$pattern = ‘\000-\011\013\014\016-\037\075\077\137\177-\377’ . $pattern;
break;
}
$matches = array();
if (preg_match_all(“/[{$pattern}]/”, $encoded, $matches)) {
// If the string contains an ‘=’, make sure it’s the first thing we replace
// so as to avoid double-encoding
$eqkey = array_search(‘=’, $matches[0]);
if (false !== $eqkey) {
unset($matches[0][$eqkey]);
array_unshift($matches[0], ‘=’);
}
foreach (array_unique($matches[0]) as $char) {
$encoded = str_replace($char, ‘=’ . sprintf(‘%02X’, ord($char)), $encoded);
}
}
// Replace every spaces to _ (more readable than =20)
return str_replace(‘ ‘, ‘_’, $encoded);
}

/**
* Add a string or binary attachment (non-filesystem).
* This method can be used to attach ascii or binary data,
* such as a BLOB record from a database.
* @param string $string String attachment data.
* @param string $filename Name of the attachment.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @param string $disposition Disposition to use
* @return void
*/
public function addStringAttachment(
$string,
$filename,
$encoding = ‘base64’,
$type = ”,
$disposition = ‘attachment’
) {
// If a MIME type is not specified, try to work it out from the file name
if ($type == ”) {
$type = self::filenameToType($filename);
}
// Append to $attachment array
$this->attachment[] = array(
0 => $string,
1 => $filename,
2 => basename($filename),
3 => $encoding,
4 => $type,
5 => true, // isStringAttachment
6 => $disposition,
7 => 0
);
}

/**
* Add an embedded (inline) attachment from a file.
* This can include images, sounds, and just about any other document type.
* These differ from ‘regular’ attachments in that they are intended to be
* displayed inline with the message, not just attached for download.
* This is used in HTML messages that embed the images
* the HTML refers to using the $cid value.
* @param string $path Path to the attachment.
* @param string $cid Content ID of the attachment; Use this to reference
* the content when using an embedded image in HTML.
* @param string $name Overrides the attachment name.
* @param string $encoding File encoding (see $Encoding).
* @param string $type File MIME type.
* @param string $disposition Disposition to use
* @return boolean True on successfully adding an attachment
*/
public function addEmbeddedImage($path, $cid, $name = ”, $encoding = ‘base64’, $type = ”, $disposition = ‘inline’)
{
if (!@is_file($path)) {
$this->setError($this->lang(‘file_access’) . $path);
return false;
}

// If a MIME type is not specified, try to work it out from the file name
if ($type == ”) {
$type = self::filenameToType($path);
}

$filename = basename($path);
if ($name == ”) {
$name = $filename;
}

// Append to $attachment array
$this->attachment[] = array(
0 => $path,
1 => $filename,
2 => $name,
3 => $encoding,
4 => $type,
5 => false, // isStringAttachment
6 => $disposition,
7 => $cid
);
return true;
}

/**
* Add an embedded stringified attachment.
* This can include images, sounds, and just about any other document type.
* Be sure to set the $type to an image type for images:
* JPEG images use ‘image/jpeg’, GIF uses ‘image/gif’, PNG uses ‘image/png’.
* @param string $string The attachment binary data.
* @param string $cid Content ID of the attachment; Use this to reference
* the content when using an embedded image in HTML.
* @param string $name
* @param string $encoding File encoding (see $Encoding).
* @param string $type MIME type.
* @param string $disposition Disposition to use
* @return boolean True on successfully adding an attachment
*/
public function addStringEmbeddedImage(
$string,
$cid,
$name = ”,
$encoding = ‘base64’,
$type = ”,
$disposition = ‘inline’
) {
// If a MIME type is not specified, try to work it out from the name
if ($type == ” and !empty($name)) {
$type = self::filenameToType($name);
}

// Append to $attachment array
$this->attachment[] = array(
0 => $string,
1 => $name,
2 => $name,
3 => $encoding,
4 => $type,
5 => true, // isStringAttachment
6 => $disposition,
7 => $cid
);
return true;
}

/**
* Check if an inline attachment is present.
* @access public
* @return boolean
*/
public function inlineImageExists()
{
foreach ($this->attachment as $attachment) {
if ($attachment[6] == ‘inline’) {
return true;
}
}
return false;
}

/**
* Check if an attachment (non-inline) is present.
* @return boolean
*/
public function attachmentExists()
{
foreach ($this->attachment as $attachment) {
if ($attachment[6] == ‘attachment’) {
return true;
}
}
return false;
}

/**
* Check if this message has an alternative body set.
* @return boolean
*/
public function alternativeExists()
{
return !empty($this->AltBody);
}

/**
* Clear queued addresses of given kind.
* @access protected
* @param string $kind ‘to’, ‘cc’, or ‘bcc’
* @return void
*/
public function clearQueuedAddresses($kind)
{
$RecipientsQueue = $this->RecipientsQueue;
foreach ($RecipientsQueue as $address => $params) {
if ($params[0] == $kind) {
unset($this->RecipientsQueue[$address]);
}
}
}

/**
* Clear all To recipients.
* @return void
*/
public function clearAddresses()
{
foreach ($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]);
}
$this->to = array();
$this->clearQueuedAddresses(‘to’);
}

/**
* Clear all CC recipients.
* @return void
*/
public function clearCCs()
{
foreach ($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]);
}
$this->cc = array();
$this->clearQueuedAddresses(‘cc’);
}

/**
* Clear all BCC recipients.
* @return void
*/
public function clearBCCs()
{
foreach ($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]);
}
$this->bcc = array();
$this->clearQueuedAddresses(‘bcc’);
}

/**
* Clear all ReplyTo recipients.
* @return void
*/
public function clearReplyTos()
{
$this->ReplyTo = array();
$this->ReplyToQueue = array();
}

/**
* Clear all recipient types.
* @return void
*/
public function clearAllRecipients()
{
$this->to = array();
$this->cc = array();
$this->bcc = array();
$this->all_recipients = array();
$this->RecipientsQueue = array();
}

/**
* Clear all filesystem, string, and binary attachments.
* @return void
*/
public function clearAttachments()
{
$this->attachment = array();
}

/**
* Clear all custom headers.
* @return void
*/
public function clearCustomHeaders()
{
$this->CustomHeader = array();
}

/**
* Add an error message to the error container.
* @access protected
* @param string $msg
* @return void
*/
protected function setError($msg)
{
$this->error_count++;
if ($this->Mailer == ‘smtp’ and !is_null($this->smtp)) {
$lasterror = $this->smtp->getError();
if (!empty($lasterror[‘error’])) {
$msg .= $this->lang(‘smtp_error’) . $lasterror[‘error’];
if (!empty($lasterror[‘detail’])) {
$msg .= ‘ Detail: ‘. $lasterror[‘detail’];
}
if (!empty($lasterror[‘smtp_code’])) {
$msg .= ‘ SMTP code: ‘ . $lasterror[‘smtp_code’];
}
if (!empty($lasterror[‘smtp_code_ex’])) {
$msg .= ‘ Additional SMTP info: ‘ . $lasterror[‘smtp_code_ex’];
}
}
}
$this->ErrorInfo = $msg;
}

/**
* Return an RFC 822 formatted date.
* @access public
* @return string
* @static
*/
public static function rfcDate()
{
// Set the time zone to whatever the default is to avoid 500 errors
// Will default to UTC if it’s not set properly in php.ini
date_default_timezone_set(@date_default_timezone_get());
return date(‘D, j M Y H:i:s O’);
}

/**
* Get the server hostname.
* Returns ‘localhost.localdomain’ if unknown.
* @access protected
* @return string
*/
protected function serverHostname()
{
$result = ‘localhost.localdomain’;
if (!empty($this->Hostname)) {
$result = $this->Hostname;
} elseif (isset($_SERVER) and array_key_exists(‘SERVER_NAME’, $_SERVER) and !empty($_SERVER[‘SERVER_NAME’])) {
$result = $_SERVER[‘SERVER_NAME’];
} elseif (function_exists(‘gethostname’) && gethostname() !== false) {
$result = gethostname();
} elseif (php_uname(‘n’) !== false) {
$result = php_uname(‘n’);
}
return $result;
}

/**
* Get an error message in the current language.
* @access protected
* @param string $key
* @return string
*/
protected function lang($key)
{
if (count($this->language) < 1) {
$this->setLanguage(‘en’); // set the default language
}

if (array_key_exists($key, $this->language)) {
if ($key == ‘smtp_connect_failed’) {
//Include a link to troubleshooting docs on SMTP connection failure
//this is by far the biggest cause of support questions
//but it’s usually not PHPMailer’s fault.
return $this->language[$key] . ‘ https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting’;
}
return $this->language[$key];
} else {
//Return the key as a fallback
return $key;
}
}

/**
* Check if an error occurred.
* @access public
* @return boolean True if an error did occur.
*/
public function isError()
{
return ($this->error_count > 0);
}

/**
* Ensure consistent line endings in a string.
* Changes every end of line from CRLF, CR or LF to $this->LE.
* @access public
* @param string $str String to fixEOL
* @return string
*/
public function fixEOL($str)
{
// Normalise to \n
$nstr = str_replace(array(“\r\n”, “\r”), “\n”, $str);
// Now convert LE as needed
if ($this->LE !== “\n”) {
$nstr = str_replace(“\n”, $this->LE, $nstr);
}
return $nstr;
}

/**
* Add a custom header.
* $name value can be overloaded to contain
* both header name and value (name:value)
* @access public
* @param string $name Custom header name
* @param string $value Header value
* @return void
*/
public function addCustomHeader($name, $value = null)
{
if ($value === null) {
// Value passed in as name:value
$this->CustomHeader[] = explode(‘:’, $name, 2);
} else {
$this->CustomHeader[] = array($name, $value);
}
}

/**
* Returns all custom headers.
* @return array
*/
public function getCustomHeaders()
{
return $this->CustomHeader;
}

/**
* Create a message from an HTML string.
* Automatically makes modifications for inline images and backgrounds
* and creates a plain-text version by converting the HTML.
* Overwrites any existing values in $this->Body and $this->AltBody
* @access public
* @param string $message HTML message string
* @param string $basedir baseline directory for path
* @param boolean|callable $advanced Whether to use the internal HTML to text converter
* or your own custom converter @see PHPMailer::html2text()
* @return string $message
*/
public function msgHTML($message, $basedir = ”, $advanced = false)
{
preg_match_all(‘/(src|background)=[“\’](.*)[“\’]/Ui’, $message, $images);
if (array_key_exists(2, $images)) {
foreach ($images[2] as $imgindex => $url) {
// Convert data URIs into embedded images
if (preg_match(‘#^data:(image[^;,]*)(;base64)?,#’, $url, $match)) {
$data = substr($url, strpos($url, ‘,’));
if ($match[2]) {
$data = base64_decode($data);
} else {
$data = rawurldecode($data);
}
$cid = md5($url) . ‘@phpmailer.0′; // RFC2392 S 2
if ($this->addStringEmbeddedImage($data, $cid, ’embed’ . $imgindex, ‘base64’, $match[1])) {
$message = str_replace(
$images[0][$imgindex],
$images[1][$imgindex] . ‘=”cid:’ . $cid . ‘”‘,
$message
);
}
} elseif (substr($url, 0, 4) !== ‘cid:’ && !preg_match(‘#^[a-z][a-z0-9+.-]*://#i’, $url)) {
// Do not change urls for absolute images (thanks to corvuscorax)
// Do not change urls that are already inline images
$filename = basename($url);
$directory = dirname($url);
if ($directory == ‘.’) {
$directory = ”;
}
$cid = md5($url) . ‘@phpmailer.0’; // RFC2392 S 2
if (strlen($basedir) > 1 && substr($basedir, -1) != ‘/’) {
$basedir .= ‘/’;
}
if (strlen($directory) > 1 && substr($directory, -1) != ‘/’) {
$directory .= ‘/’;
}
if ($this->addEmbeddedImage(
$basedir . $directory . $filename,
$cid,
$filename,
‘base64’,
self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
)
) {
$message = preg_replace(
‘/’ . $images[1][$imgindex] . ‘=[“\’]’ . preg_quote($url, ‘/’) . ‘[“\’]/Ui’,
$images[1][$imgindex] . ‘=”cid:’ . $cid . ‘”‘,
$message
);
}
}
}
}
$this->isHTML(true);
// Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
$this->Body = $this->normalizeBreaks($message);
$this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
if (!$this->alternativeExists()) {
$this->AltBody = ‘To view this email message, open it in a program that understands HTML!’ .
self::CRLF . self::CRLF;
}
return $this->Body;
}

/**
* Convert an HTML string into plain text.
* This is used by msgHTML().
* Note – older versions of this function used a bundled advanced converter
* which was been removed for license reasons in #232
* Example usage:
*
* // Use default conversion
* $plain = $mail->html2text($html);
* // Use your own custom converter
* $plain = $mail->html2text($html, function($html) {
* $converter = new MyHtml2text($html);
* return $converter->get_text();
* });
*

* @param string $html The HTML text to convert
* @param boolean|callable $advanced Any boolean value to use the internal converter,
* or provide your own callable for custom conversion.
* @return string
*/
public function html2text($html, $advanced = false)
{
if (is_callable($advanced)) {
return call_user_func($advanced, $html);
}
return html_entity_decode(
trim(strip_tags(preg_replace(‘/<(head|title|style|script)[^>]*>.*?<\/\\1>/si’, ”, $html))),
ENT_QUOTES,
$this->CharSet
);
}

/**
* Get the MIME type for a file extension.
* @param string $ext File extension
* @access public
* @return string MIME type of file.
* @static
*/
public static function _mime_types($ext = ”)
{
$mimes = array(
‘xl’ => ‘application/excel’,
‘js’ => ‘application/javascript’,
‘hqx’ => ‘application/mac-binhex40’,
‘cpt’ => ‘application/mac-compactpro’,
‘bin’ => ‘application/macbinary’,
‘doc’ => ‘application/msword’,
‘word’ => ‘application/msword’,
‘xlsx’ => ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’,
‘xltx’ => ‘application/vnd.openxmlformats-officedocument.spreadsheetml.template’,
‘potx’ => ‘application/vnd.openxmlformats-officedocument.presentationml.template’,
‘ppsx’ => ‘application/vnd.openxmlformats-officedocument.presentationml.slideshow’,
‘pptx’ => ‘application/vnd.openxmlformats-officedocument.presentationml.presentation’,
‘sldx’ => ‘application/vnd.openxmlformats-officedocument.presentationml.slide’,
‘docx’ => ‘application/vnd.openxmlformats-officedocument.wordprocessingml.document’,
‘dotx’ => ‘application/vnd.openxmlformats-officedocument.wordprocessingml.template’,
‘xlam’ => ‘application/vnd.ms-excel.addin.macroEnabled.12’,
‘xlsb’ => ‘application/vnd.ms-excel.sheet.binary.macroEnabled.12’,
‘class’ => ‘application/octet-stream’,
‘dll’ => ‘application/octet-stream’,
‘dms’ => ‘application/octet-stream’,
‘exe’ => ‘application/octet-stream’,
‘lha’ => ‘application/octet-stream’,
‘lzh’ => ‘application/octet-stream’,
‘psd’ => ‘application/octet-stream’,
‘sea’ => ‘application/octet-stream’,
‘so’ => ‘application/octet-stream’,
‘oda’ => ‘application/oda’,
‘pdf’ => ‘application/pdf’,
‘ai’ => ‘application/postscript’,
‘eps’ => ‘application/postscript’,
‘ps’ => ‘application/postscript’,
‘smi’ => ‘application/smil’,
‘smil’ => ‘application/smil’,
‘mif’ => ‘application/vnd.mif’,
‘xls’ => ‘application/vnd.ms-excel’,
‘ppt’ => ‘application/vnd.ms-powerpoint’,
‘wbxml’ => ‘application/vnd.wap.wbxml’,
‘wmlc’ => ‘application/vnd.wap.wmlc’,
‘dcr’ => ‘application/x-director’,
‘dir’ => ‘application/x-director’,
‘dxr’ => ‘application/x-director’,
‘dvi’ => ‘application/x-dvi’,
‘gtar’ => ‘application/x-gtar’,
‘php3’ => ‘application/x-httpd-php’,
‘php4’ => ‘application/x-httpd-php’,
‘php’ => ‘application/x-httpd-php’,
‘phtml’ => ‘application/x-httpd-php’,
‘phps’ => ‘application/x-httpd-php-source’,
‘swf’ => ‘application/x-shockwave-flash’,
‘sit’ => ‘application/x-stuffit’,
‘tar’ => ‘application/x-tar’,
‘tgz’ => ‘application/x-tar’,
‘xht’ => ‘application/xhtml+xml’,
‘xhtml’ => ‘application/xhtml+xml’,
‘zip’ => ‘application/zip’,
‘mid’ => ‘audio/midi’,
‘midi’ => ‘audio/midi’,
‘mp2’ => ‘audio/mpeg’,
‘mp3’ => ‘audio/mpeg’,
‘mpga’ => ‘audio/mpeg’,
‘aif’ => ‘audio/x-aiff’,
‘aifc’ => ‘audio/x-aiff’,
‘aiff’ => ‘audio/x-aiff’,
‘ram’ => ‘audio/x-pn-realaudio’,
‘rm’ => ‘audio/x-pn-realaudio’,
‘rpm’ => ‘audio/x-pn-realaudio-plugin’,
‘ra’ => ‘audio/x-realaudio’,
‘wav’ => ‘audio/x-wav’,
‘bmp’ => ‘image/bmp’,
‘gif’ => ‘image/gif’,
‘jpeg’ => ‘image/jpeg’,
‘jpe’ => ‘image/jpeg’,
‘jpg’ => ‘image/jpeg’,
‘png’ => ‘image/png’,
‘tiff’ => ‘image/tiff’,
‘tif’ => ‘image/tiff’,
’eml’ => ‘message/rfc822’,
‘css’ => ‘text/css’,
‘html’ => ‘text/html’,
‘htm’ => ‘text/html’,
‘shtml’ => ‘text/html’,
‘log’ => ‘text/plain’,
‘text’ => ‘text/plain’,
‘txt’ => ‘text/plain’,
‘rtx’ => ‘text/richtext’,
‘rtf’ => ‘text/rtf’,
‘vcf’ => ‘text/vcard’,
‘vcard’ => ‘text/vcard’,
‘xml’ => ‘text/xml’,
‘xsl’ => ‘text/xml’,
‘mpeg’ => ‘video/mpeg’,
‘mpe’ => ‘video/mpeg’,
‘mpg’ => ‘video/mpeg’,
‘mov’ => ‘video/quicktime’,
‘qt’ => ‘video/quicktime’,
‘rv’ => ‘video/vnd.rn-realvideo’,
‘avi’ => ‘video/x-msvideo’,
‘movie’ => ‘video/x-sgi-movie’
);
if (array_key_exists(strtolower($ext), $mimes)) {
return $mimes[strtolower($ext)];
}
return ‘application/octet-stream’;
}

/**
* Map a file name to a MIME type.
* Defaults to ‘application/octet-stream’, i.e.. arbitrary binary data.
* @param string $filename A file name or full path, does not need to exist as a file
* @return string
* @static
*/
public static function filenameToType($filename)
{
// In case the path is a URL, strip any query string before getting extension
$qpos = strpos($filename, ‘?’);
if (false !== $qpos) {
$filename = substr($filename, 0, $qpos);
}
$pathinfo = self::mb_pathinfo($filename);
return self::_mime_types($pathinfo[‘extension’]);
}

/**
* Multi-byte-safe pathinfo replacement.
* Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
* Works similarly to the one in PHP >= 5.2.0
* @link http://www.php.net/manual/en/function.pathinfo.php#107461
* @param string $path A filename or path, does not need to exist as a file
* @param integer|string $options Either a PATHINFO_* constant,
* or a string name to return only the specified piece, allows ‘filename’ to work on PHP < 5.2
* @return string|array
* @static
*/
public static function mb_pathinfo($path, $options = null)
{
$ret = array(‘dirname’ => ”, ‘basename’ => ”, ‘extension’ => ”, ‘filename’ => ”);
$pathinfo = array();
if (preg_match(‘%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im’, $path, $pathinfo)) {
if (array_key_exists(1, $pathinfo)) {
$ret[‘dirname’] = $pathinfo[1];
}
if (array_key_exists(2, $pathinfo)) {
$ret[‘basename’] = $pathinfo[2];
}
if (array_key_exists(5, $pathinfo)) {
$ret[‘extension’] = $pathinfo[5];
}
if (array_key_exists(3, $pathinfo)) {
$ret[‘filename’] = $pathinfo[3];
}
}
switch ($options) {
case PATHINFO_DIRNAME:
case ‘dirname’:
return $ret[‘dirname’];
case PATHINFO_BASENAME:
case ‘basename’:
return $ret[‘basename’];
case PATHINFO_EXTENSION:
case ‘extension’:
return $ret[‘extension’];
case PATHINFO_FILENAME:
case ‘filename’:
return $ret[‘filename’];
default:
return $ret;
}
}

/**
* Set or reset instance properties.
* You should avoid this function – it’s more verbose, less efficient, more error-prone and
* harder to debug than setting properties directly.
* Usage Example:
* `$mail->set(‘SMTPSecure’, ‘tls’);`
* is the same as:
* `$mail->SMTPSecure = ‘tls’;`
* @access public
* @param string $name The property name to set
* @param mixed $value The value to set the property to
* @return boolean
* @TODO Should this not be using the __set() magic function?
*/
public function set($name, $value = ”)
{
if (property_exists($this, $name)) {
$this->$name = $value;
return true;
} else {
$this->setError($this->lang(‘variable_set’) . $name);
return false;
}
}

/**
* Strip newlines to prevent header injection.
* @access public
* @param string $str
* @return string
*/
public function secureHeader($str)
{
return trim(str_replace(array(“\r”, “\n”), ”, $str));
}

/**
* Normalize line breaks in a string.
* Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
* Defaults to CRLF (for message bodies) and preserves consecutive breaks.
* @param string $text
* @param string $breaktype What kind of line break to use, defaults to CRLF
* @return string
* @access public
* @static
*/
public static function normalizeBreaks($text, $breaktype = “\r\n”)
{
return preg_replace(‘/(\r\n|\r|\n)/ms’, $breaktype, $text);
}

/**
* Set the public and private key files and password for S/MIME signing.
* @access public
* @param string $cert_filename
* @param string $key_filename
* @param string $key_pass Password for private key
* @param string $extracerts_filename Optional path to chain certificate
*/
public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = ”)
{
$this->sign_cert_file = $cert_filename;
$this->sign_key_file = $key_filename;
$this->sign_key_pass = $key_pass;
$this->sign_extracerts_file = $extracerts_filename;
}

/**
* Quoted-Printable-encode a DKIM header.
* @access public
* @param string $txt
* @return string
*/
public function DKIM_QP($txt)
{
$line = ”;
for ($i = 0; $i < strlen($txt); $i++) {
$ord = ord($txt[$i]);
if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
$line .= $txt[$i];
} else {
$line .= ‘=’ . sprintf(‘%02X’, $ord);
}
}
return $line;
}

/**
* Generate a DKIM signature.
* @access public
* @param string $signHeader
* @throws phpmailerException
* @return string
*/
public function DKIM_Sign($signHeader)
{
if (!defined(‘PKCS7_TEXT’)) {
if ($this->exceptions) {
throw new phpmailerException($this->lang(‘extension_missing’) . ‘openssl’);
}
return ”;
}
$privKeyStr = file_get_contents($this->DKIM_private);
if ($this->DKIM_passphrase != ”) {
$privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
} else {
$privKey = openssl_pkey_get_private($privKeyStr);
}
if (openssl_sign($signHeader, $signature, $privKey, ‘sha256WithRSAEncryption’)) { //sha1WithRSAEncryption
openssl_pkey_free($privKey);
return base64_encode($signature);
}
openssl_pkey_free($privKey);
return ”;
}

/**
* Generate a DKIM canonicalization header.
* @access public
* @param string $signHeader Header
* @return string
*/
public function DKIM_HeaderC($signHeader)
{
$signHeader = preg_replace(‘/\r\n\s+/’, ‘ ‘, $signHeader);
$lines = explode(“\r\n”, $signHeader);
foreach ($lines as $key => $line) {
list($heading, $value) = explode(‘:’, $line, 2);
$heading = strtolower($heading);
$value = preg_replace(‘/\s{2,}/’, ‘ ‘, $value); // Compress useless spaces
$lines[$key] = $heading . ‘:’ . trim($value); // Don’t forget to remove WSP around the value
}
$signHeader = implode(“\r\n”, $lines);
return $signHeader;
}

/**
* Generate a DKIM canonicalization body.
* @access public
* @param string $body Message Body
* @return string
*/
public function DKIM_BodyC($body)
{
if ($body == ”) {
return “\r\n”;
}
// stabilize line endings
$body = str_replace(“\r\n”, “\n”, $body);
$body = str_replace(“\n”, “\r\n”, $body);
// END stabilize line endings
while (substr($body, strlen($body) – 4, 4) == “\r\n\r\n”) {
$body = substr($body, 0, strlen($body) – 2);
}
return $body;
}

/**
* Create the DKIM header and body in a new message header.
* @access public
* @param string $headers_line Header lines
* @param string $subject Subject
* @param string $body Body
* @return string
*/
public function DKIM_Add($headers_line, $subject, $body)
{
$DKIMsignatureType = ‘rsa-sha256’; // Signature & hash algorithms
$DKIMcanonicalization = ‘relaxed/simple’; // Canonicalization of header/body
$DKIMquery = ‘dns/txt’; // Query method
$DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 – Jan 1, 1970 (UTC time zone)
$subject_header = “Subject: $subject”;
$headers = explode($this->LE, $headers_line);
$from_header = ”;
$to_header = ”;
$date_header = ”;
$current = ”;
foreach ($headers as $header) {
if (strpos($header, ‘From:’) === 0) {
$from_header = $header;
$current = ‘from_header’;
} elseif (strpos($header, ‘To:’) === 0) {
$to_header = $header;
$current = ‘to_header’;
} elseif (strpos($header, ‘Date:’) === 0) {
$date_header = $header;
$current = ‘date_header’;
} else {
if (!empty($$current) && strpos($header, ‘ =?’) === 0) {
$$current .= $header;
} else {
$current = ”;
}
}
}
$from = str_replace(‘|’, ‘=7C’, $this->DKIM_QP($from_header));
$to = str_replace(‘|’, ‘=7C’, $this->DKIM_QP($to_header));
$date = str_replace(‘|’, ‘=7C’, $this->DKIM_QP($date_header));
$subject = str_replace(
‘|’,
‘=7C’,
$this->DKIM_QP($subject_header)
); // Copied header fields (dkim-quoted-printable)
$body = $this->DKIM_BodyC($body);
$DKIMlen = strlen($body); // Length of body
$DKIMb64 = base64_encode(pack(‘H*’, hash(‘sha256’, $body))); // Base64 of packed binary SHA-256 hash of body
if (” == $this->DKIM_identity) {
$ident = ”;
} else {
$ident = ‘ i=’ . $this->DKIM_identity . ‘;’;
}
$dkimhdrs = ‘DKIM-Signature: v=1; a=’ .
$DKIMsignatureType . ‘; q=’ .
$DKIMquery . ‘; l=’ .
$DKIMlen . ‘; s=’ .
$this->DKIM_selector .
“;\r\n” .
“\tt=” . $DKIMtime . ‘; c=’ . $DKIMcanonicalization . “;\r\n” .
“\th=From:To:Date:Subject;\r\n” .
“\td=” . $this->DKIM_domain . ‘;’ . $ident . “\r\n” .
“\tz=$from\r\n” .
“\t|$to\r\n” .
“\t|$date\r\n” .
“\t|$subject;\r\n” .
“\tbh=” . $DKIMb64 . “;\r\n” .
“\tb=”;
$toSign = $this->DKIM_HeaderC(
$from_header . “\r\n” .
$to_header . “\r\n” .
$date_header . “\r\n” .
$subject_header . “\r\n” .
$dkimhdrs
);
$signed = $this->DKIM_Sign($toSign);
return $dkimhdrs . $signed . “\r\n”;
}

/**
* Detect if a string contains a line longer than the maximum line length allowed.
* @param string $str
* @return boolean
* @static
*/
public static function hasLineLongerThanMax($str)
{
//+2 to include CRLF line break for a 1000 total
return (boolean)preg_match(‘/^(.{‘.(self::MAX_LINE_LENGTH + 2).’,})/m’, $str);
}

/**
* Allows for public read access to ‘to’ property.
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
* @access public
* @return array
*/
public function getToAddresses()
{
return $this->to;
}

/**
* Allows for public read access to ‘cc’ property.
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
* @access public
* @return array
*/
public function getCcAddresses()
{
return $this->cc;
}

/**
* Allows for public read access to ‘bcc’ property.
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
* @access public
* @return array
*/
public function getBccAddresses()
{
return $this->bcc;
}

/**
* Allows for public read access to ‘ReplyTo’ property.
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
* @access public
* @return array
*/
public function getReplyToAddresses()
{
return $this->ReplyTo;
}

/**
* Allows for public read access to ‘all_recipients’ property.
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
* @access public
* @return array
*/
public function getAllRecipientAddresses()
{
return $this->all_recipients;
}

/**
* Perform a callback.
* @param boolean $isSent
* @param array $to
* @param array $cc
* @param array $bcc
* @param string $subject
* @param string $body
* @param string $from
*/
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
{
if (!empty($this->action_function) && is_callable($this->action_function)) {
$params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
call_user_func_array($this->action_function, $params);
}
}
}

/**
* PHPMailer exception handler
* @package PHPMailer
*/
class phpmailerException extends Exception
{
/**
* Prettify error message output
* @return string
*/
public function errorMessage()
{
$errorMsg = ‘‘ . $this->getMessage() . “
\n”;
return $errorMsg;
}
}
/**
* PHPMailer RFC821 SMTP email transport class.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag)
* @author Andy Prevost (codeworxtech)
* @author Brent R. Matzelle (original founder)
* @copyright 2014 Marcus Bointon
* @copyright 2010 – 2012 Jim Jagielski
* @copyright 2004 – 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful – WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/

/**
* PHPMailer RFC821 SMTP email transport class.
* Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
* @package PHPMailer
* @author Chris Ryan
* @author Marcus Bointon */
class SMTP
{
/**
* The PHPMailer SMTP version number.
* @var string
*/
const VERSION = ‘5.2.16’;

/**
* SMTP line break constant.
* @var string
*/
const CRLF = “\r\n”;

/**
* The SMTP port to use if one is not specified.
* @var integer
*/
const DEFAULT_SMTP_PORT = 25;

/**
* The maximum line length allowed by RFC 2822 section 2.1.1
* @var integer
*/
const MAX_LINE_LENGTH = 998;

/**
* Debug level for no output
*/
const DEBUG_OFF = 0;

/**
* Debug level to show client -> server messages
*/
const DEBUG_CLIENT = 1;

/**
* Debug level to show client -> server and server -> client messages
*/
const DEBUG_SERVER = 2;

/**
* Debug level to show connection status, client -> server and server -> client messages
*/
const DEBUG_CONNECTION = 3;

/**
* Debug level to show all messages
*/
const DEBUG_LOWLEVEL = 4;

/**
* The PHPMailer SMTP Version number.
* @var string
* @deprecated Use the `VERSION` constant instead
* @see SMTP::VERSION
*/
public $Version = ‘5.2.16’;

/**
* SMTP server port number.
* @var integer
* @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
* @see SMTP::DEFAULT_SMTP_PORT
*/
public $SMTP_PORT = 25;

/**
* SMTP reply line ending.
* @var string
* @deprecated Use the `CRLF` constant instead
* @see SMTP::CRLF
*/
public $CRLF = “\r\n”;

/**
* Debug output level.
* Options:
* * self::DEBUG_OFF (`0`) No debug output, default
* * self::DEBUG_CLIENT (`1`) Client commands
* * self::DEBUG_SERVER (`2`) Client commands and server responses
* * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
* * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
* @var integer
*/
public $do_debug = self::DEBUG_OFF;

/**
* How to handle debug output.
* Options:
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to `
`, appropriate for browser output
* * `error_log` Output to error log as configured in php.ini
*
* Alternatively, you can provide a callable expecting two params: a message string and the debug level:
*
* $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
*

* @var string|callable
*/
public $Debugoutput = ‘echo’;

/**
* Whether to use VERP.
* @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
* @link http://www.postfix.org/VERP_README.html Info on VERP
* @var boolean
*/
public $do_verp = false;

/**
* The timeout value for connection, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
* @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
* @var integer
*/
public $Timeout = 300;

/**
* How long to wait for commands to complete, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* @var integer
*/
public $Timelimit = 300;

/**
* The socket for the server connection.
* @var resource
*/
protected $smtp_conn;

/**
* Error information, if any, for the last SMTP command.
* @var array
*/
protected $error = array(
‘error’ => ”,
‘detail’ => ”,
‘smtp_code’ => ”,
‘smtp_code_ex’ => ”
);

/**
* The reply the server sent to us for HELO.
* If null, no HELO string has yet been received.
* @var string|null
*/
protected $helo_rply = null;

/**
* The set of SMTP extensions sent in reply to EHLO command.
* Indexes of the array are extension names.
* Value at index ‘HELO’ or ‘EHLO’ (according to command that was sent)
* represents the server name. In case of HELO it is the only element of the array.
* Other values can be boolean TRUE or an array containing extension options.
* If null, no HELO/EHLO string has yet been received.
* @var array|null
*/
protected $server_caps = null;

/**
* The most recent reply received from the server.
* @var string
*/
protected $last_reply = ”;

/**
* Output debugging info via a user-selected method.
* @see SMTP::$Debugoutput
* @see SMTP::$do_debug
* @param string $str Debug string to output
* @param integer $level The debug level of this message; see DEBUG_* constants
* @return void
*/
protected function edebug($str, $level = 0)
{
if ($level > $this->do_debug) {
return;
}
//Avoid clash with built-in function names
if (!in_array($this->Debugoutput, array(‘error_log’, ‘html’, ‘echo’)) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->do_debug);
return;
}
switch ($this->Debugoutput) {
case ‘error_log’:
//Don’t output, just log
error_log($str);
break;
case ‘html’:
//Cleans up output a bit for a better looking, HTML-safe output
echo htmlentities(
preg_replace(‘/[\r\n]+/’, ”, $str),
ENT_QUOTES,
‘UTF-8’
)
. “
\n”;
break;
case ‘echo’:
default:
//Normalize line breaks
$str = preg_replace(‘/(\r\n|\r|\n)/ms’, “\n”, $str);
echo gmdate(‘Y-m-d H:i:s’) . “\t” . str_replace(
“\n”,
“\n \t “,
trim($str)
).”\n”;
}
}

/**
* Connect to an SMTP server.
* @param string $host SMTP server IP or host name
* @param integer $port The port number to connect to
* @param integer $timeout How long to wait for the connection to open
* @param array $options An array of options for stream_context_create()
* @access public
* @return boolean
*/
public function connect($host, $port = null, $timeout = 30, $options = array())
{
static $streamok;
//This is enabled by default since 5.0.0 but some providers disable it
//Check this once and cache the result
if (is_null($streamok)) {
$streamok = function_exists(‘stream_socket_client’);
}
// Clear errors to avoid confusion
$this->setError(”);
// Make sure we are __not__ connected
if ($this->connected()) {
// Already connected, generate error
$this->setError(‘Already connected to a server’);
return false;
}
if (empty($port)) {
$port = self::DEFAULT_SMTP_PORT;
}
// Connect to the SMTP server
$this->edebug(
“Connection: opening to $host:$port, timeout=$timeout, options=”.var_export($options, true),
self::DEBUG_CONNECTION
);
$errno = 0;
$errstr = ”;
if ($streamok) {
$socket_context = stream_context_create($options);
//Suppress errors; connection failures are handled at a higher level
$this->smtp_conn = @stream_socket_client(
$host . “:” . $port,
$errno,
$errstr,
$timeout,
STREAM_CLIENT_CONNECT,
$socket_context
);
} else {
//Fall back to fsockopen which should work in more places, but is missing some features
$this->edebug(
“Connection: stream_socket_client not available, falling back to fsockopen”,
self::DEBUG_CONNECTION
);
$this->smtp_conn = fsockopen(
$host,
$port,
$errno,
$errstr,
$timeout
);
}
// Verify we connected properly
if (!is_resource($this->smtp_conn)) {
$this->setError(
‘Failed to connect to server’,
$errno,
$errstr
);
$this->edebug(
‘SMTP ERROR: ‘ . $this->error[‘error’]
. “: $errstr ($errno)”,
self::DEBUG_CLIENT
);
return false;
}
$this->edebug(‘Connection: opened’, self::DEBUG_CONNECTION);
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if (substr(PHP_OS, 0, 3) != ‘WIN’) {
$max = ini_get(‘max_execution_time’);
// Don’t bother if unlimited
if ($max != 0 && $timeout > $max) {
@set_time_limit($timeout);
}
stream_set_timeout($this->smtp_conn, $timeout, 0);
}
// Get any announcement
$announce = $this->get_lines();
$this->edebug(‘SERVER -> CLIENT: ‘ . $announce, self::DEBUG_SERVER);
return true;
}

/**
* Initiate a TLS (encrypted) session.
* @access public
* @return boolean
*/
public function startTLS()
{
if (!$this->sendCommand(‘STARTTLS’, ‘STARTTLS’, 220)) {
return false;
}

//Allow the best TLS version(s) we can
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;

//PHP 5.6.7 dropped inclusion of TLS 1.1 and 1.2 in STREAM_CRYPTO_METHOD_TLS_CLIENT
//so add them back in manually if we can
if (defined(‘STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT’)) {
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
}

// Begin encrypted connection
if (!stream_socket_enable_crypto(
$this->smtp_conn,
true,
$crypto_method
)) {
return false;
}
return true;
}

/**
* Perform SMTP authentication.
* Must be run after hello().
* @see hello()
* @param string $username The user name
* @param string $password The password
* @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2)
* @param string $realm The auth realm for NTLM
* @param string $workstation The auth workstation for NTLM
* @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth)
* @return bool True if successfully authenticated.* @access public
*/
public function authenticate(
$username,
$password,
$authtype = null,
$realm = ”,
$workstation = ”,
$OAuth = null
) {
if (!$this->server_caps) {
$this->setError(‘Authentication is not allowed before HELO/EHLO’);
return false;
}

if (array_key_exists(‘EHLO’, $this->server_caps)) {
// SMTP extensions are available. Let’s try to find a proper authentication method

if (!array_key_exists(‘AUTH’, $this->server_caps)) {
$this->setError(‘Authentication is not allowed at this stage’);
// ‘at this stage’ means that auth may be allowed after the stage changes
// e.g. after STARTTLS
return false;
}

self::edebug(‘Auth method requested: ‘ . ($authtype ? $authtype : ‘UNKNOWN’), self::DEBUG_LOWLEVEL);
self::edebug(
‘Auth methods available on the server: ‘ . implode(‘,’, $this->server_caps[‘AUTH’]),
self::DEBUG_LOWLEVEL
);

if (empty($authtype)) {
foreach (array(‘CRAM-MD5’, ‘LOGIN’, ‘PLAIN’, ‘NTLM’, ‘XOAUTH2’) as $method) {
if (in_array($method, $this->server_caps[‘AUTH’])) {
$authtype = $method;
break;
}
}
if (empty($authtype)) {
$this->setError(‘No supported authentication methods found’);
return false;
}
self::edebug(‘Auth method selected: ‘.$authtype, self::DEBUG_LOWLEVEL);
}

if (!in_array($authtype, $this->server_caps[‘AUTH’])) {
$this->setError(“The requested authentication method \”$authtype\” is not supported by the server”);
return false;
}
} elseif (empty($authtype)) {
$authtype = ‘LOGIN’;
}
switch ($authtype) {
case ‘PLAIN’:
// Start authentication
if (!$this->sendCommand(‘AUTH’, ‘AUTH PLAIN’, 334)) {
return false;
}
// Send encoded username and password
if (!$this->sendCommand(
‘User & Password’,
base64_encode(“\0” . $username . “\0” . $password),
235
)
) {
return false;
}
break;
case ‘LOGIN’:
// Start authentication
if (!$this->sendCommand(‘AUTH’, ‘AUTH LOGIN’, 334)) {
return false;
}
if (!$this->sendCommand(“Username”, base64_encode($username), 334)) {
return false;
}
if (!$this->sendCommand(“Password”, base64_encode($password), 235)) {
return false;
}
break;
case ‘XOAUTH2’:
//If the OAuth Instance is not set. Can be a case when PHPMailer is used
//instead of PHPMailerOAuth
if (is_null($OAuth)) {
return false;
}
$oauth = $OAuth->getOauth64();

// Start authentication
if (!$this->sendCommand(‘AUTH’, ‘AUTH XOAUTH2 ‘ . $oauth, 235)) {
return false;
}
break;
case ‘NTLM’:
/*
* ntlm_sasl_client.php
* Bundled with Permission
*
* How to telnet in windows:
* http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
* PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
*/
require_once ‘extras/ntlm_sasl_client.php’;
$temp = new stdClass;
$ntlm_client = new ntlm_sasl_client_class;
//Check that functions are available
if (!$ntlm_client->Initialize($temp)) {
$this->setError($temp->error);
$this->edebug(
‘You need to enable some modules in your php.ini file: ‘
. $this->error[‘error’],
self::DEBUG_CLIENT
);
return false;
}
//msg1
$msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1

if (!$this->sendCommand(
‘AUTH NTLM’,
‘AUTH NTLM ‘ . base64_encode($msg1),
334
)
) {
return false;
}
//Though 0 based, there is a white space after the 3 digit number
//msg2
$challenge = substr($this->last_reply, 3);
$challenge = base64_decode($challenge);
$ntlm_res = $ntlm_client->NTLMResponse(
substr($challenge, 24, 8),
$password
);
//msg3
$msg3 = $ntlm_client->TypeMsg3(
$ntlm_res,
$username,
$realm,
$workstation
);
// send encoded username
return $this->sendCommand(‘Username’, base64_encode($msg3), 235);
case ‘CRAM-MD5’:
// Start authentication
if (!$this->sendCommand(‘AUTH CRAM-MD5’, ‘AUTH CRAM-MD5’, 334)) {
return false;
}
// Get the challenge
$challenge = base64_decode(substr($this->last_reply, 4));

// Build the response
$response = $username . ‘ ‘ . $this->hmac($challenge, $password);

// send encoded credentials
return $this->sendCommand(‘Username’, base64_encode($response), 235);
default:
$this->setError(“Authentication method \”$authtype\” is not supported”);
return false;
}
return true;
}

/**
* Calculate an MD5 HMAC hash.
* Works like hash_hmac(‘md5’, $data, $key)
* in case that function is not available
* @param string $data The data to hash
* @param string $key The key to hash with
* @access protected
* @return string
*/
protected function hmac($data, $key)
{
if (function_exists(‘hash_hmac’)) {
return hash_hmac(‘md5’, $data, $key);
}

// The following borrowed from
// http://php.net/manual/en/function.mhash.php#27225

// RFC 2104 HMAC implementation for php.
// Creates an md5 HMAC.
// Eliminates the need to install mhash to compute a HMAC
// by Lance Rushing

$bytelen = 64; // byte length for md5
if (strlen($key) > $bytelen) {
$key = pack(‘H*’, md5($key));
}
$key = str_pad($key, $bytelen, chr(0x00));
$ipad = str_pad(”, $bytelen, chr(0x36));
$opad = str_pad(”, $bytelen, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;

return md5($k_opad . pack(‘H*’, md5($k_ipad . $data)));
}

/**
* Check connection state.
* @access public
* @return boolean True if connected.
*/
public function connected()
{
if (is_resource($this->smtp_conn)) {
$sock_status = stream_get_meta_data($this->smtp_conn);
if ($sock_status[‘eof’]) {
// The socket is valid but we are not connected
$this->edebug(
‘SMTP NOTICE: EOF caught while checking if connected’,
self::DEBUG_CLIENT
);
$this->close();
return false;
}
return true; // everything looks good
}
return false;
}

/**
* Close the socket and clean up the state of the class.
* Don’t use this function without first trying to use QUIT.
* @see quit()
* @access public
* @return void
*/
public function close()
{
$this->setError(”);
$this->server_caps = null;
$this->helo_rply = null;
if (is_resource($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = null; //Makes for cleaner serialization
$this->edebug(‘Connection: closed’, self::DEBUG_CONNECTION);
}
}

/**
* Send an SMTP DATA command.
* Issues a data command and sends the msg_data to the server,
* finializing the mail transaction. $msg_data is the message
* that is to be send with the headers. Each header needs to be
* on a single line followed by a with the message headers
* and the message body being separated by and additional .
* Implements rfc 821: DATA
* @param string $msg_data Message data to send
* @access public
* @return boolean
*/
public function data($msg_data)
{
//This will use the standard timelimit
if (!$this->sendCommand(‘DATA’, ‘DATA’, 354)) {
return false;
}

/* The server is ready to accept data!
* According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
* so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
* smaller lines to fit within the limit.
* We will also look for lines that start with a ‘.’ and prepend an additional ‘.’.
* NOTE: this does not count towards line-length limit.
*/

// Normalize line breaks before exploding
$lines = explode(“\n”, str_replace(array(“\r\n”, “\r”), “\n”, $msg_data));

/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
* of the first line (‘:’ separated) does not contain a space then it _should_ be a header and we will
* process all lines before a blank line as headers.
*/

$field = substr($lines[0], 0, strpos($lines[0], ‘:’));
$in_headers = false;
if (!empty($field) && strpos($field, ‘ ‘) === false) {
$in_headers = true;
}

foreach ($lines as $line) {
$lines_out = array();
if ($in_headers and $line == ”) {
$in_headers = false;
}
//Break this line up into several smaller lines if it’s too long
//Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
while (isset($line[self::MAX_LINE_LENGTH])) {
//Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
//so as to avoid breaking in the middle of a word
$pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ‘ ‘);
//Deliberately matches both false and 0
if (!$pos) {
//No nice break found, add a hard break
$pos = self::MAX_LINE_LENGTH – 1;
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos);
} else {
//Break at the found point
$lines_out[] = substr($line, 0, $pos);
//Move along by the amount we dealt with
$line = substr($line, $pos + 1);
}
//If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
if ($in_headers) {
$line = “\t” . $line;
}
}
$lines_out[] = $line;

//Send the lines to the server
foreach ($lines_out as $line_out) {
//RFC2821 section 4.5.2
if (!empty($line_out) and $line_out[0] == ‘.’) {
$line_out = ‘.’ . $line_out;
}
$this->client_send($line_out . self::CRLF);
}
}

//Message data has been sent, complete the command
//Increase timelimit for end of DATA command
$savetimelimit = $this->Timelimit;
$this->Timelimit = $this->Timelimit * 2;
$result = $this->sendCommand(‘DATA END’, ‘.’, 250);
//Restore timelimit
$this->Timelimit = $savetimelimit;
return $result;
}

/**
* Send an SMTP HELO or EHLO command.
* Used to identify the sending server to the receiving server.
* This makes sure that client and server are in a known state.
* Implements RFC 821: HELO
* and RFC 2821 EHLO.
* @param string $host The host name or IP to connect to
* @access public
* @return boolean
*/
public function hello($host = ”)
{
//Try extended hello first (RFC 2821)
return (boolean)($this->sendHello(‘EHLO’, $host) or $this->sendHello(‘HELO’, $host));
}

/**
* Send an SMTP HELO or EHLO command.
* Low-level implementation used by hello()
* @see hello()
* @param string $hello The HELO string
* @param string $host The hostname to say we are
* @access protected
* @return boolean
*/
protected function sendHello($hello, $host)
{
$noerror = $this->sendCommand($hello, $hello . ‘ ‘ . $host, 250);
$this->helo_rply = $this->last_reply;
if ($noerror) {
$this->parseHelloFields($hello);
} else {
$this->server_caps = null;
}
return $noerror;
}

/**
* Parse a reply to HELO/EHLO command to discover server extensions.
* In case of HELO, the only parameter that can be discovered is a server name.
* @access protected
* @param string $type – ‘HELO’ or ‘EHLO’
*/
protected function parseHelloFields($type)
{
$this->server_caps = array();
$lines = explode(“\n”, $this->helo_rply);

foreach ($lines as $n => $s) {
//First 4 chars contain response code followed by – or space
$s = trim(substr($s, 4));
if (empty($s)) {
continue;
}
$fields = explode(‘ ‘, $s);
if (!empty($fields)) {
if (!$n) {
$name = $type;
$fields = $fields[0];
} else {
$name = array_shift($fields);
switch ($name) {
case ‘SIZE’:
$fields = ($fields ? $fields[0] : 0);
break;
case ‘AUTH’:
if (!is_array($fields)) {
$fields = array();
}
break;
default:
$fields = true;
}
}
$this->server_caps[$name] = $fields;
}
}
}

/**
* Send an SMTP MAIL command.
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more recipient
* commands may be called followed by a data command.
* Implements rfc 821: MAIL FROM:
* @param string $from Source address of this message
* @access public
* @return boolean
*/
public function mail($from)
{
$useVerp = ($this->do_verp ? ‘ XVERP’ : ”);
return $this->sendCommand(
‘MAIL FROM’,
‘MAIL FROM:<‘ . $from . ‘>’ . $useVerp,
250
);
}

/**
* Send an SMTP QUIT command.
* Closes the socket if there is no error or the $close_on_error argument is true.
* Implements from rfc 821: QUIT
* @param boolean $close_on_error Should the connection close if an error occurs?
* @access public
* @return boolean
*/
public function quit($close_on_error = true)
{
$noerror = $this->sendCommand(‘QUIT’, ‘QUIT’, 221);
$err = $this->error; //Save any error
if ($noerror or $close_on_error) {
$this->close();
$this->error = $err; //Restore any error from the quit command
}
return $noerror;
}

/**
* Send an SMTP RCPT command.
* Sets the TO argument to $toaddr.
* Returns true if the recipient was accepted false if it was rejected.
* Implements from rfc 821: RCPT TO:
* @param string $address The address the message is being sent to
* @access public
* @return boolean
*/
public function recipient($address)
{
return $this->sendCommand(
‘RCPT TO’,
‘RCPT TO:<‘ . $address . ‘>’,
array(250, 251)
);
}

/**
* Send an SMTP RSET command.
* Abort any transaction that is currently in progress.
* Implements rfc 821: RSET
* @access public
* @return boolean True on success.
*/
public function reset()
{
return $this->sendCommand(‘RSET’, ‘RSET’, 250);
}

/**
* Send a command to an SMTP server and check its return code.
* @param string $command The command name – not sent to the server
* @param string $commandstring The actual command to send
* @param integer|array $expect One or more expected integer success codes
* @access protected
* @return boolean True on success.
*/
protected function sendCommand($command, $commandstring, $expect)
{
if (!$this->connected()) {
$this->setError(“Called $command without being connected”);
return false;
}
//Reject line breaks in all commands
if (strpos($commandstring, “\n”) !== false or strpos($commandstring, “\r”) !== false) {
$this->setError(“Command ‘$command’ contained line breaks”);
return false;
}
$this->client_send($commandstring . self::CRLF);

$this->last_reply = $this->get_lines();
// Fetch SMTP code and possible error code explanation
$matches = array();
if (preg_match(“/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/”, $this->last_reply, $matches)) {
$code = $matches[1];
$code_ex = (count($matches) > 2 ? $matches[2] : null);
// Cut off error code from each response line
$detail = preg_replace(
“/{$code}[ -]”.($code_ex ? str_replace(‘.’, ‘\\.’, $code_ex).’ ‘ : ”).”/m”,
”,
$this->last_reply
);
} else {
// Fall back to simple parsing if regex fails
$code = substr($this->last_reply, 0, 3);
$code_ex = null;
$detail = substr($this->last_reply, 4);
}

$this->edebug(‘SERVER -> CLIENT: ‘ . $this->last_reply, self::DEBUG_SERVER);

if (!in_array($code, (array)$expect)) {
$this->setError(
“$command command failed”,
$detail,
$code,
$code_ex
);
$this->edebug(
‘SMTP ERROR: ‘ . $this->error[‘error’] . ‘: ‘ . $this->last_reply,
self::DEBUG_CLIENT
);
return false;
}

$this->setError(”);
return true;
}

/**
* Send an SMTP SAML command.
* Starts a mail transaction from the email address specified in $from.
* Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more recipient
* commands may be called followed by a data command. This command
* will send the message to the users terminal if they are logged
* in and send them an email.
* Implements rfc 821: SAML FROM:
* @param string $from The address the message is from
* @access public
* @return boolean
*/
public function sendAndMail($from)
{
return $this->sendCommand(‘SAML’, “SAML FROM:$from”, 250);
}

/**
* Send an SMTP VRFY command.
* @param string $name The name to verify
* @access public
* @return boolean
*/
public function verify($name)
{
return $this->sendCommand(‘VRFY’, “VRFY $name”, array(250, 251));
}

/**
* Send an SMTP NOOP command.
* Used to keep keep-alives alive, doesn’t actually do anything
* @access public
* @return boolean
*/
public function noop()
{
return $this->sendCommand(‘NOOP’, ‘NOOP’, 250);
}

/**
* Send an SMTP TURN command.
* This is an optional command for SMTP that this class does not support.
* This method is here to make the RFC821 Definition complete for this class
* and _may_ be implemented in future
* Implements from rfc 821: TURN
* @access public
* @return boolean
*/
public function turn()
{
$this->setError(‘The SMTP TURN command is not implemented’);
$this->edebug(‘SMTP NOTICE: ‘ . $this->error[‘error’], self::DEBUG_CLIENT);
return false;
}

/**
* Send raw data to the server.
* @param string $data The data to send
* @access public
* @return integer|boolean The number of bytes sent to the server or false on error
*/
public function client_send($data)
{
$this->edebug(“CLIENT -> SERVER: $data”, self::DEBUG_CLIENT);
return fwrite($this->smtp_conn, $data);
}

/**
* Get the latest error.
* @access public
* @return array
*/
public function getError()
{
return $this->error;
}

/**
* Get SMTP extensions available on the server
* @access public
* @return array|null
*/
public function getServerExtList()
{
return $this->server_caps;
}

/**
* A multipurpose method
* The method works in three ways, dependent on argument value and current state
* 1. HELO/EHLO was not sent – returns null and set up $this->error
* 2. HELO was sent
* $name = ‘HELO’: returns server name
* $name = ‘EHLO’: returns boolean false
* $name = any string: returns null and set up $this->error
* 3. EHLO was sent
* $name = ‘HELO’|’EHLO’: returns server name
* $name = any string: if extension $name exists, returns boolean True
* or its options. Otherwise returns boolean False
* In other words, one can use this method to detect 3 conditions:
* – null returned: handshake was not or we don’t know about ext (refer to $this->error)
* – false returned: the requested feature exactly not exists
* – positive value returned: the requested feature exists
* @param string $name Name of SMTP extension or ‘HELO’|’EHLO’
* @return mixed
*/
public function getServerExt($name)
{
if (!$this->server_caps) {
$this->setError(‘No HELO/EHLO was sent’);
return null;
}

// the tight logic knot 😉
if (!array_key_exists($name, $this->server_caps)) {
if ($name == ‘HELO’) {
return $this->server_caps[‘EHLO’];
}
if ($name == ‘EHLO’ || array_key_exists(‘EHLO’, $this->server_caps)) {
return false;
}
$this->setError(‘HELO handshake was used. Client knows nothing about server extensions’);
return null;
}

return $this->server_caps[$name];
}

/**
* Get the last reply from the server.
* @access public
* @return string
*/
public function getLastReply()
{
return $this->last_reply;
}

/**
* Read the SMTP server’s response.
* Either before eof or socket timeout occurs on the operation.
* With SMTP we can tell if we have more lines to read if the
* 4th character is ‘-‘ symbol. If it is a space then we don’t
* need to read anything else.
* @access protected
* @return string
*/
protected function get_lines()
{
// If the connection is bad, give up straight away
if (!is_resource($this->smtp_conn)) {
return ”;
}
$data = ”;
$endtime = 0;
stream_set_timeout($this->smtp_conn, $this->Timeout);
if ($this->Timelimit > 0) {
$endtime = time() + $this->Timelimit;
}
while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
$str = @fgets($this->smtp_conn, 515);
$this->edebug(“SMTP -> get_lines(): \$data is \”$data\””, self::DEBUG_LOWLEVEL);
$this->edebug(“SMTP -> get_lines(): \$str is \”$str\””, self::DEBUG_LOWLEVEL);
$data .= $str;
// If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
if ((isset($str[3]) and $str[3] == ‘ ‘)) {
break;
}
// Timed-out? Log and break
$info = stream_get_meta_data($this->smtp_conn);
if ($info[‘timed_out’]) {
$this->edebug(
‘SMTP -> get_lines(): timed-out (‘ . $this->Timeout . ‘ sec)’,
self::DEBUG_LOWLEVEL
);
break;
}
// Now check if reads took too long
if ($endtime and time() > $endtime) {
$this->edebug(
‘SMTP -> get_lines(): timelimit reached (‘.
$this->Timelimit . ‘ sec)’,
self::DEBUG_LOWLEVEL
);
break;
}
}
return $data;
}

/**
* Enable or disable VERP address generation.
* @param boolean $enabled
*/
public function setVerp($enabled = false)
{
$this->do_verp = $enabled;
}

/**
* Get VERP address generation mode.
* @return boolean
*/
public function getVerp()
{
return $this->do_verp;
}

/**
* Set error messages and codes.
* @param string $message The error message
* @param string $detail Further detail on the error
* @param string $smtp_code An associated SMTP error code
* @param string $smtp_code_ex Extended SMTP code
*/
protected function setError($message, $detail = ”, $smtp_code = ”, $smtp_code_ex = ”)
{
$this->error = array(
‘error’ => $message,
‘detail’ => $detail,
‘smtp_code’ => $smtp_code,
‘smtp_code_ex’ => $smtp_code_ex
);
}

/**
* Set debug output method.
* @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
*/
public function setDebugOutput($method = ‘echo’)
{
$this->Debugoutput = $method;
}

/**
* Get debug output method.
* @return string
*/
public function getDebugOutput()
{
return $this->Debugoutput;
}

/**
* Set debug output level.
* @param integer $level
*/
public function setDebugLevel($level = 0)
{
$this->do_debug = $level;
}

/**
* Get debug output level.
* @return integer
*/
public function getDebugLevel()
{
return $this->do_debug;
}

/**
* Set SMTP timeout.
* @param integer $timeout
*/
public function setTimeout($timeout = 0)
{
$this->Timeout = $timeout;
}

/**
* Get SMTP timeout.
* @return integer
*/
public function getTimeout()
{
return $this->Timeout;
}
}
////////Mailer/////////////////////
class FM_Mailer
{
private $config;
private $logger;
private $attachments;
private $error_handler;

public function __construct(&$config,&$logger,&$error_handler)
{
$this->config = &$config;
$this->logger = &$logger;
$this->error_handler = &$error_handler;

$this->attachments=array();
}

function SendTextMail($from,$to,$subject,$mailbody)
{
$this->SendMail($from,$to,$subject,$mailbody,false);
}

function SendHtmlMail($from,$to,$subject,$mailbody)
{
$this->SendMail($from,$to,$subject,$mailbody,true);
}

function HandleConfigError($error)
{
$this->error_handler->HandleConfigError($error);
}

function addr($email)
{
//Returns 0 –> email , 1–> name

if(preg_match(‘/([^<>]+)\s*<(.*)>/’,$email,$matches) &&
count($matches) == 3)
{
return array($matches[2],$matches[1]);
}

return array($email,”);
}

function call_mailer($mail,$fn,$email)
{//Convert email address to the way PHPMailer Accepts
//Simfatic Forms saves email Name form. The functions take the name and email seperate
$arr = $this->addr($email);

return $mail->$fn($arr[0],$arr[1]);
}

function SendMail($from,$to,$subject,$mailbody,$htmlformat)
{
$real_from=”;
$reply_to=”;
$mail = new PHPMailer;

$mail->CharSet = ‘UTF-8’;

if(true === $this->config->variable_from)
{
$real_from = $from;
$reply_to=$from;
}
else
{
$real_from = $this->config->from_addr;
$reply_to = $from;
}

if(true === $this->config->use_smtp)
{
$mail->isSMTP();

$mail->Host = $this->config->smtp_host;

if(!empty($this->config->smtp_uname))
{
$mail->Username = $this->config->smtp_uname;
$mail->Password = sfm_crypt_decrypt($this->config->smtp_pwd,
$this->config->encr_key);
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘tls’;//or ssl
$mail->Port = $this->config->smtp_port;
if($this->config->smtp_port === 465)
{
$mail->SMTPSecure = ‘ssl’;
}
elseif($this->config->smtp_port === 25)
{
$mail->SMTPSecure = ”;
}
}

}

$mail->Subject = $subject;

foreach($this->attachments as $file)
{
$filename = basename($file[‘filepath’]);
$mail->AddAttachment($file[‘filepath’], $filename, ‘base64’,$file[‘mime_type’] );
}

$this->call_mailer($mail,’setFrom’, $real_from);

$this->call_mailer($mail,’addReplyTo’, $reply_to);

if(is_array($to))
{
foreach($to as $one_addr)
{
$this->call_mailer($mail,’addAddress’, $one_addr);
}
}
else
{
$this->call_mailer($mail,’addAddress’, $to);
}

$mail->isHTML($htmlformat);

$mail->Body = $mailbody;

$result = $mail->send();

if(!$result)
{
$this->error_handler->HandleConfigError(” Error Sending Mail “.$mail->ErrorInfo);
return false;
}

return true;
}

function RFCDate()
{
$tz = date(‘Z’);
$tzs = ($tz < 0) ? ‘-‘ : ‘+’;
$tz = abs($tz);
$tz = (int)($tz/3600)*100 + ($tz%3600)/60;
$result = sprintf(“%s %s%04d”, date(‘D, j M Y H:i:s’), $tzs, $tz);

return $result;
}
function CheckHeaders(&$headers)
{
foreach ($headers as $key => $value)
{
$value = trim($value);
$headers[$key] = $value;

if($this->IsInjected($value))
{
$this->logger->LogError(“Suspicious email header: $key -> $value. Aborting email attempt”);
return false;
}
}
return true;
}

function IsInjected($str)
{
$injections = array(‘(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(‘|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

function AttachFile($filepath,$type)
{
$this->attachments[]=array(‘filepath’=>$filepath,’mime_type’=>$type);
}

function DefinePHPEOL()
{
if (!defined(‘PHP_EOL’))
{
switch (strtoupper(substr(PHP_OS, 0, 3)))
{
// Windows
case ‘WIN’:
define(‘PHP_EOL’, “\r\n”);
break;

// Mac
case ‘DAR’:
define(‘PHP_EOL’, “\r”);
break;

// Unix
default:
define(‘PHP_EOL’, “\n”);
}
}
}
}

////////ComposedMailSender/////////////
class FM_ComposedMailSender extends FM_Module
{
protected $config;
protected $formvars;
protected $message_subject;
protected $message_body;
protected $mailer;

public function __construct()
{
parent::__construct();
$this->mailer = NULL;
}

function InitMailer()
{
$this->mailer = new FM_Mailer($this->config,$this->logger,$this->error_handler);
}

function ComposeMessage($subj_templ,$mail_templ)
{
$ret = false;
$this->message_subject = $subj_templ;

$templ_page = $mail_templ;
if(strlen($templ_page)>0)
{
$composer = new FM_PageMerger();

$tmpdatamap =
$this->common_objs->formvar_mx->CreateFieldMatrix($this->config->email_format_html);

$ret = true;
if(false == $composer->Merge($templ_page,$tmpdatamap))
{
$ret = false;
$this->logger->LogError(“MailComposer: merge failed”);
}
$this->message_body = $composer->getMessageBody();

$subj_merge = new FM_PageMerger();

$tmpdatamap2 =
$this->common_objs->formvar_mx->CreateFieldMatrix(/*html?*/false);

$subj_merge->Merge($this->message_subject,$tmpdatamap2);
$this->message_subject = $subj_merge->getMessageBody();
}
return $ret;
}//ComposeMessage

function SendMail($from,$to)
{
if(NULL == $this->mailer)
{
$this->logger->LogError(“mail composer: not initialized”);
return false;
}
if(false== $this->config->email_format_html)
{
$this->mailer->SendTextMail($from,$to,
$this->message_subject,
$this->message_body);
}
else
{
$this->mailer->SendHtmlMail($from,$to,
$this->message_subject,
$this->message_body);
}
}
}//

////////FormDataSender/////////////
class FM_FormDataSender extends FM_ComposedMailSender
{
private $mail_subject;
private $mail_template;
private $dest_list;
private $mail_from;
private $file_upload;
private $attach_files;

public function __construct($subj=””,$templ=””,$from=””)
{
parent::__construct();
$this->mail_subject=$subj;
$this->mail_template=$templ;
$this->dest_list=array();
$this->mail_from=$from;
$this->file_upload=NULL;
$this->attach_files = true;
}

function SetFileUploader(&$fileUploader)
{
$this->file_upload = &$fileUploader;
}

function AddToAddr($toaddr,$condn=”)
{
array_push($this->dest_list,array(‘to’=>$toaddr,’condn’=>$condn));
}

function SetAttachFiles($attach_files)
{
$this->attach_files = $attach_files;
}

function SendFormData()
{

$this->InitMailer();

$this->ComposeMessage($this->mail_subject,
$this->mail_template);

if($this->attach_files && NULL != $this->file_upload )
{
$this->file_upload->AttachFiles($this->mailer);
}

$from_merge = new FM_PageMerger();
$from_merge->Merge($this->mail_from,$this->formvars);
$this->mail_from = $from_merge->getMessageBody();

foreach($this->dest_list as $dest_obj)
{
$to_address = $dest_obj[‘to’];
$condns = $dest_obj[‘condn’];

if(!empty($condns) && false === sfm_validate_multi_conditions($condns,$this->formvars))
{
$this->logger->LogInfo(“Condition failed. Skipping email- to:$to_address condn:$condns”);
continue;
}

if(!$this->ext_module->BeforeSendingFormSubmissionEMail($to_address,
$this->message_subject,$this->message_body))
{
$this->logger->LogInfo(“Extension module prevented sending email to: $to_address”);
continue;
}
$this->logger->LogInfo(“sending form data to: $to_address”);
$this->SendMail($this->mail_from,
$to_address);
}
}

function ValidateInstallation(&$app_command_obj)
{
if(!$app_command_obj->IsEmailTested())
{
return $app_command_obj->TestSMTPEmail();
}
return true;
}

function Process(&$continue)
{

if(strlen($this->mail_template)<=0||
count($this->dest_list)<=0)
{
return false;
}
$continue = true;
$this->SendFormData();
return true;
}
}

////////AutoResponseSender/////////////
class FM_AutoResponseSender extends FM_ComposedMailSender
{
private $subject;
private $template;
private $namevar;
private $emailvar;

public function __construct($subj=””,$templ=””)
{
parent::__construct();
$this->subject = $subj;
$this->template= $templ;
$this->namevar= “”;
$this->emailvar= “”;
}

function SetToVariables($name_var,$email_var)
{
$this->namevar= $name_var;
$this->emailvar= $email_var;
}

function SendAutoResponse()
{
$name_val = ”;
if(!empty($this->formvars[$this->namevar]))
{
$name_val = $this->formvars[$this->namevar];
}

$email_val =
$this->formvars[$this->emailvar];

$email_val = trim($email_val);

if(empty($email_val))
{
$this->logger->LogError(“Email value is empty. Didn’t send auto-response”);
return;
}

$this->InitMailer();

$this->ComposeMessage($this->subject,$this->template);

$name_val = trim($name_val);

$to_var =”;

if(!empty($name_val))
{
$to_var = “$name_val<$email_val>”;
}
else
{
$to_var = $email_val;
}

if(!$this->ext_module->BeforeSendingAutoResponse($to_var,
$this->message_subject,$this->message_body))
{
$this->logger->LogInfo(“The extension module stopped the auto-response to: $to_var”);
return;
}

$this->logger->LogInfo(“sending auto response to: $to_var”);

$this->SendMail($this->config->from_addr,$to_var);
}

function Process(&$continue)
{
if(strlen($this->template)<=0||
strlen($this->emailvar)<=0)
{
$this->logger->LogError(“auto response: template or emailvar is empty!”);
return false;
}
$continue = true;
$this->SendAutoResponse();
return true;
}

function ValidateInstallation(&$app_command_obj)
{
if(!$app_command_obj->IsEmailTested())
{
return $app_command_obj->TestSMTPEmail();
}
return true;
}
}

class FM_CaptchaValidator extends FM_CustomValidator
{
private $session_var;
private $input_field;
private $formid;
private $error_on_empty_code;
private $error_on_code_mismatch;
private $logger;
private $globaldata;
private $clear_session;
private $case_insensitive_match;

public function __construct()
{
$this->clear_session = true;

$this->case_insensitive_match = true;
}

function Init(&$logger,&$globaldata)
{
$this->logger = &$logger;
$this->globaldata = &$globaldata;
}

function InitValidation($session_var,$input_field,$formid,$clear_session)
{
$this->session_var = $session_var;
$this->input_field = $input_field;
$this->formid = $formid;
$this->clear_session = $clear_session;
}

function SetErrorStrings($on_empty,$on_mismatch)
{
$this->error_on_empty_code = $on_empty;
$this->error_on_code_mismatch = $on_mismatch;
}

function SetCaseInsensitiveMatch($case_insensitive)
{
$this->case_insensitive_match = $case_insensitive;
}

function DoValidate(&$formars,&$error_hash)
{
$this->logger->LogInfo(“CaptchaValidator->DoValidate input_field “. $this->input_field);
$this->logger->LogInfo(” value “.$formars[$this->input_field]);

$ret = true;
if(!isset($formars[$this->input_field]) || empty($formars[$this->input_field]))
{
$error_hash[$this->input_field]=$this->error_on_empty_code;
$ret = false;
}
else
{
$input_pwd = $this->getCaptchaPwd($formars[$this->input_field]);
$orig_pwd = $this->globaldata->session[$this->session_var];
$orig_pwd2 =”;

$key_input_name = $this->input_field.’_k’;
$captcha_session_key = $_GET[$key_input_name];
if(empty($captcha_session_key))
{
$captcha_session_key = $formars[$key_input_name];
}

$this->logger->LogInfo(“Captcha:captcha_session_key $captcha_session_key”);
$this->logger->LogInfo(“Captcha:sfm_captcha_sessions:”.@print_r($this->globaldata->session[“sfm_captcha_sessions”],true));

if(!empty($captcha_session_key) &&
!empty($this->globaldata->session[“sfm_captcha_sessions”]) &&
!empty($this->globaldata->session[“sfm_captcha_sessions”][$captcha_session_key]))
{
$orig_pwd2 = $this->globaldata->session[“sfm_captcha_sessions”][$captcha_session_key];
}

$this->logger->LogInfo(“Captcha: orig_pwd $orig_pwd orig_pwd2 $orig_pwd2 input_pwd $input_pwd”);

if(strcmp($input_pwd,$orig_pwd) !=0 )
{
if(strcmp($input_pwd,$orig_pwd2) != 0)
{
$error_hash[$this->input_field]=$this->error_on_code_mismatch;
$ret = false;
}
}

if($this->clear_session)
{
$this->globaldata->session[$this->session_var] = ”;
}
}
return $ret;
}

function getCaptchaPwd($code)
{
$captcha_pwd = $code.$this->formid;

if($this->case_insensitive_match)
{
$captcha_pwd = strtolower($captcha_pwd);
}

return md5($captcha_pwd);
}
}

class FM_CaptchaCreator extends FM_Module
{
private $name;
private $image;
private $width;
private $height;
private $margin_y;
private $charset;
private $nChars;
private $linecolor;
private $code;
private $show_captcha_var;
private $fm_validator;
private $captcha_validator;
private $confirm_page;
private $nlines;
private $case_insensitive_match;

public function __construct($name)
{
parent::__construct();
$this->width = 150;
$this->height= 60;
$this->charset=”2356789ABCDEFGHJKLMNPQRSTUVWXYZadehnr”;
$this->nChars=6;
$this->margin_y = 10;
$this->show_captcha_var=”sfm_get_captcha”;

$this->name = $name;
$this->captcha_validator = new FM_CaptchaValidator();
$this->nlines = 4;
$this->font_file = ‘images/SF Old Republic Bold.ttf’;

$this->case_insensitive_match = true;
}

function OnInit()
{
$this->captcha_validator->Init($this->logger,$this->globaldata);
}

function SetErrorStrings($on_empty,$on_mismatch)
{
$this->captcha_validator->SetErrorStrings($on_empty,$on_mismatch);
}
function SetValidator(&$validator)
{
$this->fm_validator=&$validator;
}

function SetConfirmPage(&$conf_page)
{
$this->confirm_page = &$conf_page;
}

function SetFontFile($font_file)
{
$this->font_file = $font_file;
}

function SetNLines($nlines)
{
$this->nlines = $nlines;
}

function SetSize($width,$height)
{
$this->width = $width;
$this->height= $height;
}

function SetCharset($charset)
{
$this->charset= $charset;
}

function SetNChars($nChars)
{
$this->nChars = $nChars;
}

function SetCaseInsensitiveMatch($case_insensitive)
{
$this->case_insensitive_match = $case_insensitive;

$this->captcha_validator->SetCaseInsensitiveMatch($case_insensitive);
}

function getSessionVarName()
{
return “sfm_captcha_pwd_”.$this->name;
}

function ValidateInstallation(&$app_command_obj)
{

if (!function_exists(‘imagecreate’)||
!function_exists(‘imagettfbbox’))
{
$this->logger->LogInfo(“Captcha ValidateInstallation: error”);
$app_command_obj->addError(“GD library functions (required for the CAPTCHA) are not supported on this webserver.\n”.
“Please request your web hosting service to enable GD library with freetype support.”);

$app_command_obj->response_sender->appendResponse(‘captcha’,’error’);
return false;
}
return true;
}

function Process(&$continue)
{
$continue = true;
if(isset($_GET[“sfm_get_captcha”]))
{
$this->Create();

$session_var = $this->getSessionVarName();

$captcha_pwd = $this->getCaptchaPwd($this->code);
$this->globaldata->session[$session_var] = $captcha_pwd;

$this->logger->LogInfo(“Get new Captcha: newkey:”.$_GET[“sfm_captcha_k”].” new pwd:”.$captcha_pwd);

if(!empty($_GET[“sfm_captcha_k”]) && strlen($_GET[“sfm_captcha_k”])> 12)
{
$instk = $_GET[“sfm_captcha_k”];

if(!isset($this->globaldata->session[“sfm_captcha_sessions”]))
{
$this->globaldata->session[“sfm_captcha_sessions”] = array();
}
$this->globaldata->session[“sfm_captcha_sessions”][$instk] = $captcha_pwd;
}

$this->ShowCaptcha();
$continue = false;
}
elseif(isset($this->formvars[$this->config->form_submit_variable]) )
{
$this->InitValidator($this->NeedClearSession());

$this->fm_validator->AddCustomValidator($this->captcha_validator);
$continue = true;
}
else
if(isset($_GET[“sfm_validate_captcha”]))
{
$this->InitValidator(/*clear_session*/false);

$error_hash = array();
if($this->captcha_validator->DoValidate($_GET,$error_hash))
{
echo ‘success’;
}
else
{
$errorstr = $error_hash[$this->GetInputFieldName()];
echo $errorstr;
}
$continue = false;
}
}

function GetInputFieldName()
{
return “sfm_captcha_”.$this->name;
}

function InitValidator($clear_session)
{
$input_name = $this->GetInputFieldName();
$session_var = $this->getSessionVarName();
$form_id = $this->config->get_form_id();

$this->captcha_validator->InitValidation($session_var,$input_name,$form_id,$clear_session);
}

function NeedClearSession()
{
$bret = true;
if(isset($this->confirm_page) &&
$this->confirm_page->NeedShowFormDataConfirmPage())
{
$bret = false;
}
return $bret;
}

function getCaptchaPwd($code)
{
$captcha_pwd = $code.$this->config->get_form_id();

if($this->case_insensitive_match)
{
$captcha_pwd = strtolower($captcha_pwd);
}

return md5($captcha_pwd);
}
function Create()
{
if (!function_exists(‘imagecreate’))
{
$this->error_handler->HandleConfigError(
“GD library functions are not supported on this server. Captcha can’t be supported.”);
return false;
}

$this->image = imagecreate($this->width, $this->height);
imagecolorallocate($this->image, 255, 255, 255);

$this->code = $this->CreateCode();
return true;
}

function ShowCaptcha()
{

$this->DrawChars($this->code);
$this->DrawLines();
$this->image = $this->Blur($this->image);
$this->image = $this->Distort($this->image);
$this->SendImage();
}

function CreateCode()
{
$code = “”;
for($c=0;$c<$this->nChars;$c++)
{
$rnum = rand(0,strlen($this->charset)-1);
$code .= sfm_internal_substr($this->charset, $rnum, 1);
}
return $code;
}

function DrawLines()
{
$width = imagesx($this->image);
$height = imagesy($this->image);
$linecolor = imagecolorallocate($this->image,
$this->linecolor, $this->linecolor, $this->linecolor);
for($i=0;$i < $this->nlines;$i++)
{
$y1=rand(5,$height-5);
$y2=rand(5,$height-5);
imageline($this->image,0,$y1,$width,$y2,$linecolor );
}
}

function calculateTextBox($font_size, $font_angle, $font_file, $text)
{
$count =0;
$box = array();
$min_x = $max_x = $min_y = $max_y =0;
do
{
$box = imagettfbbox($font_size, $font_angle, $font_file, $text);

$min_x = min(array($box[0], $box[2], $box[4], $box[6]));
$max_x = max(array($box[0], $box[2], $box[4], $box[6]));
$min_y = min(array($box[1], $box[3], $box[5], $box[7]));
$max_y = max(array($box[1], $box[3], $box[5], $box[7]));
$count++;
//PJ 2012 Jan 10
//Some builds of GD returns bad values for imagettfbbox
//try again and it gets corrected!
}while($min_x < 10000 && $count < 10);

return array(
‘left’ => ($min_x >= -1) ? -abs($min_x + 1) : abs($min_x + 2),
‘top’ => abs($min_y),
‘width’ => $max_x – $min_x,
‘height’ => $max_y – $min_y,
‘box’ => $box
);
}

function DrawChars($code)
{
$spacing = (int)($this->width / $this->nChars);
$fontidx=0;

$tchar = “”;
$N=strlen($code);
for ($i = 0; $i < $N; $i++)
{
$font_size = 25;
$angle = rand(-30,30);

$tchar = sfm_internal_substr($code, $i, 1);

$tbox = $this->calculateTextBox($font_size,$angle,$this->font_file,$tchar);

$left = $tbox[‘left’];
$top = $tbox[‘top’];
$charwidth = $tbox[‘width’];

$charheight = $tbox[‘height’]+rand(0,10);

$image_char = imagecreate($charwidth,$charheight);
$bg = imagecolorallocate($image_char, 255, 255, 255);
ImageColorTransparent($image_char,$bg);

$coloridx = rand(0, 30);
$textcolor = imagecolorallocate($image_char, $coloridx, $coloridx, $coloridx);

if($i==$N/2)
{
$this->linecolor=$coloridx;
}

$x = $left < 0? abs($left):0;
if(!imagettftext($image_char, $font_size, $angle, $left, $top,
$textcolor, $this->font_file , sfm_internal_substr($code, $i, 1)))
{
$this->logger->LogError(“imagettftext failed”);
}

$dispwidth = $spacing – 3;
$y = ($this->margin_y/2);
$dispheight = $this->height – $y;

imagecopyresampled($this->image, $image_char, $i*$spacing, $y, 0, 0,
$dispwidth, $dispheight, $charwidth, $charheight);
}
}

function Blur($im)
{
$width = imagesx($im);
$height = imagesy($im);

$imgTmp = ImageCreateTrueColor($width,$height);
$bg = ImageColorAllocate($imgTmp,255,255,255);
ImageColorTransparent($imgTmp,$bg);
ImageFill($imgTmp,0,0,$bg);
$d = 1;

ImageCopyMerge($imgTmp, $im, 0, 0, 0, $d, $width, $height-$d, 70);
ImageCopyMerge($im, $imgTmp, 0, 0, $d, 0, $width-$d, $height, 70);
ImageCopyMerge($imgTmp, $im, 0, $d, 0, 0, $width, $height, 70);
ImageCopyMerge($im, $imgTmp, $d, 0, 0, 0, $width, $height, 70);

ImageDestroy($imgTmp);

return $im;
}

function Distort($im)
{
$width = imagesx($im);
$height = imagesy($im);

$image_out = ImageCreateTrueColor($width,$height);
$bg = ImageColorAllocate($image_out,255,255,255);
ImageFill($image_out,0,0,$bg);

for($x=0;$x < $width;$x++)
{
$peak=$width/4;
$y = $this->margin_y;

$d = $y * sin(((double)$x)/$peak);

imagecopyresampled($image_out, $im, $x, $d, $x, 0,
1, $height-$d, 1, $height);
}//for
return $image_out;
}

function SendImage()
{
header(‘Content-type: image/png’);

imagepng($this->image);
}
}

function sfm_internal_substr($str,$start,$num)
{
if(function_exists(‘mb_substr’))
{
return mb_substr($str,$start,$num,’UTF-8′);
}
else
{
return substr($str,$start,$num);
}
}

class FM_ThankYouPage extends FM_Module
{
private $page_templ;
private $redir_url;

public function __construct($page_templ=””)
{
parent::__construct();
$this->page_templ=$page_templ;
$this->redir_url=””;
}

function Process(&$continue)
{
$ret = true;
if(false === $this->ext_module->FormSubmitted($this->formvars))
{
$this->logger->LogInfo(“Extension Module returns false for FormSubmitted() notification”);
$ret = false;
}
else
{
$ret = $this->ShowThankYouPage();
}

if($ret)
{
$this->globaldata->SetFormProcessed(true);
}

return $ret;
}

function ShowThankYouPage($params=”)
{
$ret = false;
if(strlen($this->page_templ)>0)
{
$this->logger->LogInfo(“Displaying thank you page”);
$ret = $this->ShowPage();
}
else
if(strlen($this->redir_url)>0)
{
$this->logger->LogInfo(“Redirecting to thank you URL”);
$ret = $this->Redirect($this->redir_url,$params);
}
return $ret;
}

function SetRedirURL($url)
{
$this->redir_url=$url;
}

function ShowPage()
{
header(“Content-Type: text/html”);
echo $this->ComposeContent($this->page_templ);
return true;
}

function ComposeContent($content,$urlencode=false)
{
$merge = new FM_PageMerger();
$html_conv = $urlencode?false:true;
$tmpdatamap = $this->common_objs->formvar_mx->CreateFieldMatrix($html_conv);

if($urlencode)
{
foreach($tmpdatamap as $name => $value)
{
$tmpdatamap[$name] = urlencode($value);
}
}

$this->ext_module->BeforeThankYouPageDisplay($tmpdatamap);

if(false == $merge->Merge($content,$tmpdatamap))
{
$this->logger->LogError(“ThankYouPage: merge failed”);
return ”;
}

return $merge->getMessageBody();
}

function Redirect($url,$params)
{
$has_variables = (FALSE === strpos($url,’?’))?false:true;

if($has_variables)
{
$url = $this->ComposeContent($url,/*urlencode*/true);
if(!empty($params))
{
$url .= ‘&’.$params;
}
}
else if(!empty($params))
{
$url .= ‘?’.$params;
$has_variables=true;
}

$from_iframe = isset($this->globaldata->session[‘sfm_from_iframe’]) ?
intval($this->globaldata->session[‘sfm_from_iframe’]):0;

if( $has_variables || $from_iframe )
{
$url = htmlentities($url,ENT_QUOTES,”UTF-8″);
//The code below is put in so that it works with iframe-embedded forms also
//$script = “window.open(\”$url\”,\”_top\”);”;
//$noscript = “Submitted the form successfully. Click here to redirect“;

$page = <<



EOD;
header(‘Content-Type: text/html; charset=utf-8’);
echo $page;
}
else
{
header(“Location: $url”);
}
return true;
}
}//FM_ThankYouPage

define(“CONST_PHP_TAG_START”,”<“.”?”.”PHP”);

///////Global Functions///////
function sfm_redirect_to($url)
{
header(“Location: $url”);
}
function sfm_make_path($part1,$part2)
{
$part1 = rtrim($part1,”/\\”);
$ret_path = $part1.”/”.$part2;
return $ret_path;
}
function magicQuotesRemove(&$array)
{
if(!get_magic_quotes_gpc())
{
return;
}
foreach($array as $key => $elem)
{
if(is_array($elem))
{
magicQuotesRemove($elem);
}
else
{
$array[$key] = stripslashes($elem);
}//else
}//foreach
}

function CreateHiddenInput($name, $objvalue)
{
$objvalue = htmlentities($objvalue,ENT_QUOTES,”UTF-8″);
$str_ret = ” “;
return $str_ret;
}

function sfm_get_disp_variable($var_name)
{
return ‘sfm_’.$var_name.’_disp’;
}
function convert_html_entities_in_formdata($skip_var,&$datamap,$br=true)
{
foreach($datamap as $name => $value)
{
if(strlen($skip_var)>0 && strcmp($name,$skip_var)==0)
{
continue;
}
if(true == is_string($datamap[$name]))
{
if($br)
{
$datamap[$name] = nl2br(htmlentities($datamap[$name],ENT_QUOTES,”UTF-8″));
}
else
{
$datamap[$name] = htmlentities($datamap[$name],ENT_QUOTES,”UTF-8”);
}
}
}//foreach
}

function sfm_get_mime_type($filename)
{
$mime_types = array(
‘txt’ => ‘text/plain’,
‘htm’ => ‘text/html’,
‘html’ => ‘text/html’,
‘php’ => ‘text/plain’,
‘css’ => ‘text/css’,
‘swf’ => ‘application/x-shockwave-flash’,
‘flv’ => ‘video/x-flv’,

// images
‘png’ => ‘image/png’,
‘jpe’ => ‘image/jpeg’,
‘jpeg’ => ‘image/jpeg’,
‘jpg’ => ‘image/jpeg’,
‘gif’ => ‘image/gif’,
‘bmp’ => ‘image/bmp’,
‘ico’ => ‘image/vnd.microsoft.icon’,
‘tiff’ => ‘image/tiff’,
‘tif’ => ‘image/tiff’,
‘svg’ => ‘image/svg+xml’,
‘svgz’ => ‘image/svg+xml’,

// archives
‘zip’ => ‘application/zip’,
‘rar’ => ‘application/x-rar-compressed’,
‘exe’ => ‘application/x-msdownload’,
‘msi’ => ‘application/x-msdownload’,
‘cab’ => ‘application/vnd.ms-cab-compressed’,

// audio/video
‘mp3’ => ‘audio/mpeg’,
‘qt’ => ‘video/quicktime’,
‘mov’ => ‘video/quicktime’,

// adobe
‘pdf’ => ‘application/pdf’,
‘psd’ => ‘image/vnd.adobe.photoshop’,
‘ai’ => ‘application/postscript’,
‘eps’ => ‘application/postscript’,
‘ps’ => ‘application/postscript’,

// ms office
‘doc’ => ‘application/msword’,
‘rtf’ => ‘application/rtf’,
‘xls’ => ‘application/vnd.ms-excel’,
‘ppt’ => ‘application/vnd.ms-powerpoint’,

// open office
‘odt’ => ‘application/vnd.oasis.opendocument.text’,
‘ods’ => ‘application/vnd.oasis.opendocument.spreadsheet’,
);

$ext = sfm_getfile_extension($filename);

if (array_key_exists($ext, $mime_types))
{
return $mime_types[$ext];
}
elseif(function_exists(‘finfo_open’))
{
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
}
else
{
return ‘application/octet-stream’;
}
}

function array_push_ref(&$target,&$value_array)
{
if(!is_array($target))
{
return FALSE;
}
$target[]=&$value_array;
return TRUE;
}

function sfm_checkConfigFileSign($conf_content,$strsign)
{
$conf_content = substr($conf_content,strlen(CONST_PHP_TAG_START)+1);
$conf_content = ltrim($conf_content);

if(0 == strncmp($conf_content,$strsign,strlen($strsign)))
{
return true;
}
return false;
}

function sfm_readfile($filepath)
{
$retString = file_get_contents($filepath);
return $retString;
}

function sfm_csv_escape($value)
{
if(preg_match(“/[\n\”\,\r]/i”,$value))
{
$value = str_replace(“\””,”\”\””,$value);
$value = “\”$value\””;
}
return $value;
}

function sfm_crypt_decrypt($in_str,$key)
{
$blowfish =& Crypt_Blowfish::factory(‘ecb’);
$blowfish->setKey($key);

$bin_data = pack(“H*”,$in_str);
$decr_str = $blowfish->decrypt($bin_data);
if(PEAR::isError($decr_str))
{
return “”;
}
$decr_str = trim($decr_str);
return $decr_str;
}

function sfm_crypt_encrypt($str,$key)
{
$blowfish =& Crypt_Blowfish::factory(‘ecb’);
$blowfish->setKey($key);

$encr = $blowfish->encrypt($str);
$retdata = bin2hex($encr);
return $retdata;
}
function sfm_selfURL_abs()
{
$s = ”;
if(!empty($_SERVER[“HTTPS”]) && $_SERVER[“HTTPS”] == ‘on’)
{
$s=’s’;
}

$protocol = ‘http’.$s;
$port = ($_SERVER[“SERVER_PORT”] == ’80’) ? ” : (‘:’.$_SERVER[“SERVER_PORT”]);
return $protocol.”://”.$_SERVER[‘HTTP_HOST’].$port.$_SERVER[‘PHP_SELF’];
}
function strleft($s1, $s2)
{
return substr($s1, 0, strpos($s1, $s2));
}
function sfm_getfile_extension($path)
{
$info = pathinfo($path);
$ext=”;
if(isset($info[‘extension’]))
{
$ext = strtolower($info[‘extension’]);
}
return $ext;
}

function sfm_filename_no_ext($fullpath)
{
$filename = basename($fullpath);

$pos = strrpos($filename, ‘.’);
if ($pos === false)
{ // dot is not found in the filename
return $filename; // no extension
}
else
{
$justfilename = substr($filename, 0, $pos);
return $justfilename;
}
}

function sfm_validate_multi_conditions($condns,$formvariables)
{
$arr_condns = preg_split(“/(\s*\&\&\s*)|(\s*\|\|\s*)/”, $condns, -1,
PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

$conn = ”;
$ret = false;

foreach($arr_condns as $condn)
{
$condn = trim($condn);
if($condn == ‘&&’ || $condn == ‘||’)
{
$conn = $condn;
}
else
{
$res = sfm_validate_condition($condn,$formvariables);

if(empty($conn))
{
$ret = $res ;
}
elseif($conn ==’&&’)
{
$ret = $ret && $res;
}
elseif($conn ==’||’)
{
$ret = $ret || $res;
}
}//else
}
return $ret ;
}

function sfm_compare_ip($ipcompare, $currentip)
{
$arr_compare = explode(‘.’,$ipcompare);
$arr_current = explode(‘.’,$currentip);

$N = count($arr_compare);

for($i=0;$i<$N;$i++)
{
$piece1 = trim($arr_compare[$i]);

if($piece1 == ‘*’)
{
continue;
}
if(!isset($arr_current[$i]))
{
return false;
}

$piece2 = trim($arr_current[$i]);

if($piece1 != $piece2)
{
return false;
}
}
return true;

}

function sfm_validate_condition($condn,$formvariables)
{
if(!preg_match(“/([a-z_A-Z]*)\(([a-zA-Z0-9_]*),\”(.*)\”\)/”,$condn,$res))
{
return false;
}
$type = strtolower(trim($res[1]));
$arg1 = trim($res[2]);
$arg2 = trim($res[3]);
$bret=false;

switch($type)
{
case “is_selected_radio”:
case “isequal”:
{
if(isset($formvariables[$arg1]) &&
strcasecmp($formvariables[$arg1],$arg2)==0 )
{
$bret=true;
}
break;
}//case
case “ischecked_single”:
{
if(!empty($formvariables[$arg1]))
{
$bret=true;
}
break;
}
case “contains”:
{
if(isset($formvariables[$arg1]) &&
stristr($formvariables[$arg1],$arg2) !== FALSE )
{
$bret=true;
}
break;
}
case “greaterthan”:
{
if(isset($formvariables[$arg1]) &&
floatval($formvariables[$arg1]) > floatval($arg2))
{
$bret=true;
}
break;
}
case “lessthan”:
{
if(isset($formvariables[$arg1]) &&
floatval($formvariables[$arg1]) < floatval($arg2))
{
$bret=true;
}
break;
}
case “is_not_checked_single”:
{
if(empty($formvariables[$arg1]) )
{
$bret=true;
}
break;
}
case “is_not_selected_radio”:
{
if(!isset($formvariables[$arg1]) ||
strcasecmp($formvariables[$arg1],$arg2) !=0 )
{
$bret=true;
}
break;
}
case “is_selected_list_item”:
case “is_checked_group”:
{
if(isset($formvariables[$arg1]))
{
if(is_array($formvariables[$arg1]))
{
foreach($formvariables[$arg1] as $chk)
{
if(strcasecmp($chk,$arg2)==0)
{
$bret=true;break;
}
}//foreach
}
else
{
if(strcasecmp($formvariables[$arg1],$arg2)==0)
{
$bret=true;break;
}
}//else
}
break;
}//case]
case “is_not_selected_list_item”:
case “is_not_checked_group”:
{
$bret=true;
if(isset($formvariables[$arg1]))
{
if(is_array($formvariables[$arg1]))
{
foreach($formvariables[$arg1] as $chk)
{
if(strcasecmp($chk,$arg2)==0)
{
$bret=false;break;
}
}//foreach
}
else
{
if(strcasecmp($formvariables[$arg1],$arg2)==0)
{
$bret=false;break;
}
}//else
}
break;
}//case
case ‘is_empty’:
{
if(!isset($formvariables[$arg1]))
{
$bret=true;
}
else
{
$tmp_arg=trim($formvariables[$arg1]);
if(empty($tmp_arg))
{
$bret=true;
}
}
break;
}
case ‘is_not_empty’:
{
if(isset($formvariables[$arg1]))
{
$tmp_arg=trim($formvariables[$arg1]);
if(!empty($tmp_arg))
{
$bret=true;
}
}
break;
}

}//switch

return $bret;
}
if (!function_exists(‘_’))
{
function _($s)
{
return $s;
}
}

class FM_ElementInfo
{
private $elements;
public $default_values;

public function __construct()
{
$this->elements = array();
$this->default_values = array();
}
function AddElementInfo($name,$type,$extrainfo,$page)
{
$this->elements[$name][“type”] = $type;
$this->elements[$name][“extra”] = $extrainfo;
$this->elements[$name][“page”]= $page;
}
function AddDefaultValue($name,$value)
{

if(isset($this->default_values[$name]))
{
if(is_array($this->default_values[$name]))
{
array_push($this->default_values[$name],$value);
}
else
{
$curvalue = $this->default_values[$name];
$this->default_values[$name] = array($curvalue,$value);
}
}
else
{
$this->default_values[$name] = $this->doStringReplacements($value);
}
}

function doStringReplacements($strIn)
{
return str_replace(array(‘\n’),array(“\n”),$strIn);
}

function IsElementPresent($name)
{
return isset($this->elements[$name]);
}
function GetType($name)
{
if($this->IsElementPresent($name) &&
isset($this->elements[$name][“type”]))
{
return $this->elements[$name][“type”];
}
else
{
return ”;
}
}

function IsUsingDisplayVariable($name)
{
$type = $this->GetType($name);
$ret = false;
if($type == ‘datepicker’ ||
$type == ‘decimal’ ||
$type == ‘calcfield’)
{
$ret = true;
}
return $ret;
}
function GetExtraInfo($name)
{
return $this->elements[$name][“extra”];
}

function GetPageNum($name)
{
return $this->elements[$name][“page”];
}

function GetElements($page,$type=”)
{
$ret_arr = array();
foreach($this->elements as $ename => $eprops)
{
if(($eprops[‘page’] == $page) &&
(empty($type) || $type == $eprops[‘type’]))
{
$ret_arr[$ename] = $eprops;
}
}
return $ret_arr;
}

function GetAllElements()
{
return $this->elements;
}
}

/////Config/////
class FM_Config
{
public $formname;
public $form_submit_variable;
public $form_page_code;
public $error_display_variable;
public $display_error_in_formpage;
public $error_page_code;
public $email_format_html;
public $slashn;
public $installed;
public $log_flush_live;
public $encr_key;
public $form_id;
public $sys_debug_mode;
public $error_mail_to;
public $use_smtp;
public $smtp_host;
public $smtp_uname;
public $smtp_pwd;
public $from_addr;
public $variable_from;
public $common_date_format;
public $var_cur_form_page_num;
public $var_form_page_count;
public $var_page_progress_perc;
public $element_info;
public $print_preview_page;
public $v4_email_headers;
public $fmdb_host;
public $fmdb_username;
public $fmdb_pwd;
public $fmdb_database;
public $saved_message_templ;
public $default_timezone;
public $enable_auto_field_table;
public $rand_key;

//User configurable (through extension modules)
public $form_file_folder;//location to save csv file, log file etc
public $load_values_from_url;
public $allow_nonsecure_file_attachments;
public $file_upload_folder;
public $debug_mode;
public $logfile_size;
public $bypass_spammer_validations;
public $passwords_encrypted;
public $enable_p2p_header;
public $enable_session_id_url;
public $locale_name;
public $locale_dateformat;
public $array_disp_seperator;//used for imploding arrays before displaying

public function __construct()
{
$this->form_file_folder=””;
$this->installed = false;

$this->form_submit_variable =”sfm_form_submitted”;
$this->form_page_code=”

Error! code 104

%sfm_error_display_loc%”;
$this->error_display_variable = “sfm_error_display_loc”;
$this->show_errors_single_box = false;
$this->self_script_variable = “sfm_self_script”;
$this->form_filler_variable=”sfm_form_filler_place”;
$this->confirm_file_list_var = “sfm_file_uploads”;

$this->config_update_var = “sfm_conf_update”;

$this->config_update_val = “sfm_conf_update_val”;

$this->config_form_id_var = “sfm_form_id”;

$this->visitor_ip_var = “_sfm_visitor_ip_”;

$this->unique_id_var = “_sfm_unique_id_”;

$this->form_page_session_id_var = “_sfm_form_page_session_id_”;
//identifies a particular display of the form page. refreshing the page
// or opening a new browser tab creates a different id

$this->submission_time_var =”_sfm_form_submision_time_”;

$this->submission_date_var = “_sfm_form_submision_date_”;

$this->referer_page_var = “_sfm_referer_page_”;

$this->user_agent_var = “_sfm_user_agent_”;

$this->visitors_os_var = “_sfm_visitor_os_”;

$this->visitors_browser_var = “_sfm_visitor_browser_”;

$this->var_cur_form_page_num=’sfm_current_page’;

$this->var_form_page_count = ‘sfm_page_count’;

$this->var_page_progress_perc = ‘sfm_page_progress_perc’;

$this->form_id_input_var = ‘_sfm_form_id_iput_var_’;

$this->form_id_input_value = ‘_sfm_form_id_iput_value_’;

$this->display_error_in_formpage=true;
$this->error_page_code =”

Error!

%sfm_error_display_loc%”;
$this->email_format_html=false;
$this->slashn = “\r\n”;
$this->saved_message_templ = “Saved Successfully. {link}”;
$this->reload_formvars_var=”rd”;

$this->log_flush_live=false;

$this->encr_key=””;
$this->form_id=””;
$this->error_mail_to=””;
$this->sys_debug_mode = false;
$this->debug_mode = false;
$this->element_info = new FM_ElementInfo();

$this->use_smtp = false;
$this->smtp_host=”;
$this->smtp_uname=”;
$this->smtp_pwd=”;
$this->smtp_port=”;
$this->from_addr=”;
$this->variable_from=false;
$this->v4_email_headers=true;
$this->common_date_format = ‘Y-m-d’;
$this->load_values_from_url = false;
$this->rand_key=”;

$this->hidden_input_trap_var=”;

$this->allow_nonsecure_file_attachments = false;

$this->bypass_spammer_validations=false;

$this->passwords_encrypted=true;
$this->enable_p2p_header = true;
$this->enable_session_id_url=true;

$this->default_timezone = ‘default’;

$this->array_disp_seperator =”\n”;

$this->enable_auto_field_table=false;
}

function set_encrkey($key)
{
$this->encr_key=$key;
}

function set_form_id($form_id)
{
$this->form_id = $form_id;
}
function set_rand_key($key)
{
$this->rand_key=$key;
}
function set_error_email($email)
{
$this->error_mail_to = $email;
}

function get_form_id()
{
return $this->form_id;
}

function setFormPage($formpage)
{
$this->form_page_code = $formpage;
}

function setDebugMode($enable)
{
$this->debug_mode = $enable;
$this->log_flush_live = $enable?true:false;
}

function getCommonDateTimeFormat()
{
return $this->common_date_format.” H:i:s T(O \G\M\T)”;
}

function getFormConfigIncludeFileName($script_path,$formname)
{
$dir_name = dirname($script_path);

$conf_file = $dir_name.”/”.$formname.”_conf_inc.php”;

return $conf_file;
}

function getConfigIncludeSign()
{
return “//{__Simfatic Forms Config File__}”;
}

function get_uploadfiles_folder()
{
$upload_folder = ”;
if(!empty($this->file_upload_folder))
{
$upload_folder = $this->file_upload_folder;
}
else
{
$upload_folder = sfm_make_path($this->getFormDataFolder(),”uploads_”.$this->formname);
}
return $upload_folder;
}
function getFormDataFolder()
{
return $this->form_file_folder;
}
function InitSMTP($host,$uname,$pwd,$port)
{
$this->use_smtp = true;
$this->smtp_host=$host;
$this->smtp_uname=$uname;
$this->smtp_pwd=$pwd;
$this->smtp_port = $port;
}

function SetPrintPreviewPage($page)
{
$this->print_preview_page = $page;
}
function GetPrintPreviewPage()
{
return $this->print_preview_page;
}

function setFormDBLogin($host,$uname,$pwd,$database)
{
$this->fmdb_host = $host;
$this->fmdb_username = $uname;
$this->fmdb_pwd = $pwd;
$this->fmdb_database = $database;
}
function IsDBSupportRequired()
{
if(!empty($this->fmdb_host) && !empty($this->fmdb_username))
{
return true;
}
return false;
}

function IsSMTP()
{
return $this->use_smtp;
}
function GetPreParsedVar($varname)
{
return ‘sfm_’.$varname.’_parsed’;
}
function GetDispVar($varname)
{
return ‘sfm_’.$varname.’_disp’;
}
function SetLocale($locale_name,$date_format)
{
$this->locale_name = $locale_name;
$this->locale_dateformat = $date_format;
//TODO: use setLocale($locale_name) or locale_set_default
//also, use strftime instead of date()
$this->common_date_format = $this->toPHPDateFormat($date_format);
}

function toPHPDateFormat($stdDateFormat)
{
$map = array(
‘d’=>’j’,
‘dd’=>’d’,
‘ddd’=>’D’,
‘dddd’=>’l’,
‘M’=>’n’,
‘MM’=>’m’,
‘MMM’=>’M’,
‘MMMM’=>’F’,
‘yy’=>’y’,
‘yyyy’=>’Y’,
‘m’=>’i’,
‘mm’=>’i’,
‘h’=>’g’,
‘hh’=>’h’,
‘H’=>’H’,
‘HH’=>’G’,
‘s’=>’s’,
‘ss’=>’s’,
‘t’=>’A’,
‘tt’=>’A’
);

if(empty($stdDateFormat))
{
return ‘Y-m-d’;
}

$arr_ret = preg_split(‘/([^\w]+)/i’, $stdDateFormat,-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

foreach($arr_ret as $k=>$v)
{
if(isset($map[$v]))
{
$arr_ret[$k] = $map[$v];
}
}
$php_format = implode($arr_ret);
return $php_format;
}
}

/* By Grant Burton @ BURTONTECH.COM (11-30-2008): IP-Proxy-Cluster Fix */
function checkIP($ip)
{
if (!empty($ip) && ip2long($ip)!=-1 && ip2long($ip)!=false)
{
$private_ips = array (
array(‘0.0.0.0′,’2.255.255.255’),
array(‘10.0.0.0′,’10.255.255.255’),
array(‘127.0.0.0′,’127.255.255.255’),
array(‘169.254.0.0′,’169.254.255.255’),
array(‘172.16.0.0′,’172.31.255.255’),
array(‘192.0.2.0′,’192.0.2.255’),
array(‘192.168.0.0′,’192.168.255.255’),
array(‘255.255.255.0′,’255.255.255.255’)
);

foreach ($private_ips as $r)
{
$min = ip2long($r[0]);
$max = ip2long($r[1]);
if ((ip2long($ip) >= $min) && (ip2long($ip) <= $max)) return false;
}
return true;
}
else
{
return false;
}
}

function determineIP()
{
if(isset($_SERVER[“HTTP_CLIENT_IP”]) && checkIP($_SERVER[“HTTP_CLIENT_IP”]))
{
return $_SERVER[“HTTP_CLIENT_IP”];
}
if(isset($_SERVER[“HTTP_X_FORWARDED_FOR”]))
{
foreach (explode(“,”,$_SERVER[“HTTP_X_FORWARDED_FOR”]) as $ip)
{
if (checkIP(trim($ip)))
{
return $ip;
}
}
}

if(isset($_SERVER[“HTTP_X_FORWARDED”]) && checkIP($_SERVER[“HTTP_X_FORWARDED”]))
{
return $_SERVER[“HTTP_X_FORWARDED”];
}
elseif(isset($_SERVER[“HTTP_X_CLUSTER_CLIENT_IP”]) && checkIP($_SERVER[“HTTP_X_CLUSTER_CLIENT_IP”]))
{
return $_SERVER[“HTTP_X_CLUSTER_CLIENT_IP”];
}
elseif(isset($_SERVER[“HTTP_FORWARDED_FOR”]) && checkIP($_SERVER[“HTTP_FORWARDED_FOR”]))
{
return $_SERVER[“HTTP_FORWARDED_FOR”];
}
elseif(isset($_SERVER[“HTTP_FORWARDED”]) && checkIP($_SERVER[“HTTP_FORWARDED”]))
{
return $_SERVER[“HTTP_FORWARDED”];
}
else
{
return $_SERVER[“REMOTE_ADDR”];
}
}

//////GlobalData//////////
class FM_GlobalData
{
public $get_vars;
public $post_vars;
public $server_vars;
public $files;
public $formvars;
public $saved_data_varname;
public $config;
public $form_page_submitted;//means a submit button is pressed; need not be the last (final)submission
public $form_processed;
public $session;

public function __construct(&$config)
{
$this->get_vars =NULL;
$this->post_vars =NULL;
$this->server_vars =NULL;
$this->files=NULL;
$this->formvars=NULL;
$this->saved_data_varname=”sfm_saved_formdata_var”;
$this->config = &$config;
$this->form_processed = false;
$this->form_page_submitted = false;
$this->form_page_num=-1;
$this->LoadServerVars();
}

function LoadServerVars()
{
global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS,$HTTP_POST_FILES;
$parser_version = phpversion();
if ($parser_version <= “4.1.0”)
{
$this->get_vars = $HTTP_GET_VARS;
$this->post_vars = $HTTP_POST_VARS;
$this->server_vars= $HTTP_SERVER_VARS;
$this->files = $HTTP_POST_FILES;
}
if ($parser_version >= “4.1.0”)
{
$this->get_vars = $_GET;
$this->post_vars = $_POST;
$this->server_vars= $_SERVER;
$this->files = $_FILES;
}
$this->server_vars[‘REMOTE_ADDR’] = determineIP();
}

function GetGlobalVars()
{
if($this->is_submission($this->post_vars))
{
$this->formvars = $this->get_post_vars();
$this->form_page_submitted = true;
}
elseif($this->is_submission($this->get_vars))
{
$this->formvars = $this->get_get_vars();
$this->form_page_submitted = true;
}
else
{
$this->form_page_submitted = false;
$this->formvars = array();
}
magicQuotesRemove($this->formvars);

if($this->form_page_submitted)
{
$this->CollectInternalVars();
$this->NormalizeFormVars();
}

if(isset($this->formvars[$this->saved_data_varname]))
{
$this->LoadFormDataFromSession();
}

$this->formvars[$this->config->visitor_ip_var] =
$this->server_vars[‘REMOTE_ADDR’];

$visitor_unique_id = $this->get_unique_id();
$this->formvars[$this->config->unique_id_var]= $visitor_unique_id;
$this->formvars[$this->config->form_page_session_id_var] = md5($visitor_unique_id.uniqid(”));

$this->formvars[$this->config->submission_time_var]=
date($this->config->getCommonDateTimeFormat());

$this->formvars[$this->config->submission_date_var] = date($this->config->common_date_format);

$this->formvars[$this->config->referer_page_var] = $this->get_form_referer();

$ua =”;
if(!empty($this->server_vars[‘HTTP_USER_AGENT’]))
{
$ua = $this->server_vars[‘HTTP_USER_AGENT’];
}
else
{
$this->server_vars[‘HTTP_USER_AGENT’]=”;
}

$this->formvars[$this->config->user_agent_var] = $ua;

$this->formvars[$this->config->visitors_os_var] = $this->DetectOS($ua);

$this->formvars[$this->config->visitors_browser_var] = $this->DetectBrowser($ua);
}

function GetCurrentPageNum()
{
$page_num = 0;
if($this->form_page_num >= 0)
{
$page_num = $this->form_page_num;
}
return $page_num;
}
function NormalizeFormVarsBeforePageDisplay(&$var_map,$page_num)
{
$arr_elements =
$this->config->element_info->GetElements($page_num);

foreach($arr_elements as $ename => $e)
{
$disp_var = $this->config->GetDispVar($ename);
if(!empty($var_map[$disp_var]))
{
$var_map[$ename] = $var_map[$disp_var];
}
}
}

function CollectInternalVars()
{
/*
TODO: N9UVSWkdQeZF
Collect & move all internal variables here.
This way, it won’t mess up the formvars vector
To Do Add:
sfm_prev_page
sfm_save_n_close
sfm_prev_page
sfm_confirm_edit
sfm_confirm
config->form_submit_variable
sfm_saved_formdata_var
*/
if(isset($this->formvars[‘sfm_form_page_num’]) &&
is_numeric($this->formvars[‘sfm_form_page_num’]))
{
$this->form_page_num = intval($this->formvars[‘sfm_form_page_num’]);
unset($this->formvars[‘sfm_form_page_num’]);
}
}

function NormalizeFormVars()
{
//for boolean inputs like checkbox, the absense of
//the element means false. Explicitely setting this false here
//to help in later form value processing
$arr_elements =
$this->config->element_info->GetElements($this->GetCurrentPageNum());

foreach($arr_elements as $ename => $e)
{
$preparsed_var = $this->config->GetPreParsedVar($ename);
if(isset($this->formvars[$preparsed_var]))
{
$disp_var = $this->config->GetDispVar($ename);
$this->formvars[$disp_var] = $this->formvars[$ename];
$this->formvars[$ename] = $this->formvars[$preparsed_var];
}
if(isset($this->formvars[$ename])){continue;}

switch($e[‘type’])
{
case ‘single_chk’:
{
$this->formvars[$ename] = false;
break;
}
case ‘chk_group’:
case ‘multiselect’:
{
$this->formvars[$ename] = array();
break;
}
default:
{
$this->formvars[$ename]=”;
}
}
}
}

function is_submission($var_array)
{
if(empty($var_array)){ return false;}

if(isset($var_array[$this->config->form_submit_variable])//full submission
|| isset($var_array[‘sfm_form_page_num’]))//partial- page submission
{
return true;
}
return false;
}

function RecordVariables()
{
if(!empty($this->get_vars[‘sfm_from_iframe’]))
{
$this->session[‘sfm_from_iframe’]= $this->get_vars[‘sfm_from_iframe’];
}

$this->session[‘sfm_referer_page’] = $this->get_referer();
}

function GetVisitorUniqueKey()
{
$seed = $this->config->get_form_id().
$this->server_vars[‘SERVER_NAME’].
$this->server_vars[‘REMOTE_ADDR’].
$this->server_vars[‘HTTP_USER_AGENT’];
return md5($seed);
}
function get_unique_id()
{
if(empty($this->session[‘sfm_unique_id’]))
{
$this->session[‘sfm_unique_id’] =
md5($this->GetVisitorUniqueKey().uniqid(”,true));
}
return $this->session[‘sfm_unique_id’];
}
function get_form_referer()
{
if(isset($this->session[‘sfm_referer_page’]))
{
return $this->session[‘sfm_referer_page’];
}
else
{
return $this->get_referer();
}
}
function InitSession()
{
$id=$this->config->get_form_id();
if(!isset($_SESSION[$id]))
{
$_SESSION[$id]=array();
}
$this->session = &$_SESSION[$id];
}

function DestroySession()
{
$id=$this->config->get_form_id();
unset($_SESSION[$id]);
}

function RemoveSessionValue($name)
{
unset($_SESSION[$this->config->get_form_id()][$name]);
}

function RecreateSessionValues($arr_session)
{
foreach($arr_session as $varname => $values)
{
$this->session[$varname] = $values;
}
}
function SetFormVar($name,$value)
{
$this->formvars[$name] = $value;
}

function LoadFormDataFromSession()
{
$varname = $this->formvars[$this->saved_data_varname];

if(isset($this->session[$varname]))
{
$this->formvars =
array_merge($this->formvars,$this->session[$varname]);

unset($this->session[$varname]);
unset($this->session[$this->saved_data_varname]);
}
}

function SaveFormDataToSession()
{
$varname = “sfm_form_var_”.rand(1,1000).”_”.rand(2,2000);

$this->session[$varname] = $this->formvars;

unset($this->session[$varname][$this->config->form_submit_variable]);

return $varname;
}

function get_post_vars()
{
return $this->post_vars;
}
function get_get_vars()
{
return $this->get_vars;
}

function get_php_self()
{
$from_iframe = isset($this->session[‘sfm_from_iframe’]) ? intval($this->session[‘sfm_from_iframe’]):0;
$sid=0;
if($from_iframe)
{
$sid = session_id();
}
else
{
if(empty($this->session[‘sfm_rand_sid’]))
{
$this->session[‘sfm_rand_sid’] = rand(1,9999);
}
$sid = $this->session[‘sfm_rand_sid’];
}
$url = $this->server_vars[‘PHP_SELF’].”?sfm_sid=$sid”;
return $url;
}

function get_referer()
{
if(isset($this->server_vars[‘HTTP_REFERER’]))
{
return $this->server_vars[‘HTTP_REFERER’];
}
else
{
return ”;
}
}

function SetFormProcessed($processed)
{
$this->form_processed = $processed;
}

function IsFormProcessingComplete()
{
return $this->form_processed;
}

function IsButtonClicked($button_name)
{
if(isset($this->formvars[$button_name]))
{
return true;
}
if(isset($this->formvars[$button_name.”_x”])||
isset($this->formvars[$button_name.”_y”]))
{
if($this->formvars[$button_name.”_x”] == 0 &&
$this->formvars[$button_name.”_y”] == 0)
{//Chrome & safari bug
return false;
}
return true;
}
return false;
}
function ResetButtonValue($button_name)
{
unset($this->formvars[$button_name]);
unset($this->formvars[$button_name.”_x”]);
unset($this->formvars[$button_name.”_y”]);
}

function DetectOS($user_agent)
{
//code by Andrew Pociu
$OSList = array
(
‘Windows 3.11’ => ‘Win16’,

‘Windows 95’ => ‘(Windows 95)|(Win95)|(Windows_95)’,

‘Windows 98’ => ‘(Windows 98)|(Win98)’,

‘Windows 2000’ => ‘(Windows NT 5\.0)|(Windows 2000)’,

‘Windows XP’ => ‘(Windows NT 5\.1)|(Windows XP)’,

‘Windows Server 2003’ => ‘(Windows NT 5\.2)’,

‘Windows Vista’ => ‘(Windows NT 6\.0)’,

‘Windows 7’ => ‘(Windows NT 7\.0)|(Windows NT 6\.1)’,

‘Windows 8’ => ‘(Windows NT 6\.2)’,

‘Windows NT 4.0’ => ‘(Windows NT 4\.0)|(WinNT4\.0)|(WinNT)|(Windows NT)’,

‘Windows ME’ => ‘(Windows 98)|(Win 9x 4\.90)|(Windows ME)’,

‘Open BSD’ => ‘OpenBSD’,

‘Sun OS’ => ‘SunOS’,

‘Linux’ => ‘(Linux)|(X11)’,

‘Mac OS’ => ‘(Mac_PowerPC)|(Macintosh)’,

‘QNX’ => ‘QNX’,

‘BeOS’ => ‘BeOS’,

‘OS/2’ => ‘OS/2’,

‘Search Bot’=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)’
);

foreach($OSList as $CurrOS=>$Match)
{
if (preg_match(“#$Match#i”, $user_agent))
{
break;
}
}

return $CurrOS;
}

function DetectBrowser($agent)
{
$ret =””;
$browsers = array(“firefox”, “msie”, “opera”, “chrome”, “safari”,
“mozilla”, “seamonkey”, “konqueror”, “netscape”,
“gecko”, “navigator”, “mosaic”, “lynx”, “amaya”,
“omniweb”, “avant”, “camino”, “flock”, “aol”);

$agent = strtolower($agent);
foreach($browsers as $browser)
{
if (preg_match(“#($browser)[/ ]?([0-9.]*)#”, $agent, $match))
{
$br = $match[1];
$ver = $match[2];
if($br ==’safari’ && preg_match(“#version[/ ]?([0-9.]*)#”, $agent, $match))
{
$ver = $match[1];
}
$ret = ($br==’msie’)?’Internet Explorer’:ucfirst($br);
$ret .= ” “. $ver;
break ;
}
}
return $ret;
}

}

/////Logger/////
class FM_Logger
{
private $config;
private $log_file_path;
private $formname;
private $log_filename;
private $whole_log;
private $is_enabled;
private $logfile_size;
private $msg_log_enabled;
private $log_source;

public function __construct(&$config,$formname)
{
$this->config = &$config;
$this->formname = $formname;
$this->log_filename=””;
$this->whole_log=””;
$this->is_enabled = false;
$this->log_flushed = false;
$this->logfile_size=100;//In KBs
$this->msg_log_enabled = true;
$this->log_source = ”;
}

function EnableLogging($enable)
{
$this->is_enabled = $enable;
}
function SetLogSource($logSource)
{
$this->log_source = $logSource;
}
function CreateFileName()
{
$ret=false;
$filename =””;
if(strlen($this->log_filename)> 0)
{
$filename = $this->log_filename;
}
else
if(strlen($this->config->get_form_id())>0)
{
$form_id_part = substr($this->config->get_form_id(),0,8);

$filename = $this->formname.’-‘.$form_id_part.’-log.php’;
}
else
{
return false;
}

if(strlen($this->config->form_file_folder)>0)
{
$this->log_file_path = sfm_make_path($this->config->form_file_folder,
$filename);
$ret = true;
}
else
{
$this->log_file_path =””;
$ret=false;
}
return $ret;
}

function LogString($string,$type)
{
$bret = false;
$t_log = “\n”;
$t_log .= $_SERVER[‘REMOTE_ADDR’].”|”;

$t_log .= date(“Y-m-d h:i:s A|”);
$t_log .= $this->log_source.’|’;
$t_log .= “$type| “;
$string = str_replace(“\n”,”\\n”,$string);
$t_log .= $string;

if($this->is_enabled && $this->config->debug_mode)
{
$bret = $this->writeToFile($t_log);
}

$this->whole_log .= $t_log;
return $bret;
}

function FlushLog()
{
if($this->is_enabled &&
!$this->log_flushed &&
!$this->config->debug_mode)
{
$this->writeToFile($this->get_log());
$this->log_flushed = true;
}
}

function print_log()
{
echo $this->whole_log;
}

function get_log()
{
return $this->whole_log;
}

function get_log_file_path()
{
if(strlen($this->log_file_path)<=0)
{
if(!$this->CreateFileName())
{
return “”;
}
}
return $this->log_file_path;
}

function writeToFile($t_log)
{
$this->get_log_file_path();

if(strlen($this->log_file_path)<=0){ return false;}

$fp =0;
$create_file=false;

if(file_exists($this->log_file_path))
{
$maxsize= $this->logfile_size * 1024;
if(filesize($this->log_file_path) >= $maxsize)
{
$create_file = true;
}
}
else
{
$create_file = true;
}

$ret = true;
$file_maker = new SecureFileMaker($this->GetFileSignature());
if(true == $create_file)
{
$ret = $file_maker->CreateFile($this->log_file_path,$t_log);
}
else
{
$ret = $file_maker->AppendLine($this->log_file_path,$t_log);
}

return $ret;
}

function GetFileSignature()
{
return “–Simfatic Forms Log File–“;
}

function LogError($string)
{
return $this->LogString($string,”error”);
}

function LogInfo($string)
{
if(false == $this->msg_log_enabled)
{
return true;
}
return $this->LogString($string,”info”);
}
}

class FM_ErrorHandler
{
private $logger;
private $config;
private $globaldata;
private $formname;
private $sys_error;
private $formvars;
private $common_objs;

public $disable_syserror_handling;

public function __construct(&$logger,&$config,&$globaldata,$formname,&$common_objs)
{
$this->logger = &$logger;
$this->config = &$config;
$this->globaldata = &$globaldata;
$this->formname = $formname;
$this->sys_error=””;
$this->enable_error_formpagemerge=true;
$this->common_objs = &$common_objs;
}

function SetFormVars(&$formvars)
{
$this->formvars = &$formvars;
}

function InstallConfigErrorCatch()
{
set_error_handler(array(&$this, ‘sys_error_handler’));
}

function DisableErrorFormMerge()
{
$this->enable_error_formpagemerge = false;
}

function GetLastSysError()
{
return $this->sys_error;
}

function IsSysError()
{
if(strlen($this->sys_error)>0){return true;}
else { return false;}
}

function GetSysError()
{
return $this->sys_error;
}

function sys_error_handler($errno, $errstr, $errfile, $errline)
{
if(defined(‘E_STRICT’) && $errno == E_STRICT)
{
return true;
}
switch($errno)
{
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
{
$this->sys_error = “Error ($errno): $errstr\n file:$errfile\nline: $errline \n\n”;

if($this->disable_syserror_handling == true)
{
return false;
}
$this->HandleConfigError($this->sys_error);
exit;
break;
}
default:
{
$this->logger->LogError(“Error/Warning reported: $errstr\n file:$errfile\nline: $errline \n\n”);
}
}
return true;
}

function ShowError($error_code,$show_form=true)
{
if($show_form)
{
$this->DisplayError($error_code);
}
else
{
echo “Error

$error_code

“;
}
}
function ShowErrorEx($error_code,$error_extra_info)
{
$error_extra_info = trim($error_extra_info);
$this->DisplayError($error_code.”\n”.$error_extra_info);
}
function ShowInputError($error_hash,$formname)
{
$this->DisplayError(“”,$error_hash,$formname);
}
function NeedSeperateErrorPage($error_hash)
{
if(null == $error_hash)
{
if(false === strpos($this->config->form_page_code,
$this->config->error_display_variable))
{
return true;
}
}

return false;
}

function DisplayError($str_error,$error_hash=null,$formname=””)
{
$str_error = trim($str_error);
$this->logger->LogError($str_error);

if(!$this->enable_error_formpagemerge)
{
$this->sys_error = $str_error;
return;
}

$str_error = nl2br($str_error);

$var_map = array(
$this->config->error_display_variable => $str_error
);

if(null != $error_hash)
{
if($this->config->show_errors_single_box)
{
$this->CombineErrors($var_map,$error_hash);
}
else
{
foreach($error_hash as $inpname => $inp_err)
{
$err_var = $formname.”_”.$inpname.”_errorloc”;
$var_map[$err_var] = $inp_err;
}
}
}

if(!isset($this->common_objs->formpage_renderer))
{
$this->logger->LogError(‘Form page renderer not initialized’);
}
else
{
$this->logger->LogInfo(“Error display: Error map “.var_export($var_map,TRUE));
$this->common_objs->formpage_renderer->DisplayCurrentPage($var_map);
}

}

function CombineErrors(&$var_map,&$error_hash)
{
$error_str=”;
foreach($error_hash as $inpname => $inp_err)
{
$error_str .=”\n

  • “.$inp_err;
    }

    if(!empty($error_str))
    {
    $error_str=”\n

      “.$error_str.”\n

    “;
    }

    $var_map[$this->config->error_display_variable]=
    $var_map[$this->config->error_display_variable].$error_str;

    }

    function EmailError($error_code)
    {
    $this->logger->LogInfo(“Sending Error Email To: “.$this->config->error_mail_to);
    $mailbody = sprintf(_(“Error occured in form %s.\n\n%s\n\nLog:\n%s”),$this->formname,$error_code,$this->logger->get_log());
    $subj = sprintf(_(“Error occured in form %s.”),$this->formname);

    $from = empty($this->config->from_addr) ? ‘form.error@simfatic-forms.com’ : $this->config->from_addr;
    $from = $this->formname.'<‘.$from.’>’;
    @mail($this->config->error_mail_to, $subj, $mailbody,
    “From: $from”);
    }

    function NotifyError($error_code)
    {
    $this->logger->LogError($error_code);
    if(strlen($this->config->error_mail_to)>0)
    {
    $this->EmailError($error_code);
    }
    }

    function HandleConfigError($error_code,$extrainfo=””)
    {
    $logged = $this->logger->LogError($error_code);

    if(strlen($this->config->error_mail_to)>0)
    {
    $this->EmailError($error_code);
    }

    if(!$this->enable_error_formpagemerge)
    {
    $this->sys_error = “$error_code \n $extrainfo”;
    return;
    }
    $disp_error = $this->FormatError($logged,$error_code,$extrainfo);

    $this->DisplayError($disp_error);
    }

    function FormatError($logged,$error_code,$extrainfo)
    {
    $disp_error = “

    “;
    $disp_error .= _(“There was a configuration error.”);

    $extrainfo .= “\n server: “.$_SERVER[“SERVER_SOFTWARE”];

    $error_code_disp =”;
    $error_code_disp_link =”;

    if($this->config->debug_mode)
    {
    $error_code_disp = $error_code.$extrainfo;
    }
    else
    {
    if($logged)
    {
    $error_code_disp .= _(“The error is logged.”);
    }
    else
    {
    $error_code_disp .= _(“Could not log the error”);
    }

    $error_code_disp .= “
    “._(“Enable debug mode (‘Form processing options’ page) for displaying errors.”);
    }

    $link = sprintf(_(” Click here for troubleshooting information.”),
    urlencode($error_code_disp));

    $disp_error .= “
    “.$error_code_disp.”
    $link”;

    $disp_error .= “

    “;

    return $disp_error;
    }
    }

    class FM_FormFiller
    {
    private $filler_js_code;
    private $config;
    private $logger;

    public function __construct(&$config,&$logger)
    {
    $this->filler_js_code=””;
    $this->form_filler_variable = “sfm_fill_the_form”;
    $this->logger = &$logger;
    $this->config = &$config;
    }
    function GetFillerJSCode()
    {
    return $this->filler_js_code;
    }
    function GetFormFillerScriptEmbedded($formvars)
    {
    $ret_code=””;
    if($this->CreateFormFillerScript($formvars))
    {
    $self_script = htmlentities($this->globaldata->get_php_self());
    $ret_code .= “\n”;

    $ret_code .= ““;
    }
    return $ret_code;
    }

    function CreateServerSideVector($formvars,&$outvector)
    {
    foreach($formvars as $name => $value)
    {
    /*if(!$this->config->element_info->IsElementPresent($name)||
    !isset($value))
    {
    continue;
    }*/

    switch($this->config->element_info->GetType($name))
    {
    case “text”:
    case “multiline”:
    case “decimal”:
    case “calcfield”:
    case “datepicker”:
    case “hidden”:
    {
    $outvector[$name] = $value;
    break;
    }
    case “single_chk”:
    case “radio_group”:
    case “multiselect”:
    case “chk_group”:
    {
    $this->SetGroupItemValue($outvector,$name,$value,”checked”);
    break;
    }
    case “listbox”:
    {
    $this->SetGroupItemValue($outvector,$name,$value,”selected”);
    break;
    }
    default:
    {
    $outvector[$name] = $value;
    break;
    }
    }//switch
    }//foreach
    }

    function SetGroupItemValue(&$outvector,$name,$value,$set_val)
    {
    if(is_array($value))
    {
    foreach($value as $val_item)
    {
    $entry = md5($name.$val_item);
    $outvector[$entry]=$set_val;
    }
    $outvector[$name] = implode(‘,’,$value);
    }
    else
    {
    $entry = md5($name.$value);
    $outvector[$entry]=$set_val;
    $outvector[$name] = $value;
    }

    }

    function CreateFormFillerScript($formvars)
    {

    $func_body=””;
    foreach($formvars as $name => $value)
    {
    if(!$this->config->element_info->IsElementPresent($name)||
    !isset($value))
    {
    continue;
    }
    switch($this->config->element_info->GetType($name))
    {
    case “text”:
    case “multiline”:
    case “decimal”:
    case “calcfield”:
    case “datepicker”:
    {
    $value = str_replace(“\n”,”\\n”,$value);
    $value = str_replace(“‘”,”\\'”,$value);
    $func_body .= “formobj.elements[‘$name’].value = ‘$value’;\n”;
    break;
    }
    case “single_chk”:
    {
    if(strlen($value) > 0 && strcmp($value,”off”)!=0)
    {
    $func_body .= “formobj.elements[‘$name’].checked = true;\n”;
    }
    break;
    }

    case “multiselect”:
    case “chk_group”:
    {
    $name_tmp=”$name”.”[]”;
    foreach($value as $item)
    {
    $func_body .= “SFM_SelectChkItem(formobj.elements[‘$name_tmp’],’$item’);\n”;
    }
    break;
    }
    case “radio_group”:
    {
    $func_body .= “SFM_SelectChkItem(formobj.elements[‘$name’],’$value’);\n”;
    break;
    }
    case “listbox”:
    {
    if(is_array($value))
    {
    $name_tmp=”$name”.”[]”;
    foreach($value as $item)
    {
    $func_body .= “SFM_SelectListItem(formobj.elements[‘$name_tmp’],’$item’);\n”;
    }
    }
    else
    {
    $func_body .= “formobj.elements[‘$name’].value = ‘$value’;\n”;
    }
    break;
    }
    }
    }//foreach

    $bret=false;
    $this->filler_js_code=””;
    if(strlen($func_body)>0)
    {
    $function_name = “sfm_”.$this->formname.”formfiller”;

    $this->filler_js_code .= “function $function_name (){\n”;
    $this->filler_js_code .= ” var formobj= document.forms[‘”.$this->formname.”‘];\n”;
    $this->filler_js_code .= $func_body;
    $this->filler_js_code .= “}\n”;
    $this->filler_js_code .= “$function_name ();”;
    $bret= true;
    }
    return $bret;
    }

    }

    class FM_FormVarMx
    {
    private $logger;
    private $config;
    private $globaldata;
    private $formvars;
    private $html_vars;

    public function __construct(&$config,&$logger,&$globaldata)
    {
    $this->config = &$config;
    $this->logger = &$logger;
    $this->globaldata = &$globaldata;
    $this->formvars = &$this->globaldata->formvars;
    $this->html_vars = array();
    }

    function AddToHtmlVars($html_var)
    {
    $this->html_vars[] = $html_var;
    }
    function IsHtmlVar($var)
    {
    return (false === array_search($var,$this->html_vars)) ? false:true;
    }
    function CreateFieldMatrix($html=true)
    {
    $datamap = $this->formvars;
    foreach($datamap as $name => $value)
    {
    $value = $this->GetFieldValueAsString($name,/*$use_disp_var*/true);
    if($html && (false == $this->IsHtmlVar($name)) )
    {
    $datamap[$name] = nl2br(htmlentities($value,ENT_QUOTES,”UTF-8″));
    }
    else
    {
    $datamap[$name] = $value;
    }
    }

    if(true == $this->config->enable_auto_field_table)
    {
    $datamap[‘_sfm_non_blank_field_table_’] = $this->CreateFieldTable($datamap);
    }

    return $datamap;
    }

    function CreateFieldTable(&$datamap)
    {
    $ret_table =”

    “;
    $arr_elements =
    $this->config->element_info->GetAllElements();
    foreach($arr_elements as $ename => $e)
    {
    if(isset($datamap[$ename]) && strlen($datamap[$ename]) > 0 )
    {
    $value = $datamap[$ename];

    $ret_table .= “\n”;
    }
    }
    $ret_table .= “

    $ename $value

    “;
    return $ret_table;
    }

    function GetFieldValueAsString($var_name,$use_disp_var=false)
    {
    $ret_val =”;
    if(isset($this->formvars[$var_name]))
    {
    $ret_val = $this->formvars[$var_name];
    }

    if(is_array($ret_val))
    {
    $ret_val = implode($this->config->array_disp_seperator,$ret_val);
    }
    else if($use_disp_var && $this->config->element_info->IsUsingDisplayVariable($var_name))
    {
    $disp_var_name = sfm_get_disp_variable($var_name);
    if(!empty($this->formvars[$disp_var_name]))
    {
    $ret_val = $this->formvars[$disp_var_name];
    }
    }
    return $ret_val;
    }
    }

    class FM_FormPageRenderer
    {
    private $config;
    private $logger;
    private $globaldata;
    private $arr_form_pages;
    private $security_monitor;
    private $ext_module;

    public function __construct(&$config,&$logger,&$globaldata,&$security_monitor)
    {
    $this->config = &$config;
    $this->logger = &$logger;
    $this->globaldata = &$globaldata;
    $this->security_monitor = &$security_monitor;

    $this->arr_form_pages = array();
    $this->ext_module = null;
    }

    function InitExtensionModule(&$extmodule)
    {
    $this->ext_module = &$extmodule;
    }

    function SetFormPage($page_num,$templ,$condn=”)
    {
    $this->arr_form_pages[$page_num] = array();
    $this->arr_form_pages[$page_num][‘templ’] = $templ;
    $this->arr_form_pages[$page_num][‘condn’] = $condn;
    }

    function GetNumPages()
    {
    return count($this->arr_form_pages);
    }

    function GetCurrentPageNum()
    {
    return $this->globaldata->GetCurrentPageNum();
    }
    function GetLastPageNum()
    {
    return ($this->GetNumPages()-1);
    }

    function IsPageNumSet()
    {
    return ($this->globaldata->form_page_num >= 0);
    }

    function DisplayCurrentPage($addnl_vars=NULL)
    {
    $this->DisplayFormPage($this->getCurrentPageNum(),$addnl_vars);
    }

    function DisplayNextPage($addnl_vars,&$display_thankyou)
    {
    if($this->IsPageNumSet() &&
    $this->getCurrentPageNum() < $this->GetLastPageNum())
    {
    $nextpage = $this->GetNextPageNum($addnl_vars);

    if($nextpage < $this->GetNumPages())
    {
    $this->DisplayFormPage($nextpage,$addnl_vars);
    return;
    }
    else
    {
    $display_thankyou =true;
    return;
    }
    }

    $this->DisplayFormPage(0,$addnl_vars);
    }

    function DisplayFirstPage($addnl_vars)
    {
    $this->DisplayFormPage(0,$addnl_vars);
    }

    function DisplayPrevPage($addnl_vars)
    {
    if($this->IsPageNumSet())
    {
    $curpage = $this->getCurrentPageNum();

    $prevpage = $curpage-1;

    for(;$prevpage>=0;$prevpage–)
    {
    if($this->TestPageCondition($prevpage,$addnl_vars))
    {
    break;
    }
    }

    if($prevpage >= 0)
    {
    $this->DisplayFormPage($prevpage,$addnl_vars);
    return;
    }
    }

    $this->DisplayFormPage(0,$addnl_vars);
    }

    function GetNextPageNum($addnl_vars)
    {
    $nextpage = 0;

    if($this->IsPageNumSet() )
    {
    $nextpage = $this->getCurrentPageNum() + 1;

    for(;$nextpage < $this->GetNumPages(); $nextpage ++)
    {
    if($this->TestPageCondition($nextpage,$addnl_vars))
    {
    break;
    }
    }
    }
    return $nextpage;
    }

    function IsNextPageAvailable($addnl_vars)
    {
    if($this->GetNextPageNum($addnl_vars) < $this->GetNumPages())
    {
    return true;
    }
    return false;
    }

    function TestPageCondition($pagenum,$addnl_vars)
    {
    $condn = $this->arr_form_pages[$pagenum][‘condn’];

    if(empty($condn))
    {
    return true;
    }
    elseif(sfm_validate_multi_conditions($condn,$addnl_vars))
    {
    return true;
    }
    $this->logger->LogInfo(“TestPageCondition condn: returning false”);
    return false;
    }

    function DisplayFormPage($page_num,$addnl_vars=NULL)
    {
    $fillerobj = new FM_FormFiller($this->config,$this->logger);

    $var_before_proc = array();
    if(!is_null($addnl_vars))
    {
    $var_before_proc = array_merge($var_before_proc,$addnl_vars);
    }
    $var_before_proc = array_merge($var_before_proc,$this->globaldata->formvars);

    $this->globaldata->NormalizeFormVarsBeforePageDisplay($var_before_proc,$page_num);

    if($this->ext_module && false === $this->ext_module->BeforeFormDisplay($var_before_proc,$page_num))
    {
    $this->logger->LogError(“Extension Module ‘BeforeFormDisplay’ returned false! “);
    return false;
    }

    $var_map = array();
    $fillerobj->CreateServerSideVector($var_before_proc,$var_map);

    $var_map[$this->config->self_script_variable] = $this->globaldata->get_php_self();

    $var_map[‘sfm_css_rand’] = rand();
    $var_map[$this->config->var_cur_form_page_num] = $page_num+1;

    $var_map[$this->config->var_form_page_count] = $this->GetNumPages();

    $var_map[$this->config->var_page_progress_perc] = ceil((($page_num)*100)/$this->GetNumPages());

    $this->security_monitor->AddSecurityVariables($var_map);

    $page_templ=”;
    if(!isset($this->arr_form_pages[$page_num]))
    {
    $this->logger->LogError(“Page $page_num not initialized”);
    }
    else
    {
    $page_templ = $this->arr_form_pages[$page_num][‘templ’];
    }

    ob_clean();
    $merge = new FM_PageMerger();

    convert_html_entities_in_formdata(/*skip var*/$this->config->error_display_variable,$var_map,/*nl2br*/false);
    if(false == $merge->Merge($page_templ,$var_map))
    {
    return false;
    }
    $strdisp = $merge->getMessageBody();
    echo $strdisp;
    return true;
    }
    }

    class FM_SecurityMonitor
    {
    private $config;
    private $logger;
    private $globaldata;
    private $banned_ip_arr;
    private $session_input_id;

    public function __construct(&$config,&$logger,&$globaldata)
    {
    $this->config = &$config;
    $this->logger = &$logger;
    $this->globaldata = &$globaldata;
    $this->banned_ip_arr = array();
    $this->session_input_id = ‘_sfm_session_input_id_’;
    $this->session_input_value = ‘_sfm_session_input_value_’;
    }

    function AddBannedIP($ip)
    {
    $this->banned_ip_arr[] = $ip;
    }

    function IsBannedIP()
    {
    $ip = $this->globaldata->server_vars[‘REMOTE_ADDR’];

    $n = count($this->banned_ip_arr);

    for($i=0;$i<$n;$i++)
    {
    if(sfm_compare_ip($this->banned_ip_arr[$i],$ip))
    {
    $this->logger->LogInfo(“Banned IP ($ip) attempted the form. Returned error.”);
    return true;
    }
    }
    return false;

    }

    function GetFormIDInputName()
    {
    if(!empty($this->globaldata->session[$this->session_input_id]))
    {
    return $this->globaldata->session[$this->session_input_id];
    }
    $idname = $this->globaldata->GetVisitorUniqueKey();
    $idname = str_replace(‘-‘,”,$idname);
    $idname = ‘id_’.substr($idname,0,20);

    $this->globaldata->session[$this->session_input_id] = $idname;
    return $idname;
    }

    function GetFormIDInputValue()
    {
    if(!empty($this->globaldata->session[$this->session_input_value]))
    {
    return $this->globaldata->session[$this->session_input_value];
    }
    $value = $this->globaldata->GetVisitorUniqueKey();

    $value = substr(md5($value),5,25);

    $this->globaldata->session[$this->session_input_value] = $value;

    return $value;
    }

    function AddSecurityVariables(&$varmap)
    {
    $varmap[$this->config->form_id_input_var] = $this->GetFormIDInputName();
    $varmap[$this->config->form_id_input_value] = $this->GetFormIDInputValue();
    }

    function Validate($formdata)
    {
    $formid_input_name = $this->GetFormIDInputName();

    $this->logger->LogInfo(“Form ID input name: $formid_input_name “);

    if($this->IsBannedIP())
    {
    $this->logger->LogInfo(“Is Banned IP”);
    return false;
    }
    if(true == $this->config->bypass_spammer_validations)
    {
    return true;
    }
    if(!isset($formdata[$formid_input_name]))
    {
    $this->logger->LogError(“Form ID input is not set”);
    return false;
    }
    elseif($formdata[$formid_input_name] != $this->GetFormIDInputValue())
    {
    $this->logger->LogError(“Spammer attempt foiled! Form ID input value not correct. expected:”.
    $this->GetFormIDInputValue().” Received:”.$formdata[$formid_input_name]);

    return false;
    }

    if(!empty($this->config->hidden_input_trap_var) &&
    !empty($formdata[$this->config->hidden_input_trap_var]) )
    {
    $this->logger->LogError(“Hidden input trap value is not empty. Spammer attempt foiled!”);
    return false;
    }
    $this->logger->LogInfo(“Sec Monitor Validate returning true”);
    return true;
    }
    }

    class FM_Module
    {
    protected $config;
    protected $formvars;
    protected $logger;
    protected $globaldata;
    protected $error_handler;
    protected $formname;
    protected $ext_module;
    protected $common_objs;

    public function __construct()
    {
    }

    function Init(&$config,&$formvars,&$logger,&$globaldata,
    &$error_handler,$formname,&$ext_module,&$common_objs)
    {
    $this->config = &$config;
    $this->formvars = &$formvars;
    $this->logger = &$logger;
    $this->globaldata =&$globaldata;
    $this->error_handler = &$error_handler;
    $this->formname = $formname;
    $this->ext_module = &$ext_module;
    $this->common_objs = &$common_objs;
    $this->OnInit();
    }

    function OnInit()
    {
    }

    function AfterVariablessInitialized()
    {
    return true;
    }

    function Process(&$continue)
    {
    return true;
    }

    function ValidateInstallation(&$app_command_obj)
    {
    return true;
    }

    function DoAppCommand($cmd,$val,&$app_command_obj)
    {
    //Return true to indicate ‘handled’
    return false;
    }

    function Destroy()
    {

    }
    function getFormDataFolder()
    {
    if(strlen($this->config->form_file_folder)<=0)
    {
    $this->error_handler->HandleConfigError(“Config Error: No Form data folder is set; but tried to access form data folder”);
    exit;
    }
    return $this->config->form_file_folder;
    }
    }

    ///////PageMerger////////////////////
    class FM_PageMerger
    {
    var $message_body;

    public function __construct()
    {
    $this->message_body=””;
    }

    function Merge($content,$variable_map)
    {
    $this->message_body = $this->mergeStr($content,$variable_map);

    return(strlen($this->message_body)>0?true:false);
    }

    function mergeStr($template,$variable_map)
    {
    $ret_str = $template;
    $N = 0;
    $m = preg_match_all(“/%([\w]*)%/”, $template,$matches,PREG_PATTERN_ORDER);

    if($m > 0 || count($matches) > 1)
    {
    $N = count($matches[1]);
    }

    $source_arr = array();
    $value_arr = array();

    for($i=0;$i<$N;$i++)
    {
    $val = “”;
    $key = $matches[1][$i];
    if(isset($variable_map[$key]))
    {
    if(is_array($variable_map[$key]))
    {
    $val = implode(“,”,$variable_map[$key]);
    }
    else
    {
    $val = $variable_map[$key];
    }
    }
    else
    if(strlen($key)<=0)
    {
    $val =’%’;
    }
    $source_arr[$i] = $matches[0][$i];
    $value_arr[$i] = $val;
    }

    $ret_str = str_replace($source_arr,$value_arr,$template);

    return $ret_str;
    }

    function mergeArray(&$arrSource, $variable_map)
    {
    foreach($arrSource as $key => $value)
    {
    if(!empty($value) && false !== strpos($value,’%’))
    {
    $arrSource[$key] = $this->mergeStr($value,$variable_map);
    }
    }
    }
    function getMessageBody()
    {
    return $this->message_body;
    }
    }

    class FM_ExtensionModule
    {
    protected $config;
    protected $formvars;
    protected $logger;
    protected $globaldata;
    protected $error_handler;
    protected $formname;

    public function __construct()
    {

    }

    function Init(&$config,&$formvars,&$logger,&$globaldata,&$error_handler,$formname)
    {
    $this->config = &$config;
    $this->formvars = &$formvars;
    $this->logger = &$logger;
    $this->globaldata =&$globaldata;
    $this->error_handler = &$error_handler;
    $this->formname = $formname;
    }
    function BeforeStartProcessing()
    {
    return true;
    }
    function AfterVariablessInitialized()
    {
    return true;
    }
    function BeforeFormDisplay(&$formvars,$pagenum=0)
    {
    return true;
    }
    function LoadDynamicList($listname,&$rows)
    {
    //return true if this overload loaded the list
    return false;
    }
    function LoadCascadedList($listname,$parent,&$rows)
    {
    return false;
    }
    function DoValidate(&$formvars, &$error_hash)
    {
    return true;
    }

    function DoValidatePage(&$formvars, &$error_hash,$page)
    {
    return true;
    }

    function PreprocessFormSubmission(&$formvars)
    {
    return true;
    }

    function BeforeConfirmPageDisplay(&$formvars)
    {
    return true;
    }

    function FormSubmitted(&$formvars)
    {
    return true;
    }

    function BeforeThankYouPageDisplay(&$formvars)
    {
    return true;
    }

    function BeforeSendingFormSubmissionEMail(&$receipient,&$subject,&$body)
    {
    return true;
    }

    function BeforeSendingAutoResponse(&$receipient,&$subject,&$body)
    {
    return true;
    }
    function BeforeSubmissionTableDisplay(&$fields)
    {
    return true;
    }
    function BeforeDetailedPageDisplay(&$rec)
    {
    return true;
    }
    function HandleFilePreview($filepath)
    {
    return false;
    }
    }

    class FM_ExtensionModuleHolder
    {
    private $modules;

    private $config;
    private $formvars;
    private $logger;
    private $globaldata;
    private $error_handler;
    private $formname;

    function Init(&$config,&$formvars,&$logger,&$globaldata,&$error_handler,$formname)
    {
    $this->config = &$config;
    $this->formvars = &$formvars;
    $this->logger = &$logger;
    $this->globaldata =&$globaldata;
    $this->error_handler = &$error_handler;
    $this->formname = $formname;
    $this->InitModules();
    }

    public function __construct()
    {
    $this->modules = array();
    }

    function AddModule(&$module)
    {
    array_push_ref($this->modules,$module);
    }

    function InitModules()
    {
    $N = count($this->modules);

    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $mod->Init($this->config,$this->formvars,
    $this->logger,$this->globaldata,
    $this->error_handler,$this->formname);
    }
    }

    function Delegate($method,$params)
    {
    $N = count($this->modules);
    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $ret_c = call_user_func_array(array(&$mod, $method), $params);
    if(false === $ret_c)
    {
    return false;
    }
    }
    return true;
    }

    function DelegateFalseDefault($method,$params)
    {
    $N = count($this->modules);
    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $ret_c = call_user_func_array(array(&$mod, $method), $params);
    if(true === $ret_c)
    {
    return true;
    }
    }
    return false;
    }

    function DelegateEx($method,$params)
    {
    $N = count($this->modules);
    $ret = true;
    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $ret_c = call_user_func_array(array($mod, $method), $params);
    $ret = $ret && $ret_c;
    }
    return $ret;
    }

    function AfterVariablessInitialized()
    {
    return $this->Delegate(‘AfterVariablessInitialized’,array());
    }

    function BeforeStartProcessing()
    {
    return $this->Delegate(‘BeforeStartProcessing’,array());
    }

    function BeforeFormDisplay(&$formvars,$pagenum)
    {
    return $this->Delegate(‘BeforeFormDisplay’,array(&$formvars,$pagenum));
    }
    function LoadDynamicList($listname,&$rows)
    {
    return $this->DelegateFalseDefault(‘LoadDynamicList’,array($listname,&$rows));
    }

    function LoadCascadedList($listname,$parent,&$rows)
    {
    return $this->DelegateFalseDefault(‘LoadCascadedList’,array($listname,$parent,&$rows));
    }
    function DoValidatePage(&$formvars, &$error_hash,$page)
    {
    return $this->DelegateEx(‘DoValidatePage’,array(&$formvars, &$error_hash,$page));
    }

    function DoValidate(&$formvars, &$error_hash)
    {
    return $this->DelegateEx(‘DoValidate’,array(&$formvars, &$error_hash));
    }

    function PreprocessFormSubmission(&$formvars)
    {
    return $this->Delegate(‘PreprocessFormSubmission’,array(&$formvars));
    }

    function BeforeConfirmPageDisplay(&$formvars)
    {
    return $this->Delegate(‘BeforeConfirmPageDisplay’,array(&$formvars));
    }

    function FormSubmitted(&$formvars)
    {
    return $this->Delegate(‘FormSubmitted’,array(&$formvars));
    }

    function BeforeThankYouPageDisplay(&$formvars)
    {
    return $this->Delegate(‘BeforeThankYouPageDisplay’,array(&$formvars));
    }

    function BeforeSendingFormSubmissionEMail(&$receipient,&$subject,&$body)
    {
    return $this->Delegate(‘BeforeSendingFormSubmissionEMail’,array(&$receipient,&$subject,&$body));
    }

    function BeforeSendingAutoResponse(&$receipient,&$subject,&$body)
    {
    return $this->Delegate(‘BeforeSendingAutoResponse’,array(&$receipient,&$subject,&$body));
    }

    function BeforeSubmissionTableDisplay(&$fields)
    {
    return $this->Delegate(‘BeforeSubmissionTableDisplay’,array(&$fields));
    }

    function BeforeDetailedPageDisplay(&$rec)
    {
    return $this->Delegate(‘BeforeDetailedPageDisplay’,array(&$rec));
    }

    function HandleFilePreview($filepath)
    {
    return $this->Delegate(‘HandleFilePreview’,array($filepath));
    }
    }

    ///////Form Installer////////////////////
    class SFM_AppCommand
    {
    private $config;
    private $logger;
    private $error_handler;
    private $globaldata;
    public $response_sender;
    private $app_command;
    private $command_value;
    private $email_tested;
    private $dblogin_tested;

    public function __construct(&$globals, &$config,&$logger,&$error_handler)
    {
    $this->globaldata = &$globals;
    $this->config = &$config;
    $this->logger = &$logger;
    $this->error_handler = &$error_handler;
    $this->response_sender = new FM_Response($this->config,$this->logger);
    $this->app_command=”;
    $this->command_value=”;

    $this->email_tested=false;
    $this->dblogin_tested=false;
    }

    function IsAppCommand()
    {
    return empty($this->globaldata->post_vars[$this->config->config_update_var])?false:true;
    }

    function Execute(&$modules)
    {
    $continue = false;
    if(!$this->IsAppCommand())
    {
    return true;
    }
    $this->config->debug_mode = true;
    $this->error_handler->disable_syserror_handling=true;
    $this->error_handler->DisableErrorFormMerge();

    if($this->DecodeAppCommand())
    {
    switch($this->app_command)
    {
    case ‘ping’:
    {
    $this->DoPingCommand($modules);
    break;
    }
    case ‘log_file’:
    {
    $this->GetLogFile();
    break;
    }
    default:
    {
    $this->DoCustomModuleCommand($modules);
    break;
    }
    }//switch
    }//if

    $this->ShowResponse();
    return $continue;
    }

    function DoPingCommand(&$modules)
    {
    if(!$this->Ping())
    {
    return false;
    }

    $N = count($modules);

    for($i=0;$i<$N;$i++)
    {
    $mod = &$modules[$i];
    if(!$mod->ValidateInstallation($this))
    {
    $this->logger->LogError(“ValidateInstallation: module $i returns false!”);
    return false;
    }
    }
    return true;
    }

    function GetLogFile()
    {
    $log_file_path=$this->logger->get_log_file_path();

    $this->response_sender->SetNeedToRemoveHeader();

    return $this->response_sender->load_file_contents($log_file_path);
    }

    function DecodeAppCommand()
    {
    if(!$this->ValidateConfigInput())
    {
    return false;
    }
    $cmd = $this->globaldata->post_vars[$this->config->config_update_var];

    $this->app_command = $this->Decrypt($cmd);

    $val = “”;
    if(isset($this->globaldata->post_vars[$this->config->config_update_val]))
    {
    $val = $this->globaldata->post_vars[$this->config->config_update_val];
    $this->command_value = $this->Decrypt($val);
    }

    return true;
    }

    function DoCustomModuleCommand(&$modules)
    {
    $N = count($modules);

    for($i=0;$i<$N;$i++)
    {
    $mod = &$modules[$i];
    if($mod->DoAppCommand($this->app_command,$this->command_value,$this))
    {
    break;
    }
    }
    }

    function IsPingCommand()
    {
    return ($this->app_command == ‘ping’)?true:false;
    }

    function Ping()
    {
    $ret = false;
    $installed=”no”;
    if(true == $this->config->installed)
    {
    $installed=”yes”;
    $ret=true;
    }
    $this->response_sender->appendResponse(“is_installed”,$installed);
    return $ret;
    }

    function TestSMTPEmail()
    {
    if(!$this->config->IsSMTP())
    {
    return true;
    }

    $initial_sys_error = $this->error_handler->IsSysError();

    $mailer = new FM_Mailer($this->config,$this->logger,$this->error_handler);
    //Note: this is only to test the SMTP settings. It tries to send an email with subject test Email
    // If there is any error in SMTP settings, this will throw error
    $ret = $mailer->SendMail(‘tests@simfatic.com’,’tests@simfatic.com’,’Test Email’,’Test Email’,false);

    if($ret && !$initial_sys_error && $this->error_handler->IsSysError())
    {
    $ret = false;
    }

    if(!$ret)
    {
    $this->logger->LogInfo(“SFM_AppCommand: Ping-> error sending email “);
    $this->response_sender->appendResponse(’email_smtp’,’error’);
    }

    $this->email_tested = true;

    return $ret;
    }
    function rem_file($filename,$base_folder)
    {
    $filename = trim($filename);
    if(strlen($filename)>0)
    {
    $filepath = sfm_make_path($base_folder,$filename);
    $this->logger->LogInfo(“SFM_AppCommand: Removing file $filepath”);

    $success=false;
    if(unlink($filepath))
    {
    $this->response_sender->appendResponse(“result”,”success”);
    $this->logger->LogInfo(“SFM_AppCommand: rem_file removed file $filepath”);
    $success=true;
    }
    $this->response_sender->appendResultResponse($success);
    }
    }
    function IsEmailTested()
    {
    return $this->email_tested;
    }
    function TestDBLogin()
    {
    if($this->IsDBLoginTested())
    {
    return true;
    }
    $dbutil = new FM_DBUtil();
    $dbutil->Init($this->config,$this->logger,$this->error_handler);
    $dbtest_result = $dbutil->Login();

    if(false === $dbtest_result)
    {
    $this->logger->LogInfo(“SFM_AppCommand: Ping-> dblogin error”);
    $this->response_sender->appendResponse(‘dblogin’,’error’);
    }
    $this->dblogin_tested = true;
    return $dbtest_result;
    }

    function IsDBLoginTested()
    {
    return $this->dblogin_tested;
    }

    function ValidateConfigInput()
    {
    $ret=false;
    if(!isset($this->config->encr_key) ||
    strlen($this->config->encr_key)<=0)
    {
    $this->addError(“Form key is not set”);
    }
    else
    if(!isset($this->config->form_id) ||
    strlen($this->config->form_id)<=0)
    {
    $this->addError(“Form ID is not set”);
    }
    else
    if(!isset($this->globaldata->post_vars[$this->config->config_form_id_var]))
    {
    $this->addError(“Form ID is not set”);
    }
    else
    {
    $form_id = $this->globaldata->post_vars[$this->config->config_form_id_var];
    $form_id = $this->Decrypt($form_id);
    if(strcmp($form_id,$this->config->form_id)!=0)
    {
    $this->addError(“Form ID Does not match”);
    }
    else
    {
    $this->logger->LogInfo(“SFM_AppCommand:ValidateConfigInput succeeded”);
    $ret=true;
    }
    }
    return $ret;
    }
    function Decrypt($str)
    {
    return sfm_crypt_decrypt($str,$this->config->encr_key);
    }
    function ShowResponse()
    {
    if($this->error_handler->IsSysError())
    {
    $this->addError($this->error_handler->GetSysError());
    }
    $this->response_sender->ShowResponse();
    }
    function addError($error)
    {
    $this->response_sender->addError($error);
    }
    }

    class FM_Response
    {
    private $error_str;
    private $response;
    private $encr_response;
    private $extra_headers;
    private $sfm_headers;

    public function __construct(&$config,&$logger)
    {
    $this->error_str=””;
    $this->response=””;
    $this->encr_response=true;
    $this->extra_headers = array();
    $this->sfm_headers = array();
    $this->logger = &$logger;
    $this->config = &$config;
    }

    function addError($error)
    {
    $this->error_str .= $error;
    $this->error_str .= “\n”;
    }

    function isError()
    {
    return empty($this->error_str)?false:true;
    }
    function getError()
    {
    return $this->error_str;
    }

    function getResponseStr()
    {
    return $this->response;
    }

    function straighten_val($val)
    {
    $ret = str_replace(“\n”,”\\n”,$val);
    return $ret;
    }

    function appendResponse($name,$val)
    {
    $this->response .= “$name: “.$this->straighten_val($val);
    $this->response .= “\n”;
    }

    function appendResultResponse($is_success)
    {
    if($is_success)
    {
    $this->appendResponse(“result”,”success”);
    }
    else
    {
    $this->appendResponse(“result”,”failed”);
    }
    }

    function SetEncrypt($encrypt)
    {
    $this->encr_response = $encrypt;
    }

    function AddResponseHeader($name,$val,$replace=false)
    {
    $header = “$name: $val”;
    $this->extra_headers[$header] = $replace;
    }

    function AddSFMHeader($option)
    {
    $this->sfm_headers[$option]=1;
    }

    function SetNeedToRemoveHeader()
    {
    $this->AddSFMHeader(‘remove-header-footer’);
    }

    function ShowResponse()
    {
    $err=false;
    ob_clean();
    if(strlen($this->error_str)>0)
    {
    $err=true;
    $this->appendResponse(“error”,$this->error_str);
    $this->AddSFMHeader(‘sforms-error’);
    $log_str = sprintf(“FM_Response: reporting error:%s”,$this->error_str);
    $this->logger->LogError($log_str);
    }

    $resp=””;
    if(($this->encr_response || true == $err) &&
    (false == $this->config->sys_debug_mode))
    {
    $this->AddResponseHeader(‘Content-type’,’application/sforms-e’);

    $resp = $this->Encrypt($this->response);
    }
    else
    {
    $resp = $this->response;
    }

    $cust_header = “SFM_COMM_HEADER_START{\n”;
    foreach($this->sfm_headers as $sfm_header => $flag)
    {
    $cust_header .= $sfm_header.”\n”;
    }
    $cust_header .= “}SFM_COMM_HEADER_END\n”;

    $resp = $cust_header.$resp;

    $this->AddResponseHeader(‘pragma’,’no-cache’,/*replace*/true);
    $this->AddResponseHeader(‘cache-control’,’no-cache’);
    $this->AddResponseHeader(‘Content-Length’,strlen($resp));

    foreach($this->extra_headers as $header_str => $replace)
    {

    header($header_str, false);
    }

    print($resp);
    if(true == $this->config->sys_debug_mode)
    {
    $this->logger->print_log();
    }
    }

    function Encrypt($str)
    {
    //echo ” Encrypt $str “;
    //$blowfish = new Crypt_Blowfish($this->config->encr_key);
    $retdata = sfm_crypt_encrypt($str,$this->config->encr_key);
    /*$blowfish =& Crypt_Blowfish::factory(‘ecb’);
    $blowfish->setKey($this->config->encr_key);

    $encr = $blowfish->encrypt($str);
    $retdata = bin2hex($encr);*/
    return $retdata;
    }

    function load_file_contents($filepath)
    {
    $filename = basename($filepath);

    $this->encr_response=false;

    $fp = fopen($filepath,”r”);

    if(!$fp)
    {
    $err = sprintf(“Failed opening file %s”,$filepath);
    $this->addError($err);
    return false;
    }

    $this->AddResponseHeader(‘Content-Disposition’,”attachment; filename=\”$filename\””);

    $this->response = file_get_contents($filepath);

    return true;
    }

    function SetResponse($response)
    {
    $this->response = $response;
    }
    }

    class FM_CommonObjs
    {
    public $formpage_renderer;
    public $security_monitor;
    public $formvar_mx;

    public function __construct(&$config,&$logger,&$globaldata)
    {
    $this->security_monitor =
    new FM_SecurityMonitor($config,$logger,$globaldata);

    $this->formpage_renderer =
    new FM_FormPageRenderer($config,$logger,$globaldata, $this->security_monitor);

    $this->formvar_mx = new FM_FormVarMx($config,$logger,$globaldata);
    }
    function InitFormVars(&$formvars)
    {
    $this->formvar_mx->InitFormVars($formvars);
    }
    function InitExtensionModule(&$extmodule)
    {
    $this->formpage_renderer->InitExtensionModule($extmodule);
    }
    }

    ////SFM_FormProcessor////////////////
    class SFM_FormProcessor
    {
    private $globaldata;
    private $formvars;
    private $formname;
    private $logger;
    private $config;
    private $error_handler;
    private $modules;
    private $ext_module_holder;
    private $common_objs;

    public function __construct($formname)
    {
    ob_start();

    $this->formname = $formname;
    $this->config = new FM_Config();
    $this->config->formname = $formname;

    $this->globaldata = new FM_GlobalData($this->config);

    $this->logger = new FM_Logger($this->config,$formname);
    $this->logger->SetLogSource(“form:$formname”);

    $this->common_objs = new FM_CommonObjs($this->config,$this->logger,$this->globaldata);

    $this->error_handler = new FM_ErrorHandler($this->logger,$this->config,
    $this->globaldata,$formname,$this->common_objs);

    $this->error_handler->InstallConfigErrorCatch();
    $this->modules=array();
    $this->ext_module_holder = new FM_ExtensionModuleHolder();
    $this->common_objs->InitExtensionModule($this->ext_module_holder);
    $this->SetDebugMode(true);//till it is disabled explicitely

    }
    function initTimeZone($timezone)
    {
    $this->config->default_timezone = $timezone;

    if (!empty($timezone) && $timezone != ‘default’)
    {
    //for >= PHP 5.1
    if(function_exists(“date_default_timezone_set”))
    {
    date_default_timezone_set($timezone);
    }
    else// for PHP < 5.1
    {
    @putenv(“PHP_TZ=”.$timezone);
    @putenv(“TZ=” .$timezone);
    }
    }//if
    else
    {
    if(function_exists(“date_default_timezone_set”))
    {
    date_default_timezone_set(date_default_timezone_get());
    }
    }
    }

    function init_session()
    {

    $ua = empty($_SERVER[‘HTTP_USER_AGENT’]) ? ” : $_SERVER[‘HTTP_USER_AGENT’];

    if(true === $this->config->enable_p2p_header &&
    false !== stristr($ua, ‘MSIE’))
    {
    header(‘P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”‘);
    }

    session_start();
    $this->globaldata->InitSession();

    if(empty($this->globaldata->session[‘sfm_form_user_identificn’]) )
    {
    if(!empty($_GET[‘sfm_sid’]) &&
    true === $this->config->enable_session_id_url)
    {//session not loaded properly; load from sid passed through URL
    $this->logger->LogInfo(‘getting session ID from URL’);
    session_destroy();
    session_id($_GET[‘sfm_sid’]);
    session_start();
    $this->globaldata->InitSession();
    if(empty($this->globaldata->session[‘sfm_form_user_identificn’])||
    $this->globaldata->session[‘sfm_form_user_identificn’] != $this->globaldata->GetVisitorUniqueKey())
    {//safety check. If the user is not same something wrong.

    $this->logger->LogInfo(‘sfm_form_user_identificn still does not match:’.
    $this->globaldata->session[‘sfm_form_user_identificn’]);

    session_regenerate_id(FALSE);
    session_unset();
    $this->globaldata->InitSession();
    }
    }

    $this->globaldata->session[‘sfm_form_user_identificn’] = $this->globaldata->GetVisitorUniqueKey();
    }

    }

    function setEmailFormatHTML($ishtml)
    {
    $this->config->email_format_html = $ishtml;
    }
    function setFormFileFolder($folder)
    {
    $this->config->form_file_folder = $folder;
    }

    function setIsInstalled($installed)
    {
    $this->config->installed = $installed;
    }

    function SetSingleBoxErrorDisplay($enabled)
    {
    $this->config->show_errors_single_box = $enabled;
    }

    function setFormPage($page_num,$formpage_code,$condn=”)
    {
    $this->common_objs->formpage_renderer->setFormPage($page_num,$formpage_code,$condn);
    }

    function setFormID($id)
    {
    $this->config->set_form_id($id);
    }

    function setLocale($name,$date_format)
    {
    $this->config->SetLocale($name,$date_format);
    }

    function setFormKey($key)
    {
    $this->config->set_encrkey($key);
    }
    function setRandKey($key)
    {
    $this->config->set_rand_key($key);
    }

    function DisableAntiSpammerSecurityChecks()
    {
    $this->config->bypass_spammer_validations=true;
    }

    function InitSMTP($host,$uname,$pwd,$port)
    {
    $this->config->InitSMTP($host,$uname,$pwd,$port);
    }
    function setFormDBLogin($host,$uname,$pwd,$database)
    {
    $this->config->setFormDBLogin($host,$uname,$pwd,$database);
    }

    function EnableLogging($enable)
    {
    $this->logger->EnableLogging($enable);
    }

    function SetErrorEmail($email)
    {
    $this->config->set_error_email($email);
    }

    function SetPasswordsEncrypted($encrypted)
    {
    $this->config->passwords_encrypted = $encrypted;
    }

    function SetPrintPreviewPage($preview_file)
    {
    $this->config->SetPrintPreviewPage($preview_file);
    }
    function AddElementInfo($name,$type,$extra_info,$page=0)
    {
    $this->config->element_info->AddElementInfo($name,$type,$extra_info,$page);
    }
    function AddDefaultValue($name,$value)
    {
    $this->config->element_info->AddDefaultValue($name,$value);
    }

    function SetDebugMode($enable)
    {
    $this->config->setDebugMode($enable);
    }

    function SetFromAddress($from)
    {
    $this->config->from_addr = $from;
    }

    function SetVariableFrom($enable)
    {
    $this->config->variable_from = $enable;
    }

    function SetHiddenInputTrapVarName($varname)
    {
    $this->config->hidden_input_trap_var = $varname;
    }

    function EnableLoadFormValuesFromURL($enable)
    {
    $this->config->load_values_from_url = $enable;
    }

    function EnableAutoFieldTable($enable)
    {
    $this->config->enable_auto_field_table = $enable;
    }

    function BanIP($ip)
    {
    $this->common_objs->security_monitor->AddBannedIP($ip);
    }

    function SetSavedMessageTemplate($msg_templ)
    {
    $this->config->saved_message_templ = $msg_templ;
    }

    function GetVars()
    {
    $this->globaldata->GetGlobalVars();

    $this->formvars = &$this->globaldata->formvars;

    $this->logger->LogInfo(“GetVars:formvars “.@print_r($this->formvars,true).”\n”);

    if(!isset($this->formname) ||
    strlen($this->formname)==0)
    {
    $this->error_handler->HandleConfigError(“Please set the form name”,””);
    return false;
    }
    $this->error_handler->SetFormVars($this->formvars);
    return true;
    }

    function addModule(&$module)
    {
    array_push_ref($this->modules,$module);
    }

    function AddExtensionModule(&$module)
    {
    $this->ext_module_holder->AddModule($module);
    }

    function getmicrotime()
    {
    list($usec, $sec) = explode(” “,microtime());
    return ((float)$usec + (float)$sec);
    }

    function AfterVariablessInitialized()
    {
    $N = count($this->modules);
    for($i=0;$i<$N;$i++)
    {
    if(false === $this->modules[$i]->AfterVariablessInitialized())
    {
    return false;
    }
    }
    if(false === $this->ext_module_holder->AfterVariablessInitialized())
    {
    return false;
    }
    return true;
    }

    function DoAppCommand()
    {
    $continue=true;
    $app_command = new SFM_AppCommand($this->globaldata,$this->config,$this->logger,$this->error_handler);
    $continue = $app_command->Execute($this->modules);
    return $continue;
    }

    function ProcessForm()
    {
    $timestart = $this->getmicrotime();

    $this->init_session();

    $N = count($this->modules);

    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $mod->Init($this->config,$this->globaldata->formvars,
    $this->logger,$this->globaldata,
    $this->error_handler,$this->formname,
    $this->ext_module_holder,$this->common_objs);
    }

    $this->ext_module_holder->Init($this->config,$this->globaldata->formvars,
    $this->logger,$this->globaldata,
    $this->error_handler,$this->formname);

    do
    {
    if(false === $this->ext_module_holder->BeforeStartProcessing())
    {
    $this->logger->LogInfo(“Extension module returns false for BeforeStartProcessing. Stopping.”);
    break;
    }

    if(false == $this->GetVars())
    {
    $this->logger->LogError(“GetVars() Failed”);
    break;
    }

    if(false === $this->DoAppCommand())
    {
    break;
    }

    if(false === $this->AfterVariablessInitialized() )
    {
    break;
    }

    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $continue = true;

    $mod->Process($continue);
    if(!$continue){break;}
    }

    for($i=0;$i<$N;$i++)
    {
    $mod = &$this->modules[$i];
    $mod->Destroy();
    }

    if($this->globaldata->IsFormProcessingComplete())
    {
    $this->globaldata->DestroySession();
    }
    }while(0);

    $timetaken = $this->getmicrotime()-$timestart;

    $this->logger->FlushLog();

    ob_end_flush();
    return true;
    }

    function showVars()
    {
    foreach($this->formvars as $name => $value)
    {
    echo “$name $value
    “;
    }
    }

    }

    class SecureFileMaker
    {
    private $signature_line;
    private $file_pos;

    public function __construct($signature)
    {
    $this->signature_line = $signature;
    }

    function CreateFile($filepath, $first_line)
    {
    $fp = fopen($filepath,”w”);
    if(!$fp)
    {
    return false;
    }

    $header = $this->get_header().”\n”;
    $first_line = trim($first_line);
    $header .= $first_line.”\n”;

    if(!fwrite($fp,$header))
    {
    return false;
    }

    $footer = $this->get_footer();

    if(!fwrite($fp,$footer))
    {
    return false;
    }

    fclose($fp);

    return true;
    }

    function get_header()
    {
    return “signature_line”;
    }

    function get_footer()
    {
    return “$this->signature_line */ ?>”;
    }

    function gets_backward($fp)
    {
    $ret_str=””;
    $t=””;
    while ($t != “\n”)
    {
    if(0 != fseek($fp, $this->file_pos, SEEK_END))
    {
    rewind($fp);
    break;
    }
    $t = fgetc($fp);

    $ret_str = $t.$ret_str;
    $this->file_pos –;
    }
    return $ret_str;
    }

    function AppendLine($file_path,$insert_line)
    {
    $fp = fopen($file_path,”r+”);

    if(!$fp)
    {
    return false;
    }
    $all_lines=””;

    $this->file_pos = -1;
    fseek($fp,$this->file_pos,SEEK_END);

    while(1)
    {
    $pos = ftell($fp);
    if($pos <= 0)
    {
    break;
    }
    $line = $this->gets_backward($fp);
    $cmpline = trim($line);

    $all_lines .= $line;

    if(strcmp($cmpline,$this->get_footer())==0)
    {
    break;
    }
    }

    $all_lines = trim($all_lines);
    $insert_line = trim($insert_line);

    $all_lines = “$insert_line\n$all_lines”;

    if(!fwrite($fp,$all_lines))
    {
    return false;
    }

    fclose($fp);
    return true;
    }

    function ReadNextLine($fp)
    {
    while(!feof($fp))
    {
    $line = fgets($fp);
    $line = trim($line);

    if(strcmp($line,$this->get_header())!=0 &&
    strcmp($line,$this->get_footer())!=0)
    {
    return $line;
    }
    }
    return “”;
    }
    }

    /**
    * Crypt_Blowfish allows for encryption and decryption on the fly using
    * the Blowfish algorithm. Crypt_Blowfish does not require the MCrypt
    * PHP extension, but uses it if available, otherwise it uses only PHP.
    * Crypt_Blowfish supports encryption/decryption with or without a secret key.
    *
    *
    * PHP versions 4 and 5
    *
    * LICENSE: This source file is subject to version 3.0 of the PHP license
    * that is available through the world-wide-web at the following URI:
    * http://www.php.net/license/3_0.txt. If you did not receive a copy of
    * the PHP License and are unable to obtain it through the web, please
    * send a note to license@php.net so we can mail you a copy immediately.
    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @copyright 2005 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @version CVS: $Id: encr-lib.php,v 1.2 2010/02/16 06:51:02 Prasanth Exp $
    * @link http://pear.php.net/package/Crypt_Blowfish
    */

    /**
    * Engine choice constants
    */
    /**
    * To let the Crypt_Blowfish package decide which engine to use
    * @since 1.1.0
    */
    define(‘CRYPT_BLOWFISH_AUTO’, 1);
    /**
    * To use the MCrypt PHP extension.
    * @since 1.1.0
    */
    define(‘CRYPT_BLOWFISH_MCRYPT’, 2);
    /**
    * To use the PHP-only engine.
    * @since 1.1.0
    */
    define(‘CRYPT_BLOWFISH_PHP’, 3);

    /**
    * Example using the factory method in CBC mode
    *
    * $bf =& Crypt_Blowfish::factory('cbc');
    * if (PEAR::isError($bf)) {
    * echo $bf->getMessage();
    * exit;
    * }
    * $iv = 'abc123+=';
    * $key = 'My secret key';
    * $bf->setKey($key, $iv);
    * $encrypted = $bf->encrypt('this is some example plain text');
    * $bf->setKey($key, $iv);
    * $plaintext = $bf->decrypt($encrypted);
    * if (PEAR::isError($plaintext)) {
    * echo $plaintext->getMessage();
    * exit;
    * }
    * // Encrypted text is padded prior to encryption
    * // so you may need to trim the decrypted result.
    * echo 'plain text: ' . trim($plaintext);
    *

    *
    * To disable using the mcrypt library, define the CRYPT_BLOWFISH_NOMCRYPT
    * constant. This is useful for instance on Windows platform with a buggy
    * mdecrypt_generic() function.
    *
    * define('CRYPT_BLOWFISH_NOMCRYPT', true);
    *

    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @author Philippe Jausions
    * @copyright 2005-2006 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @link http://pear.php.net/package/Crypt_Blowfish
    * @version @package_version@
    * @access public
    */

    define(‘CRYPT_BLOWFISH_NOMCRYPT’, true);

    class Crypt_Blowfish
    {
    /**
    * Implementation-specific Crypt_Blowfish object
    *
    * @var object
    * @access private
    */
    var $_crypt = null;

    /**
    * Initialization vector
    *
    * @var string
    * @access protected
    */
    var $_iv = null;

    /**
    * Holds block size
    *
    * @var integer
    * @access protected
    */
    var $_block_size = 8;

    /**
    * Holds IV size
    *
    * @var integer
    * @access protected
    */
    var $_iv_size = 8;

    /**
    * Holds max key size
    *
    * @var integer
    * @access protected
    */
    var $_key_size = 56;

    /**
    * Crypt_Blowfish Constructor
    * Initializes the Crypt_Blowfish object (in EBC mode), and sets
    * the secret key
    *
    * @param string $key
    * @access public
    * @deprecated Since 1.1.0
    * @see Crypt_Blowfish::factory()
    */
    function __construct($key)
    {
    $this->_crypt =& Crypt_Blowfish::factory(‘ecb’, $key);
    if (!PEAR::isError($this->_crypt)) {
    $this->_crypt->setKey($key);
    }
    }

    /**
    * Crypt_Blowfish object factory
    *
    * This is the recommended method to create a Crypt_Blowfish instance.
    *
    * When using CRYPT_BLOWFISH_AUTO, you can force the package to ignore
    * the MCrypt extension, by defining CRYPT_BLOWFISH_NOMCRYPT.
    *
    * @param string $mode operating mode ‘ecb’ or ‘cbc’ (case insensitive)
    * @param string $key
    * @param string $iv initialization vector (must be provided for CBC mode)
    * @param integer $engine one of CRYPT_BLOWFISH_AUTO, CRYPT_BLOWFISH_PHP
    * or CRYPT_BLOWFISH_MCRYPT
    * @return object Crypt_Blowfish object or PEAR_Error object on error
    * @access public
    * @static
    * @since 1.1.0
    */
    function &factory($mode = ‘ecb’, $key = null, $iv = null, $engine = CRYPT_BLOWFISH_AUTO)
    {
    switch ($engine) {
    case CRYPT_BLOWFISH_AUTO:
    if (!defined(‘CRYPT_BLOWFISH_NOMCRYPT’)
    && extension_loaded(‘mcrypt’)) {
    $engine = CRYPT_BLOWFISH_MCRYPT;
    } else {
    $engine = CRYPT_BLOWFISH_PHP;
    }
    break;
    case CRYPT_BLOWFISH_MCRYPT:
    if (!PEAR::loadExtension(‘mcrypt’)) {
    return PEAR::raiseError(‘MCrypt extension is not available.’);
    }
    break;
    }

    switch ($engine) {
    case CRYPT_BLOWFISH_PHP:
    $mode = strtoupper($mode);
    $class = ‘Crypt_Blowfish_’ . $mode;

    $crypt = new $class(null);
    break;

    case CRYPT_BLOWFISH_MCRYPT:

    $crypt = new Crypt_Blowfish_MCrypt(null, $mode);
    break;
    }

    if (!is_null($key) || !is_null($iv)) {
    $result = $crypt->setKey($key, $iv);
    if (PEAR::isError($result)) {
    return $result;
    }
    }

    return $crypt;
    }

    /**
    * Returns the algorithm’s block size
    *
    * @return integer
    * @access public
    * @since 1.1.0
    */
    function getBlockSize()
    {
    return $this->_block_size;
    }

    /**
    * Returns the algorithm’s IV size
    *
    * @return integer
    * @access public
    * @since 1.1.0
    */
    function getIVSize()
    {
    return $this->_iv_size;
    }

    /**
    * Returns the algorithm’s maximum key size
    *
    * @return integer
    * @access public
    * @since 1.1.0
    */
    function getMaxKeySize()
    {
    return $this->_key_size;
    }

    /**
    * Deprecated isReady method
    *
    * @return bool
    * @access public
    * @deprecated
    */
    function isReady()
    {
    return true;
    }

    /**
    * Deprecated init method – init is now a private
    * method and has been replaced with _init
    *
    * @return bool
    * @access public
    * @deprecated
    */
    function init()
    {
    return $this->_crypt->init();
    }

    /**
    * Encrypts a string
    *
    * Value is padded with NUL characters prior to encryption. You may
    * need to trim or cast the type when you decrypt.
    *
    * @param string $plainText the string of characters/bytes to encrypt
    * @return string|PEAR_Error Returns cipher text on success, PEAR_Error on failure
    * @access public
    */
    function encrypt($plainText)
    {
    return $this->_crypt->encrypt($plainText);
    }

    /**
    * Decrypts an encrypted string
    *
    * The value was padded with NUL characters when encrypted. You may
    * need to trim the result or cast its type.
    *
    * @param string $cipherText the binary string to decrypt
    * @return string|PEAR_Error Returns plain text on success, PEAR_Error on failure
    * @access public
    */
    function decrypt($cipherText)
    {
    return $this->_crypt->decrypt($cipherText);
    }

    /**
    * Sets the secret key
    * The key must be non-zero, and less than or equal to
    * 56 characters (bytes) in length.
    *
    * If you are making use of the PHP MCrypt extension, you must call this
    * method before each encrypt() and decrypt() call.
    *
    * @param string $key
    * @return boolean|PEAR_Error Returns TRUE on success, PEAR_Error on failure
    * @access public
    */
    function setKey($key)
    {
    return $this->_crypt->setKey($key);
    }
    }

    /**
    * Crypt_Blowfish allows for encryption and decryption on the fly using
    * the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
    * PHP extension, but uses it if available, otherwise it uses only PHP.
    * Crypt_Blowfish support encryption/decryption with or without a secret key.
    *
    * PHP versions 4 and 5
    *
    * LICENSE: This source file is subject to version 3.0 of the PHP license
    * that is available through the world-wide-web at the following URI:
    * http://www.php.net/license/3_0.txt. If you did not receive a copy of
    * the PHP License and are unable to obtain it through the web, please
    * send a note to license@php.net so we can mail you a copy immediately.
    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @author Philippe Jausions
    * @copyright 2005-2006 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @version CVS: $Id: encr-lib.php,v 1.2 2010/02/16 06:51:02 Prasanth Exp $
    * @link http://pear.php.net/package/Crypt_Blowfish
    * @since 1.1.0
    */

    /**
    * Common class for PHP-only implementations
    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @author Philippe Jausions
    * @copyright 2005-2006 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @link http://pear.php.net/package/Crypt_Blowfish
    * @version @package_version@
    * @access public
    * @since 1.1.0
    */
    class Crypt_Blowfish_PHP extends Crypt_Blowfish
    {
    /**
    * P-Array contains 18 32-bit subkeys
    *
    * @var array
    * @access protected
    */
    var $_P = array();

    /**
    * Array of four S-Blocks each containing 256 32-bit entries
    *
    * @var array
    * @access protected
    */
    var $_S = array();

    /**
    * Whether the IV is required
    *
    * @var boolean
    * @access protected
    */
    var $_iv_required = false;

    /**
    * Hash value of last used key
    *
    * @var string
    * @access protected
    */
    var $_keyHash = null;

    /**
    * Crypt_Blowfish_PHP Constructor
    * Initializes the Crypt_Blowfish object, and sets
    * the secret key
    *
    * @param string $key
    * @param string $mode operating mode ‘ecb’ or ‘cbc’
    * @param string $iv initialization vector
    * @access protected
    */
    function x_construct($key = null, $iv = null)
    {
    $this->_iv = $iv . ((strlen($iv) < $this->_iv_size)
    ? str_repeat(chr(0), $this->_iv_size – strlen($iv))
    : ”);
    if (!is_null($key)) {
    $this->setKey($key, $this->_iv);
    }
    }

    /**
    * Initializes the Crypt_Blowfish object
    *
    * @access private
    */
    function _init()
    {
    $defaults = new Crypt_Blowfish_DefaultKey();
    $this->_P = $defaults->P;
    $this->_S = $defaults->S;
    }

    /**
    * Workaround for XOR on certain systems
    *
    * @param integer|float $l
    * @param integer|float $r
    * @return float
    * @access protected
    */
    function _binxor($l, $r)
    {
    $x = (($l < 0) ? (float)($l + 4294967296) : (float)$l)
    ^ (($r < 0) ? (float)($r + 4294967296) : (float)$r);

    return (float)(($x < 0) ? $x + 4294967296 : $x);
    }

    /**
    * Enciphers a single 64-bit block
    *
    * @param int &$Xl
    * @param int &$Xr
    * @access protected
    */
    function _encipher(&$Xl, &$Xr)
    {
    if ($Xl < 0) {
    $Xl += 4294967296;
    }
    if ($Xr < 0) {
    $Xr += 4294967296;
    }

    for ($i = 0; $i < 16; $i++) {
    $temp = $Xl ^ $this->_P[$i];
    if ($temp < 0) {
    $temp += 4294967296;
    }

    $Xl = fmod((fmod($this->_S[0][($temp >> 24) & 255]
    + $this->_S[1][($temp >> 16) & 255], 4294967296)
    ^ $this->_S[2][($temp >> 8) & 255])
    + $this->_S[3][$temp & 255], 4294967296) ^ $Xr;
    $Xr = $temp;
    }
    $Xr = $this->_binxor($Xl, $this->_P[16]);
    $Xl = $this->_binxor($temp, $this->_P[17]);
    }

    /**
    * Deciphers a single 64-bit block
    *
    * @param int &$Xl
    * @param int &$Xr
    * @access protected
    */
    function _decipher(&$Xl, &$Xr)
    {
    if ($Xl < 0) {
    $Xl += 4294967296;
    }
    if ($Xr < 0) {
    $Xr += 4294967296;
    }

    for ($i = 17; $i > 1; $i–) {
    $temp = $Xl ^ $this->_P[$i];
    if ($temp < 0) {
    $temp += 4294967296;
    }

    $Xl = fmod((fmod($this->_S[0][($temp >> 24) & 255]
    + $this->_S[1][($temp >> 16) & 255], 4294967296)
    ^ $this->_S[2][($temp >> 8) & 255])
    + $this->_S[3][$temp & 255], 4294967296) ^ $Xr;
    $Xr = $temp;
    }
    $Xr = $this->_binxor($Xl, $this->_P[1]);
    $Xl = $this->_binxor($temp, $this->_P[0]);
    }

    /**
    * Sets the secret key
    * The key must be non-zero, and less than or equal to
    * 56 characters (bytes) in length.
    *
    * If you are making use of the PHP mcrypt extension, you must call this
    * method before each encrypt() and decrypt() call.
    *
    * @param string $key
    * @param string $iv 8-char initialization vector (required for CBC mode)
    * @return boolean|PEAR_Error Returns TRUE on success, PEAR_Error on failure
    * @access public
    * @todo Fix the caching of the key
    */
    function setKey($key, $iv = null)
    {
    if (!is_string($key)) {
    return PEAR::raiseError(‘Key must be a string’, 2);
    }

    $len = strlen($key);

    if ($len > $this->_key_size || $len == 0) {
    return PEAR::raiseError(‘Key must be less than ‘ . $this->_key_size . ‘ characters (bytes) and non-zero. Supplied key length: ‘ . $len, 3);
    }

    if ($this->_iv_required) {
    if (strlen($iv) != $this->_iv_size) {
    return PEAR::raiseError(‘IV must be ‘ . $this->_iv_size . ‘-character (byte) long. Supplied IV length: ‘ . strlen($iv), 7);
    }
    $this->_iv = $iv;
    }

    if ($this->_keyHash == md5($key)) {
    return true;
    }

    $this->_init();

    $k = 0;
    $data = 0;
    $datal = 0;
    $datar = 0;

    for ($i = 0; $i < 18; $i++) {
    $data = 0;
    for ($j = 4; $j > 0; $j–) {
    $data = $data << 8 | ord($key{$k});
    $k = ($k+1) % $len;
    }
    $this->_P[$i] ^= $data;
    }

    for ($i = 0; $i <= 16; $i += 2) {
    $this->_encipher($datal, $datar);
    $this->_P[$i] = $datal;
    $this->_P[$i+1] = $datar;
    }
    for ($i = 0; $i < 256; $i += 2) {
    $this->_encipher($datal, $datar);
    $this->_S[0][$i] = $datal;
    $this->_S[0][$i+1] = $datar;
    }
    for ($i = 0; $i < 256; $i += 2) {
    $this->_encipher($datal, $datar);
    $this->_S[1][$i] = $datal;
    $this->_S[1][$i+1] = $datar;
    }
    for ($i = 0; $i < 256; $i += 2) {
    $this->_encipher($datal, $datar);
    $this->_S[2][$i] = $datal;
    $this->_S[2][$i+1] = $datar;
    }
    for ($i = 0; $i < 256; $i += 2) {
    $this->_encipher($datal, $datar);
    $this->_S[3][$i] = $datal;
    $this->_S[3][$i+1] = $datar;
    }

    $this->_keyHash = md5($key);
    return true;
    }
    }

    /**
    * PHP implementation of the Blowfish algorithm in ECB mode
    *
    * PHP versions 4 and 5
    *
    * LICENSE: This source file is subject to version 3.0 of the PHP license
    * that is available through the world-wide-web at the following URI:
    * http://www.php.net/license/3_0.txt. If you did not receive a copy of
    * the PHP License and are unable to obtain it through the web, please
    * send a note to license@php.net so we can mail you a copy immediately.
    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @author Philippe Jausions
    * @copyright 2005-2006 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @version CVS: $Id: encr-lib.php,v 1.2 2010/02/16 06:51:02 Prasanth Exp $
    * @link http://pear.php.net/package/Crypt_Blowfish
    * @since 1.1.0
    */

    /**
    * Example
    *
    * $bf =& Crypt_Blowfish::factory('ecb');
    * if (PEAR::isError($bf)) {
    * echo $bf->getMessage();
    * exit;
    * }
    * $bf->setKey('My secret key');
    * $encrypted = $bf->encrypt('this is some example plain text');
    * $plaintext = $bf->decrypt($encrypted);
    * echo "plain text: $plaintext";
    *

    *
    * @category Encryption
    * @package Crypt_Blowfish
    * @author Matthew Fonda
    * @author Philippe Jausions
    * @copyright 2005-2006 Matthew Fonda
    * @license http://www.php.net/license/3_0.txt PHP License 3.0
    * @link http://pear.php.net/package/Crypt_Blowfish
    * @version @package_version@
    * @access public
    * @since 1.1.0
    */
    class Crypt_Blowfish_ECB extends Crypt_Blowfish_PHP
    {
    /**
    * Crypt_Blowfish Constructor
    * Initializes the Crypt_Blowfish object, and sets
    * the secret key
    *
    * @param string $key
    * @param string $iv initialization vector
    * @access public
    */
    function __construct($key = null, $iv = null)
    {
    $this->x_construct($key, $iv);
    }

    /**
    * Class constructor
    *
    * @param string $key
    * @param string $iv initialization vector
    * @access public
    */
    function x_construct($key = null, $iv = null)
    {
    $this->_iv_required = false;
    parent::x_construct($key, $iv);
    }

    /**
    * Encrypts a string
    *
    * Value is padded with NUL characters prior to encryption. You may
    * need to trim or cast the type when you decrypt.
    *
    * @param string $plainText string of characters/bytes to encrypt
    * @return string|PEAR_Error Returns cipher text on success, PEAR_Error on failure
    * @access public
    */
    function encrypt($plainText)
    {
    if (!is_string($plainText)) {
    return PEAR::raiseError(‘Input must be a string’, 0);
    } elseif (empty($this->_P)) {
    return PEAR::raiseError(‘The key is not initialized.’, 8);
    }

    $cipherText = ”;
    $len = strlen($plainText);
    $plainText .= str_repeat(chr(0), (8 – ($len % 8)) % 8);

    for ($i = 0; $i < $len; $i += 8) {
    list(, $Xl, $Xr) = unpack(‘N2’, substr($plainText, $i, 8));
    $this->_encipher($Xl, $Xr);
    $cipherText .= pack(‘N2’, $Xl, $Xr);
    }

    return $cipherText;
    }

    /**
    * Decrypts an encrypted string
    *
    * The value was padded with NUL characters when encrypted. You may
    * need to trim the result or cast its type.
    *
    * @param string $cipherText
    * @return string|PEAR_Error Returns plain text on success, PEAR_Error on failure
    * @access public
    */
    function decrypt($cipherText)
    {
    if (!is_string($cipherText)) {
    return PEAR::raiseError(‘Cipher text must be a string’, 1);
    }
    if (empty($this->_P)) {
    return PEAR::raiseError(‘The key is not initialized.’, 8);
    }

    $plainText = ”;
    $len = strlen($cipherText);
    $cipherText .= str_repeat(chr(0), (8 – ($len % 8)) % 8);

    for ($i = 0; $i < $len; $i += 8) {
    list(, $Xl, $Xr) = unpack(‘N2’, substr($cipherText, $i, 8));
    $this->_decipher($Xl, $Xr);
    $plainText .= pack(‘N2’, $Xl, $Xr);
    }

    return $plainText;
    }
    }

    class Crypt_Blowfish_DefaultKey
    {
    var $P = array();

    var $S = array();

    function __construct()
    {
    $this->P = array(
    0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
    0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
    0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
    0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
    0x9216d5d9, 0x8979fb1b
    );

    $this->S = array(
    array(
    0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
    0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
    0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
    0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
    0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
    0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
    0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
    0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
    0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
    0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
    0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
    0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
    0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
    0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
    0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
    0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
    0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
    0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
    0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
    0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
    0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
    0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
    0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
    0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
    0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
    0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
    0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
    0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
    0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
    0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
    0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
    0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
    0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
    0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
    0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
    0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
    0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
    0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
    0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
    0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
    0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
    0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
    0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
    0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
    0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
    0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
    0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
    0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
    0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
    0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
    0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
    0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
    0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
    0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
    0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
    0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
    0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
    0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
    0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
    0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
    0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
    0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
    0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
    0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
    ),
    array(
    0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
    0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
    0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
    0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
    0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
    0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
    0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
    0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
    0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
    0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
    0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
    0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
    0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
    0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
    0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
    0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
    0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
    0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
    0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
    0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
    0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
    0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
    0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
    0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
    0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
    0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
    0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
    0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
    0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
    0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
    0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
    0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
    0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
    0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
    0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
    0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
    0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
    0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
    0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
    0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
    0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
    0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
    0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
    0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
    0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
    0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
    0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
    0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
    0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
    0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
    0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
    0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
    0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
    0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
    0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
    0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
    0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
    0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
    0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
    0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
    0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
    0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
    0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
    0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
    ),
    array(
    0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
    0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
    0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
    0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
    0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
    0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
    0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
    0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
    0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
    0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
    0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
    0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
    0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
    0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
    0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
    0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
    0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
    0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
    0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
    0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
    0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
    0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
    0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
    0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
    0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
    0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
    0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
    0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
    0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
    0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
    0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
    0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
    0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
    0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
    0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
    0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
    0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
    0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
    0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
    0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
    0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
    0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
    0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
    0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
    0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
    0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
    0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
    0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
    0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
    0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
    0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
    0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
    0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
    0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
    0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
    0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
    0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
    0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
    0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
    0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
    0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
    0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
    0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
    0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
    ),
    array(
    0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
    0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
    0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
    0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
    0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
    0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
    0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
    0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
    0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
    0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
    0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
    0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
    0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
    0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
    0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
    0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
    0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
    0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
    0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
    0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
    0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
    0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
    0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
    0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
    0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
    0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
    0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
    0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
    0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
    0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
    0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
    0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
    0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
    0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
    0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
    0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
    0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
    0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
    0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
    0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
    0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
    0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
    0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
    0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
    0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
    0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
    0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
    0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
    0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
    0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
    0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
    0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
    0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
    0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
    0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
    0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
    0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
    0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
    0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
    0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
    0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
    0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
    0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
    0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
    )
    );
    }

    }

    class FM_RefFileDispatcher extends FM_Module
    {
    var $ref_files;
    var $ref_file_variable;

    public function __construct()
    {
    parent::__construct();
    $this->ref_files = array();
    $this->ref_file_variable=”sfm_get_ref_file”;
    }

    function AddRefferedFile($filename,$code)
    {
    $this->ref_files[$filename] = $code;
    }

    function Process(&$continue)
    {
    if($this->NeedReturnRefFile())
    {
    $continue=false;
    $this->ReturnRefferedFile();
    }
    else
    {
    $continue=true;
    }
    }

    function ReturnRefferedFile()
    {
    $filename = $this->getCleanFileName();
    if(false === $filename || !$this->IsRefferedFilePresent($filename))
    {
    $this->logger->LogError(“File dispatcher: File not found: $filename “);
    header(“HTTP/1.0 404 Not Found”);
    }
    else
    {

    $this->SendContentType($filename);
    echo $this->getRefferedFile($filename);
    }
    }

    function SendContentType($filename)
    {
    $ext = substr($filename, strrpos($filename, ‘.’) + 1);
    $content_type=””;
    switch($ext)
    {
    case “css”:
    $content_type = “text/css”;
    break;
    case “js”:
    $content_type = “text/javascript”;
    break;
    }
    if(!empty($content_type))
    {
    header(“Content-Type: $content_type”);
    }
    }
    function IsRefferedFilePresent($filename)
    {
    if(isset($this->ref_files[$filename]))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    function NeedReturnRefFile()
    {
    if(!empty($_GET[$this->ref_file_variable]))
    {
    return true;
    }
    return false;
    }

    function getRefferedFile($filename)
    {
    return $this->ref_files[$filename];
    }

    function getCleanFileName()
    {
    if(empty($_GET[$this->ref_file_variable]))
    {
    return false;
    }

    $filename_full = $_GET[$this->ref_file_variable];

    $arr = explode(‘?’,$filename_full);
    if(empty($arr)){ return false; }
    if(empty($arr[0])){ return false; }

    return $arr[0];

    }

    }

    class FM_FormPageDisplayModule extends FM_Module
    {
    private $validator_obj;
    private $uploader_obj;

    private $formdata_cookiname;
    private $formpage_cookiname;

    public function __construct()
    {
    parent::__construct();
    $this->formdata_cookiname = ‘sfm_saved_form_data’;
    $this->formpage_cookiname = ‘sfm_saved_form_page_num’;
    }

    function SetFormValidator(&$validator)
    {
    $this->validator_obj = &$validator;
    }

    function SetFileUploader(&$uploader)
    {
    $this->uploader_obj = &$uploader;
    }

    function getSerializer()
    {
    $tablename = ‘sfm_’.substr($this->formname,0,32).’_saved’;
    return new FM_SubmissionSerializer($this->config,$this->logger,$this->error_handler,$tablename);
    }

    function Process(&$continue)
    {
    $display_thankyou = true;

    $this->SaveCurrentPageToSession();

    if($this->NeedSaveAndClose())
    {
    $serializer = $this->getSerializer();

    $id = $serializer->SerializeToTable($this->SaveAllDataToArray());
    $this->AddToSerializedIDs($id);
    $id_encr = $this->ConvertID($id,/*encrypt*/true);

    $this->SaveFormDataToCookie($id_encr);

    $continue=false;
    $display_thankyou = false;
    $url = sfm_selfURL_abs().’?’.$this->config->reload_formvars_var.’=’.$id_encr;
    $url =’'.$url.'‘;
    $msg = str_replace(‘{link}’,$url,$this->config->saved_message_templ);
    echo $msg;
    }
    else
    if($this->NeedDisplayFormPage())
    {
    $this->DisplayFormPage($display_thankyou);
    $continue=false;
    }

    if($display_thankyou)
    {
    $this->LoadAllPageValuesFromSession($this->formvars,/*load files*/true,
    /*overwrite_existing*/false);
    $continue=true;
    }
    }

    function ConvertID($id,$encrypt)
    {
    $ret=”;
    if($encrypt)
    {
    $ret = sfm_crypt_encrypt(‘x’.$id,$this->config->rand_key);
    }
    else
    {
    $ret = sfm_crypt_decrypt($id,$this->config->rand_key);
    $ret = str_replace(‘x’,”,$ret);
    }
    return $ret;
    }

    function Destroy()
    {
    if($this->globaldata->IsFormProcessingComplete())
    {
    $this->RemoveUnSerializedRows();

    $this->RemoveCookies();
    }
    }

    function NeedDisplayFormPage()
    {

    if($this->globaldata->IsButtonClicked(‘sfm_prev_page’))
    {
    return true;
    }
    elseif(false == isset($this->formvars[$this->config->form_submit_variable]))
    {
    return true;
    }
    return false;
    }

    function NeedSaveAndClose()
    {
    if($this->globaldata->IsButtonClicked(‘sfm_save_n_close’))
    {
    return true;
    }
    return false;
    }

    function DisplayFormPage(&$display_thankyou)
    {
    $display_thankyou = false;

    $var_map = array();

    $var_map = array_merge($var_map,$this->config->element_info->default_values);

    $var_map[$this->config->error_display_variable]=””;

    $this->LoadAllPageValuesFromSession($var_map,/*load files*/false,/*overwrite_existing*/true);

    $id_reload = $this->GetReloadFormID();
    if(false !== $id_reload)
    {
    $id = $id_reload;

    $this->AddToSerializedIDs($id);

    $serializer = $this->getSerializer();
    $all_formdata = array();
    $serializer->RecreateFromTable($id,$all_formdata,/*reset*/false);
    $this->LoadAllDataFromArray($all_formdata,$var_map,$page_num);

    $this->common_objs->formpage_renderer->DisplayFormPage($page_num,$var_map);
    }
    elseif($this->globaldata->IsButtonClicked(‘sfm_prev_page’))
    {
    $this->common_objs->formpage_renderer->DisplayPrevPage($var_map);
    }
    elseif($this->common_objs->formpage_renderer->IsPageNumSet())
    {
    if(isset($this->validator_obj) &&
    !$this->validator_obj->ValidateCurrentPage($var_map))
    {
    return false;
    }
    $this->logger->LogInfo(“FormPageDisplayModule: DisplayNextPage”);
    $this->common_objs->formpage_renderer->DisplayNextPage($var_map,$display_thankyou);
    }
    else
    {//display the very first page
    $this->globaldata->RecordVariables();

    if($this->config->load_values_from_url)
    {
    $this->LoadValuesFromURL($var_map);
    }

    $this->logger->LogInfo(“FormPageDisplayModule: DisplayFirstPage”);
    $this->common_objs->formpage_renderer->DisplayFirstPage($var_map);
    }
    return true;
    }

    function LoadValuesFromURL(&$varmap)
    {
    foreach($this->globaldata->get_vars as $gk => $gv)
    {

    if(!$this->config->element_info->IsElementPresent($gk))
    { continue; }

    $pagenum = $this->config->element_info->GetPageNum($gk);

    if($pagenum == 0)
    {
    $varmap[$gk] = $gv;
    }
    else
    {
    $varname = $this->GetPageDataVarName($pagenum);

    if(empty($this->globaldata->session[$varname]))
    {
    $this->globaldata->session[$varname] = array();
    }
    $this->globaldata->session[$varname][$gk] = $gv;
    }
    }
    }
    function AddToSerializedIDs($id)
    {
    if(!isset($this->globaldata->session[‘sfm_serialized_ids’]))
    {
    $this->globaldata->session[‘sfm_serialized_ids’] = array();
    }
    $this->globaldata->session[‘sfm_serialized_ids’][$id] = ‘k’;
    }

    function RemoveUnSerializedRows()
    {
    if(empty($this->globaldata->session[‘sfm_serialized_ids’]))
    {
    return;
    }
    $serializer = $this->getSerializer();
    $serializer->Login();
    foreach($this->globaldata->session[‘sfm_serialized_ids’] as $id => $val)
    {
    $serializer->DeleteRow($id);
    }
    $serializer->Close();
    }

    function GetReloadFormID()
    {
    $id_encr=”;
    if(!empty($_GET[$this->config->reload_formvars_var]))
    {
    $id_encr = $_GET[$this->config->reload_formvars_var];
    }
    elseif($this->IsFormReloadCookieSet())
    {
    $id_encr = $_COOKIE[$this->formdata_cookiname];
    }
    if(!empty($id_encr))
    {
    $id = $this->ConvertID($id_encr,false/*encrypt*/);
    return $id;
    }
    return false;
    }

    function IsFormReloadCookieSet()
    {
    if(!$this->common_objs->formpage_renderer->IsPageNumSet() &&
    isset($_COOKIE[$this->formdata_cookiname]) )
    {
    return true;
    }
    return false;
    }

    function RemoveControlVariables($session_varname)
    {
    $this->RemoveButtonVariableFromSession($session_varname,’sfm_prev_page’);
    $this->RemoveButtonVariableFromSession($session_varname,’sfm_save_n_close’);
    $this->RemoveButtonVariableFromSession($session_varname,’sfm_prev_page’);
    $this->RemoveButtonVariableFromSession($session_varname,’sfm_confirm_edit’);
    $this->RemoveButtonVariableFromSession($session_varname,’sfm_confirm’);
    }

    function RemoveButtonVariableFromSession($sess_var,$varname)
    {
    unset($this->globaldata->session[$sess_var][$varname]);
    unset($this->globaldata->session[$sess_var][$varname.”_x”]);
    unset($this->globaldata->session[$sess_var][$varname.”_y”]);
    }

    function RemoveCookies()
    {
    if(isset($_COOKIE[$this->formdata_cookiname]))
    {
    sfm_clearcookie($this->formdata_cookiname);
    sfm_clearcookie($this->formpage_cookiname);
    }
    }

    function SaveAllDataToArray()
    {
    $all_formdata = $this->globaldata->session;
    $all_formdata[‘sfm_latest_page_num’] = $this->common_objs->formpage_renderer->GetCurrentPageNum();

    return $all_formdata;
    }
    function SaveFormDataToCookie($id_encr)
    {
    setcookie($this->formdata_cookiname,$id_encr,mktime()+(86400*30));
    }

    function LoadAllDataFromArray($all_formdata,&$var_map,&$page_num)
    {
    if(isset($all_formdata[‘sfm_latest_page_num’]))
    {
    $page_num = intval($all_formdata[‘sfm_latest_page_num’]);
    }
    else
    {
    $page_num =0;
    }
    unset($all_formdata[‘sfm_latest_page_num’]);

    $this->globaldata->RecreateSessionValues($all_formdata);

    $this->LoadFormPageFromSession($var_map,$page_num);
    }

    function LoadAllPageValuesFromSession(&$varmap,$load_files,$overwrite_existing=true)
    {
    if(!$this->common_objs->formpage_renderer->IsPageNumSet())
    {
    return;
    }

    $npages = $this->common_objs->formpage_renderer->GetNumPages();

    $this->logger->LogInfo(“LoadAllPageValuesFromSession npages $npages”);

    for($p=0; $p < $npages; $p++)
    {
    $varname = $this->GetPageDataVarName($p);
    if(isset($this->globaldata->session[$varname]))
    {
    if($overwrite_existing)
    {
    $varmap = array_merge($varmap,$this->globaldata->session[$varname]);
    }
    else
    {
    //Array union: donot overwrite values
    $varmap = $varmap + $this->globaldata->session[$varname];
    }

    if($load_files && isset($this->uploader_obj))
    {
    $this->uploader_obj->LoadFileListFromSession($varname);
    }
    }
    }//for

    }//function

    function LoadFormPageFromSession(&$var_map, $page_num)
    {
    $varname = $this->GetPageDataVarName($page_num);
    if(isset($this->globaldata->session[$varname]))
    {
    $var_map = array_merge($var_map,$this->globaldata->session[$varname]);
    $this->logger->LogInfo(” LoadFormPageFromSession var_map “.var_export($var_map,TRUE));
    }
    }

    function SaveCurrentPageToSession()
    {
    if($this->common_objs->formpage_renderer->IsPageNumSet())
    {
    $page_num = $this->common_objs->formpage_renderer->GetCurrentPageNum();

    $varname = $this->GetPageDataVarName($page_num);

    $this->globaldata->session[$varname] = $this->formvars;

    $this->RemoveControlVariables($varname);

    if(isset($this->uploader_obj))
    {
    $this->uploader_obj->HandleNativeFileUpload();
    }

    $this->logger->LogInfo(” SaveCurrentPageToSession _SESSION(varname) ”
    .var_export($this->globaldata->session[$varname],TRUE));
    }
    }

    function GetPageDataVarName($page_num)
    {
    return “sfm_form_page_”.$page_num.”_data”;
    }

    function DisplayUsingTemplate(&$var_map)
    {
    $merge = new FM_PageMerger();
    if(false == $merge->Merge($this->config->form_page_code,$var_map))
    {
    $this->error_handler->HandleConfigError(_(“Failed merging form page”));
    return false;
    }
    $strdisp = $merge->getMessageBody();
    echo $strdisp;
    }
    }

    function sfm_clearcookie( $inKey )
    {
    setcookie( $inKey , ” , time()-3600 );
    unset( $_COOKIE[$inKey] );
    }

    $var17677=’New submission for the form:Dosimetry_Order_Form_for_Simply_Locum’;

    $var13396=’


    The following data was submitted in
    the form named Dosimetry_Order_Form_for_Simply_Locum by %Name%

    Phone %Phone%
    Name %Name%
    Address %Address%
    InstadoseTotal %InstadoseTotal%
    NumberOfInstadose %NumberOfInstadose%
    TraditionalMailBackDosimeters %TraditionalMailBackDosimeters%
    BillingPeriod %BillingPeriod%
    Monthly_Fee %Monthly_Fee%
    TraditionalTotalCost %TraditionalTotalCost%
    QuantityRequired %QuantityRequired%
    CostOfAllBadges %CostOfAllBadges%
    TotalPlusDeposit %TotalPlusDeposit%
    VAT %VAT%
    GRANDTOTAL %GRANDTOTAL%
    BadgeColour %BadgeColour%
    Badge_Requested %Badge_Requested%
    Email %Email%
    First_Name %First_Name%
    Last_Name %Last_Name%
    DatePicker %DatePicker%
    Signature %Signature%

    More Info:

    FormSubmissionTime %_sfm_form_submision_time_%
    VisitorsIP %_sfm_visitor_ip_%
    UniqueID %_sfm_unique_id_%

    ‘;

    $var5674=’Kindly find attached a copy of your order’;

    $var4503=’


    The following data was submitted in the form named
    Dosimetry_Order_Form_for_Simply_Locum by %Name%
     
    Phone
    %Phone%
    Name %Name%
    Address %Address%
    InstadoseTotal %InstadoseTotal%
    NumberOfInstadose %NumberOfInstadose%
    TraditionalMailBackDosimeters %TraditionalMailBackDosimeters%
    BillingPeriod %BillingPeriod%
    Monthly_Fee %Monthly_Fee%
    TraditionalTotalCost %TraditionalTotalCost%
    QuantityRequired %QuantityRequired%
    CostOfAllBadges %CostOfAllBadges%
    TotalPlusDeposit %TotalPlusDeposit%
    VAT %VAT%
    GRANDTOTAL %GRANDTOTAL%
    BadgeColour %BadgeColour%
    Badge_Requested %Badge_Requested%
    Email %Email%
    First_Name %First_Name%
    Last_Name %Last_Name%
    DatePicker %DatePicker%
    Signature %Signature%

    ‘;

    $var27830=’

    Thank you

    Thank You!

    Your order has been successfully submitted.
    Thank
    you very much for your custom, we are proud to have you as a client.

    ‘;

    $var8856=’/*! jQuery v1.7.2 jquery.com | jquery.org/license */
    (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f(“<“+a+”>”).appendTo(b),e=d.css(“display”);d.remove();if(e===”none”||e===””){ck||(ck=c.createElement(“iframe”),ck.frameBorder=ck.width=ck.height=0),b.appendChild(ck);if(!cl||!ck.createElement)cl=(ck.contentWindow||ck.contentDocument).document,cl.write((f.support.boxModel?””:””)+””),cl.close();d=cl.createElement(a),cl.body.appendChild(d),e=f.css(d,”display”),b.removeChild(ck)}cj[a]=e}return cj[a]}function ct(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function cs(){cq=b}function cr(){setTimeout(cs,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject(“Microsoft.XMLHTTP”)}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!==”border”)for(;e=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+”defer”,e=b+”queue”,g=b+”mark”,h=f._data(a,d);h&&(c===”queue”||!f._data(a,e))&&(c===”mark”||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b===”data”&&f.isEmptyObject(a[b]))continue;if(b!==”toJSON”)return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e=”data-“+c.replace(k,”-$1″).toLowerCase();d=a.getAttribute(e);if(typeof d==”string”){try{d=d===”true”?!0:d===”false”?!1:d===”null”?null:f.isNumeric(d)?+d:j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\\s+/);for(c=0,d=a.length;c)[^>]*$|#([\\w\\-]*)$)/,j=/\\S/,k=/^\\s+/,l=/\\s+$/,m=/^<(\\w+)\\s*\\/?>(?:<\\/\\1>)?$/,n=/^[\\],:{}\\s]*$/,o=/\\\\(?:[“\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/”[^”\\\\\\n\\r]*”|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,q=/(?:^|:|,)(?:\\s*\\[)+/g,r=/(webkit)[ \\/]([\\w.]+)/,s=/(opera)(?:.*version)?[ \\/]([\\w.]+)/,t=/(msie) ([\\w.]+)/,u=/(mozilla)(?:.*? rv:([\\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+””).toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a===”body”&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a==”string”){a.charAt(0)!==”<“||a.charAt(a.length-1)!==”>”||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:””,jquery:”1.7.2″,length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b===”find”?d.selector=this.selector+(this.selector?” “:””)+c:b&&(d.selector=this.selector+”.”+b+”(“+c+”)”);return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),”slice”,F.call(arguments).join(“,”))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i==”boolean”&&(l=i,i=arguments[1]||{},j=2),typeof i!=”object”&&!e.isFunction(i)&&(i={}),k===j&&(i=this,–j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger(“ready”).off(“ready”)}},bindReady:function(){if(!A){A=e.Callbacks(“once memory”);if(c.readyState===”complete”)return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener(“DOMContentLoaded”,B,!1),a.addEventListener(“load”,e.ready,!1);else if(c.attachEvent){c.attachEvent(“onreadystatechange”,B),a.attachEvent(“onload”,e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)===”function”},isArray:Array.isArray||function(a){return e.type(a)===”array”},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||”object”},isPlainObject:function(a){if(!a||e.type(a)!==”object”||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,”constructor”)&&!D.call(a.constructor.prototype,”isPrototypeOf”))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!=”string”||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,”@”).replace(p,”]”).replace(q,””)))return(new Function(“return “+b))();e.error(“Invalid JSON: “+b)},parseXML:function(c){if(typeof c!=”string”||!c)return null;var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,”text/xml”)):(d=new ActiveXObject(“Microsoft.XMLDOM”),d.async=”false”,d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName(“parsererror”).length)&&e.error(“Invalid XML: “+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,”ms-“).replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,–g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c

    a“,d=p.getElementsByTagName(“*”),e=p.getElementsByTagName(“a”)[0];if(!d||!d.length||!e)return{};g=c.createElement(“select”),h=g.appendChild(c.createElement(“option”)),i=p.getElementsByTagName(“input”)[0],b={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName(“tbody”).length,htmlSerialize:!!p.getElementsByTagName(“link”).length,style:/top/.test(e.getAttribute(“style”)),hrefNormalized:e.getAttribute(“href”)===”/a”,opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value===”on”,optSelected:h.selected,getSetAttribute:p.className!==”t”,enctype:!!c.createElement(“form”).enctype,html5Clone:c.createElement(“nav”).cloneNode(!0).outerHTML!==”<:nav>“,submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,pixelMargin:!0},f.boxModel=b.boxModel=c.compatMode===”CSS1Compat”,i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete p.test}catch(r){b.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent(“onclick”,function(){b.noCloneEvent=!1}),p.cloneNode(!0).fireEvent(“onclick”)),i=c.createElement(“input”),i.value=”t”,i.setAttribute(“type”,”radio”),b.radioValue=i.value===”t”,i.setAttribute(“checked”,”checked”),i.setAttribute(“name”,”t”),p.appendChild(i),j=c.createDocumentFragment(),j.appendChild(p.lastChild),b.checkClone=j.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,j.removeChild(i),j.appendChild(p);if(p.attachEvent)for(n in{submit:1,change:1,focusin:1})m=”on”+n,o=m in p,o||(p.setAttribute(m,”return;”),o=typeof p[m]==”function”),b[n+”Bubbles”]=o;j.removeChild(p),j=g=h=p=i=null,f(function(){var d,e,g,h,i,j,l,m,n,q,r,s,t,u=c.getElementsByTagName(“body”)[0];!u||(m=1,t=”padding:0;margin:0;border:”,r=”position:absolute;top:0;left:0;width:1px;height:1px;”,s=t+”0;visibility:hidden;”,n=”style=\'”+r+t+”5px solid #000;”,q=”

    “+””+”

    “,d=c.createElement(“div”),d.style.cssText=s+”width:0;height:0;position:static;top:0;margin-top:”+m+”px”,u.insertBefore(d,u.firstChild),p=c.createElement(“div”),d.appendChild(p),p.innerHTML=”

    t

    “,k=p.getElementsByTagName(“td”),o=k[0].offsetHeight===0,k[0].style.display=””,k[1].style.display=”none”,b.reliableHiddenOffsets=o&&k[0].offsetHeight===0,a.getComputedStyle&&(p.innerHTML=””,l=c.createElement(“div”),l.style.width=”0″,l.style.marginRight=”0″,p.style.width=”2px”,p.appendChild(l),b.reliableMarginRight=(parseInt((a.getComputedStyle(l,null)||{marginRight:0}).marginRight,10)||0)===0),typeof p.style.zoom!=”undefined”&&(p.innerHTML=””,p.style.width=p.style.padding=”1px”,p.style.border=0,p.style.overflow=”hidden”,p.style.display=”inline”,p.style.zoom=1,b.inlineBlockNeedsLayout=p.offsetWidth===3,p.style.display=”block”,p.style.overflow=”visible”,p.innerHTML=”

    “,b.shrinkWrapBlocks=p.offsetWidth!==3),p.style.cssText=r+s,p.innerHTML=q,e=p.firstChild,g=e.firstChild,i=e.nextSibling.firstChild.firstChild,j={doesNotAddBorder:g.offsetTop!==5,doesAddBorderForTableAndCells:i.offsetTop===5},g.style.position=”fixed”,g.style.top=”20px”,j.fixedPosition=g.offsetTop===20||g.offsetTop===15,g.style.position=g.style.top=””,e.style.overflow=”hidden”,e.style.position=”relative”,j.subtractsBorderForOverflowNotVisible=g.offsetTop===-5,j.doesNotIncludeMarginInBodyOffset=u.offsetTop!==m,a.getComputedStyle&&(p.style.marginTop=”1%”,b.pixelMargin=(a.getComputedStyle(p,null)||{marginTop:0}).marginTop!==”1%”),typeof d.style.zoom!=”undefined”&&(d.style.zoom=1),u.removeChild(d),l=p=d=null,f.extend(b,j))});return b}();var j=/^(?:\\{.*\\}|\\[.*\\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:”jQuery”+(f.fn.jquery+Math.random()).replace(/\\D/g,””),noData:{embed:!0,object:”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″,applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c==”string”,l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c===”events”;if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c==”object”||typeof c==”function”)e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(” “)));for(e=0,g=b.length;e1,null,!1)},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||”fx”)+”mark”,f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||”fx”;var d=c+”mark”,e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,”mark”))}},queue:function(a,b,c){var d;if(a){b=(b||”fx”)+”queue”,d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||”fx”;var c=f.queue(a,b),d=c.shift(),e={};d===”inprogress”&&(d=c.shift()),d&&(b===”fx”&&c.unshift(“inprogress”),f._data(a,b+”.run”,e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+”queue “+b+”.run”,!0),n(a,b,”queue”))}}),f.fn.extend({queue:function(a,c){var d=2;typeof a!=”string”&&(c=a,a=”fx”,d–);if(arguments.length1)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,f.prop,a,b,arguments.length>1)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a==”string”){b=a.split(p);for(c=0,d=this.length;c-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h=””:typeof h==”number”?h+=””:f.isArray(h)&&(h=f.map(h,function(a){return a==null?””:a+””})),c=f.valHooks[this.type]||f.valHooks[this.nodeName.toLowerCase()];if(!c||!(“set”in c)||c.set(this,h,”value”)===b)this.value=h}})}if(g){c=f.valHooks[g.type]||f.valHooks[g.nodeName.toLowerCase()];if(c&&”get”in c&&(d=c.get(g,”value”))!==b)return d;d=g.value;return typeof d==”string”?d.replace(q,””):d==null?””:d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type===”select-one”;if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute==”undefined”)return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&”set”in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,””+d);return d}if(h&&”get”in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h,i=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;i=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\\.]*)?(?:\\.(.+))?$/,B=/(?:^|\\s)hover(\\.\\S+)?\\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\\w*)(?:#([\\w\\-]+))?(?:\\.([\\w\\-]+))?$/,G=function(
    a){var b=F.exec(a);b&&(b[1]=(b[1]||””).toLowerCase(),b[3]=b[3]&&new RegExp(“(?:^|\\\\s)”+b[3]+”(?:\\\\s|$)”));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c[“class”]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,”mouseenter$1 mouseleave$1″)};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler,g=p.selector),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!=”undefined”&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(” “);for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(“.”)>=0&&(i=h.split(“.”),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c==”object”?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join(“.”),c.namespace_re=c.namespace?new RegExp(“(^|\\\\.)”+i.join(“\\\\.(?:.*\\\\.)?”)+”(\\\\.|$)”):null,o=h.indexOf(“:”)<0?”on”+h:””;if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\\[\\\\]+)+|[>+~])(\\s*,\\s*)?((?:.|\\r|\\n)*)/g,d=”sizcache”+(Math.random()+””).replace(“.”,””),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\\\/g,k=/\\r\\n/g,l=/\\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!=”string”)return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(“”),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]===”~”||w[0]===”+”)&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q=””,r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)===”[object Array]”)if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e“:function(a,b){var c,d=typeof b==”string”,e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,””)},TAG:function(a,b){return a[1].replace(j,””).toLowerCase()},CHILD:function(a){if(a[1]===”nth”){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\\+|\\s*/g,””);var b=/(-?)(\\d*)(?:n([+\\-]?\\d*))?/.exec(a[2]===”even”&&”2n”||a[2]===”odd”&&”2n+1″||!/\\D/.test(a[2])&&”0n+”+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,””);!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||””).replace(j,””),a[2]===”~=”&&(a[4]=” “+a[4]+” “);return a},PSEUDO:function(b,c,d,e,f){if(b[1]===”not”)if((a.exec(b[3])||””).length>1||/^\\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!==”hidden”},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute(“type”),c=a.type;return a.nodeName.toLowerCase()===”input”&&”text”===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()===”input”&&”radio”===a.type},checkbox:function(a){return a.nodeName.toLowerCase()===”input”&&”checkbox”===a.type},file:function(a){return a.nodeName.toLowerCase()===”input”&&”file”===a.type},password:function(a){return a.nodeName.toLowerCase()===”input”&&”password”===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b===”input”||b===”button”)&&”submit”===a.type},image:function(a){return a.nodeName.toLowerCase()===”input”&&”image”===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b===”input”||b===”button”)&&”reset”===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b===”input”&&”button”===a.type||b===”button”},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e===”contains”)return(a.textContent||a.innerText||n([a])||””).indexOf(b[3])>=0;if(e===”not”){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute(“id”)===b},TAG:function(a,b){return b===”*”&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(” “+(a.className||a.getAttribute(“class”))+” “).indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+””,f=b[2],g=b[4];return d==null?f===”!=”:!f&&m.attr?d!=null:f===”=”?e===g:f===”*=”?e.indexOf(g)>=0:f===”~=”?(” “+e+” “).indexOf(g)>=0:g?f===”!=”?e!==g:f===”^=”?e.indexOf(g)===0:f===”$=”?e.substr(e.length-g.length)===g:f===”|=”?e===g||e.substr(0,g.length+1)===g+”-“:!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return”\\\\”+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\\[]*\\])(?![^\\(]*\\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\\r|\\n)*?)/.source+o.match[r].source.replace(/\\\\(\\d+)/g,q));o.match.globalPOS=p;var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)===”[object Array]”)Array.prototype.push.apply(d,a);else if(typeof a.length==”number”)for(var e=a.length;c“,e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!=”undefined”&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!=”undefined”&&e.getAttributeNode(“id”).nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!=”undefined”&&a.getAttributeNode(“id”);return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement(“div”);a.appendChild(c.createComment(“”)),a.getElementsByTagName(“*”).length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]===”*”){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML=”“,a.firstChild&&typeof a.firstChild.getAttribute!=”undefined”&&a.firstChild.getAttribute(“href”)!==”#”&&(o.attrHandle.href=function(a){return a.getAttribute(“href”,2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement(“div”),d=”__sizzle__”;b.innerHTML=”

    “;if(!b.querySelectorAll||b.querySelectorAll(“.TEST”).length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\\w+$)|^\\.([\\w\\-]+$)|^#([\\w\\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b===”body”&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!==”object”){var k=e,l=e.getAttribute(“id”),n=l||d,p=e.parentNode,q=/^\\s*[+~]/.test(b);l?n=n.replace(/\’/g,”\\\\$&”):e.setAttribute(“id”,n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll(“[id=\'”+n+”\’] “+b),f)}catch(r){}finally{l||k.removeAttribute(“id”)}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement(“div”),”div”),e=!1;try{b.call(c.documentElement,”[test!=\’\’]:sizzle”)}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\\=\\s*([^\'”\\]]*)\\s*\\]/g,”=\’$1\’]”);if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement(“div”);a.innerHTML=”

    “;if(!!a.getElementsByClassName&&a.getElementsByClassName(“e”).length!==0){a.lastChild.className=”e”;if(a.getElementsByClassName(“e”).length===1)return;o.order.splice(1,0,”CLASS”),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!=”undefined”&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!==”HTML”:!1};var y=function(a,b,c){var d,e=[],f=””,g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,””);a=o.relative[a]?a+”*”:a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,”closest”,a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a==”string”)return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a==”string”?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,”parentNode”)},parentsUntil:function(a,b,c){return f.dir(a,”parentNode”,c)},next:function(a){return f.nth(a,2,”nextSibling”)},prev:function(a){return f.nth(a,2,”previousSibling”)},nextAll:function(a){return f.dir(a,”nextSibling”)},prevAll:function(a){return f.dir(a,”previousSibling”)},nextUntil:function(a,b,c){return f.dir(a,”nextSibling”,c)},prevUntil:function(a,b,c){return f.dir(a,”previousSibling”,c)},siblings:function(a){return f.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,”iframe”)?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d==”string”&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(“,”))}}),f.extend({filter:function(a,b,c){c&&(a=”:not(“+a+”)”);return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V=”abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video”,W=/ jQuery\\d+=”(?:\\d+|null)”/g,X=/^\\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\\w:]+)[^>]*)\\/>/ig,Z=/<([\\w:]+)/,$=/]”,”i”),bd=/checked\\s*(?:[^=]|=\\s*.checked.)/i,be=/\\/(java|ecma)script/i,bf=/^\\s*“,””],legend:[1,”

    “,”

    “],thead:[1,””,”

    “],tr:[2,””,”

    “],td:[3,””,”

    “],col:[2,””,”

    “],area:[1,”

    “,”

    “],_default:[0,””,””]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,”div

    “,”

    “]),f.fn.extend({text:function(a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,”body”)||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f
    .clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,”before”,arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,”after”,arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName(“*”)),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName(“*”));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){return f.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(W,””):null;if(typeof a==”string”&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||[“”,””])[1].toLowerCase()]){a=a.replace(Y,”<$1>“);try{for(;d1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||f.isXMLDoc(a)||!bc.test(“<“+a.nodeName+”>”)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g,h,i,j=[];b=b||c,typeof b.createElement==”undefined”&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);for(var k=0,l;(l=a[k])!=null;k++){typeof l==”number”&&(l+=””);if(!l)continue;if(typeof l==”string”)if(!_.test(l))l=b.createTextNode(l);else{l=l.replace(Y,”<$1>“);var m=(Z.exec(l)||[“”,””])[1].toLowerCase(),n=bg[m]||bg._default,o=n[0],p=b.createElement(“div”),q=bh.childNodes,r;b===c?bh.appendChild(p):U(b).appendChild(p),p.innerHTML=n[1]+l+n[2];while(o–)p=p.lastChild;if(!f.support.tbody){var s=$.test(l),t=m===”table”&&!s?p.firstChild&&p.firstChild.childNodes:n[1]===””&&!s?p.childNodes:[];for(i=t.length-1;i>=0;–i)f.nodeName(t[i],”tbody”)&&!t[i].childNodes.length&&t[i].parentNode.removeChild(t[i])}!f.support.leadingWhitespace&&X.test(l)&&p.insertBefore(b.createTextNode(X.exec(l)[0]),p.firstChild),l=p.childNodes,p&&(p.parentNode.removeChild(p),q.length>0&&(r=q[q.length-1],r&&r.parentNode&&r.parentNode.removeChild(r)))}var u;if(!f.support.appendChecked)if(l[0]&&typeof (u=l.length)==”number”)for(i=0;i1)},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=by(a,”opacity”);return c===””?”1″:c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{“float”:f.support.cssFloat?”cssFloat”:”styleFloat”},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&”get”in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h===”string”&&(g=bu.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h=”number”);if(d==null||h===”number”&&isNaN(d))return;h===”number”&&!f.cssNumber[i]&&(d+=”px”);if(!k||!(“set”in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c===”cssFloat”&&(c=”float”);if(g&&”get”in g&&(e=g.get(a,!0,d))!==b)return e;if(by)return by(a,c)},swap:function(a,b,c){var d={},e,f;for(f in b)d[f]=a.style[f],a.style[f]=b[f];e=c.call(a);for(f in b)a.style[f]=d[f];return e}}),f.curCSS=f.css,c.defaultView&&c.defaultView.getComputedStyle&&(bz=function(a,b){var c,d,e,g,h=a.style;b=b.replace(br,”-$1″).toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===””&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b))),!f.support.pixelMargin&&e&&bv.test(b)&&bt.test(c)&&(g=h.width,h.width=c,c=e.width,h.width=g);return c}),c.documentElement.currentStyle&&(bA=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f==null&&g&&(e=g[b])&&(f=e),bt.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b===”fontSize”?”1em”:f,f=g.pixelLeft+”px”,g.left=c,d&&(a.runtimeStyle.left=d));return f===””?”auto”:f}),by=bz||bA,f.each([“height”,”width”],function(a,b){f.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0?bB(a,b,d):f.swap(a,bw,function(){return bB(a,b,d)})},set:function(a,b){return bs.test(b)?b+”px”:b}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bq.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||””)?parseFloat(RegExp.$1)/100+””:b?”1″:””},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?”alpha(opacity=”+b*100+”)”:””,g=d&&d.filter||c.filter||””;c.zoom=1;if(b>=1&&f.trim(g.replace(bp,””))===””){c.removeAttribute(“filter”);if(d&&!d.filter)return}c.filter=bp.test(g)?g.replace(bp,e):g+” “+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){return f.swap(a,{display:”inline-block”},function(){return b?by(a,”margin-right”):a.style.marginRight})}})}),f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,”display”))===”none”},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)}),f.each({margin:””,padding:””,border:”Width”},function(a,b){f.cssHooks[a+b]={expand:function(c){var d,e=typeof c==”string”?c.split(” “):[c],f={};for(d=0;d<4;d++)f[a+bx[d]+b]=e[d]||e[d-2]||e[0];return f}}});var bC=/%20/g,bD=/\\[\\]$/,bE=/\\r?\\n/g,bF=/#.*$/,bG=/^(.*?):[ \\t]*([^\\r\\n]*)\\r?$/mg,bH=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bI=/^(?:about|app|app\\-storage|.+\\-extension|file|res|widget):$/,bJ=/^(?:GET|HEAD)$/,bK=/^\\/\\//,bL=/\\?/,bM=/)<[^<]*)*<\\/script>/gi,bN=/^(?:select|textarea)/i,bO=/\\s+/,bP=/([?&])_=[^&]*/,bQ=/^([\\w\\+\\.\\-]+:)(?:\\/\\/([^\\/?#:]*)(?::(\\d+))?)?/,bR=f.fn.load,bS={},bT={},bU,bV,bW=[“*/”]+[“*”];try{bU=e.href}catch(bX){bU=c.createElement(“a”),bU.href=””,bU=bU.href}bV=bQ.exec(bU.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!=”string”&&bR)return bR.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(” “);if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h=”GET”;c&&(f.isFunction(c)?(d=c,c=b):typeof c==”object”&&(c=f.param(c,f.ajaxSettings.traditional),h=”POST”));var i=this;f.ajax({url:a,type:h,dataType:”html”,data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f(“

    “).append(c.replace(bM,””)).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bN.test(this.nodeName)||bH.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bE,”\\r\\n”)}}):{name:b.name,value:c.replace(bE,”\\r\\n”)}}).get()}}),f.each(“ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend”.split(” “),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each([“get”,”post”],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,”script”)},getJSON:function(a,b,c){return f.get(a,b,c,”json”)},ajaxSetup:function(a,b){b?b$(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b$(a,b);return a},ajaxSettings:{url:bU,isLocal:bI.test(bV[1]),global:!0,type:”GET”,contentType:”application/x-www-form-urlencoded; charset=UTF-8″,processData:!0,async:!0,accepts:{xml:”application/xml, text/xml”,html:”text/html”,text:”text/plain”,json:”application/json, text/javascript”,”*”:bW},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:”responseXML”,text:”responseText”},converters:{“* text”:a.String,”text html”:!0,”text json”:f.parseJSON,”text xml”:f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bY(bS),ajaxTransport:bY(bT),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||””,v.readyState=a>0?4:0;var o,r,u,w=c,x=l?ca(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader(“Last-Modified”))f.lastModified[k]=y;if(z=v.getResponseHeader(“Etag”))f.etag[k]=z}if(a===304)w=”notmodified”,o=!0;else try{r=cb(d,x),w=”success”,o=!0}catch(A){w=”parsererror”,u=A}}else{u=w;if(!w||a)w=”error”,a<0&&(a=0)}v.status=a,v.statusText=””+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger(“ajax”+(o?”Success”:”Error”),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger(“ajaxComplete”,[v,d]),–f.active||f.event.trigger(“ajaxStop”))}}typeof a==”object”&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks(“once memory”),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||”abort”,p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+””).replace(bF,””).replace(bK,bV[1]+”//”),d.dataTypes=f.trim(d.dataType||”*”).toLowerCase().split(bO),d.crossDomain==null&&(r=bQ.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bV[1]&&r[2]==bV[2]&&(r[3]||(r[1]===”http:”?80:443))==(bV[3]||(bV[1]===”http:”?80:443)))),d.data&&d.processData&&typeof d.data!=”string”&&(d.data=f.param(d.data,d.traditional)),bZ(bS,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bJ.test(d.type),t&&f.active++===0&&f.event.trigger(“ajaxStart”);if(!d.hasContent){d.data&&(d.url+=(bL.test(d.url)?”&”:”?”)+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bP,”$1_=”+x);d.url=y+(y===d.url?(bL.test(d.url)?”&”:”?”)+”_=”+x:””)}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader(“Content-Type”,d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader(“If-Modified-Since”,f.lastModified[k]),f.etag[k]&&v.setRequestHeader(“If-None-Match”,f.etag[k])),v.setRequestHeader(“Accept”,d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!==”*”?”, “+bW+”; q=0.01″:””):d.accepts[“*”]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bZ(bT,d,c,v);if(!p)w(-1,”No Transport”);else{v.readyState=1,t&&g.trigger(“ajaxSend”,[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort(“timeout”)},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+”=”+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join(“&”).replace(bC,”+”)}}),f.extend({active:0,lastModified:{},etag:{}});var cc=f.now(),cd=/(\\=)\\?(&|$)|\\?\\?/i;f.ajaxSetup({jsonp:”callback”,jsonpCallback:function(){return f.expando+”_”+cc++}}),f.ajaxPrefilter(“json jsonp”,function(b,c,d){var e=typeof b.data==”string”&&/^application\\/x\\-www\\-form\\-urlencoded/.test(b.contentType);if(b.dataTypes[0]===”jsonp”||b.jsonp!==!1&&(cd.test(b.url)||e&&cd.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l=”$1″+h+”$2″;b.jsonp!==!1&&(j=j.replace(cd,l),b.url===j&&(e&&(k=k.replace(cd,l)),b.data===k&&(j+=(/\\?/.test(j)?”&”:”?”)+b.jsonp+”=”+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters[“script json”]=function(){g||f.error(h+” was not called”);return g[0]},b.dataTypes[0]=”json”;return”script”}}),f.ajaxSetup({accepts:{script:”text/javascript, application/javascript, application/ecmascript, application/x-ecmascript”},contents:{script:/javascript|ecmascript/},converters:{“text script”:function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter(“script”,function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type=”GET”,a.global=!1)}),f.ajaxTransport(“script”,function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName(“head”)[0]||c.documentElement;return{send:function(f,g){d=c.createElement(“script”),d.async=”async”,a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,”success”)},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ce=a.ActiveXObject?function(){for(var a in cg)cg[a](0,1)}:!1,cf=0,cg;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ch()||ci()}:ch,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&”withCredentials”in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e[“X-Requested-With”]&&(e[“X-Requested-With”]=”XMLHttpRequest”);try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ce&&delete cg[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n);try{m.text=h.responseText}catch(a){}try{k=h.statusText}catch(o){k=””}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cf,ce&&(cg||(cg={},f(a).unload(ce)),cg[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cj={},ck,cl,cm=/^(?:toggle|show|hide)$/,cn=/^([+\\-]=)?([\\d+.\\-]+)([a-z%]*)$/i,co,cp=[[“height”,”marginTop”,”marginBottom”,”paddingTop”,”paddingBottom”],[“width”,”marginLeft”,”marginRight”,”paddingLeft”,”paddingRight”],[“opacity”]],cq;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(ct(“show”,3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each([“”,”X”,”Y”],function(a,b){h.style[“overflow”+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,”fxshow”+b,!0),f.removeData(h,”toggle”+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),”using”in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,”marginTop”))||0,c.left-=parseFloat(f.css(a,”marginLeft”))||0,d.top+=parseFloat(f.css(b[0],”borderTopWidth”))||0,d.left+=parseFloat(f.css(b[0],”borderLeftWidth”))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,”position”)===”static”)a=a.offsetParent;return a})}}),f.each({scrollLeft:”pageXOffset”,scrollTop:”pageYOffset”},function(a,c){var d=/Y/.test(c);f.fn[a]=function(e){return f.access(this,function(a,e,g){var h=cy(a);if(g===b)return h?c in h?h[c]:f.support.boxModel&&h.document.documentElement[e]||h.document.body[e]:a[e];h?h.scrollTo(d?f(h).scrollLeft():g,d?g:f(h).scrollTop()):a[e]=g},a,e,arguments.length,null)}}),f.each({Height:”height”,Width:”width”},function(a,c){var d=”client”+a,e=”scroll”+a,g=”offset”+a;f.fn[“inner”+a]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,c,”padding”)):this[c]():null},f.fn[“outer”+a]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,c,a?”margin”:”border”)):this[c]():null},f.fn[c]=function(a){return f.access(this,function(a,c,h){var i,j,k,l;if(f.isWindow(a)){i=a.document,j=i.documentElement[d];return f.support.boxModel&&j||i.body&&i.body[d]||j}if(a.nodeType===9){i=a.documentElement;if(i[d]>=i[e])return i[d];return Math.max(a.body[e],i[e],a.body[g],i[g])}if(h===b){k=f.css(a,c),l=parseFloat(k);return f.isNumeric(l)?l:k}f(a).css(c,h)},c,a,arguments.length,null)}}),a.jQuery=a.$=f,typeof define==”function”&&define.amd&&define.amd.jQuery&&define(“jquery”,[],function(){return f})})(window);’;

    $var23777=’/*!
    * jQuery UI 1.8.18
    *
    * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * http://docs.jquery.com/UI
    */(function(a,b){function d(b){return!a(b).parents().andSelf().filter(function(){return a.curCSS(this,”visibility”)===”hidden”||a.expr.filters.hidden(this)}).length}function c(b,c){var e=b.nodeName.toLowerCase();if(“area”===e){var f=b.parentNode,g=f.name,h;if(!b.href||!g||f.nodeName.toLowerCase()!==”map”)return!1;h=a(“img[usemap=#”+g+”]”)[0];return!!h&&d(h)}return(/input|select|textarea|button|object/.test(e)?!b.disabled:”a”==e?b.href||c:c)&&d(b)}a.ui=a.ui||{};a.ui.version||(a.extend(a.ui,{version:”1.8.18″,keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}}),a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(b,c){return typeof b==”number”?this.each(function(){var d=this;setTimeout(function(){a(d).focus(),c&&c.call(d)},b)}):this._focus.apply(this,arguments)},scrollParent:function(){var b;a.browser.msie&&/(static|relative)/.test(this.css(“position”))||/absolute/.test(this.css(“position”))?b=this.parents().filter(function(){return/(relative|absolute|fixed)/.test(a.curCSS(this,”position”,1))&&/(auto|scroll)/.test(a.curCSS(this,”overflow”,1)+a.curCSS(this,”overflow-y”,1)+a.curCSS(this,”overflow-x”,1))}).eq(0):b=this.parents().filter(function(){return/(auto|scroll)/.test(a.curCSS(this,”overflow”,1)+a.curCSS(this,”overflow-y”,1)+a.curCSS(this,”overflow-x”,1))}).eq(0);return/fixed/.test(this.css(“position”))||!b.length?a(document):b},zIndex:function(c){if(c!==b)return this.css(“zIndex”,c);if(this.length){var d=a(this[0]),e,f;while(d.length&&d[0]!==document){e=d.css(“position”);if(e===”absolute”||e===”relative”||e===”fixed”){f=parseInt(d.css(“zIndex”),10);if(!isNaN(f)&&f!==0)return f}d=d.parent()}}return 0},disableSelection:function(){return this.bind((a.support.selectstart?”selectstart”:”mousedown”)+”.ui-disableSelection”,function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(“.ui-disableSelection”)}}),a.each([“Width”,”Height”],function(c,d){function h(b,c,d,f){a.each(e,function(){c-=parseFloat(a.curCSS(b,”padding”+this,!0))||0,d&&(c-=parseFloat(a.curCSS(b,”border”+this+”Width”,!0))||0),f&&(c-=parseFloat(a.curCSS(b,”margin”+this,!0))||0)});return c}var e=d===”Width”?[“Left”,”Right”]:[“Top”,”Bottom”],f=d.toLowerCase(),g={innerWidth:a.fn.innerWidth,innerHeight:a.fn.innerHeight,outerWidth:a.fn.outerWidth,outerHeight:a.fn.outerHeight};a.fn[“inner”+d]=function(c){if(c===b)return g[“inner”+d].call(this);return this.each(function(){a(this).css(f,h(this,c)+”px”)})},a.fn[“outer”+d]=function(b,c){if(typeof b!=”number”)return g[“outer”+d].call(this,b);return this.each(function(){a(this).css(f,h(this,b,!0,c)+”px”)})}}),a.extend(a.expr[“:”],{data:function(b,c,d){return!!a.data(b,d[3])},focusable:function(b){return c(b,!isNaN(a.attr(b,”tabindex”)))},tabbable:function(b){var d=a.attr(b,”tabindex”),e=isNaN(d);return(e||d>=0)&&c(b,!e)}}),a(function(){var b=document.body,c=b.appendChild(c=document.createElement(“div”));c.offsetHeight,a.extend(c.style,{minHeight:”100px”,height:”auto”,padding:0,borderWidth:0}),a.support.minHeight=c.offsetHeight===100,a.support.selectstart=”onselectstart”in c,b.removeChild(c).style.display=”none”}),a.extend(a.ui,{plugin:{add:function(b,c,d){var e=a.ui[b].prototype;for(var f in d)e.plugins[f]=e.plugins[f]||[],e.plugins[f].push([c,d[f]])},call:function(a,b,c){var d=a.plugins[b];if(!!d&&!!a.element[0].parentNode)for(var e=0;e0)return!0;b[d]=1,e=b[d]>0,b[d]=0;return e},isOverAxis:function(a,b,c){return a>b&&a=9)&&!b.button)return this._mouseUp(b);if(this._mouseStarted){this._mouseDrag(b);return b.preventDefault()}this._mouseDistanceMet(b)&&this._mouseDelayMet(b)&&(this._mouseStarted=this._mouseStart(this._mouseDownEvent,b)!==!1,this._mouseStarted?this._mouseDrag(b):this._mouseUp(b));return!this._mouseStarted},_mouseUp:function(b){a(document).unbind(“mousemove.”+this.widgetName,this._mouseMoveDelegate).unbind(“mouseup.”+this.widgetName,this._mouseUpDelegate),this._mouseStarted&&(this._mouseStarted=!1,b.target==this._mouseDownEvent.target&&a.data(b.target,this.widgetName+”.preventClickEvent”,!0),this._mouseStop(b));return!1},_mouseDistanceMet:function(a){return Math.max(Math.abs(this._mouseDownEvent.pageX-a.pageX),Math.abs(this._mouseDownEvent.pageY-a.pageY))>=this.options.distance},_mouseDelayMet:function(a){return this.mouseDelayMet},_mouseStart:function(a){},_mouseDrag:function(a){},_mouseStop:function(a){},_mouseCapture:function(a){return!0}})})(jQuery);/*
    * jQuery UI Position 1.8.18
    *
    * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * http://docs.jquery.com/UI/Position
    */(function(a,b){a.ui=a.ui||{};var c=/left|center|right/,d=/top|center|bottom/,e=”center”,f={},g=a.fn.position,h=a.fn.offset;a.fn.position=function(b){if(!b||!b.of)return g.apply(this,arguments);b=a.extend({},b);var h=a(b.of),i=h[0],j=(b.collision||”flip”).split(” “),k=b.offset?b.offset.split(” “):[0,0],l,m,n;i.nodeType===9?(l=h.width(),m=h.height(),n={top:0,left:0}):i.setTimeout?(l=h.width(),m=h.height(),n={top:h.scrollTop(),left:h.scrollLeft()}):i.preventDefault?(b.at=”left top”,l=m=0,n={top:b.of.pageY,left:b.of.pageX}):(l=h.outerWidth(),m=h.outerHeight(),n=h.offset()),a.each([“my”,”at”],function(){var a=(b[this]||””).split(” “);a.length===1&&(a=c.test(a[0])?a.concat([e]):d.test(a[0])?[e].concat(a):[e,e]),a[0]=c.test(a[0])?a[0]:e,a[1]=d.test(a[1])?a[1]:e,b[this]=a}),j.length===1&&(j[1]=j[0]),k[0]=parseInt(k[0],10)||0,k.length===1&&(k[1]=k[0]),k[1]=parseInt(k[1],10)||0,b.at[0]===”right”?n.left+=l:b.at[0]===e&&(n.left+=l/2),b.at[1]===”bottom”?n.top+=m:b.at[1]===e&&(n.top+=m/2),n.left+=k[0],n.top+=k[1];return this.each(function(){var c=a(this),d=c.outerWidth(),g=c.outerHeight(),h=parseInt(a.curCSS(this,”marginLeft”,!0))||0,i=parseInt(a.curCSS(this,”marginTop”,!0))||0,o=d+h+(parseInt(a.curCSS(this,”marginRight”,!0))||0),p=g+i+(parseInt(a.curCSS(this,”marginBottom”,!0))||0),q=a.extend({},n),r;b.my[0]===”right”?q.left-=d:b.my[0]===e&&(q.left-=d/2),b.my[1]===”bottom”?q.top-=g:b.my[1]===e&&(q.top-=g/2),f.fractions||(q.left=Math.round(q.left),q.top=Math.round(q.top)),r={left:q.left-h,top:q.top-i},a.each([“left”,”top”],function(c,e){a.ui.position[j[c]]&&a.ui.position[j[c]][e](q,{targetWidth:l,targetHeight:m,elemWidth:d,elemHeight:g,collisionPosition:r,collisionWidth:o,collisionHeight:p,offset:k,my:b.my,at:b.at})}),a.fn.bgiframe&&c.bgiframe(),c.offset(a.extend(q,{using:b.using}))})},a.ui.position={fit:{left:function(b,c){var d=a(window),e=c.collisionPosition.left+c.collisionWidth-d.width()-d.scrollLeft();b.left=e>0?b.left-e:Math.max(b.left-c.collisionPosition.left,b.left)},top:function(b,c){var d=a(window),e=c.collisionPosition.top+c.collisionHeight-d.height()-d.scrollTop();b.top=e>0?b.top-e:Math.max(b.top-c.collisionPosition.top,b.top)}},flip:{left:function(b,c){if(c.at[0]!==e){var d=a(window),f=c.collisionPosition.left+c.collisionWidth-d.width()-d.scrollLeft(),g=c.my[0]===”left”?-c.elemWidth:c.my[0]===”right”?c.elemWidth:0,h=c.at[0]===”left”?c.targetWidth:-c.targetWidth,i=-2*c.offset[0];b.left+=c.collisionPosition.left<0?g+h+i:f>0?g+h+i:0}},top:function(b,c){if(c.at[1]!==e){var d=a(window),f=c.collisionPosition.top+c.collisionHeight-d.height()-d.scrollTop(),g=c.my[1]===”top”?-c.elemHeight:c.my[1]===”bottom”?c.elemHeight:0,h=c.at[1]===”top”?c.targetHeight:-c.targetHeight,i=-2*c.offset[1];b.top+=c.collisionPosition.top<0?g+h+i:f>0?g+h+i:0}}}},a.offset.setOffset||(a.offset.setOffset=function(b,c){/static/.test(a.curCSS(b,”position”))&&(b.style.position=”relative”);var d=a(b),e=d.offset(),f=parseInt(a.curCSS(b,”top”,!0),10)||0,g=parseInt(a.curCSS(b,”left”,!0),10)||0,h={top:c.top-e.top+f,left:c.left-e.left+g};”using”in c?c.using.call(b,h):d.css(h)},a.fn.offset=function(b){var c=this[0];if(!c||!c.ownerDocument)return null;if(b)return this.each(function(){a.offset.setOffset(this,b)});return h.call(this)}),function(){var b=document.getElementsByTagName(“body”)[0],c=document.createElement(“div”),d,e,g,h,i;d=document.createElement(b?”div”:”body”),g={visibility:”hidden”,width:0,height:0,border:0,margin:0,background:”none”},b&&a.extend(g,{position:”absolute”,left:”-1000px”,top:”-1000px”});for(var j in g)d.style[j]=g[j];d.appendChild(c),e=b||document.documentElement,e.insertBefore(d,e.firstChild),c.style.cssText=”position: absolute; left: 10.7432222px; top: 10.432325px; height: 30px; width: 201px;”,h=a(c).offset(function(a,b){return b}).offset(),d.innerHTML=””,e.removeChild(d),i=h.top+h.left+(b?2e3:0),f.fractions=i>21&&i<22}()})(jQuery);/*
    * jQuery UI Draggable 1.8.18
    *
    * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * http://docs.jquery.com/UI/Draggables
    *
    * Depends:
    * jquery.ui.core.js
    * jquery.ui.mouse.js
    * jquery.ui.widget.js
    */(function(a,b){a.widget(“ui.draggable”,a.ui.mouse,{widgetEventPrefix:”drag”,options:{addClasses:!0,appendTo:”parent”,axis:!1,connectToSortable:!1,containment:!1,cursor:”auto”,cursorAt:!1,grid:!1,handle:!1,helper:”original”,iframeFix:!1,opacity:!1,refreshPositions:!1,revert:!1,revertDuration:500,scope:”default”,scroll:!0,scrollSensitivity:20,scrollSpeed:20,snap:!1,snapMode:”both”,snapTolerance:20,stack:!1,zIndex:!1},_create:function(){this.options.helper==”original”&&!/^(?:r|a|f)/.test(this.element.css(“position”))&&(this.element[0].style.position=”relative”),this.options.addClasses&&this.element.addClass(“ui-draggable”),this.options.disabled&&this.element.addClass(“ui-draggable-disabled”),this._mouseInit()},destroy:function(){if(!!this.element.data(“draggable”)){this.element.removeData(“draggable”).unbind(“.draggable”).removeClass(“ui-draggable ui-draggable-dragging ui-draggable-disabled”),this._mouseDestroy();return this}},_mouseCapture:function(b){var c=this.options;if(this.helper||c.disabled||a(b.target).is(“.ui-resizable-handle”))return!1;this.handle=this._getHandle(b);if(!this.handle)return!1;c.iframeFix&&a(c.iframeFix===!0?”iframe”:c.iframeFix).each(function(){a(\’

    \’).css({width:this.offsetWidth+”px”,height:this.offsetHeight+”px”,position:”absolute”,opacity:”0.001″,zIndex:1e3}).css(a(this).offset()).appendTo(“body”)});return!0},_mouseStart:function(b){var c=this.options;this.helper=this._createHelper(b),this._cacheHelperProportions(),a.ui.ddmanager&&(a.ui.ddmanager.current=this),this._cacheMargins(),this.cssPosition=this.helper.css(“position”),this.scrollParent=this.helper.scrollParent(),this.offset=this.positionAbs=this.element.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.originalPosition=this.position=this._generatePosition(b),this.originalPageX=b.pageX,this.originalPageY=b.pageY,c.cursorAt&&this._adjustOffsetFromHelper(c.cursorAt),c.containment&&this._setContainment();if(this._trigger(“start”,b)===!1){this._clear();return!1}this._cacheHelperProportions(),a.ui.ddmanager&&!c.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,b),this.helper.addClass(“ui-draggable-dragging”),this._mouseDrag(b,!0),a.ui.ddmanager&&a.ui.ddmanager.dragStart(this,b);return!0},_mouseDrag:function(b,c){this.position=this._generatePosition(b),this.positionAbs=this._convertPositionTo(“absolute”);if(!c){var d=this._uiHash();if(this._trigger(“drag”,b,d)===!1){this._mouseUp({});return!1}this.position=d.position}if(!this.options.axis||this.options.axis!=”y”)this.helper[0].style.left=this.position.left+”px”;if(!this.options.axis||this.options.axis!=”x”)this.helper[0].style.top=this.position.top+”px”;a.ui.ddmanager&&a.ui.ddmanager.drag(this,b);return!1},_mouseStop:function(b){var c=!1;a.ui.ddmanager&&!this.options.dropBehaviour&&(c=a.ui.ddmanager.drop(this,b)),this.dropped&&(c=this.dropped,this.dropped=!1);if((!this.element[0]||!this.element[0].parentNode)&&this.options.helper==”original”)return!1;if(this.options.revert==”invalid”&&!c||this.options.revert==”valid”&&c||this.options.revert===!0||a.isFunction(this.options.revert)&&this.options.revert.call(this.element,c)){var d=this;a(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){d._trigger(“stop”,b)!==!1&&d._clear()})}else this._trigger(“stop”,b)!==!1&&this._clear();return!1},_mouseUp:function(b){this.options.iframeFix===!0&&a(“div.ui-draggable-iframeFix”).each(function(){this.parentNode.removeChild(this)}),a.ui.ddmanager&&a.ui.ddmanager.dragStop(this,b);return a.ui.mouse.prototype._mouseUp.call(this,b)},cancel:function(){this.helper.is(“.ui-draggable-dragging”)?this._mouseUp({}):this._clear();return this},_getHandle:function(b){var c=!this.options.handle||!a(this.options.handle,this.element).length?!0:!1;a(this.options.handle,this.element).find(“*”).andSelf().each(function(){this==b.target&&(c=!0)});return c},_createHelper:function(b){var c=this.options,d=a.isFunction(c.helper)?a(c.helper.apply(this.element[0],[b])):c.helper==”clone”?this.element.clone().removeAttr(“id”):this.element;d.parents(“body”).length||d.appendTo(c.appendTo==”parent”?this.element[0].parentNode:c.appendTo),d[0]!=this.element[0]&&!/(fixed|absolute)/.test(d.css(“position”))&&d.css(“position”,”absolute”);return d},_adjustOffsetFromHelper:function(b){typeof b==”string”&&(b=b.split(” “)),a.isArray(b)&&(b={left:+b[0],top:+b[1]||0}),”left”in b&&(this.offset.click.left=b.left+this.margins.left),”right”in b&&(this.offset.click.left=this.helperProportions.width-b.right+this.margins.left),”top”in b&&(this.offset.click.top=b.top+this.margins.top),”bottom”in b&&(this.offset.click.top=this.helperProportions.height-b.bottom+this.margins.top)},_getParentOffset:function(){this.offsetParent=this.helper.offsetParent();var b=this.offsetParent.offset();this.cssPosition==”absolute”&&this.scrollParent[0]!=document&&a.ui.contains(this.scrollParent[0],this.offsetParent[0])&&(b.left+=this.scrollParent.scrollLeft(),b.top+=this.scrollParent.scrollTop());if(this.offsetParent[0]==document.body||this.offsetParent[0].tagName&&this.offsetParent[0].tagName.toLowerCase()==”html”&&a.browser.msie)b={top:0,left:0};return{top:b.top+(parseInt(this.offsetParent.css(“borderTopWidth”),10)||0),left:b.left+(parseInt(this.offsetParent.css(“borderLeftWidth”),10)||0)}},_getRelativeOffset:function(){if(this.cssPosition==”relative”){var a=this.element.position();return{top:a.top-(parseInt(this.helper.css(“top”),10)||0)+this.scrollParent.scrollTop(),left:a.left-(parseInt(this.helper.css(“left”),10)||0)+this.scrollParent.scrollLeft()}}return{top:0,left:0}},_cacheMargins:function(){this.margins={left:parseInt(this.element.css(“marginLeft”),10)||0,top:parseInt(this.element.css(“marginTop”),10)||0,right:parseInt(this.element.css(“marginRight”),10)||0,bottom:parseInt(this.element.css(“marginBottom”),10)||0}},_cacheHelperProportions:function(){this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()}},_setContainment:function(){var b=this.options;b.containment==”parent”&&(b.containment=this.helper[0].parentNode);if(b.containment==”document”||b.containment==”window”)this.containment=[b.containment==”document”?0:a(window).scrollLeft()-this.offset.relative.left-this.offset.parent.left,b.containment==”document”?0:a(window).scrollTop()-this.offset.relative.top-this.offset.parent.top,(b.containment==”document”?0:a(window).scrollLeft())+a(b.containment==”document”?document:window).width()-this.helperProportions.width-this.margins.left,(b.containment==”document”?0:a(window).scrollTop())+(a(b.containment==”document”?document:window).height()||document.body.parentNode.scrollHeight)-this.helperProportions.height-this.margins.top];if(!/^(document|window|parent)$/.test(b.containment)&&b.containment.constructor!=Array){var c=a(b.containment),d=c[0];if(!d)return;var e=c.offset(),f=a(d).css(“overflow”)!=”hidden”;this.containment=[(parseInt(a(d).css(“borderLeftWidth”),10)||0)+(parseInt(a(d).css(“paddingLeft”),10)||0),(parseInt(a(d).css(“borderTopWidth”),10)||0)+(parseInt(a(d).css(“paddingTop”),10)||0),(f?Math.max(d.scrollWidth,d.offsetWidth):d.offsetWidth)-(parseInt(a(d).css(“borderLeftWidth”),10)||0)-(parseInt(a(d).css(“paddingRight”),10)||0)-this.helperProportions.width-this.margins.left-this.margins.right,(f?Math.max(d.scrollHeight,d.offsetHeight):d.offsetHeight)-(parseInt(a(d).css(“borderTopWidth”),10)||0)-(parseInt(a(d).css(“paddingBottom”),10)||0)-this.helperProportions.height-this.margins.top-this.margins.bottom],this.relative_container=c}else b.containment.constructor==Array&&(this.containment=b.containment)},_convertPositionTo:function(b,c){c||(c=this.position);var d=b==”absolute”?1:-1,e=this.options,f=this.cssPosition==”absolute”&&(this.scrollParent[0]==document||!a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,g=/(html|body)/i.test(f[0].tagName);return{top:c.top+this.offset.relative.top*d+this.offset.parent.top*d-(a.browser.safari&&a.browser.version<526&&this.cssPosition==”fixed”?0:(this.cssPosition==”fixed”?-this.scrollParent.scrollTop():g?0:f.scrollTop())*d),left:c.left+this.offset.relative.left*d+this.offset.parent.left*d-(a.browser.safari&&a.browser.version<526&&this.cssPosition==”fixed”?0:(this.cssPosition==”fixed”?-this.scrollParent.scrollLeft():g?0:f.scrollLeft())*d)}},_generatePosition:function(b){var c=this.options,d=this.cssPosition==”absolute”&&(this.scrollParent[0]==document||!a.ui.contains(this.scrollParent[0],this.offsetParent[0]))?this.offsetParent:this.scrollParent,e=/(html|body)/i.test(d[0].tagName),f=b.pageX,g=b.pageY;if(this.originalPosition){var h;if(this.containment){if(this.relative_container){var i=this.relative_container.offset();h=[this.containment[0]+i.left,this.containment[1]+i.top,this.containment[2]+i.left,this.containment[3]+i.top]}else h=this.containment;b.pageX-this.offset.click.lefth[2]&&(f=h[2]+this.offset.click.left),b.pageY-this.offset.click.top>h[3]&&(g=h[3]+this.offset.click.top)}if(c.grid){var j=c.grid[1]?this.originalPageY+Math.round((g-this.originalPageY)/c.grid[1])*c.grid[1]:this.originalPageY;g=h?j-this.offset.click.toph[3]?j-this.offset.click.toph[2]?k-this.offset.click.left=0;k–){var l=d.snapElements[k].left,m=l+d.snapElements[k].width,n=d.snapElements[k].top,o=n+d.snapElements[k].height;if(!(l-f

    \’).css({position:this.element.css(“position”),width:this.element.outerWidth(),height:this.element.outerHeight(),top:this.element.css(“top”),left:this.element.css(“left”)})),this.element=this.element.parent().data(“resizable”,this.element.data(“resizable”)),this.elementIsWrapper=!0,this.element.css({marginLeft:this.originalElement.css(“marginLeft”),marginTop:this.originalElement.css(“marginTop”),marginRight:this.originalElement.css(“marginRight”),marginBottom:this.originalElement.css(“marginBottom”)}),this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0}),this.originalResizeStyle=this.originalElement.css(“resize”),this.originalElement.css(“resize”,”none”),this._proportionallyResizeElements.push(this.originalElement.css({position:”static”,zoom:1,display:”block”})),this.originalElement.css({margin:this.originalElement.css(“margin”)}),this._proportionallyResize()),this.handles=c.handles||(a(“.ui-resizable-handle”,this.element).length?{n:”.ui-resizable-n”,e:”.ui-resizable-e”,s:”.ui-resizable-s”,w:”.ui-resizable-w”,se:”.ui-resizable-se”,sw:”.ui-resizable-sw”,ne:”.ui-resizable-ne”,nw:”.ui-resizable-nw”}:”e,s,se”);if(this.handles.constructor==String){this.handles==”all”&&(this.handles=”n,e,s,w,se,sw,ne,nw”);var d=this.handles.split(“,”);this.handles={};for(var e=0;e\’);/sw|se|ne|nw/.test(f)&&h.css({zIndex:++c.zIndex}),”se”==f&&h.addClass(“ui-icon ui-icon-gripsmall-diagonal-se”),this.handles[f]=”.ui-resizable-“+f,this.element.append(h)}}this._renderAxis=function(b){b=b||this.element;for(var c in this.handles){this.handles[c].constructor==String&&(this.handles[c]=a(this.handles[c],this.element).show());if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var d=a(this.handles[c],this.element),e=0;e=/sw|ne|nw|se|n|s/.test(c)?d.outerHeight():d.outerWidth();var f=[“padding”,/ne|nw|n/.test(c)?”Top”:/se|sw|s/.test(c)?”Bottom”:/^e$/.test(c)?”Right”:”Left”].join(“”);b.css(f,e),this._proportionallyResize()}if(!a(this.handles[c]).length)continue}},this._renderAxis(this.element),this._handles=a(“.ui-resizable-handle”,this.element).disableSelection(),this._handles.mouseover(function(){if(!b.resizing){if(this.className)var a=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);b.axis=a&&a[1]?a[1]:”se”}}),c.autoHide&&(this._handles.hide(),a(this.element).addClass(“ui-resizable-autohide”).hover(function(){c.disabled||(a(this).removeClass(“ui-resizable-autohide”),b._handles.show())},function(){c.disabled||b.resizing||(a(this).addClass(“ui-resizable-autohide”),b._handles.hide())})),this._mouseInit()},destroy:function(){this._mouseDestroy();var b=function(b){a(b).removeClass(“ui-resizable ui-resizable-disabled ui-resizable-resizing”).removeData(“resizable”).unbind(“.resizable”).find(“.ui-resizable-handle”).remove()};if(this.elementIsWrapper){b(this.element);var c=this.element;c.after(this.originalElement.css({position:c.css(“position”),width:c.outerWidth(),height:c.outerHeight(),top:c.css(“top”),left:c.css(“left”)})).remove()}this.originalElement.css(“resize”,this.originalResizeStyle),b(this.originalElement);return this},_mouseCapture:function(b){var c=!1;for(var d in this.handles)a(this.handles[d])[0]==b.target&&(c=!0);return!this.options.disabled&&c},_mouseStart:function(b){var d=this.options,e=this.element.position(),f=this.element;this.resizing=!0,this.documentScroll={top:a(document).scrollTop(),left:a(document).scrollLeft()},(f.is(“.ui-draggable”)||/absolute/.test(f.css(“position”)))&&f.css({position:”absolute”,top:e.top,left:e.left}),this._renderProxy();var g=c(this.helper.css(“left”)),h=c(this.helper.css(“top”));d.containment&&(g+=a(d.containment).scrollLeft()||0,h+=a(d.containment).scrollTop()||0),this.offset=this.helper.offset(),this.position={left:g,top:h},this.size=this._helper?{width:f.outerWidth(),height:f.outerHeight()}:{width:f.width(),height:f.height()},this.originalSize=this._helper?{width:f.outerWidth(),height:f.outerHeight()}:{width:f.width(),height:f.height()},this.originalPosition={left:g,top:h},this.sizeDiff={width:f.outerWidth()-f.width(),height:f.outerHeight()-f.height()},this.originalMousePosition={left:b.pageX,top:b.pageY},this.aspectRatio=typeof d.aspectRatio==”number”?d.aspectRatio:this.originalSize.width/this.originalSize.height||1;var i=a(“.ui-resizable-“+this.axis).css(“cursor”);a(“body”).css(“cursor”,i==”auto”?this.axis+”-resize”:i),f.addClass(“ui-resizable-resizing”),this._propagate(“start”,b);return!0},_mouseDrag:function(b){var c=this.helper,d=this.options,e={},f=this,g=this.originalMousePosition,h=this.axis,i=b.pageX-g.left||0,j=b.pageY-g.top||0,k=this._change[h];if(!k)return!1;var l=k.apply(this,[b,i,j]),m=a.browser.msie&&a.browser.version<7,n=this.sizeDiff;this._updateVirtualBoundaries(b.shiftKey);if(this._aspectRatio||b.shiftKey)l=this._updateRatio(l,b);l=this._respectSize(l,b),this._propagate(“resize”,b),c.css({top:this.position.top+”px”,left:this.position.left+”px”,width:this.size.width+”px”,height:this.size.height+”px”}),!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize(),this._updateCache(l),this._trigger(“resize”,b,this.ui());return!1},_mouseStop:function(b){this.resizing=!1;var c=this.options,d=this;if(this._helper){var e=this._proportionallyResizeElements,f=e.length&&/textarea/i.test(e[0].nodeName),g=f&&a.ui.hasScroll(e[0],”left”)?0:d.sizeDiff.height,h=f?0:d.sizeDiff.width,i={width:d.helper.width()-h,height:d.helper.height()-g},j=parseInt(d.element.css(“left”),10)+(d.position.left-d.originalPosition.left)||null,k=parseInt(d.element.css(“top”),10)+(d.position.top-d.originalPosition.top)||null;c.animate||this.element.css(a.extend(i,{top:k,left:j})),d.helper.height(d.size.height),d.helper.width(d.size.width),this._helper&&!c.animate&&this._proportionallyResize()}a(“body”).css(“cursor”,”auto”),this.element.removeClass(“ui-resizable-resizing”),this._propagate(“stop”,b),this._helper&&this.helper.remove();return!1},_updateVirtualBoundaries:function(a){var b=this.options,c,e,f,g,h;h={minWidth:d(b.minWidth)?b.minWidth:0,maxWidth:d(b.maxWidth)?b.maxWidth:Infinity,minHeight:d(b.minHeight)?b.minHeight:0,maxHeight:d(b.maxHeight)?b.maxHeight:Infinity};if(this._aspectRatio||a)c=h.minHeight*this.aspectRatio,f=h.minWidth/this.aspectRatio,e=h.maxHeight*this.aspectRatio,g=h.maxWidth/this.aspectRatio,c>h.minWidth&&(h.minWidth=c),f>h.minHeight&&(h.minHeight=f),ea.width,k=d(a.height)&&e.minHeight&&e.minHeight>a.height;j&&(a.width=e.minWidth),k&&(a.height=e.minHeight),h&&(a.width=e.maxWidth),i&&(a.height=e.maxHeight);var l=this.originalPosition.left+this.originalSize.width,m=this.position.top+this.size.height,n=/sw|nw|w/.test(g),o=/nw|ne|n/.test(g);j&&n&&(a.left=l-e.minWidth),h&&n&&(a.left=l-e.maxWidth),k&&o&&(a.top=m-e.minHeight),i&&o&&(a.top=m-e.maxHeight);var p=!a.width&&!a.height;p&&!a.left&&a.top?a.top=null:p&&!a.top&&a.left&&(a.left=null);return a},_proportionallyResize:function(){var b=this.options;if(!!this._proportionallyResizeElements.length){var c=this.helper||this.element;for(var d=0;d\’);var d=a.browser.msie&&a.browser.version<7,e=d?1:0,f=d?2:-1;this.helper.addClass(this._helper).css({width:this.element.outerWidth()+f,height:this.element.outerHeight()+f,position:”absolute”,left:this.elementOffset.left-e+”px”,top:this.elementOffset.top-e+”px”,zIndex:++c.zIndex}),this.helper.appendTo(“body”).disableSelection()}else this.helper=this.element},_change:{e:function(a,b,c){return{width:this.originalSize.width+b}},w:function(a,b,c){var d=this.options,e=this.originalSize,f=this.originalPosition;return{left:f.left+b,width:e.width-b}},n:function(a,b,c){var d=this.options,e=this.originalSize,f=this.originalPosition;return{top:f.top+c,height:e.height-c}},s:function(a,b,c){return{height:this.originalSize.height+c}},se:function(b,c,d){return a.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[b,c,d]))},sw:function(b,c,d){return a.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[b,c,d]))},ne:function(b,c,d){return a.extend(this._change.n.apply(this,arguments),this._change.e.apply(this,[b,c,d]))},nw:function(b,c,d){return a.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[b,c,d]))}},_propagate:function(b,c){a.ui.plugin.call(this,b,[c,this.ui()]),b!=”resize”&&this._trigger(b,c,this.ui())},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}}),a.extend(a.ui.resizable,{version:”1.8.18″}),a.ui.plugin.add(“resizable”,”alsoResize”,{start:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=function(b){a(b).each(function(){var b=a(this);b.data(“resizable-alsoresize”,{width:parseInt(b.width(),10),height:parseInt(b.height(),10),left:parseInt(b.css(“left”),10),top:parseInt(b.css(“top”),10)})})};typeof e.alsoResize==”object”&&!e.alsoResize.parentNode?e.alsoResize.length?(e.alsoResize=e.alsoResize[0],f(e.alsoResize)):a.each(e.alsoResize,function(a){f(a)}):f(e.alsoResize)},resize:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d.originalSize,g=d.originalPosition,h={height:d.size.height-f.height||0,width:d.size.width-f.width||0,top:d.position.top-g.top||0,left:d.position.left-g.left||0},i=function(b,d){a(b).each(function(){var b=a(this),e=a(this).data(“resizable-alsoresize”),f={},g=d&&d.length?d:b.parents(c.originalElement[0]).length?[“width”,”height”]:[“width”,”height”,”top”,”left”];a.each(g,function(a,b){var c=(e[b]||0)+(h[b]||0);c&&c>=0&&(f[b]=c||null)}),b.css(f)})};typeof e.alsoResize==”object”&&!e.alsoResize.nodeType?a.each(e.alsoResize,function(a,b){i(a,b)}):i(e.alsoResize)},stop:function(b,c){a(this).removeData(“resizable-alsoresize”)}}),a.ui.plugin.add(“resizable”,”animate”,{stop:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d._proportionallyResizeElements,g=f.length&&/textarea/i.test(f[0].nodeName),h=g&&a.ui.hasScroll(f[0],”left”)?0:d.sizeDiff.height,i=g?0:d.sizeDiff.width,j={width:d.size.width-i,height:d.size.height-h},k=parseInt(d.element.css(“left”),10)+(d.position.left-d.originalPosition.left)||null,l=parseInt(d.element.css(“top”),10)+(d.position.top-d.originalPosition.top)||null;d.element.animate(a.extend(j,l&&k?{top:l,left:k}:{}),{duration:e.animateDuration,easing:e.animateEasing,step:function(){var c={width:parseInt(d.element.css(“width”),10),height:parseInt(d.element.css(“height”),10),top:parseInt(d.element.css(“top”),10),left:parseInt(d.element.css(“left”),10)};f&&f.length&&a(f[0]).css({width:c.width,height:c.height}),d._updateCache(c),d._propagate(“resize”,b)}})}}),a.ui.plugin.add(“resizable”,”containment”,{start:function(b,d){var e=a(this).data(“resizable”),f=e.options,g=e.element,h=f.containment,i=h instanceof a?h.get(0):/parent/.test(h)?g.parent().get(0):h;if(!!i){e.containerElement=a(i);if(/document/.test(h)||h==document)e.containerOffset={left:0,top:0},e.containerPosition={left:0,top:0},e.parentData={element:a(document),left:0,top:0,width:a(document).width(),height:a(document).height()||document.body.parentNode.scrollHeight};else{var j=a(i),k=[];a([“Top”,”Right”,”Left”,”Bottom”]).each(function(a,b){k[a]=c(j.css(“padding”+b))}),e.containerOffset=j.offset(),e.containerPosition=j.position(),e.containerSize={height:j.innerHeight()-k[3],width:j.innerWidth()-k[1]};var l=e.containerOffset,m=e.containerSize.height,n=e.containerSize.width,o=a.ui.hasScroll(i,”left”)?i.scrollWidth:n,p=a.ui.hasScroll(i)?i.scrollHeight:m;e.parentData={element:i,left:l.left,top:l.top,width:o,height:p}}}},resize:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d.containerSize,g=d.containerOffset,h=d.size,i=d.position,j=d._aspectRatio||b.shiftKey,k={top:0,left:0},l=d.containerElement;l[0]!=document&&/static/.test(l.css(“position”))&&(k=g),i.left<(d._helper?g.left:0)&&(d.size.width=d.size.width+(d._helper?d.position.left-g.left:d.position.left-k.left),j&&(d.size.height=d.size.width/e.aspectRatio),d.position.left=e.helper?g.left:0),i.top<(d._helper?g.top:0)&&(d.size.height=d.size.height+(d._helper?d.position.top-g.top:d.position.top),j&&(d.size.width=d.size.height*e.aspectRatio),d.position.top=d._helper?g.top:0),d.offset.left=d.parentData.left+d.position.left,d.offset.top=d.parentData.top+d.position.top;var m=Math.abs((d._helper?d.offset.left-k.left:d.offset.left-k.left)+d.sizeDiff.width),n=Math.abs((d._helper?d.offset.top-k.top:d.offset.top-g.top)+d.sizeDiff.height),o=d.containerElement.get(0)==d.element.parent().get(0),p=/relative|absolute/.test(d.containerElement.css(“position”));o&&p&&(m-=d.parentData.left),m+d.size.width>=d.parentData.width&&(d.size.width=d.parentData.width-m,j&&(d.size.height=d.size.width/d.aspectRatio)),n+d.size.height>=d.parentData.height&&(d.size.height=d.parentData.height-n,j&&(d.size.width=d.size.height*d.aspectRatio))},stop:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d.position,g=d.containerOffset,h=d.containerPosition,i=d.containerElement,j=a(d.helper),k=j.offset(),l=j.outerWidth()-d.sizeDiff.width,m=j.outerHeight()-d.sizeDiff.height;d._helper&&!e.animate&&/relative/.test(i.css(“position”))&&a(this).css({left:k.left-h.left-g.left,width:l,height:m}),d._helper&&!e.animate&&/static/.test(i.css(“position”))&&a(this).css({left:k.left-h.left-g.left,width:l,height:m})}}),a.ui.plugin.add(“resizable”,”ghost”,{start:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d.size;d.ghost=d.originalElement.clone(),d.ghost.css({opacity:.25,display:”block”,position:”relative”,height:f.height,width:f.width,margin:0,left:0,top:0}).addClass(“ui-resizable-ghost”).addClass(typeof e.ghost==”string”?e.ghost:””),d.ghost.appendTo(d.helper)},resize:function(b,c){var d=a(this).data(“resizable”),e=d.options;d.ghost&&d.ghost.css({position:”relative”,height:d.size.height,width:d.size.width})},stop:function(b,c){var d=a(this).data(“resizable”),e=d.options;d.ghost&&d.helper&&d.helper.get(0).removeChild(d.ghost.get(0))}}),a.ui.plugin.add(“resizable”,”grid”,{resize:function(b,c){var d=a(this).data(“resizable”),e=d.options,f=d.size,g=d.originalSize,h=d.originalPosition,i=d.axis,j=e._aspectRatio||b.shiftKey;e.grid=typeof e.grid==”number”?[e.grid,e.grid]:e.grid;var k=Math.round((f.width-g.width)/(e.grid[0]||1))*(e.grid[0]||1),l=Math.round((f.height-g.height)/(e.grid[1]||1))*(e.grid[1]||1);/^(se|s|e)$/.test(i)?(d.size.width=g.width+k,d.size.height=g.height+l):/^(ne)$/.test(i)?(d.size.width=g.width+k,d.size.height=g.height+l,d.position.top=h.top-l):/^(sw)$/.test(i)?(d.size.width=g.width+k,d.size.height=g.height+l,d.position.left=h.left-k):(d.size.width=g.width+k,d.size.height=g.height+l,d.position.top=h.top-l,d.position.left=h.left-k)}});var c=function(a){return parseInt(a,10)||0},d=function(a){return!isNaN(parseInt(a,10))}})(jQuery);/*
    * jQuery UI Button 1.8.18
    *
    * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * http://docs.jquery.com/UI/Button
    *
    * Depends:
    * jquery.ui.core.js
    * jquery.ui.widget.js
    */(function(a,b){var c,d,e,f,g=”ui-button ui-widget ui-state-default ui-corner-all”,h=”ui-state-hover ui-state-active “,i=”ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only”,j=function(){var b=a(this).find(“:ui-button”);setTimeout(function(){b.button(“refresh”)},1)},k=function(b){var c=b.name,d=b.form,e=a([]);c&&(d?e=a(d).find(“[name=\'”+c+”\’]”):e=a(“[name=\'”+c+”\’]”,b.ownerDocument).filter(function(){return!this.form}));return e};a.widget(“ui.button”,{options:{disabled:null,text:!0,label:null,icons:{primary:null,secondary:null}},_create:function(){this.element.closest(“form”).unbind(“reset.button”).bind(“reset.button”,j),typeof this.options.disabled!=”boolean”?this.options.disabled=!!this.element.propAttr(“disabled”):this.element.propAttr(“disabled”,this.options.disabled),this._determineButtonType(),this.hasTitle=!!this.buttonElement.attr(“title”);var b=this,h=this.options,i=this.type===”checkbox”||this.type===”radio”,l=”ui-state-hover”+(i?””:” ui-state-active”),m=”ui-state-focus”;h.label===null&&(h.label=this.buttonElement.html()),this.buttonElement.addClass(g).attr(“role”,”button”).bind(“mouseenter.button”,function(){h.disabled||(a(this).addClass(“ui-state-hover”),this===c&&a(this).addClass(“ui-state-active”))}).bind(“mouseleave.button”,function(){h.disabled||a(this).removeClass(l)}).bind(“click.button”,function(a){h.disabled&&(a.preventDefault(),a.stopImmediatePropagation())}),this.element.bind(“focus.button”,function(){b.buttonElement.addClass(m)}).bind(“blur.button”,function(){b.buttonElement.removeClass(m)}),i&&(this.element.bind(“change.button”,function(){f||b.refresh()}),this.buttonElement.bind(“mousedown.button”,function(a){h.disabled||(f=!1,d=a.pageX,e=a.pageY)}).bind(“mouseup.button”,function(a){!h.disabled&&(d!==a.pageX||e!==a.pageY)&&(f=!0)})),this.type===”checkbox”?this.buttonElement.bind(“click.button”,function(){if(h.disabled||f)return!1;a(this).toggleClass(“ui-state-active”),b.buttonElement.attr(“aria-pressed”,b.element[0].checked)}):this.type===”radio”?this.buttonElement.bind(“click.button”,function(){if(h.disabled||f)return!1;a(this).addClass(“ui-state-active”),b.buttonElement.attr(“aria-pressed”,”true”);var c=b.element[0];k(c).not(c).map(function(){return a(this).button(“widget”)[0]}).removeClass(“ui-state-active”).attr(“aria-pressed”,”false”)}):(this.buttonElement.bind(“mousedown.button”,function(){if(h.disabled)return!1;a(this).addClass(“ui-state-active”),c=this,a(document).one(“mouseup”,function(){c=null})}).bind(“mouseup.button”,function(){if(h.disabled)return!1;a(this).removeClass(“ui-state-active”)}).bind(“keydown.button”,function(b){if(h.disabled)return!1;(b.keyCode==a.ui.keyCode.SPACE||b.keyCode==a.ui.keyCode.ENTER)&&a(this).addClass(“ui-state-active”)}).bind(“keyup.button”,function(){a(this).removeClass(“ui-state-active”)}),this.buttonElement.is(“a”)&&this.buttonElement.keyup(function(b){b.keyCode===a.ui.keyCode.SPACE&&a(this).click()})),this._setOption(“disabled”,h.disabled),this._resetButton()},_determineButtonType:function(){this.element.is(“:checkbox”)?this.type=”checkbox”:this.element.is(“:radio”)?this.type=”radio”:this.element.is(“input”)?this.type=”input”:this.type=”button”;if(this.type===”checkbox”||this.type===”radio”){var a=this.element.parents().filter(“:last”),b=”label[for=\'”+this.element.attr(“id”)+”\’]”;this.buttonElement=a.find(b),this.buttonElement.length||(a=a.length?a.siblings():this.element.siblings(),this.buttonElement=a.filter(b),this.buttonElement.length||(this.buttonElement=a.find(b))),this.element.addClass(“ui-helper-hidden-accessible”);var c=this.element.is(“:checked”);c&&this.buttonElement.addClass(“ui-state-active”),this.buttonElement.attr(“aria-pressed”,c)}else this.buttonElement=this.element},widget:function(){return this.buttonElement},destroy:function(){this.element.removeClass(“ui-helper-hidden-accessible”),this.buttonElement.removeClass(g+” “+h+” “+i).removeAttr(“role”).removeAttr(“aria-pressed”).html(this.buttonElement.find(“.ui-button-text”).html()),this.hasTitle||this.buttonElement.removeAttr(“title”),a.Widget.prototype.destroy.call(this)},_setOption:function(b,c){a.Widget.prototype._setOption.apply(this,arguments);b===”disabled”?c?this.element.propAttr(“disabled”,!0):this.element.propAttr(“disabled”,!1):this._resetButton()},refresh:function(){var b=this.element.is(“:disabled”);b!==this.options.disabled&&this._setOption(“disabled”,b),this.type===”radio”?k(this.element[0]).each(function(){a(this).is(“:checked”)?a(this).button(“widget”).addClass(“ui-state-active”).attr(“aria-pressed”,”true”):a(this).button(“widget”).removeClass(“ui-state-active”).attr(“aria-pressed”,”false”)}):this.type===”checkbox”&&(this.element.is(“:checked”)?this.buttonElement.addClass(“ui-state-active”).attr(“aria-pressed”,”true”):this.buttonElement.removeClass(“ui-state-active”).attr(“aria-pressed”,”false”))},_resetButton:function(){if(this.type===”input”)this.options.label&&this.element.val(this.options.label);else{var b=this.buttonElement.removeClass(i),c=a(““,this.element[0].ownerDocument).addClass(“ui-button-text”).html(this.options.label).appendTo(b.empty()).text(),d=this.options.icons,e=d.primary&&d.secondary,f=[];d.primary||d.secondary?(this.options.text&&f.push(“ui-button-text-icon”+(e?”s”:d.primary?”-primary”:”-secondary”)),d.primary&&b.prepend(““),d.secondary&&b.append(““),this.options.text||(f.push(e?”ui-button-icons-only”:”ui-button-icon-only”),this.hasTitle||b.attr(“title”,c))):f.push(“ui-button-text-only”),b.addClass(f.join(” “))}}}),a.widget(“ui.buttonset”,{options:{items:”:button, :submit, :reset, :checkbox, :radio, a, :data(button)”},_create:function(){this.element.addClass(“ui-buttonset”)},_init:function(){this.refresh()},_setOption:function(b,c){b===”disabled”&&this.buttons.button(“option”,b,c),a.Widget.prototype._setOption.apply(this,arguments)},refresh:function(){var b=this.element.css(“direction”)===”rtl”;this.buttons=this.element.find(this.options.items).filter(“:ui-button”).button(“refresh”).end().not(“:ui-button”).button().end().map(function(){return a(this).button(“widget”)[0]}).removeClass(“ui-corner-all ui-corner-left ui-corner-right”).filter(“:first”).addClass(b?”ui-corner-right”:”ui-corner-left”).end().filter(“:last”).addClass(b?”ui-corner-left”:”ui-corner-right”).end().end()},destroy:function(){this.element.removeClass(“ui-buttonset”),this.buttons.map(function(){return a(this).button(“widget”)[0]}).removeClass(“ui-corner-left ui-corner-right”).end().button(“destroy”),a.Widget.prototype.destroy.call(this)}})})(jQuery);/*
    * jQuery UI Dialog 1.8.18
    *
    * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * http://docs.jquery.com/UI/Dialog
    *
    * Depends:
    * jquery.ui.core.js
    * jquery.ui.widget.js
    * jquery.ui.button.js
    * jquery.ui.draggable.js
    * jquery.ui.mouse.js
    * jquery.ui.position.js
    * jquery.ui.resizable.js
    */(function(a,b){var c=”ui-dialog ui-widget ui-widget-content ui-corner-all “,d={buttons:!0,height:!0,maxHeight:!0,maxWidth:!0,minHeight:!0,minWidth:!0,width:!0},e={maxHeight:!0,maxWidth:!0,minHeight:!0,minWidth:!0},f=a.attrFn||{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0,click:!0};a.widget(“ui.dialog”,{options:{autoOpen:!0,buttons:{},closeOnEscape:!0,closeText:”close”,dialogClass:””,draggable:!0,hide:null,height:”auto”,maxHeight:!1,maxWidth:!1,minHeight:150,minWidth:150,modal:!1,position:{my:”center”,at:”center”,collision:”fit”,using:function(b){var c=a(this).css(b).offset().top;c<0&&a(this).css(“top”,b.top-c)}},resizable:!0,show:null,stack:!0,title:””,width:300,zIndex:1e3},_create:function(){this.originalTitle=this.element.attr(“title”),typeof this.originalTitle!=”string”&&(this.originalTitle=””),this.options.title=this.options.title||this.originalTitle;var b=this,d=b.options,e=d.title||” “,f=a.ui.dialog.getTitleId(b.element),g=(b.uiDialog=a(“

    “)).appendTo(document.body).hide().addClass(c+d.dialogClass).css({zIndex:d.zIndex}).attr(“tabIndex”,-1).css(“outline”,0).keydown(function(c){d.closeOnEscape&&!c.isDefaultPrevented()&&c.keyCode&&c.keyCode===a.ui.keyCode.ESCAPE&&(b.close(c),c.preventDefault())}).attr({role:”dialog”,”aria-labelledby”:f}).mousedown(function(a){b.moveToTop(!1,a)}),h=b.element.show().removeAttr(“title”).addClass(“ui-dialog-content ui-widget-content”).appendTo(g),i=(b.uiDialogTitlebar=a(“

    “)).addClass(“ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix”).prependTo(g),j=a(\’\’).addClass(“ui-dialog-titlebar-close ui-corner-all”).attr(“role”,”button”).hover(function(){j.addClass(“ui-state-hover”)},function(){j.removeClass(“ui-state-hover”)}).focus(function(){j.addClass(“ui-state-focus”)}).blur(function(){j.removeClass(“ui-state-focus”)}).click(function(a){b.close(a);return!1}).appendTo(i),k=(b.uiDialogTitlebarCloseText=a(““)).addClass(“ui-icon ui-icon-closethick”).text(d.closeText).appendTo(j),l=a(““).addClass(“ui-dialog-title”).attr(“id”,f).html(e).prependTo(i);a.isFunction(d.beforeclose)&&!a.isFunction(d.beforeClose)&&(d.beforeClose=d.beforeclose),i.find(“*”).add(i).disableSelection(),d.draggable&&a.fn.draggable&&b._makeDraggable(),d.resizable&&a.fn.resizable&&b._makeResizable(),b._createButtons(d.buttons),b._isOpen=!1,a.fn.bgiframe&&g.bgiframe()},_init:function(){this.options.autoOpen&&this.open()},destroy:function(){var a=this;a.overlay&&a.overlay.destroy(),a.uiDialog.hide(),a.element.unbind(“.dialog”).removeData(“dialog”).removeClass(“ui-dialog-content ui-widget-content”).hide().appendTo(“body”),a.uiDialog.remove(),a.originalTitle&&a.element.attr(“title”,a.originalTitle);return a},widget:function(){return this.uiDialog},close:function(b){var c=this,d,e;if(!1!==c._trigger(“beforeClose”,b)){c.overlay&&c.overlay.destroy(),c.uiDialog.unbind(“keypress.ui-dialog”),c._isOpen=!1,c.options.hide?c.uiDialog.hide(c.options.hide,function(){c._trigger(“close”,b)}):(c.uiDialog.hide(),c._trigger(“close”,b)),a.ui.dialog.overlay.resize(),c.options.modal&&(d=0,a(“.ui-dialog”).each(function(){this!==c.uiDialog[0]&&(e=a(this).css(“z-index”),isNaN(e)||(d=Math.max(d,e)))}),a.ui.dialog.maxZ=d);return c}},isOpen:function(){return this._isOpen},moveToTop:function(b,c){var d=this,e=d.options,f;if(e.modal&&!b||!e.stack&&!e.modal)return d._trigger(“focus”,c);e.zIndex>a.ui.dialog.maxZ&&(a.ui.dialog.maxZ=e.zIndex),d.overlay&&(a.ui.dialog.maxZ+=1,d.overlay.$el.css(“z-index”,a.ui.dialog.overlay.maxZ=a.ui.dialog.maxZ)),f={scrollTop:d.element.scrollTop(),scrollLeft:d.element.scrollLeft()},a.ui.dialog.maxZ+=1,d.uiDialog.css(“z-index”,a.ui.dialog.maxZ),d.element.attr(f),d._trigger(“focus”,c);return d},open:function(){if(!this._isOpen){var b=this,c=b.options,d=b.uiDialog;b.overlay=c.modal?new a.ui.dialog.overlay(b):null,b._size(),b._position(c.position),d.show(c.show),b.moveToTop(!0),c.modal&&d.bind(“keydown.ui-dialog”,function(b){if(b.keyCode===a.ui.keyCode.TAB){var c=a(“:tabbable”,this),d=c.filter(“:first”),e=c.filter(“:last”);if(b.target===e[0]&&!b.shiftKey){d.focus(1);return!1}if(b.target===d[0]&&b.shiftKey){e.focus(1);return!1}}}),a(b.element.find(“:tabbable”).get().concat(d.find(“.ui-dialog-buttonpane :tabbable”).get().concat(d.get()))).eq(0).focus(),b._isOpen=!0,b._trigger(“open”);return b}},_createButtons:function(b){var c=this,d=!1,e=a(“

    “).addClass(“ui-dialog-buttonpane ui-widget-content ui-helper-clearfix”),g=a(“

    “).addClass(“ui-dialog-buttonset”).appendTo(e);c.uiDialog.find(“.ui-dialog-buttonpane”).remove(),typeof b==”object”&&b!==null&&a.each(b,function(){return!(d=!0)}),d&&(a.each(b,function(b,d){d=a.isFunction(d)?{click:d,text:b}:d;var e=a(\’\’).click(function(){d.click.apply(c.element[0],arguments)}).appendTo(g);a.each(d,function(a,b){a!==”click”&&(a in f?e[a](b):e.attr(a,b))}),a.fn.button&&e.button()}),e.appendTo(c.uiDialog))},_makeDraggable:function(){function f(a){return{position:a.position,offset:a.offset}}var b=this,c=b.options,d=a(document),e;b.uiDialog.draggable({cancel:”.ui-dialog-content, .ui-dialog-titlebar-close”,handle:”.ui-dialog-titlebar”,containment:”document”,start:function(d,g){e=c.height===”auto”?”auto”:a(this).height(),a(this).height(a(this).height()).addClass(“ui-dialog-dragging”),b._trigger(“dragStart”,d,f(g))},drag:function(a,c){b._trigger(“drag”,a,f(c))},stop:function(g,h){c.position=[h.position.left-d.scrollLeft(),h.position.top-d.scrollTop()],a(this).removeClass(“ui-dialog-dragging”).height(e),b._trigger(“dragStop”,g,f(h)),a.ui.dialog.overlay.resize()}})},_makeResizable:function(c){function h(a){return{originalPosition:a.originalPosition,originalSize:a.originalSize,position:a.position,size:a.size}}c=c===b?this.options.resizable:c;var d=this,e=d.options,f=d.uiDialog.css(“position”),g=typeof c==”string”?c:”n,e,s,w,se,sw,ne,nw”;d.uiDialog.resizable({cancel:”.ui-dialog-content”,containment:”document”,alsoResize:d.element,maxWidth:e.maxWidth,maxHeight:e.maxHeight,minWidth:e.minWidth,minHeight:d._minHeight(),handles:g,start:function(b,c){a(this).addClass(“ui-dialog-resizing”),d._trigger(“resizeStart”,b,h(c))},resize:function(a,b){d._trigger(“resize”,a,h(b))},stop:function(b,c){a(this).removeClass(“ui-dialog-resizing”),e.height=a(this).height(),e.width=a(this).width(),d._trigger(“resizeStop”,b,h(c)),a.ui.dialog.overlay.resize()}}).css(“position”,f).find(“.ui-resizable-se”).addClass(“ui-icon ui-icon-grip-diagonal-se”)},_minHeight:function(){var a=this.options;return a.height===”auto”?a.minHeight:Math.min(a.minHeight,a.height)},_position:function(b){var c=[],d=[0,0],e;if(b){if(typeof b==”string”||typeof b==”object”&&”0″in b)c=b.split?b.split(” “):[b[0],b[1]],c.length===1&&(c[1]=c[0]),a.each([“left”,”top”],function(a,b){+c[a]===c[a]&&(d[a]=c[a],c[a]=b)}),b={my:c.join(” “),at:c.join(” “),offset:d.join(” “)};b=a.extend({},a.ui.dialog.prototype.options.position,b)}else b=a.ui.dialog.prototype.options.position;e=this.uiDialog.is(“:visible”),e||this.uiDialog.show(),this.uiDialog.css({top:0,left:0}).position(a.extend({of:window},b)),e||this.uiDialog.hide()},_setOptions:function(b){var c=this,f={},g=!1;a.each(b,function(a,b){c._setOption(a,b),a in d&&(g=!0),a in e&&(f[a]=b)}),g&&this._size(),this.uiDialog.is(“:data(resizable)”)&&this.uiDialog.resizable(“option”,f)},_setOption:function(b,d){var e=this,f=e.uiDialog;switch(b){case”beforeclose”:b=”beforeClose”;break;case”buttons”:e._createButtons(d);break;case”closeText”:e.uiDialogTitlebarCloseText.text(“”+d);break;case”dialogClass”:f.removeClass(e.options.dialogClass).addClass(c+d);break;case”disabled”:d?f.addClass(“ui-dialog-disabled”):f.removeClass(“ui-dialog-disabled”);break;case”draggable”:var g=f.is(“:data(draggable)”);g&&!d&&f.draggable(“destroy”),!g&&d&&e._makeDraggable();break;case”position”:e._position(d);break;case”resizable”:var h=f.is(“:data(resizable)”);h&&!d&&f.resizable(“destroy”),h&&typeof d==”string”&&f.resizable(“option”,”handles”,d),!h&&d!==!1&&e._makeResizable(d);break;case”title”:a(“.ui-dialog-title”,e.uiDialogTitlebar).html(“”+(d||” “))}a.Widget.prototype._setOption.apply(e,arguments)},_size:function(){var b=this.options,c,d,e=this.uiDialog.is(“:visible”);this.element.show().css({width:”auto”,minHeight:0,height:0}),b.minWidth>b.width&&(b.width=b.minWidth),c=this.uiDialog.css({height:”auto”,width:b.width}).height(),d=Math.max(0,b.minHeight-c);if(b.height===”auto”)if(a.support.minHeight)this.element.css({minHeight:d,height:”auto”});else{this.uiDialog.show();var f=this.element.css(“height”,”auto”).height();e||this.uiDialog.hide(),this.element.height(Math.max(f,d))}else this.element.height(Math.max(b.height-c,0));this.uiDialog.is(“:data(resizable)”)&&this.uiDialog.resizable(“option”,”minHeight”,this._minHeight())}}),a.extend(a.ui.dialog,{version:”1.8.18″,uuid:0,maxZ:0,getTitleId:function(a){var b=a.attr(“id”);b||(this.uuid+=1,b=this.uuid);return”ui-dialog-title-“+b},overlay:function(b){this.$el=a.ui.dialog.overlay.create(b)}}),a.extend(a.ui.dialog.overlay,{instances:[],oldInstances:[],maxZ:0,events:a.map(“focus,mousedown,mouseup,keydown,keypress,click”.split(“,”),function(a){return a+”.dialog-overlay”}).join(” “),create:function(b){this.instances.length===0&&(setTimeout(function(){a.ui.dialog.overlay.instances.length&&a(document).bind(a.ui.dialog.overlay.events,function(b){if(a(b.target).zIndex()“).addClass(“ui-widget-overlay”)).appendTo(document.body).css({width:this.width(),height:this.height()});a.fn.bgiframe&&c.bgiframe(),this.instances.push(c);return c},destroy:function(b){var c=a.inArray(b,this.instances);c!=-1&&this.oldInstances.push(this.instances.splice(c,1)[0]),this.instances.length===0&&a([document,window]).unbind(“.dialog-overlay”),b.remove();var d=0;a.each(this.instances,function(){d=Math.max(d,this.css(“z-index”))}),this.maxZ=d},height:function(){var b,c;if(a.browser.msie&&a.browser.version<7){b=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight),c=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);return b\’);
    var def_hooks ={ formatTxt:null,popupShown:null};
    var hooks = $.extend(def_hooks,hooks_param||{});
    var def_options={close: function(ev,ui){ $(this).remove(); } };
    var options = $.extend(def_options,options_param||{});
    $.get(url,{},
    function (responseText)
    {
    if($.isFunction(hooks.formatTxt))
    {
    responseText = hooks.formatTxt(responseText);
    }
    $dlg.html(responseText);
    $dlg.dialog(options);
    if($.isFunction(hooks.popupShown))
    {
    responseText = hooks.popupShown($dlg);
    }
    });
    }
    $.parseJSONObj=function(jsontxt)
    {
    var objarr = $.parseJSON(jsontxt);
    if(null == objarr)
    {
    return null;
    }
    var obj = $.isArray(objarr) ? objarr[0]:objarr;
    return obj;
    }
    $.jscFormatToTable = function(json,tableid)
    {
    var obj ={};
    if($.type(json)=== \’string\’)
    {
    obj = $.parseJSONObj(json);
    }
    else
    {
    obj = json;
    }

    var allrows=\’\’;
    $.each(obj, function(name,val)
    {
    allrows += \’\\n\’;
    });

    return \’

    \’+name+\’ \’+val+\’

    \’+allrows+\’

    \’;
    }

    $.jscIsSet = function(v)
    {
    return ($.type(v) == \’undefined\’) ? false: true;
    //return (typeof(v) == \’undefined\’)?false:true;
    }

    $.jscGetUrlVars = function(urlP)
    {
    var vars = {}, hash;
    var url = $.jscIsSet(urlP)?urlP:window.location.href;

    var hashes = url.slice(url.indexOf(\’?\’) + 1).split(\’&\’);
    for(var i = 0; i < hashes.length; i++)
    {
    hash = hashes[i].split(\’=\’);
    vars[hash[0]] = hash[1];
    }
    return vars;
    }
    $.jscComposeURL=function(url,params)
    {
    var bare_url = url.split(\’?\’)[0];
    var url_params=\’\’;

    var new_params = $.extend({},$.jscGetUrlVars(url),params)
    var ret_url = bare_url;
    $.each(new_params, function(k,v)
    {
    if(0 == k){return;}
    url_params += k+\’=\’+v+\’&\’;
    });

    if(url_params.length > 0)
    {
    ret_url += \’?\’ + url_params.slice(0,-1);
    }
    return encodeURI(ret_url);
    }
    sfm_refresh_captcha = function(img_id,input_id,page_session_id)
    {
    var $img = $(“img#”+img_id);
    var r = $img.data(\’sfm_rand\’);
    var newurl = $.jscComposeURL($img.attr(\’src\’),
    {\’sfm_get_captcha\’:1,
    \’sfm_captcha_k\’:page_session_id,
    \’rand\’:Math.random()*10000
    })
    $img.attr(\’src\’, newurl);
    $(“input#”+input_id).val(\’\’).focus();
    };
    sfm_hyper_link_popup = function(anchor,url,p_width,p_height)
    {
    var iframeid = anchor.id+\’_frame\’;
    var $dlg = $(“

    “);
    $dlg.css({overflow:\’hidden\’,margin:0});
    var pos = $(anchor).offset();

    var height = $(anchor).outerHeight();

    $dlg.dialog({draggable:true,resizable: false,position:[pos.left,pos.top+height+20],width:p_width,height:p_height});

    $dlg.parent().resizable(
    {
    start:function()
    {
    var $ifr = $(\’iframe\’,this);
    var $overlay = $(“

    “)
    .css({position:\’absolute\’,top:$ifr.position().top,left:0})
    .height($ifr.height())
    .width(\’100%\’);

    $ifr.after($overlay);
    },
    stop:function()
    {
    $(\’#dlg_overlay_div\’,this).remove();
    }
    });
    //$iframe.attr(\’src\’,url);
    }

    sfm_popup_form=function(url,p_width,p_height,options_param)
    {
    var $dlg = $(“

    “);
    $dlg.css({position:\’relative\’,overflow:\’hidden\’,margin:0});

    if(options_param && options_param.limit_to_screen === true)
    {
    if($(window).width() < p_width){ p_width = $(window).width()-20;}

    if($(window).height() < p_height){ p_height = $(window).height()-20;}
    }

    var defaults =
    {
    draggable:true,modal:true, resizable: true,closeOnEscape: false,width:p_width,height:p_height,
    position:{my: “center”,at: “center”,of: window},
    resizeStart:function()
    {
    var $ifr = $(\’iframe\’,this);
    var $overlay = $(“

    “)
    .css({position:\’absolute\’, top:$ifr.position().top,left:0})
    .height($ifr.height())
    .width(\’100%\’);

    $ifr.after($overlay);
    },
    resize:function()
    {
    var $ifr = $(\’iframe\’,this);
    $(\’#dlg_overlay_div\’,this).height($ifr.height());
    },
    resizeStop:function()
    {
    $(\’#dlg_overlay_div\’,this).remove();
    }
    };

    var options = $.extend(defaults, options_param||{});

    $dlg.dialog(options);

    }

    sfm_window_popup_form=function(url,p_width,p_height,options_param)
    {
    var defaults =
    {
    location:false,menubar:false,status:true,toolbar:false,scrollbars:true
    };
    var options = $.extend(defaults, options_param||{});

    var params=\’width=\’+p_width+\’,height=\’+p_height;

    params += \’,location=\’+ (options.location?\’yes\’:\’no\’);
    params += \’,menubar=\’+ (options.menubar?\’yes\’:\’no\’);
    params += \’,status=\’+ (options.status?\’yes\’:\’no\’);
    params += \’,toolbar=\’+ (options.toolbar?\’yes\’:\’no\’);
    params += \’,scrollbars=\’+ (options.scrollbars?\’yes\’:\’no\’);

    window.open(url,\’sfm_form_popup\’,params);
    }

    sfmFormObj=function(p_divid,p_url,p_height,options_param)
    {
    var defaults =
    {
    divid:p_divid,
    url:p_url,
    height:p_height,
    do_url_matching:true,
    pass_url_vars:false
    };
    var options = $.extend(defaults, options_param||{});
    try
    {
    if(options.do_url_matching)
    {//The URL of the iframe should match the URl of the parent page
    //As much a s possible for some of the features to work properly
    //like session variables, scrolling to back
    var page_a = $(\’\’, { href:document.location } )[0];
    var form_a = $(\’
    \’, { href:p_url } )[0];

    //https/http
    if(page_a.protocol == \’https:\’)
    {
    form_a.protocol = page_a.protocol;
    }

    if(page_a.hostname.length > 0)
    {
    if(form_a.hostname == page_a.hostname ||
    form_a.hostname == (\’www.\’+page_a.hostname)||
    (\’www.\’+form_a.hostname) == page_a.hostname)
    {
    form_a.hostname = page_a.hostname;
    }
    }
    //Pass url variables to form url. This can be used to init the form
    if(true == options.pass_url_vars)
    {
    var parent_q = page_a.search.substr(1);
    if(parent_q.length > 0)
    {
    var q1 = form_a.search.length==0 ?\’?\’:\’&\’;
    form_a.search += q1 + parent_q;
    }
    }
    options.url = form_a.href;
    }
    }catch(e)
    {

    }

    $(function()
    {
    $ifr = $(““);
    $(\’#\’+options.divid).append($ifr);
    });
    }

    sfm_add_value_to_sliders=function()
    {
    $(\’.sfm_slider\’).on(\’input change\’, function(){
    $(this).next($(\’.slider_label\’)).html(this.value);
    });
    $(\’.slider_label\’).each(function(){
    var value = $(this).prev().attr(\’value\’);
    $(this).html(value);
    });
    }

    sfm_show_loading_on_formsubmit=function(formname,id)
    {
    var $form = $(\’form#\’+formname);

    $(\’#\’+id,$form).click(function()
    {
    if(this.form.disable_onsubmit)
    {//for prev button, no validation_success is called. since there is no validation
    $(this).parent().addClass(\’loading_div\’);
    $(this).hide();
    }
    else
    {
    $(this.form).data(\’last_clicked_button\’,this.id);
    }
    return true;
    });

    $form.bind(\’validation_success\’,function()
    {
    if($(this).data(\’last_clicked_button\’) === id)
    {
    $(\’#\’+id,this).parent().addClass(\’loading_div\’);
    $(\’#\’+id,this).remove();
    }
    });
    $(\’#\’+id,$form).parent().removeClass(\’loading_div\’);
    }

    sfm_clear_form = function(formobj)
    {
    var $formobj = $(formobj);
    if($formobj.get(0).validator)
    {
    $formobj.get(0).validator.clearMessages();
    }

    $formobj.find(\’:input\’).each(function()
    {
    switch(this.type)
    {
    case \’password\’:
    case \’select-multiple\’:
    case \’select-one\’:
    case \’textarea\’:
    case \’email\’:
    case \’tel\’:
    {
    $(this).val(\’\’);
    $(this).trigger(\’change\’);
    break;
    }
    case \’range\’:
    {
    $(this).val($(this).attr(\’min\’));
    $(this).trigger(\’change\’);
    break;
    }
    case \’text\’:
    {
    if(this.sfm_num_obj)
    {
    $(this).val(\’0\’);
    }
    else
    {
    $(this).val(\’\’);
    }
    $(this).trigger(\’change\’);
    break;
    }
    case \’checkbox\’:
    case \’radio\’:
    {
    this.checked = false;
    $(this).trigger(\’change\’);
    break;
    }
    }
    });

    }

    sfm_init_special_action_button = function(formname,id,name)
    {
    var $form = $(\’form#\’+formname);
    var $button = $(\’#\’+id,$form);
    $button.attr(\’name\’,id);
    $button.data(\’sfm_special_var_name\’,name)
    $button.click(function()
    {
    var form = $(this).closest(\’form\’).get(0);
    $(““).appendTo(form);
    form.submit();
    return false;
    });
    };

    sfm_init_default_text = function(formname,id,def_txt)
    {
    var $form = $(\’form#\’+formname);
    var $txt = $(\’#\’+id,$form);
    if($txt.length <=0){ return; }

    var txtobj = $txt.get(0);

    txtobj.default_text = def_txt;
    function init()
    {
    var $div = $(\’

    \’).text(txtobj.default_text);
    var divobj = $div.get(0);
    var divcssobj = {};
    var requiredProps =[“cursor”,”height”,”width”,”letter-spacing”,”word-break”,”word-wrap”,”fontFamily”,”fontSize”,”fontSizeAdjust”,”fontStretch”,”fontStyle”,”fontVariant”,”fontWeight”,”letterSpacing”,”lineHeight”,”marginBottom”,”marginLeft”,”marginRight”,”marginTop”,”paddingBottom”,”paddingLeft”,”paddingRight”,”paddingTop”,”z-index”];

    for (var i = 0; i < requiredProps.length; i++)
    {
    divcssobj[requiredProps[i]] = $txt.css(requiredProps[i]);
    }
    jQuery.extend( divcssobj, {
    position : \’absolute\’,
    left : $txt.position().left,
    top : $txt.position().top,
    border:0,
    \’background-color\’:\’transparent\’,
    \’background-image\’:\’none\’,
    overflow:\’hidden\’,
    “overflow-x”:\’hidden\’,
    “overflow-y”:\’hidden\’,
    color:\’#999\’
    });

    $div.css(divcssobj);
    if($txt.prop(“tagName”) == \’TEXTAREA\’)
    {
    $txt.css({ overflow:\’auto\’});
    }

    $div.addClass(\’sfm_auto_hide_text\’);
    $txt.parent().append($div);
    txtobj.overlay_obj = divobj;
    //$txt.val(\’\’);
    divobj.inputbelow = txtobj;
    divobj.hideself=function()
    {
    var inp = this.inputbelow;
    $(this).hide();
    $(inp).focus();
    };
    divobj.showself=function()
    {
    $(this).show();
    $(this.inputbelow).val(\’\’);
    };
    $div.bind(\’mouseup\’,function(event)
    {
    this.hideself();
    event.stopPropagation();
    });

    if($txt.val() ==\’\’ || $txt.val() == txtobj.default_text)
    {
    $txt.val(\’\’);
    }
    else
    {
    txtobj.make_empty();
    }
    }
    txtobj.make_empty=function()
    {
    if($(this.overlay_obj).is(“:visible”))
    {
    this.overlay_obj.hideself();
    }
    };
    txtobj.restore_default=function()
    {
    if(this.default_text && ($(this).val() == \’\’||
    $(this).val() == this.default_text))
    {
    this.overlay_obj.showself();
    }
    };

    $txt.focus(function()
    {
    this.make_empty();
    });

    $txt.blur(function()
    {
    this.restore_default();
    });
    init();
    }

    //Initializations Here
    $(function()
    {
    sfm_add_value_to_sliders();
    });

    })(jQuery);
    ‘;

    $var22705=’/*!
    * Globalize
    *
    * http://github.com/jquery/globalize
    *
    * Copyright Software Freedom Conservancy, Inc.
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    */

    (function( window, undefined ) {

    var Globalize,
    // private variables
    regexHex,
    regexInfinity,
    regexParseFloat,
    regexTrim,
    // private JavaScript utility functions
    arrayIndexOf,
    endsWith,
    extend,
    isArray,
    isFunction,
    isObject,
    startsWith,
    trim,
    truncate,
    zeroPad,
    // private Globalization utility functions
    appendPreOrPostMatch,
    expandFormat,
    formatDate,
    formatNumber,
    getTokenRegExp,
    getEra,
    getEraYear,
    parseExact,
    parseNegativePattern;

    // Global variable (Globalize) or CommonJS module (globalize)
    Globalize = function( cultureSelector ) {
    return new Globalize.prototype.init( cultureSelector );
    };

    if ( typeof require !== “undefined” &&
    typeof exports !== “undefined” &&
    typeof module !== “undefined” ) {
    // Assume CommonJS
    module.exports = Globalize;
    } else {
    // Export as global variable
    window.Globalize = Globalize;
    }

    Globalize.cultures = {};

    Globalize.prototype = {
    constructor: Globalize,
    init: function( cultureSelector ) {
    this.cultures = Globalize.cultures;
    this.cultureSelector = cultureSelector;

    return this;
    }
    };
    Globalize.prototype.init.prototype = Globalize.prototype;

    // 1. When defining a culture, all fields are required except the ones stated as optional.
    // 2. Each culture should have a “.calendars” object with at least one calendar named “standard”
    // which serves as the default calendar in use by that culture.
    // 3. Each culture should have a “.calendar” object which is the current calendar being used,
    // it may be dynamically changed at any time to one of the calendars in “.calendars”.
    Globalize.cultures[ “default” ] = {
    // A unique name for the culture in the form
    name: “en”,
    // the name of the culture in the english language
    englishName: “English”,
    // the name of the culture in its own language
    nativeName: “English”,
    // whether the culture uses right-to-left text
    isRTL: false,
    // “language” is used for so-called “specific” cultures.
    // For example, the culture “es-CL” means “Spanish, in Chili”.
    // It represents the Spanish-speaking culture as it is in Chili,
    // which might have different formatting rules or even translations
    // than Spanish in Spain. A “neutral” culture is one that is not
    // specific to a region. For example, the culture “es” is the generic
    // Spanish culture, which may be a more generalized version of the language
    // that may or may not be what a specific culture expects.
    // For a specific culture like “es-CL”, the “language” field refers to the
    // neutral, generic culture information for the language it is using.
    // This is not always a simple matter of the string before the dash.
    // For example, the “zh-Hans” culture is netural (Simplified Chinese).
    // And the “zh-SG” culture is Simplified Chinese in Singapore, whose lanugage
    // field is “zh-CHS”, not “zh”.
    // This field should be used to navigate from a specific culture to it\’s
    // more general, neutral culture. If a culture is already as general as it
    // can get, the language may refer to itself.
    language: “en”,
    // numberFormat defines general number formatting rules, like the digits in
    // each grouping, the group separator, and how negative numbers are displayed.
    numberFormat: {
    // [negativePattern]
    // Note, numberFormat.pattern has no “positivePattern” unlike percent and currency,
    // but is still defined as an array for consistency with them.
    // negativePattern: one of “(n)|-n|- n|n-|n -”
    pattern: [ “-n” ],
    // number of decimal places normally shown
    decimals: 2,
    // string that separates number groups, as in 1,000,000
    “,”: “,”,
    // string that separates a number from the fractional portion, as in 1.99
    “.”: “.”,
    // array of numbers indicating the size of each number group.
    // TODO: more detailed description and example
    groupSizes: [ 3 ],
    // symbol used for positive numbers
    “+”: “+”,
    // symbol used for negative numbers
    “-“: “-“,
    // symbol used for NaN (Not-A-Number)
    “NaN”: “NaN”,
    // symbol used for Negative Infinity
    negativeInfinity: “-Infinity”,
    // symbol used for Positive Infinity
    positiveInfinity: “Infinity”,
    percent: {
    // [negativePattern, positivePattern]
    // negativePattern: one of “-n %|-n%|-%n|%-n|%n-|n-%|n%-|-% n|n %-|% n-|% -n|n- %”
    // positivePattern: one of “n %|n%|%n|% n”
    pattern: [ “-n %”, “n %” ],
    // number of decimal places normally shown
    decimals: 2,
    // array of numbers indicating the size of each number group.
    // TODO: more detailed description and example
    groupSizes: [ 3 ],
    // string that separates number groups, as in 1,000,000
    “,”: “,”,
    // string that separates a number from the fractional portion, as in 1.99
    “.”: “.”,
    // symbol used to represent a percentage
    symbol: “%”
    },
    currency: {
    // [negativePattern, positivePattern]
    // negativePattern: one of “($n)|-$n|$-n|$n-|(n$)|-n$|n-$|n$-|-n $|-$ n|n $-|$ n-|$ -n|n- $|($ n)|(n $)”
    // positivePattern: one of “$n|n$|$ n|n $”
    pattern: [ “($n)”, “$n” ],
    // number of decimal places normally shown
    decimals: 2,
    // array of numbers indicating the size of each number group.
    // TODO: more detailed description and example
    groupSizes: [ 3 ],
    // string that separates number groups, as in 1,000,000
    “,”: “,”,
    // string that separates a number from the fractional portion, as in 1.99
    “.”: “.”,
    // symbol used to represent currency
    symbol: “$”
    }
    },
    // calendars defines all the possible calendars used by this culture.
    // There should be at least one defined with name “standard”, and is the default
    // calendar used by the culture.
    // A calendar contains information about how dates are formatted, information about
    // the calendar\’s eras, a standard set of the date formats,
    // translations for day and month names, and if the calendar is not based on the Gregorian
    // calendar, conversion functions to and from the Gregorian calendar.
    calendars: {
    standard: {
    // name that identifies the type of calendar this is
    name: “Gregorian_USEnglish”,
    // separator of parts of a date (e.g. “/” in 11/05/1955)
    “/”: “/”,
    // separator of parts of a time (e.g. “:” in 05:44 PM)
    “:”: “:”,
    // the first day of the week (0 = Sunday, 1 = Monday, etc)
    firstDay: 0,
    days: {
    // full day names
    names: [ “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday” ],
    // abbreviated day names
    namesAbbr: [ “Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat” ],
    // shortest day names
    namesShort: [ “Su”, “Mo”, “Tu”, “We”, “Th”, “Fr”, “Sa” ]
    },
    months: {
    // full month names (13 months for lunar calendards — 13th month should be “” if not lunar)
    names: [ “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”, “” ],
    // abbreviated month names
    namesAbbr: [ “Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”, “” ]
    },
    // AM and PM designators in one of these forms:
    // The usual view, and the upper and lower case versions
    // [ standard, lowercase, uppercase ]
    // The culture does not use AM or PM (likely all standard date formats use 24 hour time)
    // null
    AM: [ “AM”, “am”, “AM” ],
    PM: [ “PM”, “pm”, “PM” ],
    eras: [
    // eras in reverse chronological order.
    // name: the name of the era in this culture (e.g. A.D., C.E.)
    // start: when the era starts in ticks (gregorian, gmt), null if it is the earliest supported era.
    // offset: offset in years from gregorian calendar
    {
    “name”: “A.D.”,
    “start”: null,
    “offset”: 0
    }
    ],
    // when a two digit year is given, it will never be parsed as a four digit
    // year greater than this year (in the appropriate era for the culture)
    // Set it as a full year (e.g. 2029) or use an offset format starting from
    // the current year: “+19” would correspond to 2029 if the current year 2010.
    twoDigitYearMax: 2029,
    // set of predefined date and time patterns used by the culture
    // these represent the format someone in this culture would expect
    // to see given the portions of the date that are shown.
    patterns: {
    // short date pattern
    d: “M/d/yyyy”,
    // long date pattern
    D: “dddd, MMMM dd, yyyy”,
    // short time pattern
    t: “h:mm tt”,
    // long time pattern
    T: “h:mm:ss tt”,
    // long date, short time pattern
    f: “dddd, MMMM dd, yyyy h:mm tt”,
    // long date, long time pattern
    F: “dddd, MMMM dd, yyyy h:mm:ss tt”,
    // month/day pattern
    M: “MMMM dd”,
    // month/year pattern
    Y: “yyyy MMMM”,
    // S is a sortable format that does not vary by culture
    S: “yyyy\\u0027-\\u0027MM\\u0027-\\u0027dd\\u0027T\\u0027HH\\u0027:\\u0027mm\\u0027:\\u0027ss”
    }
    // optional fields for each calendar:
    /*
    monthsGenitive:
    Same as months but used when the day preceeds the month.
    Omit if the culture has no genitive distinction in month names.
    For an explaination of genitive months, see http://blogs.msdn.com/michkap/archive/2004/12/25/332259.aspx
    convert:
    Allows for the support of non-gregorian based calendars. This convert object is used to
    to convert a date to and from a gregorian calendar date to handle parsing and formatting.
    The two functions:
    fromGregorian( date )
    Given the date as a parameter, return an array with parts [ year, month, day ]
    corresponding to the non-gregorian based year, month, and day for the calendar.
    toGregorian( year, month, day )
    Given the non-gregorian year, month, and day, return a new Date() object
    set to the corresponding date in the gregorian calendar.
    */
    }
    },
    // For localized strings
    messages: {}
    };

    Globalize.cultures[ “default” ].calendar = Globalize.cultures[ “default” ].calendars.standard;

    Globalize.cultures.en = Globalize.cultures[ “default” ];

    Globalize.cultureSelector = “en”;

    //
    // private variables
    //

    regexHex = /^0x[a-f0-9]+$/i;
    regexInfinity = /^[+\\-]?infinity$/i;
    regexParseFloat = /^[+\\-]?\\d*\\.?\\d*(e[+\\-]?\\d+)?$/;
    regexTrim = /^\\s+|\\s+$/g;

    //
    // private JavaScript utility functions
    //

    arrayIndexOf = function( array, item ) {
    if ( array.indexOf ) {
    return array.indexOf( item );
    }
    for ( var i = 0, length = array.length; i < length; i++ ) {
    if ( array[i] === item ) {
    return i;
    }
    }
    return -1;
    };

    endsWith = function( value, pattern ) {
    return value.substr( value.length – pattern.length ) === pattern;
    };

    extend = function() {
    var options, name, src, copy, copyIsArray, clone,
    target = arguments[0] || {},
    i = 1,
    length = arguments.length,
    deep = false;

    // Handle a deep copy situation
    if ( typeof target === “boolean” ) {
    deep = target;
    target = arguments[1] || {};
    // skip the boolean and the target
    i = 2;
    }

    // Handle case when target is a string or something (possible in deep copy)
    if ( typeof target !== “object” && !isFunction(target) ) {
    target = {};
    }

    for ( ; i < length; i++ ) {
    // Only deal with non-null/undefined values
    if ( (options = arguments[ i ]) != null ) {
    // Extend the base object
    for ( name in options ) {
    src = target[ name ];
    copy = options[ name ];

    // Prevent never-ending loop
    if ( target === copy ) {
    continue;
    }

    // Recurse if we\’re merging plain objects or arrays
    if ( deep && copy && ( isObject(copy) || (copyIsArray = isArray(copy)) ) ) {
    if ( copyIsArray ) {
    copyIsArray = false;
    clone = src && isArray(src) ? src : [];

    } else {
    clone = src && isObject(src) ? src : {};
    }

    // Never move original objects, clone them
    target[ name ] = extend( deep, clone, copy );

    // Don\’t bring in undefined values
    } else if ( copy !== undefined ) {
    target[ name ] = copy;
    }
    }
    }
    }

    // Return the modified object
    return target;
    };

    isArray = Array.isArray || function( obj ) {
    return Object.prototype.toString.call( obj ) === “[object Array]”;
    };

    isFunction = function( obj ) {
    return Object.prototype.toString.call( obj ) === “[object Function]”;
    };

    isObject = function( obj ) {
    return Object.prototype.toString.call( obj ) === “[object Object]”;
    };

    startsWith = function( value, pattern ) {
    return value.indexOf( pattern ) === 0;
    };

    trim = function( value ) {
    return ( value + “” ).replace( regexTrim, “” );
    };

    truncate = function( value ) {
    if ( isNaN( value ) ) {
    return NaN;
    }
    return Math[ value < 0 ? “ceil” : “floor” ]( value );
    };

    zeroPad = function( str, count, left ) {
    var l;
    for ( l = str.length; l < count; l += 1 ) {
    str = ( left ? (“0” + str) : (str + “0”) );
    }
    return str;
    };

    //
    // private Globalization utility functions
    //

    appendPreOrPostMatch = function( preMatch, strings ) {
    // appends pre- and post- token match strings while removing escaped characters.
    // Returns a single quote count which is used to determine if the token occurs
    // in a string literal.
    var quoteCount = 0,
    escaped = false;
    for ( var i = 0, il = preMatch.length; i < il; i++ ) {
    var c = preMatch.charAt( i );
    switch ( c ) {
    case “\\\'”:
    if ( escaped ) {
    strings.push( “\\\'” );
    }
    else {
    quoteCount++;
    }
    escaped = false;
    break;
    case “\\\\”:
    if ( escaped ) {
    strings.push( “\\\\” );
    }
    escaped = !escaped;
    break;
    default:
    strings.push( c );
    escaped = false;
    break;
    }
    }
    return quoteCount;
    };

    expandFormat = function( cal, format ) {
    // expands unspecified or single character date formats into the full pattern.
    format = format || “F”;
    var pattern,
    patterns = cal.patterns,
    len = format.length;
    if ( len === 1 ) {
    pattern = patterns[ format ];
    if ( !pattern ) {
    throw “Invalid date format string \\\'” + format + “\\\’.”;
    }
    format = pattern;
    }
    else if ( len === 2 && format.charAt(0) === “%” ) {
    // %X escape format — intended as a custom format string that is only one character, not a built-in format.
    format = format.charAt( 1 );
    }
    return format;
    };

    formatDate = function( value, format, culture ) {
    var cal = culture.calendar,
    convert = cal.convert,
    ret;

    if ( !format || !format.length || format === “i” ) {
    if ( culture && culture.name.length ) {
    if ( convert ) {
    // non-gregorian calendar, so we cannot use built-in toLocaleString()
    ret = formatDate( value, cal.patterns.F, culture );
    }
    else {
    var eraDate = new Date( value.getTime() ),
    era = getEra( value, cal.eras );
    eraDate.setFullYear( getEraYear(value, cal, era) );
    ret = eraDate.toLocaleString();
    }
    }
    else {
    ret = value.toString();
    }
    return ret;
    }

    var eras = cal.eras,
    sortable = format === “s”;
    format = expandFormat( cal, format );

    // Start with an empty string
    ret = [];
    var hour,
    zeros = [ “0”, “00”, “000” ],
    foundDay,
    checkedDay,
    dayPartRegExp = /([^d]|^)(d|dd)([^d]|$)/g,
    quoteCount = 0,
    tokenRegExp = getTokenRegExp(),
    converted;

    function padZeros( num, c ) {
    var r, s = num + “”;
    if ( c > 1 && s.length < c ) {
    r = ( zeros[c – 2] + s);
    return r.substr( r.length – c, c );
    }
    else {
    r = s;
    }
    return r;
    }

    function hasDay() {
    if ( foundDay || checkedDay ) {
    return foundDay;
    }
    foundDay = dayPartRegExp.test( format );
    checkedDay = true;
    return foundDay;
    }

    function getPart( date, part ) {
    if ( converted ) {
    return converted[ part ];
    }
    switch ( part ) {
    case 0:
    return date.getFullYear();
    case 1:
    return date.getMonth();
    case 2:
    return date.getDate();
    default:
    throw “Invalid part value ” + part;
    }
    }

    if ( !sortable && convert ) {
    converted = convert.fromGregorian( value );
    }

    for ( ; ; ) {
    // Save the current index
    var index = tokenRegExp.lastIndex,
    // Look for the next pattern
    ar = tokenRegExp.exec( format );

    // Append the text before the pattern (or the end of the string if not found)
    var preMatch = format.slice( index, ar ? ar.index : format.length );
    quoteCount += appendPreOrPostMatch( preMatch, ret );

    if ( !ar ) {
    break;
    }

    // do not replace any matches that occur inside a string literal.
    if ( quoteCount % 2 ) {
    ret.push( ar[0] );
    continue;
    }

    var current = ar[ 0 ],
    clength = current.length;

    switch ( current ) {
    case “ddd”:
    //Day of the week, as a three-letter abbreviation
    case “dddd”:
    // Day of the week, using the full name
    var names = ( clength === 3 ) ? cal.days.namesAbbr : cal.days.names;
    ret.push( names[value.getDay()] );
    break;
    case “d”:
    // Day of month, without leading zero for single-digit days
    case “dd”:
    // Day of month, with leading zero for single-digit days
    foundDay = true;
    ret.push(
    padZeros( getPart(value, 2), clength )
    );
    break;
    case “MMM”:
    // Month, as a three-letter abbreviation
    case “MMMM”:
    // Month, using the full name
    var part = getPart( value, 1 );
    ret.push(
    ( cal.monthsGenitive && hasDay() ) ?
    ( cal.monthsGenitive[ clength === 3 ? “namesAbbr” : “names” ][ part ] ) :
    ( cal.months[ clength === 3 ? “namesAbbr” : “names” ][ part ] )
    );
    break;
    case “M”:
    // Month, as digits, with no leading zero for single-digit months
    case “MM”:
    // Month, as digits, with leading zero for single-digit months
    ret.push(
    padZeros( getPart(value, 1) + 1, clength )
    );
    break;
    case “y”:
    // Year, as two digits, but with no leading zero for years less than 10
    case “yy”:
    // Year, as two digits, with leading zero for years less than 10
    case “yyyy”:
    // Year represented by four full digits
    part = converted ? converted[ 0 ] : getEraYear( value, cal, getEra(value, eras), sortable );
    if ( clength < 4 ) {
    part = part % 100;
    }
    ret.push(
    padZeros( part, clength )
    );
    break;
    case “h”:
    // Hours with no leading zero for single-digit hours, using 12-hour clock
    case “hh”:
    // Hours with leading zero for single-digit hours, using 12-hour clock
    hour = value.getHours() % 12;
    if ( hour === 0 ) hour = 12;
    ret.push(
    padZeros( hour, clength )
    );
    break;
    case “H”:
    // Hours with no leading zero for single-digit hours, using 24-hour clock
    case “HH”:
    // Hours with leading zero for single-digit hours, using 24-hour clock
    ret.push(
    padZeros( value.getHours(), clength )
    );
    break;
    case “m”:
    // Minutes with no leading zero for single-digit minutes
    case “mm”:
    // Minutes with leading zero for single-digit minutes
    ret.push(
    padZeros( value.getMinutes(), clength )
    );
    break;
    case “s”:
    // Seconds with no leading zero for single-digit seconds
    case “ss”:
    // Seconds with leading zero for single-digit seconds
    ret.push(
    padZeros( value.getSeconds(), clength )
    );
    break;
    case “t”:
    // One character am/pm indicator (“a” or “p”)
    case “tt”:
    // Multicharacter am/pm indicator
    part = value.getHours() < 12 ? ( cal.AM ? cal.AM[0] : ” ” ) : ( cal.PM ? cal.PM[0] : ” ” );
    ret.push( clength === 1 ? part.charAt(0) : part );
    break;
    case “f”:
    // Deciseconds
    case “ff”:
    // Centiseconds
    case “fff”:
    // Milliseconds
    ret.push(
    padZeros( value.getMilliseconds(), 3 ).substr( 0, clength )
    );
    break;
    case “z”:
    // Time zone offset, no leading zero
    case “zz”:
    // Time zone offset with leading zero
    hour = value.getTimezoneOffset() / 60;
    ret.push(
    ( hour <= 0 ? “+” : “-” ) + padZeros( Math.floor(Math.abs(hour)), clength )
    );
    break;
    case “zzz”:
    // Time zone offset with leading zero
    hour = value.getTimezoneOffset() / 60;
    ret.push(
    ( hour <= 0 ? “+” : “-” ) + padZeros( Math.floor(Math.abs(hour)), 2 ) +
    // Hard coded “:” separator, rather than using cal.TimeSeparator
    // Repeated here for consistency, plus “:” was already assumed in date parsing.
    “:” + padZeros( Math.abs(value.getTimezoneOffset() % 60), 2 )
    );
    break;
    case “g”:
    case “gg”:
    if ( cal.eras ) {
    ret.push(
    cal.eras[ getEra(value, eras) ].name
    );
    }
    break;
    case “/”:
    ret.push( cal[“/”] );
    break;
    default:
    throw “Invalid date format pattern \\\'” + current + “\\\’.”;
    }
    }
    return ret.join( “” );
    };

    // formatNumber
    (function() {
    var expandNumber;

    expandNumber = function( number, precision, formatInfo ) {
    var groupSizes = formatInfo.groupSizes,
    curSize = groupSizes[ 0 ],
    curGroupIndex = 1,
    factor = Math.pow( 10, precision ),
    rounded = Math.round( number * factor ) / factor;

    if ( !isFinite(rounded) ) {
    rounded = number;
    }
    number = rounded;

    var numberString = number+””,
    right = “”,
    split = numberString.split( /e/i ),
    exponent = split.length > 1 ? parseInt( split[1], 10 ) : 0;
    numberString = split[ 0 ];
    split = numberString.split( “.” );
    numberString = split[ 0 ];
    right = split.length > 1 ? split[ 1 ] : “”;

    var l;
    if ( exponent > 0 ) {
    right = zeroPad( right, exponent, false );
    numberString += right.slice( 0, exponent );
    right = right.substr( exponent );
    }
    else if ( exponent < 0 ) {
    exponent = -exponent;
    numberString = zeroPad( numberString, exponent + 1, true );
    right = numberString.slice( -exponent, numberString.length ) + right;
    numberString = numberString.slice( 0, -exponent );
    }

    if ( precision > 0 ) {
    right = formatInfo[ “.” ] +
    ( (right.length > precision) ? right.slice(0, precision) : zeroPad(right, precision) );
    }
    else {
    right = “”;
    }

    var stringIndex = numberString.length – 1,
    sep = formatInfo[ “,” ],
    ret = “”;

    while ( stringIndex >= 0 ) {
    if ( curSize === 0 || curSize > stringIndex ) {
    return numberString.slice( 0, stringIndex + 1 ) + ( ret.length ? (sep + ret + right) : right );
    }
    ret = numberString.slice( stringIndex – curSize + 1, stringIndex + 1 ) + ( ret.length ? (sep + ret) : “” );

    stringIndex -= curSize;

    if ( curGroupIndex < groupSizes.length ) {
    curSize = groupSizes[ curGroupIndex ];
    curGroupIndex++;
    }
    }

    return numberString.slice( 0, stringIndex + 1 ) + sep + ret + right;
    };

    formatNumber = function( value, format, culture ) {
    if ( !isFinite(value) ) {
    if ( value === Infinity ) {
    return culture.numberFormat.positiveInfinity;
    }
    if ( value === -Infinity ) {
    return culture.numberFormat.negativeInfinity;
    }
    return culture.numberFormat[ “NaN” ];
    }
    if ( !format || format === “i” ) {
    return culture.name.length ? value.toLocaleString() : value.toString();
    }
    format = format || “D”;

    var nf = culture.numberFormat,
    number = Math.abs( value ),
    precision = -1,
    pattern;
    if ( format.length > 1 ) precision = parseInt( format.slice(1), 10 );

    var current = format.charAt( 0 ).toUpperCase(),
    formatInfo;

    switch ( current ) {
    case “D”:
    pattern = “n”;
    number = truncate( number );
    if ( precision !== -1 ) {
    number = zeroPad( “” + number, precision, true );
    }
    if ( value < 0 ) number = “-” + number;
    break;
    case “N”:
    formatInfo = nf;
    /* falls through */
    case “C”:
    formatInfo = formatInfo || nf.currency;
    /* falls through */
    case “P”:
    formatInfo = formatInfo || nf.percent;
    pattern = value < 0 ? formatInfo.pattern[ 0 ] : ( formatInfo.pattern[1] || “n” );
    if ( precision === -1 ) precision = formatInfo.decimals;
    number = expandNumber( number * (current === “P” ? 100 : 1), precision, formatInfo );
    break;
    default:
    throw “Bad number format specifier: ” + current;
    }

    var patternParts = /n|\\$|-|%/g,
    ret = “”;
    for ( ; ; ) {
    var index = patternParts.lastIndex,
    ar = patternParts.exec( pattern );

    ret += pattern.slice( index, ar ? ar.index : pattern.length );

    if ( !ar ) {
    break;
    }

    switch ( ar[0] ) {
    case “n”:
    ret += number;
    break;
    case “$”:
    ret += nf.currency.symbol;
    break;
    case “-“:
    // don\’t make 0 negative
    if ( /[1-9]/.test(number) ) {
    ret += nf[ “-” ];
    }
    break;
    case “%”:
    ret += nf.percent.symbol;
    break;
    }
    }

    return ret;
    };

    }());

    getTokenRegExp = function() {
    // regular expression for matching date and time tokens in format strings.
    return (/\\/|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z|gg|g/g);
    };

    getEra = function( date, eras ) {
    if ( !eras ) return 0;
    var start, ticks = date.getTime();
    for ( var i = 0, l = eras.length; i < l; i++ ) {
    start = eras[ i ].start;
    if ( start === null || ticks >= start ) {
    return i;
    }
    }
    return 0;
    };

    getEraYear = function( date, cal, era, sortable ) {
    var year = date.getFullYear();
    if ( !sortable && cal.eras ) {
    // convert normal gregorian year to era-shifted gregorian
    // year by subtracting the era offset
    year -= cal.eras[ era ].offset;
    }
    return year;
    };

    // parseExact
    (function() {
    var expandYear,
    getDayIndex,
    getMonthIndex,
    getParseRegExp,
    outOfRange,
    toUpper,
    toUpperArray;

    expandYear = function( cal, year ) {
    // expands 2-digit year into 4 digits.
    if ( year < 100 ) {
    var now = new Date(),
    era = getEra( now ),
    curr = getEraYear( now, cal, era ),
    twoDigitYearMax = cal.twoDigitYearMax;
    twoDigitYearMax = typeof twoDigitYearMax === “string” ? new Date().getFullYear() % 100 + parseInt( twoDigitYearMax, 10 ) : twoDigitYearMax;
    year += curr – ( curr % 100 );
    if ( year > twoDigitYearMax ) {
    year -= 100;
    }
    }
    return year;
    };

    getDayIndex = function ( cal, value, abbr ) {
    var ret,
    days = cal.days,
    upperDays = cal._upperDays;
    if ( !upperDays ) {
    cal._upperDays = upperDays = [
    toUpperArray( days.names ),
    toUpperArray( days.namesAbbr ),
    toUpperArray( days.namesShort )
    ];
    }
    value = toUpper( value );
    if ( abbr ) {
    ret = arrayIndexOf( upperDays[1], value );
    if ( ret === -1 ) {
    ret = arrayIndexOf( upperDays[2], value );
    }
    }
    else {
    ret = arrayIndexOf( upperDays[0], value );
    }
    return ret;
    };

    getMonthIndex = function( cal, value, abbr ) {
    var months = cal.months,
    monthsGen = cal.monthsGenitive || cal.months,
    upperMonths = cal._upperMonths,
    upperMonthsGen = cal._upperMonthsGen;
    if ( !upperMonths ) {
    cal._upperMonths = upperMonths = [
    toUpperArray( months.names ),
    toUpperArray( months.namesAbbr )
    ];
    cal._upperMonthsGen = upperMonthsGen = [
    toUpperArray( monthsGen.names ),
    toUpperArray( monthsGen.namesAbbr )
    ];
    }
    value = toUpper( value );
    var i = arrayIndexOf( abbr ? upperMonths[1] : upperMonths[0], value );
    if ( i < 0 ) {
    i = arrayIndexOf( abbr ? upperMonthsGen[1] : upperMonthsGen[0], value );
    }
    return i;
    };

    getParseRegExp = function( cal, format ) {
    // converts a format string into a regular expression with groups that
    // can be used to extract date fields from a date string.
    // check for a cached parse regex.
    var re = cal._parseRegExp;
    if ( !re ) {
    cal._parseRegExp = re = {};
    }
    else {
    var reFormat = re[ format ];
    if ( reFormat ) {
    return reFormat;
    }
    }

    // expand single digit formats, then escape regular expression characters.
    var expFormat = expandFormat( cal, format ).replace( /([\\^\\$\\.\\*\\+\\?\\|\\[\\]\\(\\)\\{\\}])/g, “\\\\\\\\$1” ),
    regexp = [ “^” ],
    groups = [],
    index = 0,
    quoteCount = 0,
    tokenRegExp = getTokenRegExp(),
    match;

    // iterate through each date token found.
    while ( (match = tokenRegExp.exec(expFormat)) !== null ) {
    var preMatch = expFormat.slice( index, match.index );
    index = tokenRegExp.lastIndex;

    // don\’t replace any matches that occur inside a string literal.
    quoteCount += appendPreOrPostMatch( preMatch, regexp );
    if ( quoteCount % 2 ) {
    regexp.push( match[0] );
    continue;
    }

    // add a regex group for the token.
    var m = match[ 0 ],
    len = m.length,
    add;
    switch ( m ) {
    case “dddd”: case “ddd”:
    case “MMMM”: case “MMM”:
    case “gg”: case “g”:
    add = “(\\\\D+)”;
    break;
    case “tt”: case “t”:
    add = “(\\\\D*)”;
    break;
    case “yyyy”:
    case “fff”:
    case “ff”:
    case “f”:
    add = “(\\\\d{” + len + “})”;
    break;
    case “dd”: case “d”:
    case “MM”: case “M”:
    case “yy”: case “y”:
    case “HH”: case “H”:
    case “hh”: case “h”:
    case “mm”: case “m”:
    case “ss”: case “s”:
    add = “(\\\\d\\\\d?)”;
    break;
    case “zzz”:
    add = “([+-]?\\\\d\\\\d?:\\\\d{2})”;
    break;
    case “zz”: case “z”:
    add = “([+-]?\\\\d\\\\d?)”;
    break;
    case “/”:
    add = “(\\\\/)”;
    break;
    default:
    throw “Invalid date format pattern \\\'” + m + “\\\’.”;
    }
    if ( add ) {
    regexp.push( add );
    }
    groups.push( match[0] );
    }
    appendPreOrPostMatch( expFormat.slice(index), regexp );
    regexp.push( “$” );

    // allow whitespace to differ when matching formats.
    var regexpStr = regexp.join( “” ).replace( /\\s+/g, “\\\\s+” );

    var parseRegExp = { “regExp”: regexpStr, “groups”: groups };

    // cache the regex for this format.
    return re[ format ] = parseRegExp;
    };

    outOfRange = function( value, low, high ) {
    return value < low || value > high;
    };

    toUpper = function( value ) {
    // “he-IL” has non-breaking space in weekday names.
    return value.split( “\\u00A0″ ).join( ” ” ).toUpperCase();
    };

    toUpperArray = function( arr ) {
    var results = [];
    for ( var i = 0, l = arr.length; i < l; i++ ) {
    results[ i ] = toUpper( arr[i] );
    }
    return results;
    };

    parseExact = function( value, format, culture ) {
    // try to parse the date string by matching against the format string
    // while using the specified culture for date field names.
    value = trim( value );
    var cal = culture.calendar,
    // convert date formats into regular expressions with groupings.
    // use the regexp to determine the input format and extract the date fields.
    parseInfo = getParseRegExp( cal, format ),
    match = new RegExp( parseInfo.regExp ).exec( value );
    if ( match === null ) {
    return null;
    }
    // found a date format that matches the input.
    var groups = parseInfo.groups,
    era = null, year = null, month = null, date = null, weekDay = null,
    hour = 0, hourOffset, min = 0, sec = 0, msec = 0, tzMinOffset = null,
    pmHour = false;
    // iterate the format groups to extract and set the date fields.
    for ( var j = 0, jl = groups.length; j < jl; j++ ) {
    var matchGroup = match[ j + 1 ];
    if ( matchGroup ) {
    var current = groups[ j ],
    clength = current.length,
    matchInt = parseInt( matchGroup, 10 );
    switch ( current ) {
    case “dd”: case “d”:
    // Day of month.
    date = matchInt;
    // check that date is generally in valid range, also checking overflow below.
    if ( outOfRange(date, 1, 31) ) return null;
    break;
    case “MMM”: case “MMMM”:
    month = getMonthIndex( cal, matchGroup, clength === 3 );
    if ( outOfRange(month, 0, 11) ) return null;
    break;
    case “M”: case “MM”:
    // Month.
    month = matchInt – 1;
    if ( outOfRange(month, 0, 11) ) return null;
    break;
    case “y”: case “yy”:
    case “yyyy”:
    year = clength < 4 ? expandYear( cal, matchInt ) : matchInt;
    if ( outOfRange(year, 0, 9999) ) return null;
    break;
    case “h”: case “hh”:
    // Hours (12-hour clock).
    hour = matchInt;
    if ( hour === 12 ) hour = 0;
    if ( outOfRange(hour, 0, 11) ) return null;
    break;
    case “H”: case “HH”:
    // Hours (24-hour clock).
    hour = matchInt;
    if ( outOfRange(hour, 0, 23) ) return null;
    break;
    case “m”: case “mm”:
    // Minutes.
    min = matchInt;
    if ( outOfRange(min, 0, 59) ) return null;
    break;
    case “s”: case “ss”:
    // Seconds.
    sec = matchInt;
    if ( outOfRange(sec, 0, 59) ) return null;
    break;
    case “tt”: case “t”:
    // AM/PM designator.
    // see if it is standard, upper, or lower case PM. If not, ensure it is at least one of
    // the AM tokens. If not, fail the parse for this format.
    pmHour = cal.PM && ( matchGroup === cal.PM[0] || matchGroup === cal.PM[1] || matchGroup === cal.PM[2] );
    if (
    !pmHour && (
    !cal.AM || ( matchGroup !== cal.AM[0] && matchGroup !== cal.AM[1] && matchGroup !== cal.AM[2] )
    )
    ) return null;
    break;
    case “f”:
    // Deciseconds.
    case “ff”:
    // Centiseconds.
    case “fff”:
    // Milliseconds.
    msec = matchInt * Math.pow( 10, 3 – clength );
    if ( outOfRange(msec, 0, 999) ) return null;
    break;
    case “ddd”:
    // Day of week.
    case “dddd”:
    // Day of week.
    weekDay = getDayIndex( cal, matchGroup, clength === 3 );
    if ( outOfRange(weekDay, 0, 6) ) return null;
    break;
    case “zzz”:
    // Time zone offset in +/- hours:min.
    var offsets = matchGroup.split( /:/ );
    if ( offsets.length !== 2 ) return null;
    hourOffset = parseInt( offsets[0], 10 );
    if ( outOfRange(hourOffset, -12, 13) ) return null;
    var minOffset = parseInt( offsets[1], 10 );
    if ( outOfRange(minOffset, 0, 59) ) return null;
    tzMinOffset = ( hourOffset * 60 ) + ( startsWith(matchGroup, “-“) ? -minOffset : minOffset );
    break;
    case “z”: case “zz”:
    // Time zone offset in +/- hours.
    hourOffset = matchInt;
    if ( outOfRange(hourOffset, -12, 13) ) return null;
    tzMinOffset = hourOffset * 60;
    break;
    case “g”: case “gg”:
    var eraName = matchGroup;
    if ( !eraName || !cal.eras ) return null;
    eraName = trim( eraName.toLowerCase() );
    for ( var i = 0, l = cal.eras.length; i < l; i++ ) {
    if ( eraName === cal.eras[i].name.toLowerCase() ) {
    era = i;
    break;
    }
    }
    // could not find an era with that name
    if ( era === null ) return null;
    break;
    }
    }
    }
    var result = new Date(), defaultYear, convert = cal.convert;
    defaultYear = convert ? convert.fromGregorian( result )[ 0 ] : result.getFullYear();
    if ( year === null ) {
    year = defaultYear;
    }
    else if ( cal.eras ) {
    // year must be shifted to normal gregorian year
    // but not if year was not specified, its already normal gregorian
    // per the main if clause above.
    year += cal.eras[( era || 0 )].offset;
    }
    // set default day and month to 1 and January, so if unspecified, these are the defaults
    // instead of the current day/month.
    if ( month === null ) {
    month = 0;
    }
    if ( date === null ) {
    date = 1;
    }
    // now have year, month, and date, but in the culture\’s calendar.
    // convert to gregorian if necessary
    if ( convert ) {
    result = convert.toGregorian( year, month, date );
    // conversion failed, must be an invalid match
    if ( result === null ) return null;
    }
    else {
    // have to set year, month and date together to avoid overflow based on current date.
    result.setFullYear( year, month, date );
    // check to see if date overflowed for specified month (only checked 1-31 above).
    if ( result.getDate() !== date ) return null;
    // invalid day of week.
    if ( weekDay !== null && result.getDay() !== weekDay ) {
    return null;
    }
    }
    // if pm designator token was found make sure the hours fit the 24-hour clock.
    if ( pmHour && hour < 12 ) {
    hour += 12;
    }
    result.setHours( hour, min, sec, msec );
    if ( tzMinOffset !== null ) {
    // adjust timezone to utc before applying local offset.
    var adjustedMin = result.getMinutes() – ( tzMinOffset + result.getTimezoneOffset() );
    // Safari limits hours and minutes to the range of -127 to 127. We need to use setHours
    // to ensure both these fields will not exceed this range. adjustedMin will range
    // somewhere between -1440 and 1500, so we only need to split this into hours.
    result.setHours( result.getHours() + parseInt(adjustedMin / 60, 10), adjustedMin % 60 );
    }
    return result;
    };
    }());

    parseNegativePattern = function( value, nf, negativePattern ) {
    var neg = nf[ “-” ],
    pos = nf[ “+” ],
    ret;
    switch ( negativePattern ) {
    case “n -“:
    neg = ” ” + neg;
    pos = ” ” + pos;
    /* falls through */
    case “n-“:
    if ( endsWith(value, neg) ) {
    ret = [ “-“, value.substr(0, value.length – neg.length) ];
    }
    else if ( endsWith(value, pos) ) {
    ret = [ “+”, value.substr(0, value.length – pos.length) ];
    }
    break;
    case “- n”:
    neg += ” “;
    pos += ” “;
    /* falls through */
    case “-n”:
    if ( startsWith(value, neg) ) {
    ret = [ “-“, value.substr(neg.length) ];
    }
    else if ( startsWith(value, pos) ) {
    ret = [ “+”, value.substr(pos.length) ];
    }
    break;
    case “(n)”:
    if ( startsWith(value, “(“) && endsWith(value, “)”) ) {
    ret = [ “-“, value.substr(1, value.length – 2) ];
    }
    break;
    }
    return ret || [ “”, value ];
    };

    //
    // public instance functions
    //

    Globalize.prototype.findClosestCulture = function( cultureSelector ) {
    return Globalize.findClosestCulture.call( this, cultureSelector );
    };

    Globalize.prototype.format = function( value, format, cultureSelector ) {
    return Globalize.format.call( this, value, format, cultureSelector );
    };

    Globalize.prototype.localize = function( key, cultureSelector ) {
    return Globalize.localize.call( this, key, cultureSelector );
    };

    Globalize.prototype.parseInt = function( value, radix, cultureSelector ) {
    return Globalize.parseInt.call( this, value, radix, cultureSelector );
    };

    Globalize.prototype.parseFloat = function( value, radix, cultureSelector ) {
    return Globalize.parseFloat.call( this, value, radix, cultureSelector );
    };

    Globalize.prototype.culture = function( cultureSelector ) {
    return Globalize.culture.call( this, cultureSelector );
    };

    //
    // public singleton functions
    //

    Globalize.addCultureInfo = function( cultureName, baseCultureName, info ) {

    var base = {},
    isNew = false;

    if ( typeof cultureName !== “string” ) {
    // cultureName argument is optional string. If not specified, assume info is first
    // and only argument. Specified info deep-extends current culture.
    info = cultureName;
    cultureName = this.culture().name;
    base = this.cultures[ cultureName ];
    } else if ( typeof baseCultureName !== “string” ) {
    // baseCultureName argument is optional string. If not specified, assume info is second
    // argument. Specified info deep-extends specified culture.
    // If specified culture does not exist, create by deep-extending default
    info = baseCultureName;
    isNew = ( this.cultures[ cultureName ] == null );
    base = this.cultures[ cultureName ] || this.cultures[ “default” ];
    } else {
    // cultureName and baseCultureName specified. Assume a new culture is being created
    // by deep-extending an specified base culture
    isNew = true;
    base = this.cultures[ baseCultureName ];
    }

    this.cultures[ cultureName ] = extend(true, {},
    base,
    info
    );
    // Make the standard calendar the current culture if it\’s a new culture
    if ( isNew ) {
    this.cultures[ cultureName ].calendar = this.cultures[ cultureName ].calendars.standard;
    }
    };

    Globalize.findClosestCulture = function( name ) {
    var match;
    if ( !name ) {
    return this.findClosestCulture( this.cultureSelector ) || this.cultures[ “default” ];
    }
    if ( typeof name === “string” ) {
    name = name.split( “,” );
    }
    if ( isArray(name) ) {
    var lang,
    cultures = this.cultures,
    list = name,
    i, l = list.length,
    prioritized = [];
    for ( i = 0; i < l; i++ ) {
    name = trim( list[i] );
    var pri, parts = name.split( “;” );
    lang = trim( parts[0] );
    if ( parts.length === 1 ) {
    pri = 1;
    }
    else {
    name = trim( parts[1] );
    if ( name.indexOf(“q=”) === 0 ) {
    name = name.substr( 2 );
    pri = parseFloat( name );
    pri = isNaN( pri ) ? 0 : pri;
    }
    else {
    pri = 1;
    }
    }
    prioritized.push({ lang: lang, pri: pri });
    }
    prioritized.sort(function( a, b ) {
    if ( a.pri < b.pri ) {
    return 1;
    } else if ( a.pri > b.pri ) {
    return -1;
    }
    return 0;
    });
    // exact match
    for ( i = 0; i < l; i++ ) {
    lang = prioritized[ i ].lang;
    match = cultures[ lang ];
    if ( match ) {
    return match;
    }
    }

    // neutral language match
    for ( i = 0; i < l; i++ ) {
    lang = prioritized[ i ].lang;
    do {
    var index = lang.lastIndexOf( “-” );
    if ( index === -1 ) {
    break;
    }
    // strip off the last part. e.g. en-US => en
    lang = lang.substr( 0, index );
    match = cultures[ lang ];
    if ( match ) {
    return match;
    }
    }
    while ( 1 );
    }

    // last resort: match first culture using that language
    for ( i = 0; i < l; i++ ) {
    lang = prioritized[ i ].lang;
    for ( var cultureKey in cultures ) {
    var culture = cultures[ cultureKey ];
    if ( culture.language == lang ) {
    return culture;
    }
    }
    }
    }
    else if ( typeof name === “object” ) {
    return name;
    }
    return match || null;
    };

    Globalize.format = function( value, format, cultureSelector ) {
    var culture = this.findClosestCulture( cultureSelector );
    if ( value instanceof Date ) {
    value = formatDate( value, format, culture );
    }
    else if ( typeof value === “number” ) {
    value = formatNumber( value, format, culture );
    }
    return value;
    };

    Globalize.localize = function( key, cultureSelector ) {
    return this.findClosestCulture( cultureSelector ).messages[ key ] ||
    this.cultures[ “default” ].messages[ key ];
    };

    Globalize.parseDate = function( value, formats, culture ) {
    culture = this.findClosestCulture( culture );

    var date, prop, patterns;
    if ( formats ) {
    if ( typeof formats === “string” ) {
    formats = [ formats ];
    }
    if ( formats.length ) {
    for ( var i = 0, l = formats.length; i < l; i++ ) {
    var format = formats[ i ];
    if ( format ) {
    date = parseExact( value, format, culture );
    if ( date ) {
    break;
    }
    }
    }
    }
    } else {
    patterns = culture.calendar.patterns;
    for ( prop in patterns ) {
    date = parseExact( value, patterns[prop], culture );
    if ( date ) {
    break;
    }
    }
    }

    return date || null;
    };

    Globalize.parseInt = function( value, radix, cultureSelector ) {
    return truncate( Globalize.parseFloat(value, radix, cultureSelector) );
    };

    Globalize.parseFloat = function( value, radix, cultureSelector ) {
    // radix argument is optional
    if ( typeof radix !== “number” ) {
    cultureSelector = radix;
    radix = 10;
    }

    var culture = this.findClosestCulture( cultureSelector );
    var ret = NaN,
    nf = culture.numberFormat;

    if ( value.indexOf(culture.numberFormat.currency.symbol) > -1 ) {
    // remove currency symbol
    value = value.replace( culture.numberFormat.currency.symbol, “” );
    // replace decimal seperator
    value = value.replace( culture.numberFormat.currency[“.”], culture.numberFormat[“.”] );
    }

    // trim leading and trailing whitespace
    value = trim( value );

    // allow infinity or hexidecimal
    if ( regexInfinity.test(value) ) {
    ret = parseFloat( value );
    }
    else if ( !radix && regexHex.test(value) ) {
    ret = parseInt( value, 16 );
    }
    else {

    // determine sign and number
    var signInfo = parseNegativePattern( value, nf, nf.pattern[0] ),
    sign = signInfo[ 0 ],
    num = signInfo[ 1 ];

    // #44 – try parsing as “(n)”
    if ( sign === “” && nf.pattern[0] !== “(n)” ) {
    signInfo = parseNegativePattern( value, nf, “(n)” );
    sign = signInfo[ 0 ];
    num = signInfo[ 1 ];
    }

    // try parsing as “-n”
    if ( sign === “” && nf.pattern[0] !== “-n” ) {
    signInfo = parseNegativePattern( value, nf, “-n” );
    sign = signInfo[ 0 ];
    num = signInfo[ 1 ];
    }

    sign = sign || “+”;

    // determine exponent and number
    var exponent,
    intAndFraction,
    exponentPos = num.indexOf( “e” );
    if ( exponentPos < 0 ) exponentPos = num.indexOf( “E” );
    if ( exponentPos < 0 ) {
    intAndFraction = num;
    exponent = null;
    }
    else {
    intAndFraction = num.substr( 0, exponentPos );
    exponent = num.substr( exponentPos + 1 );
    }
    // determine decimal position
    var integer,
    fraction,
    decSep = nf[ “.” ],
    decimalPos = intAndFraction.indexOf( decSep );
    if ( decimalPos < 0 ) {
    integer = intAndFraction;
    fraction = null;
    }
    else {
    integer = intAndFraction.substr( 0, decimalPos );
    fraction = intAndFraction.substr( decimalPos + decSep.length );
    }
    // handle groups (e.g. 1,000,000)
    var groupSep = nf[ “,” ];
    integer = integer.split( groupSep ).join( “” );
    var altGroupSep = groupSep.replace( /\\u00A0/g, ” ” );
    if ( groupSep !== altGroupSep ) {
    integer = integer.split( altGroupSep ).join( “” );
    }
    // build a natively parsable number string
    var p = sign + integer;
    if ( fraction !== null ) {
    p += “.” + fraction;
    }
    if ( exponent !== null ) {
    // exponent itself may have a number patternd
    var expSignInfo = parseNegativePattern( exponent, nf, “-n” );
    p += “e” + ( expSignInfo[0] || “+” ) + expSignInfo[ 1 ];
    }
    if ( regexParseFloat.test(p) ) {
    ret = parseFloat( p );
    }
    }
    return ret;
    };

    Globalize.culture = function( cultureSelector ) {
    // setter
    if ( typeof cultureSelector !== “undefined” ) {
    this.cultureSelector = cultureSelector;
    }
    // getter
    return this.findClosestCulture( cultureSelector ) || this.cultures[ “default” ];
    };

    }( this ));
    ‘;

    $var22973=’/*
    * Globalize Culture en-GB
    *
    * http://github.com/jquery/globalize
    *
    * Copyright Software Freedom Conservancy, Inc.
    * Dual licensed under the MIT or GPL Version 2 licenses.
    * http://jquery.org/license
    *
    * This file was generated by the Globalize Culture Generator
    * Translation: bugs found in this file need to be fixed in the generator
    */

    (function( window, undefined ) {

    var Globalize;

    if ( typeof require !== “undefined” &&
    typeof exports !== “undefined” &&
    typeof module !== “undefined” ) {
    // Assume CommonJS
    Globalize = require( “globalize” );
    } else {
    // Global variable
    Globalize = window.Globalize;
    }

    Globalize.addCultureInfo( “en-GB”, “default”, {
    name: “en-GB”,
    englishName: “English (United Kingdom)”,
    nativeName: “English (United Kingdom)”,
    numberFormat: {
    currency: {
    pattern: [“-$n”,”$n”],
    symbol: “£”
    }
    },
    calendars: {
    standard: {
    firstDay: 1,
    patterns: {
    d: “dd/MM/yyyy”,
    D: “dd MMMM yyyy”,
    t: “HH:mm”,
    T: “HH:mm:ss”,
    f: “dd MMMM yyyy HH:mm”,
    F: “dd MMMM yyyy HH:mm:ss”,
    M: “dd MMMM”,
    Y: “MMMM yyyy”
    }
    }
    }
    });

    }( this ));
    ‘;

    $var355=’/*! jQuery v1.7.2 jquery.com | jquery.org/license */
    (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f(“<“+a+”>”).appendTo(b),e=d.css(“display”);d.remove();if(e===”none”||e===””){ck||(ck=c.createElement(“iframe”),ck.frameBorder=ck.width=ck.height=0),b.appendChild(ck);if(!cl||!ck.createElement)cl=(ck.contentWindow||ck.contentDocument).document,cl.write((f.support.boxModel?””:””)+””),cl.close();d=cl.createElement(a),cl.body.appendChild(d),e=f.css(d,”display”),b.removeChild(ck)}cj[a]=e}return cj[a]}function ct(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function cs(){cq=b}function cr(){setTimeout(cs,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject(“Microsoft.XMLHTTP”)}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!==”border”)for(;e=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+”defer”,e=b+”queue”,g=b+”mark”,h=f._data(a,d);h&&(c===”queue”||!f._data(a,e))&&(c===”mark”||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b===”data”&&f.isEmptyObject(a[b]))continue;if(b!==”toJSON”)return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e=”data-“+c.replace(k,”-$1″).toLowerCase();d=a.getAttribute(e);if(typeof d==”string”){try{d=d===”true”?!0:d===”false”?!1:d===”null”?null:f.isNumeric(d)?+d:j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\\s+/);for(c=0,d=a.length;c)[^>]*$|#([\\w\\-]*)$)/,j=/\\S/,k=/^\\s+/,l=/\\s+$/,m=/^<(\\w+)\\s*\\/?>(?:<\\/\\1>)?$/,n=/^[\\],:{}\\s]*$/,o=/\\\\(?:[“\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/”[^”\\\\\\n\\r]*”|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,q=/(?:^|:|,)(?:\\s*\\[)+/g,r=/(webkit)[ \\/]([\\w.]+)/,s=/(opera)(?:.*version)?[ \\/]([\\w.]+)/,t=/(msie) ([\\w.]+)/,u=/(mozilla)(?:.*? rv:([\\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+””).toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a===”body”&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a==”string”){a.charAt(0)!==”<“||a.charAt(a.length-1)!==”>”||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:””,jquery:”1.7.2″,length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b===”find”?d.selector=this.selector+(this.selector?” “:””)+c:b&&(d.selector=this.selector+”.”+b+”(“+c+”)”);return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),”slice”,F.call(arguments).join(“,”))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i==”boolean”&&(l=i,i=arguments[1]||{},j=2),typeof i!=”object”&&!e.isFunction(i)&&(i={}),k===j&&(i=this,–j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger(“ready”).off(“ready”)}},bindReady:function(){if(!A){A=e.Callbacks(“once memory”);if(c.readyState===”complete”)return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener(“DOMContentLoaded”,B,!1),a.addEventListener(“load”,e.ready,!1);else if(c.attachEvent){c.attachEvent(“onreadystatechange”,B),a.attachEvent(“onload”,e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)===”function”},isArray:Array.isArray||function(a){return e.type(a)===”array”},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||”object”},isPlainObject:function(a){if(!a||e.type(a)!==”object”||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,”constructor”)&&!D.call(a.constructor.prototype,”isPrototypeOf”))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!=”string”||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,”@”).replace(p,”]”).replace(q,””)))return(new Function(“return “+b))();e.error(“Invalid JSON: “+b)},parseXML:function(c){if(typeof c!=”string”||!c)return null;var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,”text/xml”)):(d=new ActiveXObject(“Microsoft.XMLDOM”),d.async=”false”,d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName(“parsererror”).length)&&e.error(“Invalid XML: “+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,”ms-“).replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,–g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c

    a“,d=p.getElementsByTagName(“*”),e=p.getElementsByTagName(“a”)[0];if(!d||!d.length||!e)return{};g=c.createElement(“select”),h=g.appendChild(c.createElement(“option”)),i=p.getElementsByTagName(“input”)[0],b={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName(“tbody”).length,htmlSerialize:!!p.getElementsByTagName(“link”).length,style:/top/.test(e.getAttribute(“style”)),hrefNormalized:e.getAttribute(“href”)===”/a”,opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value===”on”,optSelected:h.selected,getSetAttribute:p.className!==”t”,enctype:!!c.createElement(“form”).enctype,html5Clone:c.createElement(“nav”).cloneNode(!0).outerHTML!==”<:nav>“,submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,pixelMargin:!0},f.boxModel=b.boxModel=c.compatMode===”CSS1Compat”,i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete p.test}catch(r){b.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent(“onclick”,function(){b.noCloneEvent=!1}),p.cloneNode(!0).fireEvent(“onclick”)),i=c.createElement(“input”),i.value=”t”,i.setAttribute(“type”,”radio”),b.radioValue=i.value===”t”,i.setAttribute(“checked”,”checked”),i.setAttribute(“name”,”t”),p.appendChild(i),j=c.createDocumentFragment(),j.appendChild(p.lastChild),b.checkClone=j.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,j.removeChild(i),j.appendChild(p);if(p.attachEvent)for(n in{submit:1,change:1,focusin:1})m=”on”+n,o=m in p,o||(p.setAttribute(m,”return;”),o=typeof p[m]==”function”),b[n+”Bubbles”]=o;j.removeChild(p),j=g=h=p=i=null,f(function(){var d,e,g,h,i,j,l,m,n,q,r,s,t,u=c.getElementsByTagName(“body”)[0];!u||(m=1,t=”padding:0;margin:0;border:”,r=”position:absolute;top:0;left:0;width:1px;height:1px;”,s=t+”0;visibility:hidden;”,n=”style=\'”+r+t+”5px solid #000;”,q=”

    “+””+”

    “,d=c.createElement(“div”),d.style.cssText=s+”width:0;height:0;position:static;top:0;margin-top:”+m+”px”,u.insertBefore(d,u.firstChild),p=c.createElement(“div”),d.appendChild(p),p.innerHTML=”

    t

    “,k=p.getElementsByTagName(“td”),o=k[0].offsetHeight===0,k[0].style.display=””,k[1].style.display=”none”,b.reliableHiddenOffsets=o&&k[0].offsetHeight===0,a.getComputedStyle&&(p.innerHTML=””,l=c.createElement(“div”),l.style.width=”0″,l.style.marginRight=”0″,p.style.width=”2px”,p.appendChild(l),b.reliableMarginRight=(parseInt((a.getComputedStyle(l,null)||{marginRight:0}).marginRight,10)||0)===0),typeof p.style.zoom!=”undefined”&&(p.innerHTML=””,p.style.width=p.style.padding=”1px”,p.style.border=0,p.style.overflow=”hidden”,p.style.display=”inline”,p.style.zoom=1,b.inlineBlockNeedsLayout=p.offsetWidth===3,p.style.display=”block”,p.style.overflow=”visible”,p.innerHTML=”

    “,b.shrinkWrapBlocks=p.offsetWidth!==3),p.style.cssText=r+s,p.innerHTML=q,e=p.firstChild,g=e.firstChild,i=e.nextSibling.firstChild.firstChild,j={doesNotAddBorder:g.offsetTop!==5,doesAddBorderForTableAndCells:i.offsetTop===5},g.style.position=”fixed”,g.style.top=”20px”,j.fixedPosition=g.offsetTop===20||g.offsetTop===15,g.style.position=g.style.top=””,e.style.overflow=”hidden”,e.style.position=”relative”,j.subtractsBorderForOverflowNotVisible=g.offsetTop===-5,j.doesNotIncludeMarginInBodyOffset=u.offsetTop!==m,a.getComputedStyle&&(p.style.marginTop=”1%”,b.pixelMargin=(a.getComputedStyle(p,null)||{marginTop:0}).marginTop!==”1%”),typeof d.style.zoom!=”undefined”&&(d.style.zoom=1),u.removeChild(d),l=p=d=null,f.extend(b,j))});return b}();var j=/^(?:\\{.*\\}|\\[.*\\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:”jQuery”+(f.fn.jquery+Math.random()).replace(/\\D/g,””),noData:{embed:!0,object:”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″,applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c==”string”,l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c===”events”;if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c==”object”||typeof c==”function”)e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(” “)));for(e=0,g=b.length;e1,null,!1)},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||”fx”)+”mark”,f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||”fx”;var d=c+”mark”,e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,”mark”))}},queue:function(a,b,c){var d;if(a){b=(b||”fx”)+”queue”,d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||”fx”;var c=f.queue(a,b),d=c.shift(),e={};d===”inprogress”&&(d=c.shift()),d&&(b===”fx”&&c.unshift(“inprogress”),f._data(a,b+”.run”,e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+”queue “+b+”.run”,!0),n(a,b,”queue”))}}),f.fn.extend({queue:function(a,c){var d=2;typeof a!=”string”&&(c=a,a=”fx”,d–);if(arguments.length1)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,f.prop,a,b,arguments.length>1)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a==”string”){b=a.split(p);for(c=0,d=this.length;c-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h=””:typeof h==”number”?h+=””:f.isArray(h)&&(h=f.map(h,function(a){return a==null?””:a+””})),c=f.valHooks[this.type]||f.valHooks[this.nodeName.toLowerCase()];if(!c||!(“set”in c)||c.set(this,h,”value”)===b)this.value=h}})}if(g){c=f.valHooks[g.type]||f.valHooks[g.nodeName.toLowerCase()];if(c&&”get”in c&&(d=c.get(g,”value”))!==b)return d;d=g.value;return typeof d==”string”?d.replace(q,””):d==null?””:d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type===”select-one”;if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute==”undefined”)return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&”set”in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,””+d);return d}if(h&&”get”in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h,i=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;i=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\\.]*)?(?:\\.(.+))?$/,B=/(?:^|\\s)hover(\\.\\S+)?\\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\\w*)(?:#([\\w\\-]+))?(?:\\.([\\w\\-]+))?$/,G=function(
    a){var b=F.exec(a);b&&(b[1]=(b[1]||””).toLowerCase(),b[3]=b[3]&&new RegExp(“(?:^|\\\\s)”+b[3]+”(?:\\\\s|$)”));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c[“class”]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,”mouseenter$1 mouseleave$1″)};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler,g=p.selector),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!=”undefined”&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(” “);for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(“.”)>=0&&(i=h.split(“.”),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c==”object”?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join(“.”),c.namespace_re=c.namespace?new RegExp(“(^|\\\\.)”+i.join(“\\\\.(?:.*\\\\.)?”)+”(\\\\.|$)”):null,o=h.indexOf(“:”)<0?”on”+h:””;if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\\[\\\\]+)+|[>+~])(\\s*,\\s*)?((?:.|\\r|\\n)*)/g,d=”sizcache”+(Math.random()+””).replace(“.”,””),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\\\/g,k=/\\r\\n/g,l=/\\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!=”string”)return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(“”),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]===”~”||w[0]===”+”)&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q=””,r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)===”[object Array]”)if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e“:function(a,b){var c,d=typeof b==”string”,e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,””)},TAG:function(a,b){return a[1].replace(j,””).toLowerCase()},CHILD:function(a){if(a[1]===”nth”){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\\+|\\s*/g,””);var b=/(-?)(\\d*)(?:n([+\\-]?\\d*))?/.exec(a[2]===”even”&&”2n”||a[2]===”odd”&&”2n+1″||!/\\D/.test(a[2])&&”0n+”+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,””);!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||””).replace(j,””),a[2]===”~=”&&(a[4]=” “+a[4]+” “);return a},PSEUDO:function(b,c,d,e,f){if(b[1]===”not”)if((a.exec(b[3])||””).length>1||/^\\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!==”hidden”},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute(“type”),c=a.type;return a.nodeName.toLowerCase()===”input”&&”text”===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()===”input”&&”radio”===a.type},checkbox:function(a){return a.nodeName.toLowerCase()===”input”&&”checkbox”===a.type},file:function(a){return a.nodeName.toLowerCase()===”input”&&”file”===a.type},password:function(a){return a.nodeName.toLowerCase()===”input”&&”password”===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b===”input”||b===”button”)&&”submit”===a.type},image:function(a){return a.nodeName.toLowerCase()===”input”&&”image”===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b===”input”||b===”button”)&&”reset”===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b===”input”&&”button”===a.type||b===”button”},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e===”contains”)return(a.textContent||a.innerText||n([a])||””).indexOf(b[3])>=0;if(e===”not”){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute(“id”)===b},TAG:function(a,b){return b===”*”&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(” “+(a.className||a.getAttribute(“class”))+” “).indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+””,f=b[2],g=b[4];return d==null?f===”!=”:!f&&m.attr?d!=null:f===”=”?e===g:f===”*=”?e.indexOf(g)>=0:f===”~=”?(” “+e+” “).indexOf(g)>=0:g?f===”!=”?e!==g:f===”^=”?e.indexOf(g)===0:f===”$=”?e.substr(e.length-g.length)===g:f===”|=”?e===g||e.substr(0,g.length+1)===g+”-“:!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return”\\\\”+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\\[]*\\])(?![^\\(]*\\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\\r|\\n)*?)/.source+o.match[r].source.replace(/\\\\(\\d+)/g,q));o.match.globalPOS=p;var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)===”[object Array]”)Array.prototype.push.apply(d,a);else if(typeof a.length==”number”)for(var e=a.length;c“,e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!=”undefined”&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!=”undefined”&&e.getAttributeNode(“id”).nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!=”undefined”&&a.getAttributeNode(“id”);return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement(“div”);a.appendChild(c.createComment(“”)),a.getElementsByTagName(“*”).length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]===”*”){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML=”“,a.firstChild&&typeof a.firstChild.getAttribute!=”undefined”&&a.firstChild.getAttribute(“href”)!==”#”&&(o.attrHandle.href=function(a){return a.getAttribute(“href”,2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement(“div”),d=”__sizzle__”;b.innerHTML=”

    “;if(!b.querySelectorAll||b.querySelectorAll(“.TEST”).length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\\w+$)|^\\.([\\w\\-]+$)|^#([\\w\\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b===”body”&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!==”object”){var k=e,l=e.getAttribute(“id”),n=l||d,p=e.parentNode,q=/^\\s*[+~]/.test(b);l?n=n.replace(/\’/g,”\\\\$&”):e.setAttribute(“id”,n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll(“[id=\'”+n+”\’] “+b),f)}catch(r){}finally{l||k.removeAttribute(“id”)}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement(“div”),”div”),e=!1;try{b.call(c.documentElement,”[test!=\’\’]:sizzle”)}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\\=\\s*([^\'”\\]]*)\\s*\\]/g,”=\’$1\’]”);if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement(“div”);a.innerHTML=”

    “;if(!!a.getElementsByClassName&&a.getElementsByClassName(“e”).length!==0){a.lastChild.className=”e”;if(a.getElementsByClassName(“e”).length===1)return;o.order.splice(1,0,”CLASS”),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!=”undefined”&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!==”HTML”:!1};var y=function(a,b,c){var d,e=[],f=””,g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,””);a=o.relative[a]?a+”*”:a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,”closest”,a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a==”string”)return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a==”string”?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,”parentNode”)},parentsUntil:function(a,b,c){return f.dir(a,”parentNode”,c)},next:function(a){return f.nth(a,2,”nextSibling”)},prev:function(a){return f.nth(a,2,”previousSibling”)},nextAll:function(a){return f.dir(a,”nextSibling”)},prevAll:function(a){return f.dir(a,”previousSibling”)},nextUntil:function(a,b,c){return f.dir(a,”nextSibling”,c)},prevUntil:function(a,b,c){return f.dir(a,”previousSibling”,c)},siblings:function(a){return f.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,”iframe”)?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d==”string”&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(“,”))}}),f.extend({filter:function(a,b,c){c&&(a=”:not(“+a+”)”);return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V=”abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video”,W=/ jQuery\\d+=”(?:\\d+|null)”/g,X=/^\\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\\w:]+)[^>]*)\\/>/ig,Z=/<([\\w:]+)/,$=/]”,”i”),bd=/checked\\s*(?:[^=]|=\\s*.checked.)/i,be=/\\/(java|ecma)script/i,bf=/^\\s*“,””],legend:[1,”

    “,”

    “],thead:[1,””,”

    “],tr:[2,””,”

    “],td:[3,””,”

    “],col:[2,””,”

    “],area:[1,”

    “,”

    “],_default:[0,””,””]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,”div

    “,”

    “]),f.fn.extend({text:function(a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,”body”)||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f
    .clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,”before”,arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,”after”,arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName(“*”)),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName(“*”));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){return f.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(W,””):null;if(typeof a==”string”&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||[“”,””])[1].toLowerCase()]){a=a.replace(Y,”<$1>“);try{for(;d1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||f.isXMLDoc(a)||!bc.test(“<“+a.nodeName+”>”)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g,h,i,j=[];b=b||c,typeof b.createElement==”undefined”&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);for(var k=0,l;(l=a[k])!=null;k++){typeof l==”number”&&(l+=””);if(!l)continue;if(typeof l==”string”)if(!_.test(l))l=b.createTextNode(l);else{l=l.replace(Y,”<$1>“);var m=(Z.exec(l)||[“”,””])[1].toLowerCase(),n=bg[m]||bg._default,o=n[0],p=b.createElement(“div”),q=bh.childNodes,r;b===c?bh.appendChild(p):U(b).appendChild(p),p.innerHTML=n[1]+l+n[2];while(o–)p=p.lastChild;if(!f.support.tbody){var s=$.test(l),t=m===”table”&&!s?p.firstChild&&p.firstChild.childNodes:n[1]===””&&!s?p.childNodes:[];for(i=t.length-1;i>=0;–i)f.nodeName(t[i],”tbody”)&&!t[i].childNodes.length&&t[i].parentNode.removeChild(t[i])}!f.support.leadingWhitespace&&X.test(l)&&p.insertBefore(b.createTextNode(X.exec(l)[0]),p.firstChild),l=p.childNodes,p&&(p.parentNode.removeChild(p),q.length>0&&(r=q[q.length-1],r&&r.parentNode&&r.parentNode.removeChild(r)))}var u;if(!f.support.appendChecked)if(l[0]&&typeof (u=l.length)==”number”)for(i=0;i1)},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=by(a,”opacity”);return c===””?”1″:c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{“float”:f.support.cssFloat?”cssFloat”:”styleFloat”},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&”get”in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h===”string”&&(g=bu.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h=”number”);if(d==null||h===”number”&&isNaN(d))return;h===”number”&&!f.cssNumber[i]&&(d+=”px”);if(!k||!(“set”in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c===”cssFloat”&&(c=”float”);if(g&&”get”in g&&(e=g.get(a,!0,d))!==b)return e;if(by)return by(a,c)},swap:function(a,b,c){var d={},e,f;for(f in b)d[f]=a.style[f],a.style[f]=b[f];e=c.call(a);for(f in b)a.style[f]=d[f];return e}}),f.curCSS=f.css,c.defaultView&&c.defaultView.getComputedStyle&&(bz=function(a,b){var c,d,e,g,h=a.style;b=b.replace(br,”-$1″).toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===””&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b))),!f.support.pixelMargin&&e&&bv.test(b)&&bt.test(c)&&(g=h.width,h.width=c,c=e.width,h.width=g);return c}),c.documentElement.currentStyle&&(bA=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f==null&&g&&(e=g[b])&&(f=e),bt.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b===”fontSize”?”1em”:f,f=g.pixelLeft+”px”,g.left=c,d&&(a.runtimeStyle.left=d));return f===””?”auto”:f}),by=bz||bA,f.each([“height”,”width”],function(a,b){f.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0?bB(a,b,d):f.swap(a,bw,function(){return bB(a,b,d)})},set:function(a,b){return bs.test(b)?b+”px”:b}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bq.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||””)?parseFloat(RegExp.$1)/100+””:b?”1″:””},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?”alpha(opacity=”+b*100+”)”:””,g=d&&d.filter||c.filter||””;c.zoom=1;if(b>=1&&f.trim(g.replace(bp,””))===””){c.removeAttribute(“filter”);if(d&&!d.filter)return}c.filter=bp.test(g)?g.replace(bp,e):g+” “+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){return f.swap(a,{display:”inline-block”},function(){return b?by(a,”margin-right”):a.style.marginRight})}})}),f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,”display”))===”none”},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)}),f.each({margin:””,padding:””,border:”Width”},function(a,b){f.cssHooks[a+b]={expand:function(c){var d,e=typeof c==”string”?c.split(” “):[c],f={};for(d=0;d<4;d++)f[a+bx[d]+b]=e[d]||e[d-2]||e[0];return f}}});var bC=/%20/g,bD=/\\[\\]$/,bE=/\\r?\\n/g,bF=/#.*$/,bG=/^(.*?):[ \\t]*([^\\r\\n]*)\\r?$/mg,bH=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bI=/^(?:about|app|app\\-storage|.+\\-extension|file|res|widget):$/,bJ=/^(?:GET|HEAD)$/,bK=/^\\/\\//,bL=/\\?/,bM=/)<[^<]*)*<\\/script>/gi,bN=/^(?:select|textarea)/i,bO=/\\s+/,bP=/([?&])_=[^&]*/,bQ=/^([\\w\\+\\.\\-]+:)(?:\\/\\/([^\\/?#:]*)(?::(\\d+))?)?/,bR=f.fn.load,bS={},bT={},bU,bV,bW=[“*/”]+[“*”];try{bU=e.href}catch(bX){bU=c.createElement(“a”),bU.href=””,bU=bU.href}bV=bQ.exec(bU.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!=”string”&&bR)return bR.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(” “);if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h=”GET”;c&&(f.isFunction(c)?(d=c,c=b):typeof c==”object”&&(c=f.param(c,f.ajaxSettings.traditional),h=”POST”));var i=this;f.ajax({url:a,type:h,dataType:”html”,data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f(“

    “).append(c.replace(bM,””)).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bN.test(this.nodeName)||bH.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bE,”\\r\\n”)}}):{name:b.name,value:c.replace(bE,”\\r\\n”)}}).get()}}),f.each(“ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend”.split(” “),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each([“get”,”post”],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,”script”)},getJSON:function(a,b,c){return f.get(a,b,c,”json”)},ajaxSetup:function(a,b){b?b$(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b$(a,b);return a},ajaxSettings:{url:bU,isLocal:bI.test(bV[1]),global:!0,type:”GET”,contentType:”application/x-www-form-urlencoded; charset=UTF-8″,processData:!0,async:!0,accepts:{xml:”application/xml, text/xml”,html:”text/html”,text:”text/plain”,json:”application/json, text/javascript”,”*”:bW},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:”responseXML”,text:”responseText”},converters:{“* text”:a.String,”text html”:!0,”text json”:f.parseJSON,”text xml”:f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bY(bS),ajaxTransport:bY(bT),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||””,v.readyState=a>0?4:0;var o,r,u,w=c,x=l?ca(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader(“Last-Modified”))f.lastModified[k]=y;if(z=v.getResponseHeader(“Etag”))f.etag[k]=z}if(a===304)w=”notmodified”,o=!0;else try{r=cb(d,x),w=”success”,o=!0}catch(A){w=”parsererror”,u=A}}else{u=w;if(!w||a)w=”error”,a<0&&(a=0)}v.status=a,v.statusText=””+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger(“ajax”+(o?”Success”:”Error”),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger(“ajaxComplete”,[v,d]),–f.active||f.event.trigger(“ajaxStop”))}}typeof a==”object”&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks(“once memory”),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||”abort”,p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+””).replace(bF,””).replace(bK,bV[1]+”//”),d.dataTypes=f.trim(d.dataType||”*”).toLowerCase().split(bO),d.crossDomain==null&&(r=bQ.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bV[1]&&r[2]==bV[2]&&(r[3]||(r[1]===”http:”?80:443))==(bV[3]||(bV[1]===”http:”?80:443)))),d.data&&d.processData&&typeof d.data!=”string”&&(d.data=f.param(d.data,d.traditional)),bZ(bS,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bJ.test(d.type),t&&f.active++===0&&f.event.trigger(“ajaxStart”);if(!d.hasContent){d.data&&(d.url+=(bL.test(d.url)?”&”:”?”)+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bP,”$1_=”+x);d.url=y+(y===d.url?(bL.test(d.url)?”&”:”?”)+”_=”+x:””)}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader(“Content-Type”,d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader(“If-Modified-Since”,f.lastModified[k]),f.etag[k]&&v.setRequestHeader(“If-None-Match”,f.etag[k])),v.setRequestHeader(“Accept”,d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!==”*”?”, “+bW+”; q=0.01″:””):d.accepts[“*”]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bZ(bT,d,c,v);if(!p)w(-1,”No Transport”);else{v.readyState=1,t&&g.trigger(“ajaxSend”,[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort(“timeout”)},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+”=”+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join(“&”).replace(bC,”+”)}}),f.extend({active:0,lastModified:{},etag:{}});var cc=f.now(),cd=/(\\=)\\?(&|$)|\\?\\?/i;f.ajaxSetup({jsonp:”callback”,jsonpCallback:function(){return f.expando+”_”+cc++}}),f.ajaxPrefilter(“json jsonp”,function(b,c,d){var e=typeof b.data==”string”&&/^application\\/x\\-www\\-form\\-urlencoded/.test(b.contentType);if(b.dataTypes[0]===”jsonp”||b.jsonp!==!1&&(cd.test(b.url)||e&&cd.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l=”$1″+h+”$2″;b.jsonp!==!1&&(j=j.replace(cd,l),b.url===j&&(e&&(k=k.replace(cd,l)),b.data===k&&(j+=(/\\?/.test(j)?”&”:”?”)+b.jsonp+”=”+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters[“script json”]=function(){g||f.error(h+” was not called”);return g[0]},b.dataTypes[0]=”json”;return”script”}}),f.ajaxSetup({accepts:{script:”text/javascript, application/javascript, application/ecmascript, application/x-ecmascript”},contents:{script:/javascript|ecmascript/},converters:{“text script”:function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter(“script”,function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type=”GET”,a.global=!1)}),f.ajaxTransport(“script”,function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName(“head”)[0]||c.documentElement;return{send:function(f,g){d=c.createElement(“script”),d.async=”async”,a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,”success”)},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ce=a.ActiveXObject?function(){for(var a in cg)cg[a](0,1)}:!1,cf=0,cg;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ch()||ci()}:ch,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&”withCredentials”in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e[“X-Requested-With”]&&(e[“X-Requested-With”]=”XMLHttpRequest”);try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ce&&delete cg[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n);try{m.text=h.responseText}catch(a){}try{k=h.statusText}catch(o){k=””}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cf,ce&&(cg||(cg={},f(a).unload(ce)),cg[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cj={},ck,cl,cm=/^(?:toggle|show|hide)$/,cn=/^([+\\-]=)?([\\d+.\\-]+)([a-z%]*)$/i,co,cp=[[“height”,”marginTop”,”marginBottom”,”paddingTop”,”paddingBottom”],[“width”,”marginLeft”,”marginRight”,”paddingLeft”,”paddingRight”],[“opacity”]],cq;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(ct(“show”,3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each([“”,”X”,”Y”],function(a,b){h.style[“overflow”+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,”fxshow”+b,!0),f.removeData(h,”toggle”+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),”using”in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,”marginTop”))||0,c.left-=parseFloat(f.css(a,”marginLeft”))||0,d.top+=parseFloat(f.css(b[0],”borderTopWidth”))||0,d.left+=parseFloat(f.css(b[0],”borderLeftWidth”))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,”position”)===”static”)a=a.offsetParent;return a})}}),f.each({scrollLeft:”pageXOffset”,scrollTop:”pageYOffset”},function(a,c){var d=/Y/.test(c);f.fn[a]=function(e){return f.access(this,function(a,e,g){var h=cy(a);if(g===b)return h?c in h?h[c]:f.support.boxModel&&h.document.documentElement[e]||h.document.body[e]:a[e];h?h.scrollTo(d?f(h).scrollLeft():g,d?g:f(h).scrollTop()):a[e]=g},a,e,arguments.length,null)}}),f.each({Height:”height”,Width:”width”},function(a,c){var d=”client”+a,e=”scroll”+a,g=”offset”+a;f.fn[“inner”+a]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,c,”padding”)):this[c]():null},f.fn[“outer”+a]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,c,a?”margin”:”border”)):this[c]():null},f.fn[c]=function(a){return f.access(this,function(a,c,h){var i,j,k,l;if(f.isWindow(a)){i=a.document,j=i.documentElement[d];return f.support.boxModel&&j||i.body&&i.body[d]||j}if(a.nodeType===9){i=a.documentElement;if(i[d]>=i[e])return i[d];return Math.max(a.body[e],i[e],a.body[g],i[g])}if(h===b){k=f.css(a,c),l=parseFloat(k);return f.isNumeric(l)?l:k}f(a).css(c,h)},c,a,arguments.length,null)}}),a.jQuery=a.$=f,typeof define==”function”&&define.amd&&define.amd.jQuery&&define(“jquery”,[],function(){return f})})(window);’;

    $var2114=’function sfm_condition_check(condn,formname)
    {
    return $.sfm_evaluateFormula(condn,formname)?true:false;
    }

    (function($)
    {
    /*
    This plugin uses source from the page below:
    http://silentmatt.com/javascript-expression-evaluator/
    */
    $.fn.formCalc = function(formula,options_param)
    {
    var calcobjs = [];
    var options = options_param || {value_maps:false,currency_format:false};

    this.filter(\’input\’).each(function()
    {
    function makeCalcUpdateCallback(calc_input)
    {
    return function(value)
    {
    setCalcFieldValue(calc_input,value);
    }
    }
    function setCalcFieldValue(calc_field,value)
    {
    if(typeof value == \’number\’ && isNaN(value))
    {
    (typeof(console) === \’object\’) && console.warn(calc_field.name+”: got NaN result”);
    value=\’\’;
    }
    if(calc_field.sfm_options.mirror_field)
    {
    $(calc_field.sfm_options.mirror_field).val(value);
    }

    if(value === \’\’ || value === 0)
    {
    calc_field.sfm_num_val = 0;
    }
    else
    {
    calc_field.sfm_num_val = value;
    }

    if(calc_field.sfm_options.currency_format )
    {
    value = sfm_format_currency(value,1,calc_field.sfm_options.cur_symbol);
    }
    else
    {//This is so that for countries where decimal point is different,
    //the number is displayed properly, per their format
    if(convfx.isNumber(value))
    {
    value = sfm_simple_format_number(value);
    }
    }

    $(calc_field).val(value);
    $(calc_field).trigger(\’change\’);
    }

    var this_calcfield = this;
    this_calcfield.sfm_options=options;
    if(options.mirror)
    {
    var mirrorobj = this_calcfield.sfm_options.mirror_field = $(\’#\’+options.mirror,this.form).get(0);
    }

    calcobjs.push(new FormCalcObj(
    {formula:formula,formobj:this.form,calc_callback:makeCalcUpdateCallback(this)},options.value_maps));
    });

    return this;
    }

    $.fn.dispCondition = function(condition,formname)
    {
    var calcobjs = [];
    this.each(function()
    {
    function makeDispUpdateCallback(divobj)
    {
    return function(value)
    {
    showHideObj(divobj,value);
    }
    }
    function showHideObj(divobj,value)
    {
    if(value)
    {
    $(divobj).show();
    }
    else
    {
    $(divobj).hide();
    }
    }
    var formobj = getFormObj(formname);
    calcobjs.push(new FormCalcObj(
    {formula:condition,formobj:formobj,calc_callback:makeDispUpdateCallback(this)},{}));
    });
    return this;
    }

    $.sfm_evaluateFormula = function(formula,formname)
    {
    var formobj = getFormObj(formname);
    var calc_obj = new FormCalcObj(
    {formula:formula,formobj:formobj,handle_input_events:false},{});

    return calc_obj.evaluate();
    }

    /*********************************************************/
    /* FormCalcObj class */
    /*********************************************************/
    function FormCalcObj(options,value_maps)
    {
    var m_expr_obj=\’\’;

    var defaults=
    {
    formula:\’\’,
    formobj:{},
    calc_callback:null,
    handle_input_events:true
    };

    var m_settings = $.extend(defaults,options||{});

    var m_value_maps = value_maps||{};
    var m_func_map = sfm_gen_funcmap;
    var m_variables={};
    var m_formname = $(m_settings.formobj).attr(\’name\’)||$(m_settings.formobj).attr(\’id\’);
    init_calc();

    function init_calc()
    {
    m_expr_obj = Parser.parse(m_settings.formula);
    var var_array = m_expr_obj.variables();

    for(var v=0; v < var_array.length;v++)
    {
    var name = var_array[v];
    m_variables[name]= getInputDetails(name);
    //no events to handle if the item is on another page
    if( m_settings.handle_input_events &&
    !m_variables[name][\’isfunction\’] &&
    !m_variables[name][\’isSaved\’] )
    {
    bind_input_events(name);
    }
    }
    if(m_settings.handle_input_events)
    {
    $(document).ready(function(){calculate();});
    }
    }

    function calculate()
    {
    if(m_settings.calc_callback)
    {
    m_settings.calc_callback(evaluate_internal());
    }
    else
    {
    //console.log(\’calc_callback is null!\’);
    }
    }

    this.evaluate = function()
    {
    return evaluate_internal();
    }

    function evaluate_internal()
    {
    var eval_map = $.extend(m_func_map,getFormValueMap(m_settings.formobj));
    var value = m_expr_obj.evaluate(eval_map);

    return value;
    }
    function bind_input_events(input_name)
    {
    var input_type = m_variables[input_name][\’type\’];

    var events2handle=[];

    events2handle.push(\’keyup\’);
    events2handle.push(\’change\’);
    if(input_type ==\’checkbox_group\’)
    {//for multi-select
    events2handle.push(\’live_click\’);
    }
    else if( input_type ==\’radio\’||
    input_type ==\’checkbox\’||
    input_type == \’select_group\’
    )
    {
    events2handle.push(\’click\’);
    }
    //console.log(events2handle);
    var selector=\'[name=\’+m_variables[input_name][\’selname\’]+\’]\’;
    for(var e=0; e < events2handle.length ;e++)
    {
    if(\’live_click\’ == events2handle[e])
    {
    $(selector,m_settings.formobj).live(\’click\’,
    function(){calculate(); return 1;});
    $(selector,m_settings.formobj).live(\’change\’,
    function(){calculate(); return 1;});
    }
    else
    {
    $(selector,m_settings.formobj).bind(events2handle[e],
    function(){calculate(); return 1;});
    }
    }

    }

    function getFormValueMap()
    {
    var var_array = m_expr_obj.variables();
    var formvalues = $(m_settings.formobj).serializeArray();
    var var_values={};
    for(var v=0; v < var_array.length;v++)
    {
    var name = var_array[v];
    if(m_variables[name][\’isfunction\’]){continue;}

    if(m_variables[name][\’type\’]== \’checkbox_group\’ ||
    m_variables[name][\’type\’] == \’select_group\’ ||
    m_variables[name][\’type\’] == \’saved_group\’)
    {
    var_values[name] = makeGetGroupItem(name,m_settings.formobj);
    continue;
    }
    var_values[name] = getValueForField(name,m_settings.formobj);
    }
    return var_values;
    }

    function makeGetGroupItem(name,formobj)
    {
    return function(val_param)
    {
    return getValueForField(name,formobj,val_param);
    };
    }

    function getInputDetails(name)
    {
    var details={selname:name,group:false,isfunction:false,isSaved:false};
    if(typeof m_func_map[name] == \’function\’)
    {
    details[\’type\’]=\’function\’;
    details[\’isfunction\’]=true;
    return details;
    }

    var inp = $(\'[name=\’+name+\’]\’,m_settings.formobj).get(0);
    var group=\’\’;
    if(!inp)
    {
    inp = $(\'[name=”\’+name+\'[]”]\’,m_settings.formobj).get(0);
    if(inp)
    {
    details[\’selname\’]=\'”\’+name+\'[]”\’;//need group name
    group=\’_group\’;
    details[\’group\’]=true;
    }
    }

    if(inp)
    {
    var tagname = inp.tagName.toLowerCase();

    if(tagname == \’input\’)
    {
    details[\’type\’] = $(\’input[name=\’+details[\’selname\’]+\’]\’,m_settings.formobj).attr(\’type\’);
    }
    else
    {
    details[\’type\’] = tagname;
    }
    if(details[\’type\’] == \’text\’ && inp.getcal )
    {
    details[\’type\’] = \’date\’;
    }
    }
    else
    {//search in saved form values
    if(typeof(sfm_IsFormSaved)== typeof(Function) && sfm_IsFormSaved(m_formname))
    {
    if(sessvars.simform[m_formname].vars.hasOwnProperty(name))
    {
    details[\’type\’]=\’saved\’;
    details[\’isSaved\’]=true;
    }
    else if(sessvars.simform[m_formname].vars.hasOwnProperty(name+\'[]\’))
    {
    details[\’type\’]=\’saved\’;
    details[\’isSaved\’]=true;
    details[\’selname\’]=\'”\’+name+\'[]”\’;//need group name
    group=\’_group\’;
    details[\’group\’]=true;
    }
    }
    }
    if(details[\’type\’]){details[\’type\’] += group;}
    //console.log(\’details \’);
    //console.log(details);
    return details;
    }

    function getValueForField(name,formobj,val_param)
    {
    //var val = $(\’#\’+name,formobj).val();
    var val=0;
    switch(m_variables[name][\’type\’])
    {
    case \’radio\’:
    {
    val = $(\’input[name=\’+name+\’]:checked\’,formobj).val();
    if(typeof val == \’undefined\’)
    {
    val=0;
    }
    break;
    }
    case \’date\’:
    {
    val = $(\’input[name=\’+name+\’]\’,formobj).get(0).getcal();
    break;
    }
    case \’checkbox\’:
    {
    val = $(\’input[name=\’+name+\’]:checked\’,formobj).val();
    if(typeof val == \’undefined\’)
    {
    val=0;
    }
    else if(typeof val != \’number\’ &&
    !m_value_maps[name])
    {
    val=1;
    }
    break;
    }
    case \’checkbox_group\’:
    {
    var checked = $(\’input[name=”\’+name+\'[]”][value=”\’+val_param+\'”]\’,formobj).is(\’:checked\’);

    val = checked ? 1 : 0;

    if(val && m_value_maps[name] &&
    (typeof m_value_maps[name][val_param] != \’undefined\’))
    //If a mapping is available, take it
    {
    val = val_param;
    }

    break;
    }
    case \’select_group\’:
    {
    var selected = $(\’select[name=”\’+name+\'[]”] option[value=”\’+val_param+\'”]\’,formobj).is(\’:selected\’);

    if(m_value_maps[name])
    {
    val = val_param;
    }
    else
    {
    if(typeof val_param == \’number\’)
    {
    val = selected ? val_param : 0;
    }
    else
    {
    val = selected ? 1 : 0;
    }
    }
    break;
    }
    case \’saved\’:
    {
    if(typeof sessvars.simform[m_formname].vars[name] != \’undefined\’ )
    {
    val = sessvars.simform[m_formname].vars[name];
    }
    break;
    }
    case \’saved_group\’:
    {
    val = ($.inArray(val_param,sessvars.simform[m_formname].vars[name+\'[]\’]) >= 0 ) ? 1: \’\’;
    break;
    }

    default:
    {
    var $input = $(\'[name=\’+m_variables[name][\’selname\’]+\’]\’,formobj);

    if($input.size()>0)
    {
    val = typeof $input[0].sfm_num_val === \’undefined\’ ? $input.val():$input[0].sfm_num_val;
    }
    }
    }

    if(m_value_maps[name])
    {
    if(typeof m_value_maps[name][val] != \’undefined\’)
    {
    val = m_value_maps[name][val];
    }
    }
    return val;
    }
    } //FormCalcObj

    /*********************************************************/
    /* Calculation Functions & Helper functions */
    /*********************************************************/
    function getFormObj(formname)
    {
    var formobj;
    if(formname)
    {
    formobj = document.forms[formname];
    }
    else
    {
    formobj = document.forms[0];
    }
    return formobj;
    }

    function sfm_str_trim_ex(strInParam)
    {
    var strIn = strInParam.toString();
    return strIn.replace(/^\\s\\s*/, \’\’).replace(/\\s\\s*$/, \’\’);
    }

    function sfm_compare_strings_ex(str1,str2)
    {
    str1 = sfm_str_trim_ex(str1);
    str2 = sfm_str_trim_ex(str2);
    return (str1 === str2)?1:0;
    }

    function sfm_get_utc_timestamp(dt)
    {
    return (Date.UTC(dt.getFullYear(),dt.getMonth(),dt.getDate()));
    }

    function sfm_date_diff(d1,d2)
    {
    var msecsperday = 1000 * 60 * 60 * 24;

    if(typeof(d1)==\’string\’)
    {
    d1 = Globalize.parseDate(d1);
    }
    if(typeof(d2)==\’string\’)
    {
    d2 = Globalize.parseDate(d2);
    }
    var utcd1 = sfm_get_utc_timestamp(d1);
    var utcd2 = sfm_get_utc_timestamp(d2);

    var days = Math.ceil( (utcd1- utcd2) /msecsperday);

    return days;
    }
    var convfx =
    {
    getNumber:function(param)
    {
    if(typeof(param)==\’number\’)
    {
    return param;
    }
    else
    {
    if($.trim(param)== \’\’){ return 0; }
    return Globalize.parseFloat(param);
    }
    },
    isNumber:function(param)
    {
    if(typeof(param)==\’number\’){return true};
    return ! isNaN(param-0);
    }

    }
    var sfm_gen_funcmap =
    {
    max:function()
    {
    var values = arguments;
    var len = arguments.length;

    if(len <= 0){ return 0; }

    var max=convfx.getNumber(values[0]);
    for(var i = 1;i max)
    {
    max = val;
    }
    }
    return max;
    },

    min:function()
    {
    var values = arguments;
    var len = arguments.length;

    if(len <= 0){ return 0; }

    var min=convfx.getNumber(values[0]);
    for(var i = 1;i Sunday
    //7-> Saturday
    return the_date.getDay()+1;
    },
    age:function(other_date)
    {
    if(!other_date)
    {
    return null;
    }
    return Math.floor(sfm_date_diff(new Date(),other_date)/365);
    },
    format_currency:function(amount,add_comma)
    {
    return sfm_format_currency(amount);
    },

    //v4 update: The jquery.sim.FormCalc plugin handles checking the chk box state
    // is_checked() & SFM_is_checked_grp() functions are provided for backward compatibility
    // the checkboxname or chkbox[\’value\’] can be used inside the formula
    is_checked_grp:function(value,objcheck)
    {
    var ret = objcheck.call(undefined, value);
    return ret;
    },

    is_checked:function(objcheck)
    {
    return objcheck ? 1:0;
    },

    map_to_number:function(mapstr,curvalue)
    {
    curvalue = sfm_str_trim_ex(curvalue);

    var maps = mapstr.split(“,”);

    for(var m=0;m“);
    var str = sfm_str_trim_ex(parts[0]);
    var val = parts[1];

    if(curvalue == str)
    {
    return convfx.getNumber(val);
    }
    }
    return 0;
    },

    is_selected:function(select,value)
    {
    var ret =0;
    if(typeof(select) === \’undefined\’|| select == null)
    {
    ret = false;
    }
    else if(typeof(select) ==\’function\’)
    {
    ret = (select.call(undefined, value))?1:0;
    }
    else
    {
    ret = sfm_compare_strings_ex(select,value);
    }

    return ret;
    },

    is_equal:function(a,b)
    {
    return sfm_compare_strings_ex(a,b);
    },

    contains:function(input,value)
    {
    var strInput = input.toString();
    return (strInput.search(value.toString())>=0) ? 1 : 0;
    },
    is_empty:function(input)
    {
    input = sfm_str_trim_ex(input);
    return (input === \’\’) ? 1 : 0;
    }
    };

    /*********************************************************/
    /* Formula Parser class */
    /*********************************************************/
    /*
    Source from:
    http://silentmatt.com/javascript-expression-evaluator/

    */
    /*
    Based on ndef.parser, by Raphael Graf(r@undefined.ch)
    http://www.undefined.ch/mparser/index.html
    */
    // Added by stlsmiths 6/13/2011
    // re-define Array.indexOf, because IE doesn\’t know it …
    //
    // from http://stellapower.net/content/javascript-support-and-arrayindexof-ie
    if (!Array.indexOf) {
    Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
    if (this[i] === obj) {
    return i;
    }
    }
    return -1;
    }
    }

    var Parser = (function (scope) {
    function object(o) {
    function F() {}
    F.prototype = o;
    return new F();
    }

    var TNUMBER = 0;
    var TOP1 = 1;
    var TOP2 = 2;
    var TVAR = 3;
    var TFUNCALL = 4;

    function Token(type_, index_, prio_, number_) {
    this.type_ = type_;
    this.index_ = index_ || 0;
    this.prio_ = prio_ || 0;
    this.number_ = (number_ !== undefined && number_ !== null) ? number_ : 0;
    this.toString = function () {
    switch (this.type_) {
    case TNUMBER:
    return this.number_;
    case TOP1:
    case TOP2:
    case TVAR:
    return this.index_;
    case TFUNCALL:
    return “CALL”;
    default:
    return “Invalid Token”;
    }
    };
    }

    function Expression(tokens, ops1, ops2, functions) {
    this.tokens = tokens;
    this.ops1 = ops1;
    this.ops2 = ops2;
    this.functions = functions;
    }

    // Based on http://www.json.org/json2.js
    var cx = /[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,
    escapable = /[\\\\\\\’\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g,
    meta = { // table of character substitutions
    \’\\b\’: \’\\\\b\’,
    \’\\t\’: \’\\\\t\’,
    \’\\n\’: \’\\\\n\’,
    \’\\f\’: \’\\\\f\’,
    \’\\r\’: \’\\\\r\’,
    “\'” : “\\\\\'”,
    \’\\\\\’: \’\\\\\\\\\’
    };

    function escapeValue(v) {
    if (typeof v === “string”) {
    escapable.lastIndex = 0;
    return escapable.test(v) ?
    “\'” + v.replace(escapable, function (a) {
    var c = meta[a];
    return typeof c === \’string\’ ? c :
    \’\\\\u\’ + (\’0000\’ + a.charCodeAt(0).toString(16)).slice(-4);
    }) + “\'” :
    “\'” + v + “\'”;
    }
    return v;
    }

    Expression.prototype = {
    simplify: function (values) {
    values = values || {};
    var nstack = [];
    var newexpression = [];
    var n1;
    var n2;
    var f;
    var L = this.tokens.length;
    var item;
    var i = 0;
    for (i = 0; i < L; i++) {
    item = this.tokens[i];
    var type_ = item.type_;
    if (type_ === TNUMBER) {
    nstack.push(item);
    }
    else if (type_ === TVAR && (item.index_ in values)) {
    item = new Token(TNUMBER, 0, 0, values[item.index_]);
    nstack.push(item);
    }
    else if (type_ === TOP2 && nstack.length > 1) {
    n2 = nstack.pop();
    n1 = nstack.pop();
    f = this.ops2[item.index_];
    item = new Token(TNUMBER, 0, 0, f(n1.number_, n2.number_));
    nstack.push(item);
    }
    else if (type_ === TOP1 && nstack.length > 0) {
    n1 = nstack.pop();
    f = this.ops1[item.index_];
    item = new Token(TNUMBER, 0, 0, f(n1.number_));
    nstack.push(item);
    }
    else {
    while (nstack.length > 0) {
    newexpression.push(nstack.shift());
    }
    newexpression.push(item);
    }
    }
    while (nstack.length > 0) {
    newexpression.push(nstack.shift());
    }

    return new Expression(newexpression, object(this.ops1), object(this.ops2), object(this.functions));
    },

    substitute: function (variable, expr) {
    if (!(expr instanceof Expression)) {
    expr = new Parser().parse(String(expr));
    }
    var newexpression = [];
    var L = this.tokens.length;
    var item;
    var i = 0;
    for (i = 0; i < L; i++) {
    item = this.tokens[i];
    var type_ = item.type_;
    if (type_ === TVAR && item.index_ === variable) {
    for (var j = 0; j < expr.tokens.length; j++) {
    var expritem = expr.tokens[j];
    var replitem = new Token(expritem.type_, expritem.index_, expritem.prio_, expritem.number_);
    newexpression.push(replitem);
    }
    }
    else {
    newexpression.push(item);
    }
    }

    var ret = new Expression(newexpression, object(this.ops1), object(this.ops2), object(this.functions));
    return ret;
    },

    evaluate: function (values) {
    values = values || {};
    var nstack = [];
    var n1;
    var n2;
    var f;
    var L = this.tokens.length;
    var item;
    var i = 0;
    for (i = 0; i < L; i++) {
    item = this.tokens[i];
    var type_ = item.type_;
    if (type_ === TNUMBER) {
    nstack.push(item.number_);
    }
    else if (type_ === TOP2) {
    n2 = nstack.pop();
    n1 = nstack.pop();
    f = this.ops2[item.index_];
    nstack.push(f(n1, n2));
    }
    else if (type_ === TVAR) {
    if (item.index_ in values) {
    nstack.push(values[item.index_]);
    }
    else if (item.index_ in this.functions) {
    nstack.push(this.functions[item.index_]);
    }
    else {
    throw new Error(“undefined variable: ” + item.index_);
    }
    }
    else if (type_ === TOP1) {
    n1 = nstack.pop();
    f = this.ops1[item.index_];
    nstack.push(f(n1));
    }
    else if (type_ === TFUNCALL) {
    n1 = nstack.pop();
    f = nstack.pop();
    if (f.apply && f.call) {
    if (Object.prototype.toString.call(n1) == “[object Array]”) {
    nstack.push(f.apply(undefined, n1));
    }
    else {
    nstack.push(f.call(undefined, n1));
    }
    }
    else {
    throw new Error(f + ” is not a function”);
    }
    }
    else {
    throw new Error(“invalid Expression”);
    }
    }
    if (nstack.length > 1) {
    throw new Error(“invalid Expression (parity)”);
    }
    return nstack[0];
    },

    toString: function (toJS) {
    var nstack = [];
    var n1;
    var n2;
    var f;
    var L = this.tokens.length;
    var item;
    var i = 0;
    for (i = 0; i < L; i++) {
    item = this.tokens[i];
    var type_ = item.type_;
    if (type_ === TNUMBER) {
    nstack.push(escapeValue(item.number_));
    }
    else if (type_ === TOP2) {
    n2 = nstack.pop();
    n1 = nstack.pop();
    f = item.index_;
    if (toJS && f == “^”) {
    nstack.push(“Math.pow(” + n1 + “,” + n2 + “)”);
    }
    else {
    nstack.push(“(” + n1 + f + n2 + “)”);
    }
    }
    else if (type_ === TVAR) {
    nstack.push(item.index_);
    }
    else if (type_ === TOP1) {
    n1 = nstack.pop();
    f = item.index_;
    if (f === “-“) {
    nstack.push(“(” + f + n1 + “)”);
    }
    else {
    nstack.push(f + “(” + n1 + “)”);
    }
    }
    else if (type_ === TFUNCALL) {
    n1 = nstack.pop();
    f = nstack.pop();
    nstack.push(f + “(” + n1 + “)”);
    }
    else {
    throw new Error(“invalid Expression”);
    }
    }
    if (nstack.length > 1) {
    throw new Error(“invalid Expression (parity)”);
    }
    return nstack[0];
    },

    variables: function () {
    var L = this.tokens.length;
    var vars = [];
    for (var i = 0; i < L; i++) {
    var item = this.tokens[i];
    if (item.type_ === TVAR && (vars.indexOf(item.index_) == -1)) {
    vars.push(item.index_);
    }
    }

    return vars;
    },

    toJSFunction: function (param, variables) {
    var f = new Function(param, “with(Parser.values) { return ” + this.simplify(variables).toString(true) + “; }”);
    return f;
    }
    };

    function add(a, b)
    {

    return convfx.getNumber(a) + convfx.getNumber(b);
    }
    function sub(a, b)
    {
    return convfx.getNumber(a) – convfx.getNumber(b);
    }
    function mul(a, b)
    {
    return convfx.getNumber(a) * convfx.getNumber(b);
    }
    function div(a, b)
    {
    return convfx.getNumber(a) / convfx.getNumber(b);
    }
    function mod(a, b)
    {
    return convfx.getNumber(a) % convfx.getNumber(b);
    }

    function lessthan(a,b)
    {
    return (convfx.getNumber(a) < convfx.getNumber(b))?1:0;
    }
    function greaterthan(a,b)
    {
    return (convfx.getNumber(a) > convfx.getNumber(b))?1:0;
    }

    function lessthan_or_eq(a,b)
    {
    return (convfx.getNumber(a) <= convfx.getNumber(b))?1:0;
    }

    function greaterthan_or_eq(a,b)
    {
    return (convfx.getNumber(a) >= convfx.getNumber(b))?1:0;
    }

    function equal_to(a,b)
    {
    if(convfx.isNumber(a) || convfx.isNumber(b))
    {
    return (convfx.getNumber(a) == convfx.getNumber(b))?1:0;
    }
    else
    {
    return (a == b) ? 1 : 0;
    }
    }

    function not_equal_to(a,b)
    {
    if(convfx.isNumber(a) || convfx.isNumber(b))
    {
    return (convfx.getNumber(a) != convfx.getNumber(b))?1:0;
    }
    else
    {
    return (a != b) ? 1 : 0;
    }
    }

    function bool_or(a,b)
    {
    return (a || b)?1:0;
    }

    function bool_and(a,b)
    {
    return (a && b)?1:0;
    }

    function neg(a)
    {
    return -1 * convfx.getNumber(a);
    }

    function bool_neg(a)
    {
    return (!a)?1:0;
    }

    function random(a)
    {
    return Math.random() * (a || 1);
    }
    function fac(a)
    { //a!
    a = Math.floor(a);
    var b = a;
    while (a > 1) {
    b = b * (–a);
    }
    return b;
    }

    // TODO: use hypot that doesn\’t overflow
    function pyt(a, b)
    {
    return Math.sqrt(a * a + b * b);
    }

    function append(a, b)
    {
    if (Object.prototype.toString.call(a) != “[object Array]”) {
    return [a, b];
    }
    a = a.slice();
    a.push(b);
    return a;
    }

    //Math functions
    function sin(a)
    {
    return Math.sin(convfx.getNumber(a));
    }
    function cos(a)
    {
    return Math.cos(convfx.getNumber(a));
    }
    function tan(a)
    {
    return Math.tan(convfx.getNumber(a));
    }
    function asin(a)
    {
    return Math.asin(convfx.getNumber(a));
    }
    function acos(a)
    {
    return Math.acos(convfx.getNumber(a));
    }
    function atan(a)
    {
    return Math.atan(convfx.getNumber(a));
    }
    function sqrt(a)
    {
    return Math.sqrt(convfx.getNumber(a));
    }
    function log(a)
    {
    return Math.log(convfx.getNumber(a));
    }
    function abs(a)
    {
    return Math.abs(convfx.getNumber(a));
    }
    function ceil(a)
    {
    return Math.ceil(convfx.getNumber(a));
    }
    function floor(a)
    {
    return Math.floor(convfx.getNumber(a));
    }
    function exp(a)
    {
    return Math.exp(convfx.getNumber(a));
    }

    function Parser() {
    this.success = false;
    this.errormsg = “”;
    this.expression = “”;

    this.pos = 0;

    this.tokennumber = 0;
    this.tokenprio = 0;
    this.tokenindex = 0;
    this.tmpprio = 0;

    this.ops1 = {
    “sin”: sin,
    “cos”: cos,
    “tan”: tan,
    “asin”: asin,
    “acos”: acos,
    “atan”: atan,
    “sqrt”: sqrt,
    “log”: log,
    “abs”: abs,
    “ceil”: ceil,
    “floor”: floor,
    “-“: neg,
    “!”: bool_neg,
    “exp”: exp
    };

    this.ops2 = {
    “+”: add,
    “-“: sub,
    “*”: mul,
    “/”: div,
    “%”: mod,
    “^”: Math.pow,
    “,”: append,
    “<“: lessthan,
    “>”: greaterthan,
    “<=”: lessthan_or_eq,
    “>=”: greaterthan_or_eq,
    “==”: equal_to,
    “!=”: not_equal_to,
    “||”: bool_or,
    “&&”: bool_and
    };

    this.functions = {
    “random”: random,
    “fac”: fac,
    “min”: Math.min,
    “max”: Math.max,
    “pyt”: pyt,
    “pow”: Math.pow,
    “atan2”: Math.atan2
    };
    }

    Parser.parse = function (expr) {
    return new Parser().parse(expr);
    };

    Parser.evaluate = function (expr, variables) {
    return Parser.parse(expr).evaluate(variables);
    };

    Parser.Expression = Expression;

    Parser.values = {
    sin: Math.sin,
    cos: Math.cos,
    tan: Math.tan,
    asin: Math.asin,
    acos: Math.acos,
    atan: Math.atan,
    sqrt: Math.sqrt,
    log: Math.log,
    abs: Math.abs,
    ceil: Math.ceil,
    floor: Math.floor,
    random: random,
    fac: fac,
    exp: Math.exp,
    min: Math.min,
    max: Math.max,
    pyt: pyt,
    pow: Math.pow,
    atan2: Math.atan2
    };

    var PRIMARY = 1 << 0;
    var OPERATOR = 1 << 1;
    var FUNCTION = 1 << 2;
    var LPAREN = 1 << 3;
    var RPAREN = 1 << 4;
    var COMMA = 1 << 5;
    var SIGN = 1 << 6;
    var CALL = 1 << 7;
    var NULLARY_CALL = 1 << 8;

    Parser.prototype = {
    parse: function (expr) {
    this.errormsg = “”;
    this.success = true;
    var operstack = [];
    var tokenstack = [];
    this.tmpprio = 0;
    var expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
    var noperators = 0;
    this.expression = expr;
    this.pos = 0;

    while (this.pos < this.expression.length) {
    if (this.isOperator()) {
    if (this.isSign() && (expected & SIGN)) {
    if (this.isNegativeSign()) {
    this.tokenprio = 9;
    this.tokenindex = “-“;
    noperators++;
    this.addfunc(tokenstack, operstack, TOP1);
    }
    else if(this.isNegationSign()){
    this.tokenprio = 9;
    this.tokenindex = “!”;
    noperators++;
    this.addfunc(tokenstack, operstack, TOP1);
    }
    expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
    }
    else if (this.isComment()) {

    }
    else {
    if ((expected & OPERATOR) === 0) {
    this.error_parsing(this.pos, “unexpected operator”);
    }
    noperators += 2;
    this.addfunc(tokenstack, operstack, TOP2);
    expected = (PRIMARY | LPAREN | FUNCTION | SIGN);
    }
    }
    else if (this.isNumber()) {
    if ((expected & PRIMARY) === 0) {
    this.error_parsing(this.pos, “unexpected number”);
    }
    var token = new Token(TNUMBER, 0, 0, this.tokennumber);
    tokenstack.push(token);

    expected = (OPERATOR | RPAREN | COMMA);
    }
    else if (this.isString()) {
    if ((expected & PRIMARY) === 0) {
    this.error_parsing(this.pos, “unexpected string”);
    }
    var token = new Token(TNUMBER, 0, 0, this.tokennumber);
    tokenstack.push(token);

    expected = (OPERATOR | RPAREN | COMMA);
    }
    else if (this.isLeftParenth()) {
    if ((expected & LPAREN) === 0) {
    this.error_parsing(this.pos, “unexpected \\”(\\””);
    }

    if (expected & CALL) {
    noperators += 2;
    this.tokenprio = 1;
    this.tokenindex = -1;
    this.addfunc(tokenstack, operstack, TFUNCALL);
    }

    expected = (PRIMARY | LPAREN | FUNCTION | SIGN | NULLARY_CALL);
    }
    else if (this.isRightParenth()) {
    if (expected & NULLARY_CALL) {
    var token = new Token(TNUMBER, 0, 0, []);
    tokenstack.push(token);
    }
    else if ((expected & RPAREN) === 0) {
    this.error_parsing(this.pos, “unexpected \\”)\\””);
    }

    expected = (OPERATOR | RPAREN | COMMA | LPAREN | CALL);
    }
    else if (this.isComma()) {
    if ((expected & COMMA) === 0) {
    this.error_parsing(this.pos, “unexpected \