// +------------------------------------------------------------------+
// | JavaScript version 1.0                                           |
// +------------------------------------------------------------------+
// | general.js – Some standard functions used in the CMS cleint      |
// |              side. Script is loaded in template by parser.       |
// +------------------------------------------------------------------+
// | Copyright (c) 2008 MultiMove                                     |
// +------------------------------------------------------------------+
// | Authors: S.F.Beck <sander@multimove.nl>     					  |
// +------------------------------------------------------------------+

/**
 * The load function
 * 
 * @return void
 */
function doLoad(){
	
	}

/**
 * Make pop-up windows
 * 
 * @return void
 */
function popup( url, width, height )
{
	var iLeft = (screen.width - width) / 2 ;
	var iTop  = (screen.height - height) / 2 ;

	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes," ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;

	window.open( url, "FCKBrowseWindow", sOptions ) ;
}


/**
 * Clear textfields preset text and turn to black
 * 
 * @return void
 */
function clearText(thefield) {
	if (thefield.defaultValue == thefield.value) {
		thefield.value = "";
		thefield.style.color = "#b2b2b2";
	}
	else thefield.value = thefield.defaultValue;
}


var PositionX = 100;
var PositionY = 100;
var defaultWidth  = 100;
var defaultHeight = 100;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}
var optNN='scrollbars=no, status=yes, width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no, status=yes, width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle,imageTitle2){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');
		writeln('if (isIE){');
		writeln('window.resizeTo(100,100);');
		writeln('width=10+document.images[0].width;');
		writeln('height=59+document.images[0].height;');
		
		writeln('window.resizeTo(width,height);}');
		writeln('if (isNN){');
		writeln('window.innerWidth=document.images["George"].width;');
		writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle2+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle(); self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src="'+imageURL+'" alt="'+imageTitle+'" onClick="window.close();" style="display: block; cursor: pointer;"></body></html>');
		close();
	}
}

function xmlhttpPost(url, query, element)
{
    var xmlHttpReq = false;
    var self = this;
    
    // Mozilla/Safari
    if (window.XMLHttpRequest)
    {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject)
    {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    self.xmlHttpReq.open('POST', url, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function()
    {
      if(self.xmlHttpReq.readyState == 4)
      {
        document.getElementById(element).innerHTML = self.xmlHttpReq.responseText;
      }
    }
    
    self.xmlHttpReq.send(query);
}
<!-- Begin hoteliers.com -->
var curDate = new Date();
function dInM(mon)
	{           
		if (mon == 2)
			{
			 Year = curDate.getFullYear();
			 if(Math.round(Year/4) == Year/4)
				{
					if(Math.round(Year/100) == Year/100)
					{
						if(Math.round(Year/400) == Year/400)
						return 29;
						else return 28;
					}
				else return 29;
				}
			return 28;
			}
			else if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
			{
			 return 30;
			}
			return 31;
	}

function getNDay()
{
theMonth = document.hcomForm.am.options.selectedIndex;
theDay = parseInt(document.hcomForm.ad.options.selectedIndex);

 if (! theMonth == 0 && ! theDay == 0)
 {
  dInMonth = dInM(theMonth);
  
  if (theDay > dInMonth)
  {
	document.hcomForm.ad.options.selectedIndex = theDay = dInMonth;
  }
  newDay = theDay + 1;
  newMonth = theMonth;
  
  if (newDay > dInMonth)
  {
			newDay = 1;
			newMonth = theMonth + 1;
			if (newMonth > 12)
			{
				newMonth = 1;
			}
  }

document.hcomForm.dd.selectedIndex = newDay;
document.hcomForm.dm.selectedIndex = newMonth;
 }
}

function checkDDate()
{
 theMonth = document.hcomForm.dm.options.selectedIndex;
 theDay = parseInt(document.hcomForm.dd.options.selectedIndex);
 dInMonth = dInM(theMonth);
 
 if (theDay > dInMonth)
 {
  document.hcomForm.dd.options.selectedIndex = theDay = dInMonth;
 }
}

function chkCT(selectID){
	if(selectID != 'city'){
		$('#city option').removeAttr('selected');
		$('#city option:first').attr('selected', 'selected');
	}

	if(selectID != 'hotelID'){
		$('#hotelID option').removeAttr('selected');
		$('#hotelID option:first').attr('selected', 'selected');
	}
}

function doCheckFormPortal(){
	am = document.hcomForm.am.options.selectedIndex;
	ad = document.hcomForm.ad.options.selectedIndex;
	dm = document.hcomForm.dm.options.selectedIndex;
	dd = document.hcomForm.dd.options.selectedIndex;
	if (am > 0 && ad > 0 && dm > 0 && dd > 0) {
		var el = $('#hoteliers');
		var n = el.length;
		if(n > 0){
			if($('#iframeContainer').length == 0){
				el.html('<div id="iframeContainer"><iframe name="hoteliersIframe" src="" frameborder="0" style="width:100%; height: 700px;" /></div>');
			}
		}

		//document.hcomForm.target = document.hcomForm.hTarget.value;
		//document.hcomForm.action = ('http://www.hoteliers.com/cgEngine.php?ID=13&lang=nl');
		$('#hcomForm').submit();
		
	}
}

/**
 *
 */
function strpos(haystack, needle, offset)
{
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

/**
 *
 */
function initShadowbox(backcolor, frontcolor, lightcolor, text_cancel, text_previous, text_next, text_close, text_of)
{
	try { Shadowbox.init(backcolor+';'+frontcolor+';'+lightcolor+';'+text_cancel+';'+text_previous+';'+text_next+';'+text_close+';'+text_of); }
	catch(e) { alert(e.toString()); }
}
<!-- End hoteliers.com -->

