function resetInput($form) {
	$($form).each(function() {
		var $that = $(this);
		$that.find("input[type='image'],input[type='submit'],input[type='text'],textarea").each(function() {
			$(this).attr("value", "");
		});
	});

	
	return false;
};



function disabledInput($form) {
	$($form).each(function() {
		var $that = $(this);
		$that.find("input[type='image'],input[type='submit'],input[type='text'],textarea").each(function() {
			$(this).attr("disabled", "disabled");
		});
	});

	
	return false;
};




function enabledInput($form, $field, $reset) {
	if ($reset == "reset") {
		$($form + " " + $field).attr("value", "").each(function() {
			this.value = (this.defaultValue ? this.defaultValue : '');
		});
	}
	$($form).each(function() {
		var $that = $(this);
		$that.find("input[type='image'],input[type='submit'],input[type='text'],textarea").each(function() {
			$(this).removeAttr("disabled");
		});
	});

	
	return false;
};

// Versi : 1.0
// Fungsi untuk membuat modal windows

function modal(url, caption) {
	if ($("#modal").length == 0) {
		$("body :first").wrap('<div class="modal wide PaddingLess hidden" style="top:48px;" id="modal"></div>');
	}


	$('#modal').fadeIn().removeClass('hidden').addClass("show").html('<div class="center"><img src="images/indicator_blue_large.gif" align="absmiddle"/></div>');

	$.ajax({
		type: "POST",
		url: url,
		data: "action",
		timeout: 2000,
		cache: false,
		success: function(response) {
			$('#modal').html(' <div class="header lg"><a class="close" href="javascript:void(0);" onClick="$(\'#overlay\').click(); return false;" ><strong>Close</strong><span></span></a><h2>' + caption + '</h2></div><div id="modal-content">' + response + '</div><div class="footer-bar">&nbsp;</div>');
		},
		

		error: function(xhr) {
			$('#modal').fadeOut('fast');
			messageBox("Error : " + xhr.status, "Ops,Error! " + xhr.status + ", We will be fix this later, you can try again", "error", "#windows-ui");
		}
	});



	
	$('#overlay').fadeIn('fast', function() {
		$('#modal').fadeIn('fast', function() {
			//    $(element).animate({'top':'160px'},500);
			$('#modal').fadeIn('fast');
			$('#modal').removeClass('hidden');
		});
	});


	
	$('#modal .close').click(function() {
		// $('#modal').animate({'top':'-200px'},500,function(){
		$('#modal').addClass('hidden').removeClass("show");
		$('#modal').fadeOut('fast');
		$('#overlay').fadeOut('fast');
		$('#modal').html('');

	});



	
	$('#overlay').click(function() {
		$('#overlay').fadeOut('fast', function() {
			//$('#modal').animate({'top':'-200px'},500,function(){
			$('#overlay').fadeOut('fast');
			$('#modal').addClass('hidden').removeClass("show");
			$('#modal').fadeOut('fast');
			$('#modal').html('');
		});
	});

};



// Versi : 1.0	
//	Fungsi untuk menghitung jumlah yang sudah di shoot pada webcam

function countfilewebcam(max) {
	var max = max;
	if ($("#photos a").length >= max) {
		$("#shootButton").attr("disabled", "disabled").removeClass("blue").addClass("disable-blue");
	} else {
		$("#shootButton").removeAttr('disabled').addClass("blue").removeClass("disable-blue");
	};
};




function removeFromPhotoListWebCam(photoname) {
	var match = new RegExp(" " + photoname, "ig");
	var replaced = " ";
	var aphoto = $('#list_photo').attr("value");
	var replacement = '';
	if (isInList(photoname, $('#list_photo').attr("value"))) {
		replaced = aphoto.replace(match, replacement);
	}
	replaced = replaced;
	$('#list_photo').attr("value", replaced);
	$('#remove-' + photoname).each(function() {
		$('[id=' + this.id + ']').fadeOut("slow", function() {
			$('[id=' + this.id + ']').remove();
		});
	});

};


// Versi : 1.0	
//	Fungsi untuk menghitung jumlah gambar yang akan diupload

function countfile(max) {
	var max = max;
	if ($("#apple-list img").length >= max) {
		$("#filePicture").attr("disabled", "disabled");
	} else {
		$("#filePicture").removeAttr('disabled');
	}

};

// Versi : 1.0	
//	Fungsi untuk menghapus gambar yang akan diupload

