function isDate(mm,dd,yyyy) {
   var d = new Date(mm + "/" + dd + "/" + yyyy);
   return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}

Number.prototype.formatMoney = function(c, d, t){
	var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};

function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

function strrpos (haystack, needle, offset) {
    // Finds position of last occurrence of a string within another string  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strrpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: strrpos('Kevin van Zonneveld', 'e');
    // *     returns 1: 16
    var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
}


function check_no_discount()
{
  $('#book_rooms tr').each(function() {
    
    if ( $(this).find('.cancelled').eq(0).text() != null && $(this).find('.final_price').eq(0).text() != null )
    {
      var full_price;
      var final_price;
      
      
      
      full_price = $(this).find('.cancelled').eq(0).text();
      full_price = trim10(full_price);
      final_price = $(this).find('.final_price').eq(0).text();
      final_price = trim10(final_price);
      
      //console.log( final_price + ' ' + full_price );
      
      if(final_price == full_price) {
        $(this).find('.cancelled').hide();
      }
      
      delete( full_price );
      delete( final_price );
    };

  });
}

function trim11 (str) {
  if( str != null ) {
    str = str.replace(/^\s+/, '');
  	for (var i = str.length - 1; i >= 0; i--) {
  		if (/\S/.test(str.charAt(i))) {
  			str = str.substring(0, i + 1);
  			break;
  		}
  	}
  }

	return str;
}

function trim(stringa){
  if ((typeof stringa === "string")) {
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
  } else {
    return stringa;
  }

}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title">' + title + '</div>';
}


function trim10 (str) {
  
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}


function goto( address ) {
  parent.top.location.href=address;
}

if (!window.console) console = {};
console.log = console.log || function(){};
console.warn = console.warn || function(){};
console.error = console.error || function(){};
console.info = console.info || function(){};

