/*-----------------------------------------------------------------------------*/
/* White label common functions extracted from ghrsCommon.js  and messagePopup */
/*-----------------------------------------------------------------------------*/

var ghrs_onload_setted = false;

/* This function has the behaviour to create an element with attributes and a beginning value. */
function ghrs_createElementWithAttribute(type,attributes,val){
	var elem = document.createElement(type);
	if(val) elem.innerHTML = val;
	if(attributes){
		for(var id in attributes){
			ghrs_setAttribute(elem, id, attributes[id]);
		}
	}
	// Explorer fix.
	if(attributes['style']=='display : none;') elem.style.display = 'none';
	return elem;
}

/* This function replace the normal setAttribute javascript function to allow us */
/* to set the attribute in all browsers without errors. */
function ghrs_setAttribute(node,name,value){
	var attr = '';
	if(node.getAttribute(name)) node.setAttribute(name, value);
	else{
		attr = document.createAttribute(name);
		attr.value = value;
		node.setAttributeNode(attr);
	}
}

function ghrs_IEDomTrick(){
	return (document.readyState=='complete' || !(/*@cc_on!@*/false));
}

/* This function has the behaviour of tell us if the browser is Explorer 6. */
function ghrs_isExplorer6(){
	return (String(navigator.userAgent).indexOf("MSIE 6") > -1);
}

/* This function allow us to obtain the position of an object contain inside other objects. */
function ghrs_findPosition(element){
	var left_pos = top_pos = 0;
	var tmp_element = element;
	if(element.offsetParent){
		do{
			left_pos = left_pos + element.offsetLeft + ((element!=tmp_element && !ghrs_isOpera()) ? ghrs_getCSSTypeInfo(element, "border-left-width") : 0);
			top_pos = top_pos + element.offsetTop + ((element!=tmp_element && !ghrs_isOpera()) ? ghrs_getCSSTypeInfo(element, "border-top-width") : 0);
			element = element.offsetParent;
		} while(element);
	}
	return [left_pos,top_pos];
}

/* This function has the behaviour of tell us if the browser is Opera. */
function ghrs_isOpera(){
	return String(navigator.userAgent).indexOf("Opera") > -1;
}

/* This function will stop the forwarding of the datas if sumbit check returt am */
/* error message. 								 */
function ghrs_stopEventPropagation(event){
	if (!event) event = window.event;
	event.cancelBubble = true;
	if (event.stopPropagation) event.stopPropagation();

	return true;
}

/* This function allow us to obtain a desired rule CSS of an object. */
function ghrs_getCSSTypeInfo(element,rule){
	var value = 0;
	if(document.defaultView && document.defaultView.getComputedStyle){
		value = parseInt(document.defaultView.getComputedStyle(element, null).getPropertyValue(rule),10);
	}
	else if(element.currentStyle){
		rule = rule.replace(/\-(\w)/g, function (str, p1){
				return p1.toUpperCase();
		});
		value = parseInt(element.currentStyle[rule],10);
	}
	return (value>0) ? value : 0;
}

function getScrollLeft(){
	var pos = 0;
	if (window.pageXOffset)	{	pos = window.pageXOffset; }
	else if (document.documentElement && document.documentElement.scrollLeft)	{	pos += document.documentElement.scrollLeft; }
	else if (document.body)	{	pos += document.body.scrollLeft; }
	return pos;
}

function getScrollTop(){
	var pos = 0;
	if (window.pageYOffset)	{	pos = window.pageYOffset;	}
	else if (document.documentElement && document.documentElement.scrollTop) { pos = document.documentElement.scrollTop; }
	else if (document.body) { pos = document.body.scrollTop; }
	return pos;
}

/*----------------------------------------------*/
/*				  Ghrs Calendar 				*/
/*----------------------------------------------*/

/* Global variables */
var ghrs_jsDate = new Array(); 

/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* The nexts functions allows us to obtain the correct name of the month, the 	*/
/* correct name of the day and the correct number of days in a month. 			*/
/*------------------------------------------------------------------------------*/
function ghrs_getMonthName(i){
	return months[i];
}

function ghrs_getDayName(i){
	return dayNames[i];
}

function ghrs_daysInMonth(month,year) {
	var months_days = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return months_days[month - 1];
	if (year%4 != 0) return months_days[1];
	if (year%100 == 0 && year%400 != 0) return months_days[1];
	return months_days[1] + 1;
}
/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* The next functions are called from the selects elements in the page in which */
/* a  calendar is contained to set correctly day, month and year desired. 		*/
/*------------------------------------------------------------------------------*/

