<?
class inputs
{//DigiHex Systems\\


	function init() {}


	//TEXT FIELDS =====================================================
	function input($name, $width=300, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false, $center=false) {
		return $this->input_id($name, $name, $width, $value, $readonly, $disabled, $custom_class, $maxlen, $center);
	}
	function input_id($name, $id, $width=300, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false, $center=false) {
		$class=(!empty($custom_class) ? $custom_class : 'input form-control').($readonly==true || $disabled==true ? ' disabled':'');
		return '<input type="text" name="'.$name.'" '.(!empty($id) ? 'id="'.$id.'" ':'').'value="'.$value.'" class="'.$class.'" style="width:'.$width.'px;'.($center==true ? ' text-align:center;':'').'"'.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').($maxlen>0 ? ' maxlength="'.$maxlen.'"':'').' />';
	}
	function input_center($name, $width=300, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false, $mask=false, $default_value=false) {
		return $this->input_id($name, $name, $width, $value, $readonly, $disabled, $custom_class, $maxlen, true);
	}
	function input_id_center($name, $id, $width=300, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false, $mask=false, $default_value=false) {
		return $this->input_id($name, $id, $width, $value, $readonly, $disabled, $custom_class, $maxlen, true);
	}


	function textarea($name, $width=300, $height=63, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false) {
		return $this->textarea_id($name, $name, $width, $height, $value, $readonly, $disabled, $custom_class, $maxlen);
	}
	function textarea_id($name, $id, $width=300, $height=63, $value=false, $readonly=false, $disabled=false, $custom_class=false, $maxlen=false) {
		$class=(!empty($custom_class) ? $custom_class : 'textarea form-control').($readonly==true || $disabled==true ? ' disabled':'');
		return '<textarea name="'.$name.'" id="'.$id.'" class="'.$class.'" rows="10" cols="60" style="width:'.$width.'px; height:'.$height.'px;"'.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').($maxlen>0 ? ' maxlength="'.$maxlen.'"':'').'>'.$value.'</textarea>'.($maxlen>0 ? '<script type="text/javascript">$("#'.$id.'").on("keyup keypress paste blur",function(){ if($(this).val().length>'.$maxlen.') $(this).val($(this).val().substring(0,'.$maxlen.')); })</script>':'');
	}


	function ck($name, $value=false, $width=false, $height=false, $toolbar=false) {
		if(empty($width)) $width=790;
		if(empty($height)) $height=400;
		$width = ($width<790 ? 790:$width);
		$height = ($height<100 ? 100:$height);
		if(empty($toolbar)) $toolbar='Full';

		$lang=(empty($_SESSION['backend']['ui_lang']) ? 'PL':$_SESSION['backend']['ui_lang']);
		$timestamp=1.01;

		$inited=$this->CK_INITIATED;
		$this->CK_INITIATED=true;

		@mkdir(USR.'/_CMS_',true,0755);

		return '
			<a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block; width:'.$width.'px;"></a>
			<textarea name="'.$name.'" id="'.$name.'" rows="10" cols="60">'.htmlspecialchars($value).'</textarea>
			'.($inited!=true ? '<script type="text/javascript" src="'.$this->DIR.'/ck/ckeditor.js?t='.$timestamp.'"></script>':'').'
			<script type="text/javascript">'.($inited!=true ? 'window.CKEDITOR_BASEPATH="'.$this->DIR.'/ck/"; CKEDITOR.timestamp = "'.$timestamp.'";':'').'
				CKEDITOR.replace("'.$name.'", {"language":"'.$lang.'", "toolbar":"'.$toolbar.'", "width":'.(int)$width.', "height":'.(int)$height.' });
			</script>
		';

		/*
		require($this->DIR.'/ck/ckeditor.php');
		$CKEditor = new CKEditor();
		$CKEditor->basePath = $this->DIR.'/ck/';
		$CKEditor->timestamp = '1.02';

		$config['language'] = 'PL';
		$config['toolbar'] = $toolbar;
		$config['width'] = $width;
		$config['height'] = $height;
		//$events['instanceReady'] = ' function(ev) { alert("Loaded: " + ev.editor.name); } ';

		return $CKEditor->editor($name, $value, $config, $events);
		*/
	}


