/*   Project    : GrandSakura Hotel Medan
 *   Created on : Jul 12, 2011, 8:26:23 AM
 *   Author     : Philips Tel - PT. Cimeric Indonesia
 *   Framework  : Codeigniter v 2.0.2 - EllisLab, Inc
 *   Decription : This file contains simple javascript functions that used
 *                to handle common task, such as validation, autocomplete, etc.
 **/

/* Blur and focus effects */
function search_text()
{
    if(this.value == 'SEARCH')
    {
        this.value = '';
    }
    else if(this.value == '')
    {
        this.value = 'SEARCH';
    }
}


/* Return false if email is not valid */
function check_email( email ) {
    return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
}

/* Send contact */
function send_contact()
{
   var myform = document.frmcontact;
    
   if( myform.txtcontactname.value == '' || myform.txtcontactemail.value == '' || myform.txtcontactmessage.value == '' )
   {
      alert('Please fill the required fields');
   }
   else if( !check_email( myform.txtcontactemail.value ) ) 
   {
      alert('Your email is not valid');
   }
   else if( isNaN(myform.txtcontactphone.value) )
   {
       alert('Your phone number is not valid');
   }
   else
   {
       myform.submit();
   }
   
}

function send_guestbook()
{
    var myform = document.frmguestbook;
    
   if( myform.txtname.value == '' || myform.txtemail.value == '' || myform.txtmessage.value == '' )
   {
      alert('Please fill the required fields');
   }
   else if( !check_email( myform.txtemail.value ) ) 
   {
      alert('Your email is not valid');
   }
   else
   {
       myform.submit();
   }  
}

function select_photo_category( base_url )
{
    var select = document.getElementById('selcat');
    location.href = base_url + 'photo/category/' + select.value;
}

function harusangka(jumlah) // <-- this is from schrammek's programmer. Thx...
{
  var karakter = (jumlah.which) ? jumlah.which : event.keyCode
  if (karakter > 31 && (karakter < 48 || karakter > 57)) {
    return false;
  }
  return true;
}

function order()
{
    var myform = document.frmorder;
    if( myform.txtordername.value == '' || myform.txtnumadults.value == '' || myform.txtarrivaldate.value == '' || myform.txtdeparturedate.value == '')
    {
        alert('Please complete the fields');
    }
    else
    {
        myform.submit();
    }
}

function okay()
{
    var myform = document.frmokay;
    if( myform.txtname.value == '' || myform.txtemail.value == '' || myform.txtaddress.value == '' ||
        myform.txtcity.value == '' || myform.txtstate.value == '' || myform.txtcountry.value == '' ||
        myform.txtphone.value   == '' || myform.txthp.value == '')
    {
        alert('Please complete the required fields');
    } 
    else if( !check_email( myform.txtemail.value) ) 
    {
        alert('Your email is not valid');
    }
    else
    {
        myform.submit();
    }
}

function book_room()
{
	document.frmhotel.submit();
}

function book_package()
{
	document.frmpackage.submit();
}

function book_package_now( gotobook )
{
	location.href = gotobook;
}

function callNewForm(file) 
{
    window.open(file, 'mywindow', 'toolbar=no,resizeable=yes,statusbar=no,scrollbars=yes,location=no, fullscreen=yes');
}