/* This function set correctly day, month and year of check in and check out date. */
function ghrs_setCalendarCiDay(random){
	
	// If spans do not exist, we have to create them
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	// The use of p element is due to diversify the dates containers.
	var slc_ci_day = "ci_day_slc_"+random;
	var slc_co_day = "co_day_slc_"+random;
	var slc_co_month = "co_month_slc_"+random;
	var slc_co_year = "co_year_slc_"+random;
	var ci_day = parseInt(document.getElementById("ci_"+random+"_day").innerHTML,10);
	var ci_month = parseInt(document.getElementById("ci_"+random+"_month").innerHTML,10);
	var ci_year = parseInt(document.getElementById("ci_"+random+"_year").innerHTML,10);
	var co_day = parseInt(document.getElementById("co_"+random+"_day").innerHTML,10);
	var co_month = parseInt(document.getElementById("co_"+random+"_month").innerHTML,10);
	var co_year = parseInt(document.getElementById("co_"+random+"_year").innerHTML,10);
	// Next series of checks is used to set up correcly day, month and year
	// in the p's check-in as in the p's check out dates.
	var days_in_month = ghrs_daysInMonth(ci_month,ci_year);
	ci_day = parseInt(document.getElementById(slc_ci_day).value,10);
	if((ci_year == last_year)&&(ci_day == 31)&&(ci_month == 12)){
		co_day = ci_day;
		document.getElementById(slc_co_day).value = co_day;
		ci_day = ci_day - 1;
		document.getElementById(slc_ci_day).value = ci_day;
		document.getElementById(slc_co_month).value = ci_month;
	}
	else {
		if(ci_day + 1 <= days_in_month){
			co_day = ci_day + 1;
			document.getElementById(slc_co_day).value = co_day;
			co_month = ci_month;
			document.getElementById(slc_co_month).value = co_month;
			co_year = ci_year;
			document.getElementById(slc_co_year).value= co_year;
		}
		else{
			ci_day = days_in_month;
			document.getElementById(slc_ci_day).value = ci_day;
			co_day = 1;
			document.getElementById(slc_co_day).value = co_day;
			if((ci_month + 1) <= 12){
				co_month = ci_month + 1;
				document.getElementById(slc_co_month).value = co_month;
				co_year = ci_year;
				document.getElementById(slc_co_year).value= co_year;
			}
			else{
				co_month = 1;
				document.getElementById(slc_co_month).value = co_month;
				co_year = ci_year + 1;
				document.getElementById(slc_co_year).value= co_year;
			}
		}
	}
	
	// Saving variables placed inside an html p element's attributes and
	// in the global variables.
	document.getElementById("ci_"+random+"_day").innerHTML = ci_day;
	document.getElementById("ci_"+random+"_month").innerHTML = ci_month;
	document.getElementById("ci_"+random+"_year").innerHTML = ci_year;
	document.getElementById("co_"+random+"_day").innerHTML = co_day;
	document.getElementById("co_"+random+"_month").innerHTML = co_month;
	document.getElementById("co_"+random+"_year").innerHTML = co_year;
	document.getElementById("ci_"+random+"_temp_month").innerHTML = ci_month;
	document.getElementById("ci_"+random+"_temp_year").innerHTML = ci_year;
	document.getElementById("co_"+random+"_temp_month").innerHTML = co_month;
	document.getElementById("co_"+random+"_temp_year").innerHTML = co_year;
}

/* This function set correctly the check in month and then call the 'ghrs_setCalendarCiDay' */
/* function to change correctly also the day of the date. */
function ghrs_setCalendarCiMonth(random){
	
	// If spans do not exist, we have to create them
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	var slc_ci_month = "ci_month_slc_"+random;
	var slc_co_month = "co_month_slc_"+random;
	var ci_month = parseInt(document.getElementById("ci_"+random+"_month").innerHTML,10);
	var co_month = parseInt(document.getElementById("co_"+random+"_month").innerHTML,10);
	
	ci_month = parseInt(document.getElementById(slc_ci_month).value,10);
	co_month = ci_month;
	document.getElementById(slc_co_month).value = co_month;
	
	// Saving variables placed inside an html p element's attributes.
	document.getElementById("ci_"+random+"_month").innerHTML = ci_month;
	document.getElementById("co_"+random+"_month").innerHTML = co_month;
	
	ghrs_setCalendarCiDay(random);
	
}

/* This function set correctly the check in year and then call the 'ghrs_setCalendarCiMonth' */
/* function to change correctly also the month and the day of the date. */
function ghrs_setCalendarCiYear(random){
	
	// If spans do not exist, we have to create them
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	var slc_ci_year = "ci_year_slc_"+random;
	var slc_co_year = "co_year_slc_"+random;
	var ci_year = parseInt(document.getElementById("ci_"+random+"_year").innerHTML,10);
	var co_year = parseInt(document.getElementById("co_"+random+"_year").innerHTML,10);
	
	ci_year = parseInt(document.getElementById(slc_ci_year).value,10);
	co_year = ci_year;
	document.getElementById(slc_co_year).value = co_year;
	
	// Saving variables placed inside an html p element's attributes.
	document.getElementById("ci_"+random+"_year").innerHTML = ci_year;
	document.getElementById("co_"+random+"_year").innerHTML = co_year;
	
	ghrs_setCalendarCiMonth(random);
	
}

/* This function set correctly the check out day. */
function ghrs_setCalendarCoDay(random){
	
	// If spans do not exist, we have to create them.
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	var slc_co_day = "co_day_slc_"+random;
	var co_day = parseInt(document.getElementById("co_"+random+"_day").innerHTML,10);
	
	co_day = parseInt(document.getElementById(slc_co_day).value,10);
	
	// Saving variables placed inside an html p element's attributes.
	document.getElementById("co_"+random+"_day").innerHTML = co_day;
}

/* This function set correctly the check out month. */
function ghrs_setCalendarCoMonth(random){
	
	// If spans do not exist, we have to create them.
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	var slc_co_month = "co_month_slc_"+random;
	var co_month = parseInt(document.getElementById("co_"+random+"_month").innerHTML,10);
	
	co_month = parseInt(document.getElementById(slc_co_month).value,10);
	
	// Saving variables placed inside an html p element's attributes.
	document.getElementById("co_"+random+"_month").innerHTML = co_month;
	document.getElementById("co_"+random+"_temp_month").innerHTML = co_month;
}

/* This function set correctly the check out year. */
function ghrs_setCalendarCoYear(random){
	
	// If spans do not exist, we have to create them.
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	
	// Loading variables placed inside an html p element's attributes.
	var p_co = "p_co_"+random;
	var slc_co_year = "co_year_slc_"+random;
	var co_year = parseInt(document.getElementById("co_"+random+"_year").innerHTML,10);
	
	co_year = parseInt(document.getElementById(slc_co_year).value,10);
	
	// Saving variables placed inside an html p element's attributes.
	document.getElementById("co_"+random+"_year").innerHTML = co_year;
	document.getElementById("co_"+random+"_temp_year").innerHTML = co_year;
}
/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* The next functions has the behaviour to reset the previous values of the 	*/
/* calendar and of the selects in case that it has been closed. 				*/
/*------------------------------------------------------------------------------*/