function removeFromPhotoList(photoname) {
	var match = new RegExp(" " + photoname, "ig");
	var replaced = " ";
	var aphoto = $('#list_photo').attr("value");
	var replacement = '';
	$("#filePicture").val('');
	if (isInList(photoname, $('#list_photo').attr("value"))) {
		replaced = aphoto.replace(match, replacement);
	}
	replaced = replaced;
	$('#list_photo').attr("value", replaced);
	//	$('#'+photoname).hide().remove();
	$('#remove-' + photoname).each(function() {
		$('[id=' + this.id + ']').fadeOut("slow", function() {
			$('[id=' + this.id + ']').remove();
		});
	});

};




function switch_tab(obj) {
	$(".tabs > a").attr("class", "tab");
	$(obj).attr("class", "current_tab");
};
//create auto paging

function createPaging(page, url, element) {
	//$("html, body").animate({scrollTop:110}, 'slow');
	$("#loading_top").show();

	
	$.ajax({
		type: "POST",
		url: url,
		data: "page=" + page,
		success: function(response) {
			$("#loading_top").hide();

			
			$("#" + element).html(response);
		},
		

		error: function(xhr) {
			$("#loading_top").hide();

			
			messageBox("Error : " + xhr.status, "Ops,Error! " + xhr.status + ", We will be fix this later, you can try again", "error", "#windows-ui");
		}
	});
};



function requestGet(url, data, updated, elementcontent, elementremove, elementloading) {

	$(elementloading).show().css("display", "block");
	$.ajax({
		type: "GET",
		url: url,
		data: data,
		timeout: 3000,
		cache: true,
		success: function(response) {
			$(elementremove).css({
				"display": "none"
			}).remove();

			
			if (updated == 'appended') {
				$(elementcontent).append(response);
			} else if (updated == 'prepended') {
				$(elementcontent).prepend(response);
			} else if (updated == 'replaced') {
				$(elementcontent).html(response);
			} else {
				$(elementcontent).html(response);
			}
			$(elementloading).hide();
		},
		

		error: function(xhr) {
			$(elementloading).hide();
		}
	});
};



function request(url, data, updated, elementcontent, elementremove, elementloading) {

	$(elementloading).show().css("display", "block");
	$.ajax({
		type: "POST",
		url: url,
		data: data,
		//timeout: 2000,
		cache: false,
		success: function(response) {
			$(elementremove).css({
				"display": "none"
			}).remove();

			
			if (updated == 'appended') {
				$(elementcontent).append(response);
			} else if (updated == 'prepended') {
				$(elementcontent).prepend(response);
			} else if (updated == 'replaced') {
				$(elementcontent).html(response);
			} else {
				$(elementcontent).html(response);
			}
			$(elementloading).hide();
		},
		

		error: function(xhr) {
			$(elementloading).hide();

			
			messageBox("Error : " + xhr.status, "Ops,Error! " + xhr.status + ", We will be fix this later, you can try again", "error", "#windows-ui");

		}

	});
};



function hideMessage(element) {
	$(function() {
		var $alert = $(element);
		if ($alert.length) {
			$(element).fadeIn("slow", function() {
				setTimeout(function() {
					$(element).fadeOut("slow", function() {
						$(element).hide();
					});
				}, 3000);
			});
		}
	});
};




function loading() {
	///loading ajax
	//-------------------------------------------------------
	/*shows the loading div every time we have an Ajax call*/
	$("#loading").bind("ajaxSend", function() {
		$(this).show();
		// Find ALL <form> tags on your page
		$('form').submit(function() {
			// On submit disable its submit button
			$('input[type=submit]', this).attr('disabled', 'disabled');
		});
	}).bind("ajaxComplete", function() {
		$(this).hide();

		
		$('form').submit(function() {
			// On submit disable its submit button
			$('input[type=submit]', this).removeAttr('disabled');
		});
	}).bind("ajaxError", function() {
		$(this).hide();

		
		$('form').submit(function() {
			// On submit disable its submit button
			$('input[type=submit]', this).removeAttr('disabled');
		});
	});
	//-------------------------------------------------------	
};



function showlayer(layer) {
	var myLayer = document.getElementById(layer);
	if (myLayer.style.display == "none" || myLayer.style.display == "") {
		myLayer.style.display = "block";
	} else {
		myLayer.style.display = "none";
	}
};



function frameBreaker() {
	if (top.location != location) {
		top.location.href = document.location.href;
	}
};