	function tiny_normal($name, $width, $height, $value=false, $skip_bottom_space=false, $simple=false) {
		global $X;
		$X->JS[] = $this->DIR.'/tinymce/tinymce.min.js';

		if($width<500) $width=500;

//autolink,
//				$(document).ready(function() {
//				});
//						paste_text_linebreaktype: "br",

//,|,link,unlink
//charmap,
//wordcount
		return '
			<a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block; margin:0px; padding:0px;"></a>
			<div style="width:'.$width.'px;">'.$this->textarea($name, $width, $height, $value).'</div>


			<script type="text/javascript">
				tinymce.init({
					selector: "#'.$name.'",
					theme: "modern",
					schema: "html5",
					language : "pl",
					plugins: [
						"advlist lists link charmap anchor searchreplace visualblocks visualchars code nonbreaking paste",
					],
					rel_list: [
						{title: "follow", value: "follow"},
						{title: "nofollow", value: "nofollow"}
					],
					toolbar1: "undo redo | searchreplace | bold italic underline | link unlink | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent",
					toolbar2: "",
					object_resizing : false,
					force_hex_style_colors: true,
					content_css : "/libs/_form/tinymce/editor.css?_1",

					paste_as_text: false,
					paste_auto_cleanup_on_paste: true,
				   paste_data_images: false,
				   valid_elements: "b,strong,i,em,u,a[href|target|rel|name|id],link,ul,ol,li,sub,sup,br,p[align|style]",
				   paste_word_valid_elements: "b,strong,i,em,u,a[href|target|rel|name|id],link,ul,ol,li,sub,sup,br,p[align|style]",
					paste_remove_spans: true,
					paste_remove_styles: true,
					paste_postprocess: function(plugin, args) {
						$.each($(args.node).find("p"),function(index,item){
							if($(item).attr("align")!="") {
								align=$(item).attr("align");
								$(item).removeAttr("align").css("text-align",align);
							}
						});

						$.each($(args.node).find("img"),function(index,item){
							$(item).closest("a").remove();
							$(item).remove();
						});



					},
					menubar: "insert edit format view",
					setup: function(editor) {
						editor.on("blur", function(e){ tinymce.activeEditor.save(); })
					}
				});
			</script>
			'.($skip_bottom_space!=true ? '<div style="height:16px;"></div>':'').'
		';
/*
					style_formats: [
						{title: "średni", inline: "span", classes: "med"},
						{title: "duży", inline: "span", classes: "big"},
					] //  | styleselect
*/
	}


	function tiny($name, $width, $height, $value=false, $skip_bottom_space=false, $simple=false) {
		global $X;
		$X->JS[] = $this->DIR.'/tinymce/tinymce.min.js';

		return '
			<a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block; margin:0px; padding:0px;"></a>
			<div style="width:'.$width.'px;">'.$this->textarea($name, $width, $height, $value).'</div>

			<script type="text/javascript">
				tinymce.init({
					selector: "#'.$name.'",
					theme: "modern",
					schema: "html5",
					language : "pl",
					plugins: [
						"advlist lists link charmap anchor searchreplace visualblocks visualchars code nonbreaking paste",
					],
					toolbar1: "undo redo | bold italic underline bullist numlist link unlink | alignleft aligncenter alignright alignjustify",
					toolbar2: "",
					object_resizing : false,
					force_hex_style_colors: true,
					content_css : "/libs/_form/tinymce/editor.css?_2",

					paste_as_text: false,
					paste_auto_cleanup_on_paste: true,
				   paste_data_images: false,
				   valid_elements: "b,strong,i,em,u,a[href|target|rel|name|id],link,ul,ol,li,sub,sup,br,p[align|style]",
				   paste_word_valid_elements: "b,strong,i,em,u,a[href|target|rel|name|id],link,ul,ol,li,sub,sup,br,p[align|style]",
					paste_remove_spans: true,
					paste_remove_styles: true,
					paste_postprocess: function(plugin, args) {
						$.each($(args.node).find("p"),function(index,item){
							if($(item).attr("align")!="") {
								align=$(item).attr("align");
								$(item).removeAttr("align").css("text-align",align);
							}
						});

						$.each($(args.node).find("img"),function(index,item){
							$(item).closest("a").remove();
							$(item).remove();
						});
					},
					menubar: "insert edit format view",
					setup: function(editor) {
						editor.on("blur", function(e){ tinymce.activeEditor.save(); })
					}
				});
			</script>
			'.($skip_bottom_space!=true ? '<div style="height:16px;"></div>':'').'
		';
/*
					style_formats: [
						{title: "średni", inline: "span", classes: "med"},
						{title: "duży", inline: "span", classes: "big"},
					] //  | styleselect
*/
	}


	//PASSWORD ========================================================
	function password($name, $width=300, $value=false, $readonly=false, $disabled=false, $maxlen=false, $custom_class=false) {
		return $this->password_id($name, $name, $width, $value, $readonly, $disabled, $maxlen, $custom_class);
	}
	function password_id($name, $id, $width=300, $value=false, $readonly=false, $disabled=false, $maxlen=false, $custom_class=false) {
		$class=(!empty($custom_class) ? $custom_class : 'input password form-control').($disabled==true ? ' disabled':'');
		return '<input type="password" name="'.$name.'" '.(!empty($id) ? 'id="'.$id.'" ':'').'value="'.$value.'" class="'.$class.'" style="width:'.$width.'px" autocomplete="off" '.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').($maxlen>0 ? ' maxlength="'.$maxlen.'"':'').' />';
	}