/* This function has the behavior to reflesh select elements. */
function ghrs_setCalendarDayBase(random,check){
	
	var slcElementDay = check + "day_slc_" + random;
	var slcElementMonth = check + "month_slc_" + random;
	var slcElementYear = check + "year_slc_" + random;
	
	// Loading variables placed inside an html p element's attributes.
	var day = parseInt(document.getElementById(check+random+"_day").innerHTML,10);
	var month = parseInt(document.getElementById(check+random+"_temp_month").innerHTML,10);
	var year = parseInt(document.getElementById(check+random+"_temp_year").innerHTML,10);	
	
	document.getElementById(slcElementDay).value = day;
	document.getElementById(slcElementMonth).value = month;
	document.getElementById(slcElementYear).value = year;
	document.getElementById(check+random+"_month").innerHTML = month;
	document.getElementById(check+random+"_year").innerHTML = year;
	
	if(check=='ci_'){
		ghrs_setCalendarCiYear(random);
	}
	else{
		ghrs_setCalendarCoDay(random);
		ghrs_setCalendarCoMonth(random);
		ghrs_setCalendarCoYear(random);
	}
}

/* This function is called when the calendar is closed correctly with a change of any kind*/
/* of data. */
function ghrs_calendarSelfClose(random,check){
	
	var slcElementDay = check + "day_slc_" + random;
	var slcElementMonth = check + "month_slc_" + random;
	var slcElementYear = check + "year_slc_" + random;
	var day = parseInt(document.getElementById(check+random+"_day").innerHTML,10);
	var month = parseInt(document.getElementById(check+random+"_month").innerHTML,10);
	var year = parseInt(document.getElementById(check+random+"_year").innerHTML,10);
	
	if(check=='ci_'){
		document.getElementById("ci_"+random+"_day").innerHTML = day;
		document.getElementById("ci_"+random+"_month").innerHTML = month;
		document.getElementById("ci_"+random+"_year").innerHTML = year;
		document.getElementById("ci_"+random+"_temp_month").innerHTML = month;
		document.getElementById("ci_"+random+"_temp_year").innerHTML = year;
	}
	else{
		document.getElementById("co_"+random+"_day").innerHTML = day;
		document.getElementById("co_"+random+"_month").innerHTML = month;
		document.getElementById("co_"+random+"_year").innerHTML = year;
		document.getElementById("co_"+random+"_temp_month").innerHTML = month;
		document.getElementById("co_"+random+"_temp_year").innerHTML = year;
	}
}
/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* The next functions are used from the top buttons of the calendar to set up  	*/
/* correctly the month selected. 								 				*/
/*------------------------------------------------------------------------------*/

/* This function is used from the left button to set up calendar's month correctly. */
function ghrs_sxSetsMonth(check,random){
	var month = parseInt(document.getElementById(check+random+"_temp_month").innerHTML,10);
	var year = parseInt(document.getElementById(check+random+"_temp_year").innerHTML,10);
	month -= 1;
	ghrs_setButton('dx',check,random);
	if(month==today_month && year==today_year){
		ghrs_removeButton('sx',check,random);
		ghrs_saveModify(month,year,check,random);
		ghrs_changeCalendarDays(month,year,random,check)
	}
	else{
		ghrs_setButton('sx',check,random);
		if(month < 1){
			month = 12;
			year -= 1;
		}
		ghrs_saveModify(month,year,check,random);
		ghrs_changeCalendarDays(month,year,random,check)
	}
}

/* This function is used from the right button to set up calendar's month correctly. */
function ghrs_dxSetsMonth(check,random){
	var month = parseInt(document.getElementById(check+random+"_temp_month").innerHTML,10);
	var year = parseInt(document.getElementById(check+random+"_temp_year").innerHTML,10);
	month += 1;
	ghrs_setButton('sx',check,random);
	if(month==12 && year==today_year+1){
		ghrs_removeButton('dx',check,random);
		ghrs_saveModify(month,year,check,random);
		ghrs_changeCalendarDays(month,year,random,check)
	}
	else{
		ghrs_setButton('dx',check,random);
		if(month > 12){
			month = 1;
			year += 1;
		}
		ghrs_saveModify(month,year,check,random);
		ghrs_changeCalendarDays(month,year,random,check)
	}
}

/* This function is used to display the button when it is hidden. */
function ghrs_setButton(pos,check,random){
	var elem = document.getElementById("calendar_"+ pos +"_button");
	if(pos == 'dx'){
		elem.onclick = function() { ghrs_dxSetsMonth(check, random); };
		elem.style.cursor = 'pointer';
		document.getElementById("calendar_right_arrow").style.display = "";
	}
	else{
		elem.onclick = function() { ghrs_sxSetsMonth(check, random); };
		elem.style.cursor = 'pointer';
		document.getElementById("calendar_left_arrow").style.display = "";		
	}
}

/* This function is used to hide the button when it is displayed. */
function ghrs_removeButton(pos,check,random){
	var elem = document.getElementById("calendar_"+ pos +"_button");
	elem.style.cursor = 'default';
	elem.onclick = function() { };
	ghrs_disableColumnSelection(elem, 1);
	if(pos == 'dx') document.getElementById("calendar_right_arrow").style.display = "none";
	else document.getElementById("calendar_left_arrow").style.display = "none";
}

/* This function has the behaviour to save changes maded by buttons */
function ghrs_saveModify(month,year,check,random){
	document.getElementById(check+random+"_temp_month").innerHTML = month;
	document.getElementById(check+random+"_temp_year").innerHTML = year;
	document.getElementById("calendar_month").innerHTML = ghrs_getMonthName(month - 1) + ' ' + year;
}
/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* The next functions have the behaviour to set up correctly the calendar code 	*/
/* when the user change some values. 											*/
/*------------------------------------------------------------------------------*/

