$(document).ready(function() {
	$(".pic_includer a").lightBox();
});
function submitbutton(pressbutton) {
	submitform(pressbutton);
}

function getimg(img_path){
	document.getElementById('pic_container').innerHTML = '<img src="'+ img_path +'" />';	
}
function getimg2(img_path){
	document.getElementById('pic_container').innerHTML = '<img src="'+ img_path +'" width="588" height="361" />';	
}
function checkAll( n, fldName ) {
  if (!fldName) {
     fldName = 'cb';
  }
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}
function submitform_once(pressbutton){
	
	document.adminForm.rule.value=pressbutton;
	try {
		document.adminForm.onsubmit();	
		}
	catch(e){}
	
	document.adminForm.submit();
}

function confirm_(task,txt)
{
	
	if (confirm(txt)){
		submitbutton(task);
	}
}

function conSubmit(){
	
	document.adminForm.addon.value='ok';
	
	try {
		document.adminForm.onsubmit();	
		}
	catch(e){}
	
	document.adminForm.submit();
}
function confirmAction(theMessage)
{
    // TODO: Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') {
        return true;
    }

    var is_confirmed = confirm(theMessage);

    return is_confirmed;
}

function bgcolor(object, color) { object.style.backgroundColor = color; }
function checked(id) 
{ 
	if(document.getElementById(id).checked != true) document.getElementById(id).checked = true;
	else document.getElementById(id).checked = false;  
}
// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}
function issubmit(obj){
	//alert(obj.search_key.value)	
	if(obj.search_key.value != 'Хайлт...')
		return true;
	else
		return false;
}

function open_menu(id){
	document.getElementById(id).style.display = "block";
}
function hide_menu(id){
	document.getElementById(id).style.display = "none";
}
function hover_sub(obj)
{
	obj.style.background = "#A37041";
}
function out_sub(obj){
	obj.style.background = "none";
}
function checkRequestForm()
 {
	 var input = null;	
	 input = document.requestform;
	 if (input.txtName.value === "Таны нэр" )
	 { 
		 alert("Нэрээ оруулна уу!");
		 input.txtName.focus();
		 return false; 
	 }
	 if (input.txtName.value.length < 3 ){
	 	 alert("Таны оруулсан нэр 3 тэмдэгтээс багагүй урттай байх ёстой!");
		 input.txtName.focus();
		 return false;
	 }
	 input = document.requestform.txtEmail;
	 if(!check_email(input, "E-mail буруу байна")){ return false;}
	 
	 
	 input = document.requestform.txtSubject;
	 if (input.value === "Гарчиг" )
	 { 
		 alert("Та гарчигийг оруулна уу!");
		 input.focus();
		 return false; 
	 }
	 
	 input = document.requestform.txtMessage;
	 if (input.value === "" || input.value < 100)
	 { 
		 alert("Таны илгээх гэж буй мессеж хэтэрхий богино байна!");
		 input.focus();
		 return false; 
	 }
	 
	 return true;
}

function checkReservationForm()
 {
	 var input = null;	
	 input = document.reservationform;
	 if (input.txtName.value === "Таны нэр" )
	 { 
		 alert("Нэрээ оруулна уу!");
		 input.txtName.focus();
		 return false; 
	 }
	 if (input.txtName.value.length < 3 ){
	 	 alert("Таны оруулсан нэр 3 тэмдэгтээс багагүй урттай байх ёстой!");
		 input.txtName.focus();
		 return false;
	 }
	 input = document.reservationform.txtEmail;
	 if(!check_email(input, "E-mail буруу байна")){ return false;}
	 
	 input = document.reservationform.txtPhone;
	 if (input.value === "Утас" )
	 { 
		 alert("Холбоо барих утсаа оруулна уу!");
		 input.focus();
		 return false; 
	 }
	 if(input.value.length < 6){
	  	alert("Таны оруулсан өгөгдөл 6 тэмдэгтээс багагүй урттай байх ёстой!");
		input.focus();
		return false;
	 }
	 
	 
	 input = document.reservationform.txtSubject;
	 if (input.value === "Гарчиг" )
	 { 
		 alert("Та гарчигийг оруулна уу!");
		 input.focus();
		 return false; 
	 }
	 
	 input = document.reservationform.txtMessage;
	 if (input.value === "" || input.value < 100)
	 { 
		 alert("Таны илгээх гэж буй мессеж хэтэрхий богино байна!");
		 input.focus();
		 return false; 
	 }
	 
	 return true;
}


function check_number(input, mesg)
{
 var re = /^[0-9]*$/;

 if (input.length != 0)
 {
 if (!re.test(input.value))
 {
 alert (mesg);
 input.focus();
 return false;
 }
 }

 return true;
}

function check_currency(input, mesg)
{
 var re = /^([0-9]+)(\.)([0-9]{2})*$/;

 if (input.length != 0)
 {
 if (!re.test(input.value))
 {
 alert (mesg);
 input.focus();
 return false;
 }
 }

 return true;
}

function check_email(input, mesg)
{
 var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

 if (input.length != 0)
 {
	 if (!re.test(input.value))
	 {
		 alert (mesg);
		 input.focus();
		 return false;
	 }
 }

 return true;
}