	//CHECKBOX-o-RADIO-SELECTS ========================================
	function checkbox($name, $value=1, $checked=false, $OC_action=false, $id=false, $tip=false, $disabled=false, $readonly=false) {
		if(empty($id)) $id=$name;
		return '<input type="checkbox" name="'.$name.'" id="'.$id.'" value="'.$value.'" class="checkbox"'.($checked==true ? ' checked="checked"':'').($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').(!empty($OC_action) ? ' onclick="'.$OC_action.'"':'').(!empty($tip) ? ' onmouseover="tip(this,\''.$tip.'\')"':'').' />';
	}

	function radio($name, $value, $label, $sel_value=false, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		return '<input type="radio" name="'.$name.'" id="'.$name.'_'.$value.'" value="'.$value.'" class="radio" '.($value==$sel_value || $checked==true ? ' checked="checked"':'').($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').(!empty($OC_action) ? ' onclick="'.$OC_action.'"':'').(!empty($tip) ? ' onmouseover="tip(this,\''.$tip.'\')"':'').' />'.(!empty($label) ? '<label for="'.$name.'_'.$value.'">'.$label.'</label>':'');
	}

	function select($name, $options, $width=false, $disabled=false, $OCH_action=false, $custom_class=false, $id=false) {
		if(empty($id)) $id=$name;
		if(!empty($OCH_action)) $if_OCH=' onchange="'.$OCH_action.'"';
		if(!empty($width)) $style=' style="width:'.$width.'px;"';
		$class=(!empty($custom_class) ? $custom_class : 'select form-control').($disabled==true ? ' disabled':'');
		return '<select name="'.$name.'" id="'.$id.'" class="'.$class.'"'.$style.$if_OCH.($disabled==true ? ' disabled="disabled"':'').'>'.$options.'</select>';
	}

	function multiselect_normal($name, $options, $width=false, $size=10, $disabled=false, $OCH_action=false, $custom_class=false, $id=false) {
		if(empty($id)) $id=$name;
		if(!empty($OCH_action)) $if_OCH=' onchange="'.$OCH_action.'"';
		if(!empty($width)) $style='width:'.$width.'px;';
		$class=(!empty($custom_class) ? $custom_class : 'select').($disabled==true ? ' disabled':'');
		return '<select name="'.$name.'" id="'.$id.'" multiple="multiple" size="'.$size.'" style="font-size:12px;'.$style.'" class="'.$class.'"'.$if_OCH.($disabled==true ? ' disabled="disabled"':'').'>'.$options.'</select>';
	}

	function multiselect($name, $options, $width=false, $height=false, $vertical=false, $single=false, $show_addons=true, $show_counter=false) {
		global $X;
		$X->JS[]=JS.'/jquery.multiselect/multiselect.js';
		$X->CSS[]=JS.'/jquery.multiselect/multiselect.css';
		if(!empty($width)) $if_width=' style="width:'.$width.'px;"';
		if(!empty($disabled)) $if_dis=' disabled="disabled"';

		if($width>0) $w = ($vertical==true ? ($width+8) : ((int)(($width-34)/2)) );
		if($height>0) $h = ($vertical==true ? $height : $height );

		return '
			<a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block; width:'.$w.'px;"></a>
			<select name="'.$name.'[]" id="'.$name.'" multiple="multiple" class="select">'.$options.'</select>
			<script type="text/javascript">
				$("#'.$name.'").multiSelect({'.($single==true ? 'single:true':'selectableHeader:\'<span class="header">Dostępne</span>\', selectedHeader:\'<span class="header">Wybrane</span>\'').($vertical==true ? ', vertical:true':'').'});
				'.($w>0 ? '$("#ms-'.$name.' ul.ms-list").css("width","'.$w.'px");':'').'
				'.($h>0 ? '$("#ms-'.$name.' ul.ms-list").css("height","'.$h.'px");':'').'
			</script>
			'.($show_addons==true && !empty($options) && substr_count($options,'<option ')>1 ? '
				<div style="display:inline-block; vertical-align:top; width:24px; font-size:0px; margin-top:7px; margin-left:1px;">
					<a href="#" onclick="$(\'#'.$name.'\').multiSelect(\'deselect_all\'); $(\'#'.$name.'\').multiSelect(\'select_all\'); return false;"><span class="ico b_plus"></span></a>
					<a href="#" onclick="$(\'#'.$name.'\').multiSelect(\'deselect_all\'); return false;"><span class="ico b_minus" style="margin-top:-1px;"></span></a>
					'.($show_counter==true ? '<div id="'.$name.'_sel_count" style="font-size:11px; margin-top:12px; width:16px; text-align:center; font-weight:bold;"></div>':'').'
				</div>
			':'').'
		';
	}



	//HIDDEN ==========================================================
	function hidden($name, $value=false) {	return $this->hidden_id($name, $name, $value); }
	function hidden_id($name, $id=false, $value=false) { return '<input type="hidden" style="display:none;" name="'.$name.'" '.(!empty($id) ? 'id="'.$id.'" ':'').'value="'.$value.'" />';	}



	//FILE ============================================================
	function file($name, $width=300) { return $this->file_id($name, $name, $width); }
	function file_id($name, $id, $width=300) {
		if(empty($id)) $id=$name;
		$size=round(($width-110)*0.195);
		return '<a id="'.$id.'_focus" name="'.$id.'_focus" style="position:absolute; font-size:0px;"></a><input type="file" style="width:'.$width.'px;" size="'.$size.'" class="input" name="'.$name.'" id="'.$id.'" onchange="$(\'#'.$id.'_\').val(this.value)" />'.$this->hidden($id.'_');
	}

	function flash_upload($form_name, $name, $dir, $multiple, $ext, $size_limit=false) {
		global $X;

		$dont_use_HTML5=false;

		$X->JS[]=JS.'/jquery.uploadifive/jquery.uploadifive.min.js';
		$fallback_script=JS.'/jquery.uploadify/jquery.uploadify.js';


		$size_limit_env=@min($X->CONF->ENV['post_max_size'], $X->CONF->ENV['upload_max_filesize']);
		$size_limit=($size_limit>0 ? @min($size_limit, $size_limit_env) : $size_limit_env);

		$ext_arr=explode('|', $ext);
		foreach($ext_arr as $e) {
			$ext_arr_star[]='*.'.$e;
			$ext_arr_star2[]='.'.$e;
		}

		unset($_SESSION['flash_upload'][$form_name.'_form'][$name]['uploaded']);

		$temp=CACHE.'/uploadify/'.session_id().'/'.$form_name.'_form/';
		if(is_dir($temp)) $X->UTIL->rmdir_rf($temp);

		$temp=CACHE.'/uploadify/'.session_id().'/';
		if($X->UTIL->count_dir_size($temp)==0) $X->UTIL->rmdir_rf($temp);

		$_SESSION['flash_upload'][$form_name.'_form'][$name]['config'] = array(
			'dir' => $dir,
			'ext' => $ext,
			'size' => $size_limit*1024*1024,
			'multiple' => $multiple
		);

		$timestamp=time();


		if($dont_use_HTML5!=true) {
//				<div style="height:23px; float:left" class="button_cont">'.$X->FORM->button_OC('Wybierz plik'.($multiple==true ? 'i':''), 'return false;', 76, 'button center').'</div>
//				'.(ADMIN===true ? '<div style="float:left; padding-left:5px;">'.$X->FORM->button_OC('<span class="ico w_dl"></span>','flash_download_file(\''.$name.'\')',false,'button button_gfx_small',false,'Ściągnij zdalny plik z adresu').'</div>':'').'
			return '
				<div id="'.$name.'_uploader_cont">
					<a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block;"></a>
					<div>'.$this->file($name,200).'</div>
				</div>

				'.(ADMIN!==true && $_GET['allow_downloadify']==true ? '<div style="float:left; margin-left:5px;">'.$X->FORM->button_OC('<img src="images/download_icon.png" alt="" '.$X->FORM->tip('Pobierz plik z adresu URL').' />','flash_download_file(\''.$name.'\')',false,'button button_gfx_small',false,'Ściągnij zdalny plik z adresu').'</div>':'').'

				<div style="float:left; padding-left:28px;"><span class="ico b_warn" style="margin-top:4px;"></span></div>
				<div style="float:left; padding-left:10px; font-size:11px; line-height:11px;" class="ext_info">
					Max. rozmiar pliku: <b>'.$size_limit.' MB</b><br />
					Rozszerzenia: <b>'.strtoupper(@implode(', ',$ext_arr)).'</b><br />
				</div>

				<div class="clear"></div>
				<div id="'.$name.'_queue" class="uploadifyQueueCont"></div>

				<script type="text/javascript">
					$(document).ready(function() {
						$("#'.$name.'").uploadifive({
							"uploadScript"			: "'.(ADMIN===true ? '/admin':'').'/includes/uploadify.php?SID='.SID.'",
							"formData"				: { "form_name":"'.$form_name.'", "timestamp":"'.$timestamp.'", "token":"'.md5('@dh_cms#upload#'.$timestamp).'", "single":"'.($multiple==true ? 0:1).'" },
							"auto"					: true,
							"buttonText"			: "<div class=\"label_default\">Wybierz plik'.($multiple==true ? 'i':'').' lub przeciągnij</div><div class=\"label_drop\">Tutaj upuść plik'.($multiple==true ? 'i':'').'</div>",
							"buttonClass"			: "button uploadify",
							"width"					: 200,
							"height"					: 27,
							"fileObjName"			: "'.$name.'",
							"multi"					: '.($multiple==true ? 'true':'false').',
							"fileSizeLimit"		: '.($size_limit*1024*1024).',
							"fileType"				: "'.@implode(',',$ext_arr_star2).'",
							"queueID"				: "'.$name.'_queue",
							"simUploadLimit"		: 1,
							"onFallback"			: function() {
								$(\'#'.$name.'_uploader_cont\').html(\''.addslashes('<div style="position:absolute; width:102px; height:23px;"><a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block;"></a>'.$this->file($name,100).'</div><div style="height:23px; float:left" class="button_cont">'.$X->FORM->button_OC('Wybierz plik'.($multiple==true ? 'i':''), 'return false;', 76, 'button center').'</div>').'\');

								$.ajax({
									url: "'.JS.'/swfobject.js",
									dataType: "script",
									cache: true,
									complete: function() {
									///
										$.ajax({
											url: "'.$fallback_script.'",
											dataType: "script",
											cache: true,
											complete: function() {
												$("#'.$name.'").uploadify({
													"expressInstall" 	: "'.JS.'/jquery.uploadify/expressInstall.swf",
													"uploader"  		: "'.JS.'/jquery.uploadify/uploadify.swf?SID='.SID.'",
													"script"    		: "'.(ADMIN===true ? '/admin':'').'/includes/uploadify.php?SID='.SID.'",
													"scriptData"    	: {"form_name":"'.$form_name.'"},
													"auto"      		: true,
													"buttonText"		: " ",
													"hideButton"		: true,
													"width"				: 102,
													"height"				: 25,
													"fileDataName"		: "'.$name.'",
													"multi"				: '.($multiple==true ? 'true':'false').',
													"simUploadLimit"	: 1,
													"queueID"			: "'.$name.'_queue",
													"sizeLimit"			: '.($size_limit*1024*1024).',
													"fileExt"			: "'.@implode(';',$ext_arr_star).'",
													"fileDesc"			: "Pliki: '.strtoupper(@implode(', ',$ext_arr)).'",
													"onComplete"		: flash_upload_complete,
													"onCancel"			: flash_upload_cancel
												});
											}
										});
									///
									}
								});
							}
						});
					});
				</script>
			';
		} else {
//				'.(ADMIN===true ? '<div style="float:left; padding-left:5px;">'.$X->FORM->button_OC('<span class="ico w_dl"></span>','flash_download_file(\''.$name.'\')',false,'button button_gfx_small',false,'Ściągnij zdalny plik z adresu').'</div>':'').'
			return '
				<div style="position:absolute; width:102px; height:23px;"><a id="'.$name.'_focus" name="'.$name.'_focus" style="display:block;"></a>'.$this->file($name,100).'</div>
				<div style="height:23px; float:left" class="button_cont">'.$X->FORM->button_OC('Wybierz plik'.($multiple==true ? 'i':''), 'return false;', 76, 'button center').'</div>
				'.(ADMIN!==true && $_GET['allow_downloadify']==true ? '<div style="float:left; margin-left:5px;">'.$X->FORM->button_OC('<img src="images/download_icon.png" alt="" '.$X->FORM->tip('Pobierz plik z adresu URL').' />','flash_download_file(\''.$name.'\')',false,'button button_gfx_small',false,'Ściągnij zdalny plik z adresu').'</div>':'').'

				<div style="float:left; padding-left:28px;"><span class="ico b_warn" style="margin-top:4px;"></span></div>
				<div style="float:left; padding-left:10px; font-size:11px; line-height:11px;" class="ext_info">
					Max. rozmiar pliku: <b>'.$size_limit.' MB</b><br />
					Dozwolone rozszerzenia: <b>'.strtoupper(@implode(', ',$ext_arr)).'</b><br />
				</div>

				<div class="clear"></div>
				<div id="'.$name.'_queue" class="uploadifyQueueCont"></div>

				<script type="text/javascript">
					$(document).ready(function() {
						$("#'.$name.'").uploadify({
							"expressInstall" 	: "'.JS.'/jquery.uploadify/expressInstall.swf",
							"uploader"  		: "'.JS.'/jquery.uploadify/uploadify.swf?SID='.SID.'",
							"script"    		: "'.(ADMIN===true ? '/admin':'').'/includes/uploadify.php?SID='.SID.'",
							"scriptData"    	: {"form_name":"'.$form_name.'"},
							"auto"      		: true,
							"buttonText"		: " ",
							"hideButton"		: true,
							"width"				: 102,
							"height"				: 25,
							"fileDataName"		: "'.$name.'",
							"multi"				: '.($multiple==true ? 'true':'false').',
							"simUploadLimit"	: 1,
							"queueID"			: "'.$name.'_queue",
							"sizeLimit"			: '.($size_limit*1024*1024).',
							"fileExt"			: "'.@implode(';',$ext_arr_star).'",
							"fileDesc"			: "Pliki: '.strtoupper(@implode(', ',$ext_arr)).'",
							"onComplete"		: flash_upload_complete,
							"onCancel"			: flash_upload_cancel
						});
					});
				</script>
			';
		}
	}


	//BUTTONS =========================================================
	function button($value, $link, $width=false, $custom_class=false, $disabled=false, $blank=false) {
		if(!empty($width)) $style=' style="width:'.$width.'px"';
		$class=(!empty($custom_class) ? $custom_class : 'button').($disabled==true ? ' button_dis':'');
		return '<a '.($disabled==true && $_SESSION['backend']['is_root']!=1 ? 'href="#" onmouseover="this.ondragstart=function(){return false}" onclick="javscript:void(0); this.blur(); return false;"':'href="'.$link.'"').' class="'.$class.'"'.$style.($blank==true ? ' target="_blank"':'').'>'.$value.'</a>';
	}

	function button_OC($value, $action, $width=false, $custom_class=false, $disabled=false, $tip=false) {
		if(!empty($width)) $style=' style="width:'.$width.'px"';
		$class=(!empty($custom_class) ? $custom_class : 'button').($disabled==true ? ' button_dis':'');
		return '<a href="#" onmouseover="this.ondragstart=function(){return false}" onclick="'.($disabled==true && $_SESSION['backend']['is_root']!=1 ? 'this.blur(); return false;' : $action.'; return false;').'" class="'.$class.'"'.$style.$this->tip($tip,true).'>'.$value.'</a>';
	}

	function button_potwierdzenie($value, $link, $width=false, $tekst=false, $custom_class=false, $disabled=false) {
		if(empty($tekst)) $tekst='Na pewno usunąć?';
		if(!empty($width)) $style='style="width:'.$width.'px"';
		$class=(!empty($custom_class) ? $custom_class : 'button').($disabled==true ? ' button_dis':'');
		return '<a href="#"'.$style.' onmouseover="this.ondragstart=function(){return false}" onclick="'.($disabled==true && $_SESSION['backend']['is_root']!=1 ? 'this.blur(); return false;' : 'return question(\''.$tekst.'\', \''.$link.'\'); return false;').'" class="'.$class.'">'.$value.'</a>';
	}

	function submit($value=false, $width=false, $custom_class=false) {
		if(!empty($width)) $style=' style="width:'.$width.'px"';
		if(empty($value)) $value='Wyślij';
		$class=(!empty($custom_class) ? $custom_class : 'button submit');
		return '<input type="submit" class="'.$class.'"'.$style.' value="'.$value.'" />';
	}


	function submit_link($value=false, $width=false, $custom_class=false) {
		if(!empty($width)) $style=' style="width:'.$width.'px"';
		if(empty($value)) $value='Wyślij';
		$class=(!empty($custom_class) ? $custom_class : 'button button_gfx submit');
		return '<input type="submit" style="position:absolute;margin:0px;padding:0px;border:0px;width:1px;height:1px;background:transparent;" value="" /><a href="#" onmouseover="this.ondragstart=function(){return false}" onclick="$(this).addClass(\'button_dis\').attr(\'disabled\',\'disabled\').prev().click(); return false;" class="'.$class.'"'.$style.'><span>'.$value.'</span></a>';
	}


	function submit_link_potwierdzenie($value, $width=false, $tekst=false, $custom_class=false) {
		if(empty($tekst)) $tekst='Na pewno?';
		if(!empty($width)) $style='style="width:'.$width.'px"';
		$class=(!empty($custom_class) ? $custom_class : 'button').($disabled==true ? ' disabled':'');
		return '<input type="submit" style="position:absolute;margin:0px;padding:0px;border:0px;width:1px;height:1px;background:transparent;" value="" /><a href="#" onmouseover="this.ondragstart=function(){return false}" onclick="elem_context=this; return_question(\''.$tekst.'\', function(){ $(elem_context).addClass(\'button_dis\').attr(\'disabled\',\'disabled\').prev().click(); return false; }); return false;" class="'.$class.'"'.$style.'><span>'.$value.'</span></a>';
	}


	function dodaj($title=false, $link=false) {
		global $X;

		if(empty($link)) $link='action=form';

		if($title==-1) {
			return '<a href="'.$X->URL->get($link).'" class="button button_gfx2"><span class="ico w_add"></span></a>';
		} else {
			if(empty($title)) $title='Dodaj';
			return '<a href="'.$X->URL->get($link).'" class="button button_gfx"><span class="ico w_add"></span><span>'.$title.'</span></a>';
		}
	}


	function powrot($title=false, $link=false, $gray=true) {
		global $X;
		if(empty($link)) $link='action&id';

		if($title==-1) {
			return '<a href="#" onclick="go(\''.$X->URL->get($link).'\'); return false;" onmouseover="this.ondragstart=function(){return false}" class="button button_gfx2"><span class="ico w_left"></span></a>';
		} else {
			if(empty($title)) $title='Powrót';
			return '<a href="#" onclick="go(\''.$X->URL->get($link).'\'); return false;" onmouseover="this.ondragstart=function(){return false}" class="button'.($gray==true ? ' button_gray':'').' button_gfx"><span class="ico w_left"></span><span>'.$title.'</span></a>';
		}
	}


	function powrot_OC($title=false, $action=false, $gray=true) {
		global $X;
		if(empty($link)) $link='action&id';

		if($title==-1) {
			return '<a href="#" onclick="'.$action.'; return false;" onmouseover="this.ondragstart=function(){return false}" class="button button_gfx2"><span class="ico w_left"></span></a>';
		} else {
			if(empty($title)) $title='Powrót';
			return '<a href="#" onclick="'.$action.'; return false;" onmouseover="this.ondragstart=function(){return false}" class="button'.($gray==true ? ' button_gray':'').' button_gfx"><span class="ico w_left"></span><span>'.$title.'</span></a>';
		}
	}



	//X-PICKERS =======================================================
//	function kalendarz() { $a=func_get_args(); return call_user_func_array(array($this, 'calendar'), $a); }
	function calendar($name, $value=false, $format='Y-m-d', $readonly=false, $disabled=false, $id=false, $force_width=false) {
		global $X;
		$X->JS[] = JS.'/jquery.datepicker'.(ADMIN!==true ? '_front':'').'.js';
		$X->JS[] = JS.'/jquery.mask.js';

		if($format=='Y-m-d H:i:s') {
			$format='Y-m-d';
			$use_time=true;
			$tmp_value=@explode(' ',$value);
			$value=$tmp_value[0];
			$time_value=$tmp_value[1];
		}

		if(empty($force_width)) $force_width=90;
		$id=(!empty($id)?$id:$name);

		if($use_time==true) {
			if(stristr($name,'[]')) {
				$base=@explode('[]',$name);
				$base=$base[0];

				$time_name=$base.'_time[]';
				$time_id=$id.'_time';
			} else {
				$time_name=$name.'_time';
				$time_id=$id.'_time';
			}
		}


		return '
			'.$this->input_id($name,$id,$force_width,$value,$readonly,$disabled,'form-control input spaced',10,true).($use_time==true ? '&nbsp;'.$this->input_id($time_name, $time_id,70,$time_value,$readonly,$disabled,'form-control input spaced',10,true).'&nbsp;&nbsp;' : '').(ADMIN===true ? '&nbsp; <a '.$X->FORM->tip('Wstaw dzisiaj').' href="#" onclick="$(\'#'.$id.'\').val(\''.date('Y-m-d').'\'); $(\'#'.$id.'_time\').val(\''.date('H:i:s').'\'); return false;"><span class="ico b_cal"></span></a>':'').'
			<script type="text/javascript">
				$("#'.$id.'")
					.DatePicker({
						format: "'.$format.'",
						date: "'.$value.'",
						current: "'.$value.'",
						onBeforeShow: function(){
							if($.str_replace(["_","-"], ["",""], $("#'.$id.'").val()).length==8) $("#'.$id.'").DatePickerSetDate($("#'.$id.'").val(), true);
						},
						onChange: function(formated, dates){
							$("#'.$id.'").val(formated);
							$("#'.$id.'").DatePickerHide();
						}
					})
					.change(function(){	if($.str_replace(["_","-"], ["",""], $("#'.$id.'").val()).length==8) $("#'.$id.'").DatePickerSetDate($(this).val(), true);		})
					.keyup(function(){	if($.str_replace(["_","-"], ["",""], $("#'.$id.'").val()).length==8) $("#'.$id.'").DatePickerSetDate($(this).val(), true);		})
					.mask("9999-99-99");
				'.($use_time==true ? '
					$("#'.$time_id.'").mask("99:99:99");
				':'').'
			</script>
		';
/*
	onRender: function(date) {
		d=(date.valueOf()+"").substring(0,10);
		return { disabled: (d < '.(time()-3600*24).') }
	}
*/
	}


	function color_picker($name, $value=false, $id=false) {
		global $X;
		$X->CSS[] = JS.'/jquery.colorpicker/colorpicker.css';
		$X->JS[] = JS.'/jquery.colorpicker/colorpicker.js';
		$X->JS[] = JS.'/jquery.mask.js';
		if(empty($id)) $id=$name;

		return '
			'.$this->input_id($name,$id,60,$value,false,false,false,6,true).'
			<div id="'.$id.'_picker" class="color_picker"><div style="'.(strlen($value)==6 ? 'background-color:#'.$value : '').'"></div></div>
			<script type="text/javascript">
				color_picker("'.$id.'");
				$("#'.$id.'").mask("hex");
			</script>
		';
	}



	//AJAX ============================================================
	function ajax_checkbox($table, $dane, $col, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		global $X;
		$checked=($dane[$col]==1);

		return '<input type="checkbox" value="'.$value.'" class="checkbox"'.($checked==true ? ' checked="checked"':'').($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').' onclick="ajax_input(\'checkbox\',\''.md5('ajax:'.$col.'@'.$table.'=>'.$dane['id']).'\', \''.$_GET['module'].'\',  \''.$table.'\', \''.$col.'\', \''.$dane['id'].'\', $(this).attr(\'checked\')==\'checked\' ? 1:0); '.(!empty($OC_action) ? $OC_action:'').'"'.(!empty($tip) ? ' '.$X->FORM->tip($tip,true,-9):'').' />';
	}


	function ajax_radio($table, $dane, $col, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		global $X;
		$checked=($dane[$col]==1);

		return '<input type="radio" name="ajax_'.$col.'" value="'.$value.'" class="radio"'.($checked==true ? ' checked="checked"':'').($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').' onclick="ajax_input(\'radio\',\''.md5('ajax:'.$col.'@'.$table.'=>'.$dane['id']).'\', \''.$_GET['module'].'\', \''.$table.'\', \''.$col.'\', \''.$dane['id'].'\', $(this).attr(\'checked\')==\'checked\' ? 1:0); '.(!empty($OC_action) ? $OC_action:'').'"'.(!empty($tip) ? ' '.$X->FORM->tip($tip,true):'').' />';
	}


	function ajax_select($table, $options, $col, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		global $X;
		return '<select name="ajax_'.$col.'" class="select"'.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').' onchange="ajax_input(\'select\',\''.md5('ajax:'.$col.'@'.$table.'=>'.$dane['id']).'\', \''.$_GET['module'].'\', \''.$table.'\', \''.$col.'\', \''.$dane['id'].'\', $(this).val()); '.(!empty($OC_action) ? $OC_action:'').'"'.(!empty($tip) ? ' '.$X->FORM->tip($tip,true):'').'>'.$options.'</select>';
	}


	function ajax_pozycja($table, $dane, $col, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		global $X;

		return '<input type="text" name="ajax_'.$col.'" value="'.$dane[$col].'" style="width:24px;" class="center input input_small"'.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').' onchange="ajax_input(\'text\',\''.md5('ajax:'.$col.'@'.$table.'=>'.$dane['id']).'\', \''.$_GET['module'].'\', \''.$table.'\', \''.$col.'\', \''.$dane['id'].'\', this.value); '.(!empty($OC_action) ? $OC_action:'').'"'.(!empty($tip) ? ' '.$X->FORM->tip($tip,true):'').' />';
	}


	function ajax_cena($table, $dane, $col, $OC_action=false, $tip=false, $disabled=false, $readonly=false) {
		global $X;

		return '<input type="text" name="ajax_'.$col.'" value="'.$dane[$col].'" style="width:52px;" class="center input"'.($readonly==true ? ' readonly="readonly"':'').($disabled==true ? ' disabled="disabled"':'').' onchange="ajax_input(\'text\',\''.md5('ajax:'.$col.'@'.$table.'=>'.$dane['id']).'\', \''.$_GET['module'].'\', \''.$table.'\', \''.$col.'\', \''.$dane['id'].'\', this.value); '.(!empty($OC_action) ? $OC_action:'').'"'.(!empty($tip) ? ' '.$X->FORM->tip($tip,true):'').' />';
	}



}//DigiHex Systems\\
?>