<?php

class Ajax
{
	public function getAjaxValStart()
	{
		echo '<script type="text/javascript">';
		echo '$(document).ready(function(){';
		return;
	}
	
	public function getAjaxValEnd()
	{
		echo "})";
		echo "</script>";
		return;
	}
	
	public function retWrite($js)
	{
		return "$js;";
	}
	
	public function getWrite($js)
	{
		echo "$js;";
	}
	
	public function getEmptyForm()
	{
		echo "$('.text, .textarea, .select').val('');";
		echo "$('#simpan').removeAttr('style');";
		echo "$('#update').css('display', 'none');";
	}
	
	public function getShow($kode)
	{
		echo "$('#$kode').removeAttr('style');";
	}
	
	public function getHidden($kode)
	{
		echo "$('#$kode').css('display', 'none');";
	}
	
	public function getAjaxVal($kode, $val)
	{
		echo "$('$kode').val('$val');";
	}
	
	public function getReadonly($kode)
	{
		echo "$('#$kode').attr('readonly', true).addClass('text readonly');";
	}
	
	public function getRemoveReadonly($kode)
	{
		echo "$('#$kode').removeAttr('readonly').removeAttr('class').addClass('text');";
	}
	
	public function getLoad($div, $url)
	{
		echo "$('$div').load('$url');";
	}
	
	public function getGridStartXml()
	{
		echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
		echo "<rows>";
	}
	
	public function getGridPage($page)
	{
		echo "<page>$page</page>";
	}
	
	public function getGridTotal($total)
	{
		echo "<total>$total</total>";
	}
	
	public function getGridStartRows($kode)
	{
		echo "<row id='$kode'>";
	}
	
	public function getGridCell($val)
	{
		echo "<cell><![CDATA[$val]]></cell>";
	}
	
	public function getGridEndRows()
	{
		echo "</row>";
	}
	
	public function getGridEndXml()
	{
		echo "</rows>";
	}
	
	public function createButtonCek($kode, $id)
	{
		return "<input type='button' class='$kode cekGridPop' id='cek_".$id."' alt='Cek' title='Cek'>";
	}
	
	public function createButtonUpdate($kode, $id)
	{
		return "<input type='button' class='$kode update' id='update_".$id."' alt='Update' title='Update'>";
	}
	
	public function createButtonDelete($kode, $id, $ket)
	{
		return "<input type='button' class='$kode delete' id='confirmDelete_".$id.'_'.$ket."' alt='Delete' title='Delete'>";
	}
	
	public function createButtonCustom($class, $id, $title)
	{
		return "<input type='button' class='$class' id='$id' alt='$title' title='$title'>";
	}
	
	public function createFilterText($id, $post, $width, $class = '', $lain = '')
	{
		$id = str_ireplace('.', '', $id);
		return '<input autocomplete="off" type="text" name="'.$id.'" id="'.$id.'" class="inputGrid '.$class.'" '.$lain.' number="0" style="width: '.$width.'px" value="'.$post[$id].'">';
	}
	
	public function createTextLink($kode, $val, $width, $no, $max)
	{
		$id = str_ireplace('.', '', $id);
		return "<input autocomplete='off' type='text' readonly value='$val' class='_linkPopUp _textGridNone _noGrid_$no' max='$max' number='$no' style='width: ".$width."px' id='$kode'>";
	}
	
	public function createButtonCetak($id, $link)
	{
		$id = str_ireplace('.', '', $id);
		$input = "<a href='$link$id' target='_blank'>";
		$input.= "<input type='button' class='cetakDataJurnal cetak' alt='cetak' title='Cetak'>";
		$input.= '</a>';
		return $input;
	}

	public function createFilterTgl($id, $post, $kosong)
	{
		$id = str_ireplace('.', '', $id);
		$input = '<input type="text" id="'.$id.'" name="'.$id.'" class="inputGrid date readonly" readonly style="width: 65px; margin-right: 0px" value="'.$post[$id].'">';
		if($kosong == true){
			$input.= '<label class="reset" style="margin-left: 0px" id="reset'.$id.'">&nbsp;&nbsp;&nbsp;&nbsp;</label>';
		}
		return $input;
	}
	
	public function createFilterSelect($id, $post, $width, $data)
	{
		$id = str_ireplace('.', '', $id);
		$n = '<select name="'.$id.'" class="inputGrid" style="width: '.$width.'px">';
		foreach($data as $key => $row){
			$sel = '';
			if($key == $post[$id]){
				$sel = 'selected';
			}
			$n.= "<option value='$key' $sel>$row";
		}
		$n.= '</select>';
		return $n;
	}
}