/* This function has the behaviour to change the calendar's table contents. */
function ghrs_changeCalendarDays(month,year,random,check){
	
	// The code contained between '-' allow us to obtain the first day of a month 
	// and use it to build up the calendar correctly. 
	//------------------------------------------------
	var month_names = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var this_month = month_names[parseInt(month,10) - 1];
	var this_date = new Date(this_month + ' 1, ' + year);
	var first_month_day = this_date.getDay();
	if(first_month_day > 0) first_month_day = first_month_day - 1;
	else first_month_day = 6;
	//------------------------------------------------
	
	var current_ci_day = parseInt(document.getElementById("ci_"+random+"_day").innerHTML,10);
	var current_ci_month = parseInt(document.getElementById("ci_"+random+"_month").innerHTML,10);
	var current_ci_year = parseInt(document.getElementById("ci_"+random+"_year").innerHTML,10);
	var current_co_day = parseInt(document.getElementById("co_"+random+"_day").innerHTML,10);
	var current_co_month = parseInt(document.getElementById("co_"+random+"_month").innerHTML,10);
	var current_co_year = parseInt(document.getElementById("co_"+random+"_year").innerHTML,10);
	var quit = 1; // Variable that check the complement of the calendar.
	
	// Generating empty days columns.
	for(var i=0;i<first_month_day;i++){
		ghrs_setTd(i, '&#160;', '', 0, '');
	}
	
	// Generating days columns.
	for(i; quit; i++){
		var this_day = i - first_month_day + 1;
		var params = this_day + ',\'' + random + '\'' + ', \'' + check + '\'';
		if(this_day <= ghrs_daysInMonth(month,year)){
			if((month<today_month)&&(year<=today_year)){
				ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
			}
			else{
				if((this_day==today)&&(month==today_month)&&(year==today_year)){
					if(check=='ci_'){
						ghrs_setTd(i, this_day, 'today_day_cal_href', 1, random, check);
					}
					else{
						if((current_ci_day==today)&&(current_ci_month==today_month)&&(current_ci_year==today_year)){
							ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
						}
						else{
							ghrs_setTd(i, this_day, 'today_day_cal_no_href', 0, '');
						}
					}
				}
				else{
					if((this_day<today)&&(month==today_month)&&(year==today_year)){
						ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
					}
					else{
						if(check=='co_'){
							if(current_ci_year>current_co_year){
								if(year==current_co_year){
									if((month==current_co_month)&&(this_day==current_co_day)){
										ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
									}
									else{
										ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
									}
								}
								else{
									if(month<=current_ci_month){
										if(month==current_ci_month){
											if(this_day<=current_ci_day){
												if(this_day==current_ci_day){
													ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
												}
												else{
													ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
												}
											}
											else{
												ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
											}
										}
										else{
											ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
										}
									}
									else{
										ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
									}
								}
							}
							if(current_ci_year==current_co_year){
								if(year<current_ci_year){
									ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
								}
								else{
									if(year>current_ci_year){
										ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
									}
									else{
										if(current_ci_month<current_co_month){
											if(month<current_ci_month){
												ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
											}
											else{
												if(month==current_ci_month){
													if(this_day<=current_ci_day){
														if(this_day==current_ci_day){
															ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
														}
														else{
															ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
														}
													}
													else{
														ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
													}
												}
												else{
													if(month==current_co_month){
														if(this_day<=current_co_day){
															if(this_day==current_co_day){
																ghrs_setTd(i, this_day, 'selected_day_cal', 1, random, check);
															}
															else{
																ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
															}
														}
														else{
															ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
														}
													}
													else{
														if(month<current_co_month){
															ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
														}
														else{
															ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
														}
													}
												}
											}
										}
										else{
											if(current_ci_month==current_co_month){
												if(month<current_ci_month){
													ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
												}
												else{
													if(month==current_ci_month){
														if(this_day<=current_ci_day){
															if(this_day==current_ci_day){
																ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
															}
															else{
																ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
															}
														}
														else{
															if(this_day<=current_co_day){
																if(this_day==current_co_day){
																	ghrs_setTd(i, this_day, 'selected_day_cal', 1, random, check);
																}
																else{
																	ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
																}
															}
															else{
																ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
															}
														}
													}
													else{
														ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
													}
												}
											}
											else{
												if(month<current_ci_month){
													if((month==current_co_month)&&(this_day==current_co_day)){
														ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
													}
													else{
														ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
													}
												}
												else{
													if(month==current_ci_month){
														if(this_day==current_ci_day){
															ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
														}
														else{
															if(this_day<current_ci_day){
																ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
															}
															else{
																ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
															}
														}
													}
													else{
														ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
													}
												}
											}
										}
									}
								}
							}
							if(current_ci_year<current_co_year){
								if(year==current_ci_year){
									if(month<current_ci_month){
										ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
									}
									else{
										if(month==current_ci_month){
											if(this_day==current_ci_day){
												ghrs_setTd(i, this_day, 'selected_day_cal_no_href', 0, '');
											}
											else{
												if(this_day<current_ci_day){
													ghrs_setTd(i, this_day, 'past_day_cal', 0, '');
												}
												else{
													ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
												}
											}
										}
										else{
											ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
										}
									}
								}
								else{
									if(month<current_co_month){
										ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
									}
									else{
										if(month==current_co_month){
											if(this_day==current_co_day){
												ghrs_setTd(i, this_day, 'selected_day_cal', 1, random, check);
											}
											else{
												if(this_day<current_co_day){
													ghrs_setTd(i, this_day, 'selected_period_cal', 1, random, check);
												}
												else{
													ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
												}
											}
										}
										else{
											ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
										}
									}
								}
							}
						}
						else{
							if((this_day==current_ci_day)&&(month==current_ci_month)&&(year==current_ci_year)){
								ghrs_setTd(i, this_day, 'selected_day_cal', 1, random, check);
							}
							else{
								ghrs_setTd(i, this_day, 'future_day_cal', 1, random, check);
							}
						}
					}
				}
			}
		}
		else{
			quit = 0;
		}
	}
	i--;
	while(document.getElementById("row_" + parseInt((i/7),10))){
		ghrs_setTd(i, '&#160;', '', 0, '');
		i++;
	}
}