function showhideMe(id, elem) {
	var access = $('#' + elem + id);

	var test = access.css("display");
	if (test == 'none') {
		access.slideDown("slow");
		$("#text-right-" + id).slideUp('slow');

	} else {

		access.slideUp("slow");
		$("#text-right-" + id).slideDown('slow');

	}
	return false;
};



function showOrhide(id, elem) {
	var access = $('#' + elem + id);

	var test = access.css("display");
	if (test == 'none') {
		access.slideDown("slow");
	} else {
		access.slideUp("slow");
	}
	return false;
};



function showAndhide(elemid) {
	var access = $("#" + elemid);

	var test = access.css("display");
	if (test == 'none') {
		access.slideDown("fast");
	} else {
		access.slideUp("fast");
	}
	return false;
};




function isInList(pString, pList) {
	// declare variables
	var List;
	var i;
	var bFound = false;

	// turn delimited string into an array
	List = pList.split(",");

	// loop through all array positions
	for (i = 0; i < List.length; i++) {
		if (pString == List[i]) {
			// found the string 
			bFound = true;
		}
	}

	// return the answer as a string
	return bFound.toString();
};




function disableButton(myform) {
	// Find ALL <form> tags on your page
	$('#' + myform).submit(function() {
		// On submit disable its submit button
		//$('input[type=submit]', this).attr('disabled', 'disabled');
		$('input[type=submit]:disabled', this).attr("value");
	});
};




function enableButton(myform) {
	// Find ALL <form> tags on your page
	$('#' + myform).submit(function() {
		// On submit disable its submit button
		//$('input[type=submit]', this).attr('disabled', '');
		$('input[type=submit]', this).removeAttr('disabled');

	});
};


/*
Make sure that textBox only contain number
 */

function checkNumber(textBox) {
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}

	textBox.value = trim(textBox.value);
/* 	if (textBox.value.length == 0) {
   textBox.value = 0;
   } else {
   textBox.value = parseInt(textBox.value);
   } */
};

/*
Check if a form element is empty.
If it is display an alert box and focus
on the element
 */

function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);

	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		//  		alert(message);
		overlayErrorMessage("Error ", message, "#overlay-message-box");
		formElement.focus();

	};


	
	return _isEmpty;
};



function hideTextBox(element, msg) {
	$("#" + element).val(msg);
	$("#" + element).css("visibility", "hidden");
	$("#" + element).css("display", "none");
};



function showTextBox(element, msg) {
	$("#" + element).show();
	
	$("#" + element).val(msg);
	$("#" + element).css("visibility", "visible");
	$("#" + element).css("display", "block");

};



function hideBox(targetElement, type) {
	if (type == 1) {
		//$("#"+targetElement).fadeOut("slow");
		$("#" + targetElement).fadeOut("fast");
	} else if (type == 2) {
		$("." + targetElement).fadeOut("fast");
	} else {
		$(targetElement).fadeOut("fast");
	}
};



function showBox(targetElement, type) {
	if (type == 1) {
		$("#" + targetElement).fadeIn("fast");
		$("#" + targetElement).css("visibility", "visible");
		$("#" + targetElement).css("display", "block");
	} else if (type == 2) {
		$("." + targetElement).fadeIn("fast");
		$("." + targetElement).css("visibility", "visible");
		$("." + targetElement).css("display", "block");
	} else {
		$(targetElement).fadeIn("fast");
		$(targetElement).css("visibility", "visible");
		$(targetElement).css("display", "block");
	}
};

//function display top alert message

function displayAlert() {
	var $alert = $('#alert');
	if ($alert.length) {
		var alerttimer = window.setTimeout(function() {
			$alert.trigger('click');
		}, 3000);
		$alert.animate({
			height: $alert.css('line-height') || '50px'
		}, 200).click(function() {
			window.clearTimeout(alerttimer);
			$alert.animate({
				height: '0'
			}, 200);
			$('#alert').slideUp('slow');
			//$('#alert').fadeOut();
			//$('#alert').hide();
		});
	}

};




function messageAlert(element) {
	var $alert = $('#' + element);
	if ($alert.length) {
		var alerttimer = window.setTimeout(function() {
			$alert.fadeOut('slow');
			//$alert.hide('slow');
		}, 9000);
	}
};