/* This function will set up correctly each content of each column. */
function ghrs_setTd(pos, value, css_class, onclick, random, check){
	var link = document.getElementById("row_" + parseInt((pos/7),10)).getElementsByTagName("td")[pos%7];
	link.innerHTML = value;
	if(onclick == 1){
		link.onclick = function() { ghrs_calendarSetsDayDiv(value, random, check); };
		link.style.cursor = "pointer";
	}
	else{
		link.onclick = function() {};
		link.style.cursor = "default";
	}
	ghrs_setAttribute(link, 'class', css_class);
	ghrs_setAttribute(link, 'className', css_class);
	if(onclick == 0) ghrs_disableColumnSelection(link, 1);
	if(ghrs_isExplorer6()){
		if(onclick == 1){
			link.onmouseover = function() { this.className = css_class + '_hover' };
			link.onmouseout = function() { this.className = css_class };
		}
		else{
			link.onmouseover = function() {};
			link.onmouseout = function() {};
		}
	}
}

/* This function will disable the column selection with the mouse. */
function ghrs_disableColumnSelection(elem,cursor_def) {
	elem.onselectstart = function() { return false; };
	elem.unselectable = "on";
	elem.style.MozUserSelect = "none";
	if(cursor_def == 1) elem.style.cursor = "default";
}

/* This function will be called when the user chooses a day in the calendar. */
function ghrs_calendarSetsDayDiv(day,random,check){
	document.getElementById(check+random+"_day").innerHTML = day;
	document.getElementById(check+random+"_month").innerHTML = document.getElementById(check+random+"_temp_month").innerHTML;
	document.getElementById(check+random+"_year").innerHTML = document.getElementById(check+random+"_temp_year").innerHTML;
	ghrs_closeCalendarDiv();
	//ghrs_removeDateSelectorsAlert();
	ghrs_setCalendarDayBase(random,check);
}

/* This function has the behaviour of show or hide the calendar. */
function ghrs_buildCalendarDiv(random,check,event){
	if(ghrs_loaded){
		if(ghrs_fixCalendarHtmlElements(random,event)) ghrs_addCalendarElements(random,event);
		var calendar = document.getElementById('external_calendar_div');
		if(ghrs_isExplorer6()) var ifr = document.getElementById('calendar_iframe');
		var status = parseInt(document.getElementById("div_calendar_status").innerHTML,10);
		var current_check = document.getElementById('current_div_check').innerHTML;
		var current_random = document.getElementById('current_div_random').innerHTML;
		if(status == 1 && current_check == check && current_random == random){
			calendar.style.display = 'none';
			if(ghrs_isExplorer6()) ifr.style.display = 'none'; 
			document.getElementById("div_calendar_status").innerHTML = 0;
			ghrs_calendarSelfClose(random,check)
		}
		else{
			if(current_check != '' && current_random != '') ghrs_calendarSelfClose(current_random,current_check);
			ghrs_buildDiv(random,check,event);
			document.getElementById("div_calendar_status").innerHTML = 1;
			calendar.style.display = "block";
			if(ghrs_isExplorer6()){ 
				ifr.style.zIndex = 200;
				calendar.style.zIndex = ifr.style.zIndex + 1;
				ifr.style.display = 'block'; 
			}
		}
		var month_name = document.getElementById("calendar_month");
		var days_names_row = document.getElementById("days_name").getElementsByTagName("td");
		var close_span = document.getElementById("close_calendar_div").getElementsByTagName("span");
		var image_co = document.getElementById("img_co_"+random);
		var image_ci = document.getElementById("img_ci_"+random);
		ghrs_disableColumnSelection(month_name, 1);
		for(var i = 0; days_names_row[i]; i++){
			ghrs_disableColumnSelection(days_names_row[i], 1);
		}
		ghrs_disableColumnSelection(close_span[0], 0);
		ghrs_disableColumnSelection(image_co, 0);
		ghrs_disableColumnSelection(image_ci, 0);
		ghrs_stopEventPropagation(event);
	}
}

function ghrs_addCalendarElements(random,event){
	// Setting  calendar code and inseting calendar into page.
	var attributes = new Array();
	var span;
	if(event){
		if(!document.getElementById("external_calendar_div")){
			document.getElementsByTagName("body")[0].appendChild(ghrs_calendar_div);
			// Internet Explorer e Opera fix.
			if(window.attachEvent) ghrs_calendar_div.attachEvent('onclick', function() { ghrs_stopEventPropagation(event); });
		}
		if(!document.getElementById("calendar_iframe") && ghrs_isExplorer6()){
			attributes = { 'name':'calendar_iframe', 'id':'calendar_iframe', 'class':'calendar_destinations', 'src':'.', 'scrolling':'no', 'frameborder':'0', 'marginheight':'0', 'marginwidth':'0' };
			var calendar_iframe = ghrs_createElementWithAttribute('iframe',attributes,null);
			document.getElementsByTagName("body")[0].appendChild(calendar_iframe);
			self.frames['calendar_iframe'].document.write(""); 
			self.frames['calendar_iframe'].document.close();
		}
		if(!document.getElementById("span_calendar_" + random + "_status")){
			attributes = { 'id':('span_calendar_' + random + '_status'), 'style':'display : none;' };
			var calendar_iframe = ghrs_createElementWithAttribute('span',attributes,null);
			document.getElementsByTagName("body")[0].appendChild(calendar_iframe);
		}
	}
	var checks = new Array()
	checks[0] = "ci";
	checks[1] = "co";
	for(var i=0; i<checks.length; i++){
		if(!document.getElementById(checks[i] + '_' + random + "_day")){
			attributes = { 'id':(checks[i] + '_' + random + "_day"), 'style':'display : none;' };
			span = ghrs_createElementWithAttribute('span',attributes,ghrs_jsDate[checks[i]]['testDay']);
			document.getElementsByTagName("body")[0].appendChild(span);
		}
		if(!document.getElementById(checks[i] + '_' + random + "_month")){
			attributes = { 'id':(checks[i] + '_' + random + "_month"), 'style':'display : none;' };
			span = ghrs_createElementWithAttribute('span',attributes,ghrs_jsDate[checks[i]]['testMonth']);
			document.getElementsByTagName("body")[0].appendChild(span);
		}
		if(!document.getElementById(checks[i] + '_' + random + "_year")){
			attributes = { 'id':(checks[i] + '_' + random + "_year"), 'style':'display : none;' };
			span = ghrs_createElementWithAttribute('span',attributes,ghrs_jsDate[checks[i]]['year']);
			document.getElementsByTagName("body")[0].appendChild(span);
		}
		if(!document.getElementById(checks[i] + '_' + random + "_temp_month")){
			attributes = { 'id':(checks[i] + '_' + random + "_temp_month"), 'style':'display : none;' };
			span = ghrs_createElementWithAttribute('span',attributes,ghrs_jsDate[checks[i]]['testMonth']);
			document.getElementsByTagName("body")[0].appendChild(span);
		}
		if(!document.getElementById(checks[i] + '_' + random + "_temp_year")){
			attributes = { 'id':(checks[i] + '_' + random + "_temp_year"), 'style':'display : none;' };
			span = ghrs_createElementWithAttribute('span',attributes, ghrs_jsDate[checks[i]]['year']);
			document.getElementsByTagName("body")[0].appendChild(span);
		}
	}
}