function overlayErrorMessage(caption, message, element) {
	$(element).html("<a class=\"boxclose\" id=\"boxclose\"></a><h1>" + caption + "</h1> <p>" + message + "</p> <div><input name=\"btnCancel\" type=\"submit\" class=\"boxclose blue\" id=\"btnCancel\" value=\"Oke\" /></div>");
	$('#overlay').fadeIn('fast', function() {
		$(element).animate({
			'top': '160px'
		}, 500);
	});


	
	$('.boxclose').click(function() {
		$(element).animate({
			'top': '-200px'
		}, 500, function() {
			$('#overlay').fadeOut('fast');
		});
	});

};




function messageBox(caption, message, type, element) {
	if ($(".modal").length == 0) {
		$("body").prepend('<div class="modal wide PaddingLess hidden" style="top:48px;" id="modal"></div>');
	}

	var thisclass = '';
	if (type == 'info') {
		thisclass = "info";
	} else if (type == 'error') {
		thisclass = "error";
	} else if (type == 'warning') {
		thisclass = "warning";
	} else if (type == 'success') {
		thisclass = "success";
	} else if (type == 'validation') {
		thisclass = "validation";
	} else {
		thisclass = "info";
	};

	//$(element).css("z-index","auto");				
	$(element).html("<div class=\"top-bar\">" + caption + "</div><div class=\"windows-content\">" + "<div class=\"" + thisclass + "\">" + message + "</div></div><div class=\"bottom-bar right\"><input name=\"Send\" type=\"submit\" value=\"Close\"  class=\"blue\" id=\"close-windows-ui\"/></div>");

	$('#overlay').fadeIn('fast', function() {
		$('#windows-ui').fadeIn('fast', function() {
			$(element).animate({
				'top': '160px'
			}, 500);
		});
	});


	
	$('#close-windows-ui').click(function() {
		$(element).animate({
			'top': '-200px'
		}, 500, function() {
			$(element).fadeOut('fast');
			if ($('.modal').is(':hidden')) {
				$('#overlay').fadeOut('fast');
			}
		});
	});



	
	$('#overlay').click(function() {
		if ($('.modal').is(':hidden')) {
			$('#overlay').fadeOut('fast');
		};

		
		$(element).animate({
			'top': '-200px'
		}, 500, function() {
			$(element).fadeOut('fast');
		});
	});


};




function confirmation(url, caption, message, element) {
	$(element).css({
		display: "block",
		position: 'fixed',
		margin: 'auto',
	}).addClass("show").removeClass("hidden");
/*	$(window).resize(function(){
			  $(element).css({
			   position:'fixed',
			   margin:'auto',
			   left: ($(window).width() - $(element).outerWidth())/2,
			   top: ($(window).height() - $(element).outerHeight())/2
			  });
				$(document.ent).scrollTop(); 
		});
	$(window).resize();*/
	$(element).html('<div class="top-bar">' + caption + '</div><div class="windows-content">' + message + '</div><div class="bottom-bar right"><input name="Send" type="submit" value="Yes"  class="blue" id="btnSubmit" /><input name="btnCancel" type="button" value="Cancel" class="sexybutton" id="btnCancel"/></div>');

	$('#overlay').fadeIn('fast', function() {
		$(element).fadeIn('fast', function() {
			//    $(element).animate({'top':'160px'},500);
			$(element).fadeIn('fast');
			$(element).removeClass('hidden').addClass("show");
		});
	});


	
	$('#btnSubmit').click(function() {
		$.ajax({
			type: "POST",
			url: url,
			data: "action",
			timeout: 2000,
			cache: false,
			success: function(response) {
				$(element).prepend(response);
			},
			

			error: function(xhr) {
				messageBox("Error : " + xhr.status, "Ops,Error! " + xhr.status + ", We will be fix this later, you can try again", "error", "#windows-ui");
			}
		});



		//    $(element).animate({'top':'-200px'},500,function(){
		$('#overlay').fadeOut('fast');
		$(element).addClass('hidden');
		$(element).fadeOut('fast');
		$(element).html('');
		//  });
	});


	
	$('#btnCancel').click(function() {

		// $(element).animate({'top':'-200px'},500,function(){
		$(element).addClass('hidden');
		$(element).fadeOut('fast');
		if ($('#modal:visible').length == 0) {
			$('#overlay').fadeOut('fast');
		}
		$(element).html('');
		//   });
	});



	
	$('#overlay').click(function() {
		//      $(element).animate({'top':'-200px'},500,function(){
		$('#overlay').fadeOut('fast');
		$(element).addClass('hidden');
		$(element).fadeOut('fast');
		$(element).html('');
		//     });
	});

};