function ghrs_fixCalendarHtmlElements(random,event){
	if(event){
		var cal_div = (!document.getElementById("external_calendar_div"));
		var cal_ifr = (!document.getElementById("calendar_iframe") && ghrs_isExplorer6());
		var cal_span = (!document.getElementById("span_calendar_" + random + "_status"));
		var cal_ver = cal_div || cal_ifr || cal_span;
	}
	else{
		var cal_ver = false;
	}
	var ci_span_day= (!document.getElementById("ci_" + random + "_day"));
	var ci_span_month= (!document.getElementById("ci_" + random + "_month"));
	var ci_span_year= (!document.getElementById("ci_" + random + "_year"));
	var ci_span_temp_month= (!document.getElementById("ci_" + random + "_temp_month"));
	var ci_span__temp_year= (!document.getElementById("ci_" + random + "_temp_year"));
	var co_span_day= (!document.getElementById("co_" + random + "_day"));
	var co_span_month= (!document.getElementById("co_" + random + "_month"));
	var co_span_year= (!document.getElementById("co_" + random + "_year"));
	var co_span_temp_month= (!document.getElementById("co_" + random + "_temp_month"));
	var co_span__temp_year= (!document.getElementById("co_" + random + "_temp_year"));
	var ci_ver = ci_span_day || ci_span_month || ci_span_year || ci_span_temp_month || ci_span__temp_year;
	var co_ver = co_span_day || co_span_month || co_span_year || co_span_temp_month || co_span__temp_year;
	return cal_ver || ci_ver || co_ver;
}

function ghrs_generateDivCode(table_code, img_url, msg, random){
	// Creating calendar's div in javascript.
	var attributes = { 'id':'external_calendar_div', 'class':'external_calendar_div', 'onclick':'ghrs_stopEventPropagation(event);' };
	var str='<table id="calendar_table" class="calendar_table" align="center" cellspacing="0" cellpadding="0">';
		str+='<tr>';
			str+='<td id="calendar_sx_button" class="button">';
				str+='<img id="calendar_left_arrow" style="display:none;" src="' + img_url +'/form/calendar_arrowsx-trasparent.gif" alt="" />';
			str+='</td>';
			str+='<td id="calendar_month" class="month" colspan="5">&#160;</td>';
			str+='<td id="calendar_dx_button" class="button">';
				str+='<img id="calendar_right_arrow" style="display:none;" src="' + img_url +'/form/calendar_arrowdx-trasparent.gif" alt=""/>';
			str+='</td>';
		str+='</tr>';
		str+='<tr id="days_name">';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
			str+='<td>&#160;</td>';
		str+='</tr>';
		str+=table_code;
		str+='<tr>';
			str+='<td id="close_calendar_div" class="close_calendar_div" colspan="7">';
				str+='<span onclick="ghrs_closeCalendarDiv()">';
					str+=msg;
				str+='</span>';
			str+='</td>';
		str+='</tr>';
	str+='</table>';
	str+='<span id="div_calendar_status" style="display : none;">0</span>';
	str+='<span id="current_div_check" style="display : none;"></span>';
	str+='<span id="current_div_random" style="display : none;">' + random + '</span>';
	ghrs_calendar_div = ghrs_createElementWithAttribute('div',attributes,str);
}

/* This function has the main behaviour of set calendar dimensions and contents.  */
function ghrs_buildDiv(random,check,event){
	var calendar = document.getElementById('external_calendar_div');
	var day = parseInt(document.getElementById(check+random+"_day").innerHTML,10);
	var month = parseInt(document.getElementById(check+random+"_temp_month").innerHTML,10);
	var year = parseInt(document.getElementById(check+random+"_temp_year").innerHTML,10);
	document.getElementById('calendar_month').innerHTML = ghrs_getMonthName(month - 1) + ' ' + year;
	ghrs_calendarDaysNamesDiv();
	ghrs_changeCalendarDays(month,year,random,check);
	ghrs_setDivDimensionsAndPosition(random,check,event);// Call to the function that set up correcly iframe's dimensions and position.
	if(!(month==today_month && year==today_year)) ghrs_setButton('sx',check,random);
	else ghrs_removeButton('sx',check,random);
	if(!(month==12 && year==today_year+1)) ghrs_setButton('dx',check,random);
	else ghrs_removeButton('dx',check,random);
	document.getElementById('current_div_check').innerHTML = check;
	document.getElementById('current_div_random').innerHTML = random;
}

/* This function will sett the names of the calendar's days. */
function ghrs_calendarDaysNamesDiv(){
	var td_array = document.getElementById('days_name').getElementsByTagName('td');
	for(var i=0; i<7; i++){
		td_array[i].innerHTML = ghrs_getDayName(i).charAt(0);
		ghrs_setAttribute(td_array[i], 'class', 'day_name');
	}
}