function errorMessage(captionText, messageText, elementTarget) {

	//Get the window height and width
	//var winH = $(window).height();
	//	var winW = $(window).width();
	//Set the popup window to center
	//$(elementTarget).css('top',  winH/2-$(elementTarget).height()/2);
	//	$(elementTarget).css('left', winW/2-$(elementTarget).width()/2);
	$(elementTarget).html("<div class=\"box-alert-shadow\" id=\"box-alert\"> <div class=\"error-box\"><div class=\"box-alert-caption\">" + captionText + "<a href=\"#\" onclick=\"hideBox('box-alert',1);return false;\" class=\"box-alert-caption-close-image\"></a> </div><div class=\"box-alert-content\">" + messageText + "</div><div class=\"box-alert-button\"> <input name=\"btnOk\" type=\"submit\" class=\"blue\" id=\"btnOk\" value=\"Ok\" onclick=\"hideBox('box-alert',1);return false;\" /></div></div></div>");

	$('#box-alert').css({
		display: 'block',
		left: ($(window).width() - $('#box-alert').width()) / 2,
		top: ($(window).height() - $('#box-alert').height()) / 2,
		position: 'absolute'
	});


	
	showBox("box-alert", 1);


};

/*
Set one value in combo box as the selected value
 */

function setSelect(listElement, listValue) {
	for (i = 0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue) {
			listElement.selectedIndex = i;
		}
	}
};

/* *
 * DHTML date validation script for dd / mm / yyyy. Courtesy of SmartWebby.com (http : // www.smartwebby.com / dhtml / )
 */
// Declaring valid date character, minimum year and maximum year
var dtCh = "-";
var minYear = 1900;
var maxYear = 2900;

function isInteger(s) {
	var i;
	for (i = 0; i < s.length; i++) {
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
};



function stripCharsInBag(s, bag) {
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
};



function daysInFebruary(year) {
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
};



function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i == 4 || i == 6 || i == 9 || i == 11) {
			this[i] = 30;
		}
		if (i == 2) {
			this[i] = 29;
		}
	}
	return this
};



function isDate(dtStr) {
	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strDay = dtStr.substring(0, pos1);
	var strMonth = dtStr.substring(pos1 + 1, pos2);
	var strYear = dtStr.substring(pos2 + 1);
	strYr = strYear;
	if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
	};

	
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);
	if (pos1 == -1 || pos2 == -1) {
		alert("Format tanggal adalah : dd-mm-yyyy");
		return false;
	};

	
	if (strMonth.length < 1 || month < 1 || month > 12) {
		alert("Mohon masukkan bulan yang benar");
		return false
	};

	
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
		alert("Mohon masukkan tanggal yang benar");
		return false;
	};

	
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
		alert("Mohon masukkan 4 digit tahun antara " + minYear + " and " + maxYear);
		return false;
	};

	
	if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
		alert("Mohon masukkan tanggal yang benar");
		return false;
	};
	
	return true;
};



function CheckIsDate(dtStr) {
	//   var ErrorMessage = '';
	//	var elem = document.getElementById(divElementId);
	//	    elem.innerHTML = "";
	//		elem.style.display = 'block';
	//    	elem.style.visibility = 'visible';
	var daysInMonth = DaysArray(12);
	var pos1 = dtStr.indexOf(dtCh);
	var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
	var strDay = dtStr.substring(0, pos1);
	var strMonth = dtStr.substring(pos1 + 1, pos2);
	var strYear = dtStr.substring(pos2 + 1);
	strYr = strYear;
	if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1);
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1);
	}
	month = parseInt(strMonth);
	day = parseInt(strDay);
	year = parseInt(strYr);
	if (pos1 == -1 || pos2 == -1) {
		//alert("Format tanggal adalah : dd-mm-yyyy")
		// ErrorMessage = 'Format tanggal adalah : dd-mm-yyyy';
		// elem.innerHTML = ErrorMessage;
		return false;
	};

	
	if (strMonth.length < 1 || month < 1 || month > 12) {
		//alert("Mohon masukkan bulan yang benar")
		// ErrorMessage = 'Mohon masukkan bulan yang benar';
		//   elem.innerHTML = ErrorMessage;
		return false
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
		//alert("Mohon masukkan tanggal yang benar");
		// ErrorMessage = 'Mohon masukkan tanggal yang benar';
		//  elem.innerHTML = ErrorMessage;
		return false;
	};

	
	if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
		//alert("Mohon masukkan 4 digit tahun antara " + minYear + " and " + maxYear);
		// ErrorMessage = 'Mohon masukkan 4 digit tahun antara ' + minYear + ' and ' + maxYear;
		// elem.innerHTML = ErrorMessage;
		return false;
	};

	
	if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
		//alert("Mohon masukkan tanggal yang benar")
		//  ErrorMessage = 'Mohon masukkan tanggal yang benar';
		//  elem.innerHTML = ErrorMessage;
		return false;
	};
	
	return true;
};





function ValidateForm() {
	var dt = document.frmListAllOrderByDate.txtDate;
	if (isDate(dt.value) == false) {
		dt.focus();
		
		return false;
	};
	
	return true;
};

// Function cari

function viewHasilCari(q) {
	var q = window.document.frmIndex.q.value;

	if (q != '') {
		window.location.href = 'index.php?q=' + q;
	} else {
		// 	alert("Masukkan nama produk yang ingin dicari")
		window.document.frmIndex.q.focus();

		
		return;
	}
};




function subcribe(e) {
	var e = window.document.frmIndex.txtEmail.value;

	if (e != '') {
		window.location.href = 'index.php?email=' + e;
	} else {
		alert("Masukkan email anda untuk subscribe");
		window.document.frmIndex.txtEmail.focus();

		
		return;
	}
};




function checkAddMsgForm() {
	with(window.document.frmMsg) {
		if (isEmpty(txtNama, 'Masukkan Nama anda')) {
			alert('Pilih kategori artikel');
			txtNama.focus();

			
			return;
		} else if (isEmpty(txtEmail, 'Masukkan email valid anda')) {
			txtEmail.focus();

			
			return;
		} else if (isEmpty(txtSubject, 'Masukkan subject yang anda maksud')) {
			txtSubject.focus();

			
			return;
		} else if (isEmpty(txtMessage, 'Tulis pesan anda')) {
			txtMessage.focus();

			
			return;
		} else if (isEmpty(txtNumber, 'Masukkan kode yang terlihat pada gambar')) {
			txtNumber.focus();

			
			return;
		} else {
			submit();
		}
	}
};

//start for upload photo
<!--

function startUpload() {
	$("#loading-upload-process").css("visibility", "visible").removeClass('hidden').addClass('show');
	$("#loading-upload-process").css("display", "block");
	$("#loading-upload-process").show();
	//  	$("#loading-upload-process").html(' Please, wait until processing finish<img src="../images/dot-loading.gif" align="absmiddle" />');
	// $("#upload-form").hide();
	// startLoadingUpload("#loading-upload-process");
	return true;
};




function startLoadingUpload(elementloading) {
	$(elementloading).css('display', 'block');
	$(elementloading).css('visibility', 'visible');
	$(elementloading).show();

	
	$(elementloading).html("Please, wait until processing finish <img src=\"images/dot-loading.gif\" align=\"absmiddle\" />");
};


// upload image
// onclick = "UploadImage(this.form, this.form.imageUpload.value)"
//

function UploadImage(form, file, loading) {
	//startUpload();
	$('form input').attr("disabled", "disabled");
	allowSubmit = false;
	extArray = new Array(".gif", ".jpeg", ".jpg", ".png");
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1).toLowerCase();

	
	ext = file.slice(file.indexOf(".")).toLowerCase();

	
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) {
			allowSubmit = true;
			$('form input').removeAttr("disabled");
			form.submit();

			
			startLoadingUpload($('#' + loading));
			break;

		}
	}

	if (allowSubmit == false) {
		$('form input').removeAttr("disabled");
		$("form input[type='file']").val("");
		$("form input[type='file']").removeClass("hidden").addClass("show").css({
			"display": "block"
		});

		
		alert("File with this extention does not allowed, types: " + (extArray.join(" ")) + "\nPlease, choose another file.");

	}
	return allowSubmit;
};
// -->
/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
 */

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
};

/*
Check if a string is in valid email format.
Input  : the string to check
Output : true if the string is a valid email address, false otherwise.
 */

function isEmail(str) {
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
};



function getScrollTopRight() {
	if (document.documentElement.scrollTop) return document.documentElement.scrollTop;
	return document.body.scrollTop;
};