/* This function has the behaviour of set up correctly the calendar's dimensions and positions. */
function ghrs_setDivDimensionsAndPosition(random,check,event){
	var calendar = document.getElementById('external_calendar_div');
	var ifr = document.getElementById('calendar_iframe');
	var slc_ci = "ci_day_slc_"+random;
	var slc_co = "co_day_slc_"+random;
	var img = "img_" + check + random;
	var slc_ci_day = document.getElementById(slc_ci);
	var slc_co_day = document.getElementById(slc_co);
	var current_img = document.getElementById(img);
	var found_position_slc_ci = ghrs_findPosition(slc_ci_day);
	var found_position_slc_co = ghrs_findPosition(slc_co_day);
	var found_position_image = ghrs_findPosition(current_img);
	var pos_left_slc_ci = found_position_slc_ci[0];
	var pos_left_slc_co = found_position_slc_co[0];
	var pos_top_slc_ci = found_position_slc_ci[1];
	var pos_top_slc_co = found_position_slc_co[1];
	var pos_height_slc = slc_ci_day.offsetHeight;
	if(pos_top_slc_ci>(pos_top_slc_co-pos_height_slc)&&pos_top_slc_ci<(pos_top_slc_co+pos_height_slc)){
		calendar.style.left = event.clientX - 150 + 'px';
		calendar.style.top = event.clientY + slc_ci_day.offsetHeight + 'px';
	}
	else{
		calendar.style.left = event.clientX + current_img.offsetWidth + 'px';
		calendar.style.top = event.clientY - 7 + 'px';
	}
	calendar.style.width = '175px';
	calendar.style.height = '225px';
	calendar.style.left = parseInt(calendar.style.left,10) + getScrollLeft() + 'px';
	calendar.style.top = parseInt(calendar.style.top,10) + getScrollTop() + 'px';
	var browser = String(navigator.userAgent);
	if(browser.search("Firefox") > -1){
		calendar.style.borderWidth = "3px";
		if(browser.search("3.0") > -1){
			calendar.style.paddingBottom = '4px';
		}
	}
	if(ghrs_isExplorer6()){ 
		var ifr = document.getElementById('calendar_iframe');
		ifr.style.width = '179px';
		ifr.style.height = '229px';
		ifr.style.left = parseInt(calendar.style.left,10) + 'px';
		ifr.style.top = parseInt(calendar.style.top,10) + 'px';
	}
	if(browser.search("Opera") > -1){
		calendar.style.borderBottom = '0';
		calendar.style.paddingTop = '1px';
		calendar.style.paddingRight = '1px';
		calendar.style.paddingBottom = '0px';
		calendar.style.borderBottom = '1px';
	}
}

/* This function is used to close the calendar. */
function ghrs_closeCalendarDiv(){
	if(document.getElementById("external_calendar_div")){
		var calendar = document.getElementById('external_calendar_div');
		if(ghrs_isExplorer6()) var calendar = document.getElementById('external_calendar_div');
		var ifr = document.getElementById('calendar_iframe');
		var check = document.getElementById('current_div_check').innerHTML;
		var random = document.getElementById('current_div_random').innerHTML;
		calendar.style.display = 'none';
		if(ghrs_isExplorer6()) ifr.style.display = 'none';
		if(document.getElementById("div_calendar_status")) document.getElementById("div_calendar_status").innerHTML = 0;
		if(check != '') ghrs_calendarSelfClose(random,check);
		document.getElementById('current_div_check').innerHTML = '';
		document.getElementById('current_div_random').innerHTML = '';
	}
}

function ghrs_closeCalendarDivEmbedded(){
	try{
		ghrs_closeCalendarDiv(); 
	}catch(e){}
}
/*------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------*/
/* Next piece of code has the behavior to manage the submit of the form in the  */
/* same page of the calendar and the "view_all_destinations" list.	        */
/*------------------------------------------------------------------------------*/

/* This function is called from the submit listener to check the dates inseted. */
/* If dates are corrects the submit is forward otherwise will be showed a       */
/* warning message and the submit will be stopped.				*/
function ghrs_checkInputDate(event,random,form,display){
	ghrs_list_random = random;
	ghrs_closeCalendarDiv();
	if(ghrs_fixCalendarHtmlElements(random,null)) ghrs_addCalendarElements(random,null);
	//ghrs_removeAlertForm(random);
	var elem;
	var current_form = document.getElementById("check_"+random);
	var ci_day = parseInt(document.getElementById("ci_"+random+"_day").innerHTML,10);
	var ci_month = parseInt(document.getElementById("ci_"+random+"_month").innerHTML,10);
	var ci_year = parseInt(document.getElementById("ci_"+random+"_year").innerHTML,10);
	var co_day = parseInt(document.getElementById("co_"+random+"_day").innerHTML,10);
	var co_month = parseInt(document.getElementById("co_"+random+"_month").innerHTML,10);
	var co_year = parseInt(document.getElementById("co_"+random+"_year").innerHTML,10);
	var error_array = new Array();
	var msg_error_array = new Array();
	var codate_error_array = new Array();
	var cidate_error_array = new Array();
	var date_error = false;
	
	if(document.getElementById("loc_search_" + random)){
		if(ghrs_trimValue(document.getElementById("loc_search_" + random).value).length<3){
			if(document.getElementById("loc_search_" + random).value ==''){
				alert(msgEmptyInputLoc);
			}
			else{
				alert(msgWrongInputLoc);
			}
			return false;
		}
	}
	if(ci_year>co_year){
		if(document.getElementById("date_selectors_error")){
			date_error=true;
			codate_error_array.push("co_year");	
		}
		else {
			ghrs_validateDate(event, msgInvalidDate);
			return false;
		}
	}
	if(ci_year==co_year){
		if(ci_month>co_month){
			if(document.getElementById("date_selectors_error")){
				date_error=true;
				codate_error_array.push("co_month");	
			}
			else{
				ghrs_validateDate(event, msgInvalidDate);
				return false;
			}
		}
		if(ci_month==co_month){
			if(ci_day>=co_day){
				if(document.getElementById("date_selectors_error")){
					date_error=true;
					codate_error_array.push("co_day");
				}
				else{
					ghrs_validateDate(event, msgInvalidDate);
					return false;
				}
			}
		}
	}
	if(ci_year == today_year){
		if(ci_month<today_month){
			if(document.getElementById("date_selectors_error")){
				date_error=true;
				cidate_error_array.push("ci_month");
			}
			else{
				ghrs_validateDate(event, msgInvalidDate);
				return false;
			}
		}
		if(ci_month==today_month){
			if(ci_day<today){
				if(document.getElementById("date_selectors_error")){
					date_error=true;
					cidate_error_array.push("ci_day");	
				}
				else{
					ghrs_validateDate(event, msgInvalidDate);
					return false;
				}
			}
		}
	}
	if(date_error){ 
		error_array.push("date_selectors");
		msg_error_array.push(msgInvalidDate);
	}
	if(document.getElementById("form_qty_" + random)){
		if(isNaN(parseInt(document.getElementById("form_qty_" + random).value,10)) || parseInt(document.getElementById("form_qty_" + random).value,10)<1){
			if(document.getElementById("other_selectors_error")){
				error_array.push("other_selectors");
				msg_error_array.push(msgWrongInputRoom);
				ghrs_setAttribute(document.getElementById("form_qty_" + random), "class", "wrong_input calendar_input");
			}
			else{
				alert(msgWrongInputRoom);
				return false;
			}
		}
	}
	if(cidate_error_array.length>0){
		ghrs_setDateSelectClass("ci", "calendar_select wrong_input");
	}
	if(codate_error_array.length>0){
		ghrs_setDateSelectClass("co", "calendar_select wrong_input");
	}
	var error_length = error_array.length;
	while(error_array.length>0) ghrs_showAlertForm(error_array.pop(), msg_error_array.pop());
	if(error_length>0) return false;
	if(document.getElementById("loc_search_" + random)){
		if(!(ghrs_trimValue(document.getElementById("loc_search_" + random).value).length<3)){
			document.getElementById("loc_search_" + random).value = ghrs_trimValue(document.getElementById("loc_search_" + random).value);
		}
	}
	if(document.getElementById("loc_country")&&document.getElementById("loc_search_" + random)&&document.getElementById("loc_country")&&document.getElementById("prev_loc")){
		var loc_search_value = document.getElementById("loc_search_" + random).value;
		var previous_value = document.getElementById("prev_loc").value;
		if(previous_value==loc_search_value) document.getElementById("loc_country").disabled = false;
	}
	if(display) ghrs_displayWaitingPage(random);
	return true;
}