function scrollHandlerTopRight() {
	var e = document.getElementById('LoadingTopRight');
	e.style.top = getScrollTopRight();
};

//// notify 2

function getScrollTopLeft() {
	if (document.documentElement.scrollTop) return document.documentElement.scrollTop;
	return document.body.scrollTop;
};



function scrollHandlerNotifyLeft() {
	var e = document.getElementById('LoadingTopLeft');
	e.style.top = getScrollTopLeft();
};


///for loading gif

function getScrollLoading() {
	if (document.documentElement.scrollTop) return document.documentElement.scrollTop;

	return document.body.scrollTop;
};



function scrollHandlerLoading() {
	var e = document.getElementById('loading');
	e.style.top = getScrollTopLoading();
};



function showNotifyLoading(str) {
	var elem = document.getElementById('loading');
	elem.style.display = 'block';
	elem.style.visibility = 'visible';

	if (elem.currentStyle && elem.currentStyle.position == 'absolute') {
		elem.style.top = getScrollTopLoading();

		
		window.onscroll = scrollHandlerLoading;
	}

	elem.innerHTML = str;
};



function hideNotifyLoading() {
	var elem = document.getElementById('Loading');
	elem.style.display = 'none';
	elem.style.visibility = 'hidden';
	window.onscroll = null;
};



function imageLoading(elementId) {
	elementId.style.visibility = 'visible';
	elementId.style.display = 'block';
	$(elementId).show("slow");
	//          $(elementId).fadeTo("slow", 0.33);
	$(elementId).fadeTo("slow", 0);
};







function init() {

	var ld = (document.all);
	var ns4 = document.layers;
	var ns6 = document.getElementById && !document.all;
	var ie4 = document.all;

	if (ns4) ld = document.loading;
	else if (ns6) ld = document.getElementById("loading").style;
	else if (ie4) ld = document.all.loading.style;
	else
	ld = document.all.loading.style;
	if (ns4) {
		ld.visibility = "hidden";
	} else if (ns6 || ie4) ld.display = "none";
};

//window.onload=init();

function removeBox(id) {
	var box = document.getElementById(id);
	if (box && box.parentNode) {
		box.parentNode.removeChild(box);
	}
};



function MyObject(id) {
	this.id = id;
	this.front = document.createElement("div");
	this.front.backingObj = this;
};


///

function CountLeft(field, count, max, displayelement) { // if the length of the string in the input field is greater than the max value, trim it  
	if (field.value.length > max) field.value = field.value.substring(0, max);
	else
	// calculate the remaining characters   
	count.value = max - field.value.length;
	$("#" + displayelement).html(count.value + " characters left");
};




function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) {
		alert('A maximum of ' + maxlimit + ' characters is allowed.');
		field.value = field.value.substring(0, maxlimit);
	}
};




function limitChars2(textarea, limit, infodiv) {
	var text = textarea.value;
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if (textlength > limit) {
		//		info.innerHTML = 'You cannot write more then '+limit+' characters!';
		info.innerHTML = (limit - textlength);
		textarea.value = text.substr(0, limit);
		return false;
	} else {
		//	info.innerHTML = 'You have '+ (limit - textlength) +' characters left.';
		info.innerHTML = (limit - textlength);
		return true;
	}
};




function limitChars(textid, limit, infodiv) {
	var text = $('#' + textid).val();

	
	var textlength = text.length;
	if (textlength > limit)
	//{
	$('#' + textid).val(text.substr(0, limit));
	//	$('#' + infodiv).html(limit - textlength);
	//		return false;
	//	}
	else
	//{
	$('#' + infodiv).html(limit - textlength);
	//return true;
	//	}
};


///
// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate

function getExpDate(days, hours, minutes) {
	var expDate = new Date();

	
	if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
};

// utility function called by getCookie( )

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
};

// primary function to retrieve cookie by name

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return "";
};

// store cookie value with optional details as needed

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
};

// remove the cookie by setting ancient expiration date

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
};



function showLoadingGear(elementId) {
	$("#" + elementId).html('<div style="padding-top:10px;" align="center"><img src="../images/loading.gif" align="absmiddle" /></div>');
};



function showLoadingLarge(elementId) {
	$("#" + elementId).html('<div style="padding-top:10px;" align="center"><img src="../images/indicator_blue_large.gif" align="absmiddle" /></div>');
};



function showLoadingSignup(elementId) {
	$("#" + elementId).html('<div style="padding-top:10px;" align="center"><img src="images/indicator_blue_large.gif" align="absmiddle" /></div>');
};