/* Function used to test the search input */
function ghrs_trimValue(value){
    while (value.substring(0,1) == ' '){
        value = value.substring(1, value.length);
    }
    while (value.substring(value.length-1, value.length) == ' '){
        value = value.substring(0,value.length-1);
    }
    return value;
}

/* This function is called from the submit listener to check the dates inseted. */
/* This function is called when the inserted dates are wrong. It has the        */
/* behaviour to hide calendar */
function ghrs_validateDate(event, msg){
	ghrs_closeCalendarDiv()
	ghrs_stopEventPropagation(event);
	alert(msg);
}

/*----------------------------------------------*/
/*				Ghrs Waiting Page  				*/
/*----------------------------------------------*/

/*var ghrs_wait_img;*/

/* Function that display the waiting page usually called when button "Find" is pressed */
function ghrs_displayWaitingPage(random){
	
	var page_html = document.getElementsByTagName("html")[0];
	var page_body = document.getElementsByTagName("body")[0];
	ghrs_setAttribute(page_html, "class", "wait_page_html");
	ghrs_setAttribute(page_body, "class", "wait_page_body"); 
	
	
	// If the browser is Explorer 6 we must show the iframe.
	if(ghrs_isExplorer6()){ 
		if(!document.getElementById('iframe_wait_page_filler')){
			attributes = { 'id':'iframe_wait_page_filler', 'name':'iframe_wait_page_filler', 'src':'.' };
			var iframe = ghrs_createElementWithAttribute('iframe',attributes,null);
			document.getElementsByTagName("body")[0].appendChild(iframe);
			self.frames['iframe_wait_page_filler'].document.write(""); 
			self.frames['iframe_wait_page_filler'].document.close();
		}
		var wait_ifr = document.getElementById('iframe_wait_page_filler');
		wait_ifr.style.position="absolute";
		wait_ifr.style.height = window.document.body.scrollHeight + "px";
		wait_ifr.style.width = ghrs_getWidth() + "px";
		wait_ifr.style.left="0";
		wait_ifr.style.right="0";
		wait_ifr.style.top="0";
		wait_ifr.style.bottom="0";
		wait_ifr.style.margin="0";
		wait_ifr.style.background="white";
		wait_ifr.style.display='';
		wait_ifr.style.textAlign='center';
	}
	// Setting the code and displaing the waiting page.
	if(!document.getElementById('wait_page_filler')){
		attributes = { 'id':'wait_page_filler' };
		var div = ghrs_createElementWithAttribute('div',attributes,null);
		document.getElementsByTagName("body")[0].appendChild(div);
	}
	var wait_div = document.getElementById('wait_page_filler');
	ghrs_insertDivCode(wait_div,random);
	wait_div.style.position="fixed";
	if(ghrs_isExplorer6()){
		wait_div.style.position="absolute";
		wait_div.style.height = document.body.clientHeight + "px";
		wait_div.style.width = document.body.clientWidth + "px";
	}
	else{
		wait_div.style.height="100%";
		wait_div.style.width="100%";
	}
	wait_div.style.left="0";
	wait_div.style.right="0";
	wait_div.style.top="0";
	wait_div.style.bottom="0";
	wait_div.style.margin="0";
	wait_div.style.background="white";
	wait_div.style.display='';
	wait_div.style.textAlignt='center';
	if(ghrs_isExplorer6()){
		ghrs_wait_img = document.getElementById("wait_page_img_id");
		ghrs_wait_img.style.top = "30%"; 
		wait_ifr.style.zIndex = 200
		wait_div.style.zIndex = wait_ifr.style.zIndex + 1;
	}
	else wait_div.style.zIndex = 200;
}

/* Function that insert the code in the waiting page div */
function ghrs_insertDivCode(div,random){
	if(typeof div == 'object'){
		div.appendChild(ghrs_wait_img);
	}
}