function showLoadingSmall(elementId) {
	$("#" + elementId).html('<div style="padding-top:10px;" align="center"><img src="../images/indicator_blue_small.gif" align="absmiddle" /></div>');
};



function passwordStrength(password) {
	var desc = new Array();

	
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	document.getElementById("passwordDescription").innerHTML = desc[score];
	document.getElementById("passwordStrength").className = "strength" + score;
};


// Password strength meter v1.0
// Matthew R. Miller - 2007
// www.codeandcoffee.com
// Based off of code from  http://www.intelligent-web.co.uk
// Settings
// -- Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;

// Check password

function checkPassword(strPassword) {
	// Reset combination count
	nCombinations = 0;

	// Check numbers
	if (bCheckNumbers) {
		strCheck = "0123456789";
		if (doesContain(strPassword, strCheck) > 0) {
			nCombinations += strCheck.length;
		}
	}

	// Check upper case
	if (bCheckUpperCase) {
		strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if (doesContain(strPassword, strCheck) > 0) {
			nCombinations += strCheck.length;
		}
	}

	// Check lower case
	if (bCheckLowerCase) {
		strCheck = "abcdefghijklmnopqrstuvwxyz";
		if (doesContain(strPassword, strCheck) > 0) {
			nCombinations += strCheck.length;
		}
	}

	// Check punctuation
	if (bCheckPunctuation) {
		strCheck = ";:-_=+\|//?^&!.@$£#*()%~<>{}[]";
		if (doesContain(strPassword, strCheck) > 0) {
			nCombinations += strCheck.length;
		}
	}

	// Calculate
	// -- 500 tries per second => minutes 
	var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;

	// Number of days out of password lifetime setting
	var nPerc = nDays / nPasswordLifetime;

	return nPerc;
};

// Runs password through check and then updates GUI 

function runPassword(strPassword, strFieldID) {
	// Check password
	nPerc = checkPassword(strPassword);

	// Get controls
	var ctlBar = document.getElementById(strFieldID + "_bar");
	var ctlText = document.getElementById(strFieldID + "_text");
	if (!ctlBar || !ctlText) return;

	// Set new width
	var nRound = Math.round(nPerc * 100);
	if (nRound < (strPassword.length * 5)) {
		nRound += strPassword.length * 5;
	}
	if (nRound > 100) nRound = 100;
	ctlBar.style.width = nRound + "%";

	// Color and text
	if (nRound > 95) {
		strText = "Very Secure";
		strColor = "#3bce08";
	} else if (nRound > 75) {
		strText = "Secure";
		strColor = "orange";
	} else if (nRound > 50) {
		strText = "Mediocre";
		strColor = "#ffd801";
	} else {
		strColor = "red";
		strText = "Insecure";
	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
};

// Checks a string for a list of characters

function doesContain(strPassword, strCheck) {
	nCount = 0;

	for (i = 0; i < strPassword.length; i++) {
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) {
			nCount++;
		}
	}

	return nCount;
};

//check verication password
// Runs password through check and then updates GUI 

function runVerificationPassword(strRePassword, strFieldID) {

	// Get controls
	var password = document.getElementById('txtPassword').value;
	var verificationPassword = document.getElementById('txtRePassword').value;
	var ctlText = document.getElementById('verificationPassword');
	if (!ctlText) return;

	// Color and text
	if (verificationPassword != password) {
		strColor = "red";
		strText = "Verification password does not macth";
	} else {
		strColor = "green";
		strText = "Verification password is macth";
	}

	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
};



function validateImage(file) {
	var filename = file;
	var result = true;
	var ext = getExt(filename);
	if ((ext == "gif") || (ext == "jpg") || (ext == "jpeg") || (ext == "png") || (ext == "bmp")) {
		result = true;
		return true;
	} else {
		$("form  input[type='file']").val("");
		alert("Please, choose file with extention  .gif, .jpeg, .jpg or .png");
		//   $("#info-box").slideDown("slow");
		// $("#info-box").html('Please, choose file with extention  .gif, .jpeg, .jpg or .png');
		// messageAlert("info-box");
		filename = '';
		result = false;
		return false;
	}
	return result;
};



function getExt(filename) {
	var dot_pos = filename.lastIndexOf(".");
	if (dot_pos == -1) return "";
	return filename.substr(dot_pos + 1).toLowerCase();
};


