// JavaScript Document

var kliknjen =""

function nav_on(id){
	
	if(id != kliknjen){
		
	var target = document.getElementById(id)
	target.style.backgroundColor="#cdd2d3";
	}
}
function nav_off(id){
	if(id != kliknjen){
	var target = document.getElementById(id)
	target.style.backgroundColor="#e3e7e8";
	}
}
	function klik(id){
		//alert(id)
	kliknjen = id
	var target = document.getElementById(id)
	target.style.backgroundColor="#cdd2d3";
	}
	



// POVECAVA FONTOV //

// Copyright 2003 Eddie Traversa
// http://www.dhtmlnirvana.com/
// free to use as long as this copyright notice stays intact
var tags = new Array( 'div','td','tr','p','b','table','strong','span','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd');
var pixelArray =  new Array('9','10','11','13','15','17','19','21');
var emArray =  new Array('0.7','0.9','1.0','1.5','2.0','2.5','3');
var initSize = parseInt(getCookie("fontsize"));

function getInitSize() {
	if (!initSize) { 
		initSize = 2;
		var now = new Date();
		now.setTime(now.getTime() + 2 * 24 * 60 * 60 * 1000);
		setCookie("fontsize", initSize, now);
	} else if (initSize != 2) {
		tmp = initSize-2;
		initSize = 2;
		fontSizer(tmp, 'px');
	}
}

function fontSizer(inc,unit) {
		
	if (!document.getElementById) 
		return;
	var size = initSize;
		size += inc;
	if (size < 3 ) {
		size = 2;
	}
	if (size > 5 ) {
		size = 5;
	}
		var diff = size - initSize;
		initSize = size;
		var now = new Date();
		now.setTime(now.getTime() + 2 * 24 * 60 * 60 * 1000);
		setCookie("fontsize", initSize, now);
		
		getBody = document.getElementsByTagName('body')[0];
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
		for (k = 0 ; k < getallTags.length ; k++) {
			if (getallTags[k].className != 'fixed' && getallTags[k].className != 'gl_nav' && getallTags[k].className != 'navbar') {
				if (getallTags[k].style.fontSize.length > 0) {
					px = toInt(getallTags[k].style.fontSize);
					getallTags[k].style.fontSize = (unit=='px') ? (pixelArray[size]*1 + px-pixelArray[size-diff])+unit : (emArray[size]*1 + px-emArray[size-diff])+unit;
				} else
					getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit : emArray[size]+unit;
			}
		}
	}
}

function toInt(str) {
	for (j = 0; j <= str.length; j++) {
		if (j == str.length || str.charAt(j) < '0' || str.charAt(j) > '9') {
			return str.substring(0,j)*1;
		}
	}
}

/////////////////////

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

// END cookeis //


var xmlhttp=false;

///  TA KOMENTIRANA KODA MORA TU OBVEZNO BIT!!!!

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
  try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var ajax_done = true;
function loadFragmentInToElement(fragment_url, element_id, baseurl, notify) {
	if (!ajax_done) {
		xmlhttp.abort();
	}
	ajax_done = false;
	myPreAjaxLoad(element_id, baseurl);
	var element = document.getElementById(element_id);
	xmlhttp.open("GET", fragment_url, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) { /*  && xmlhttp.status == 200 this was originally added to condition inside parenthesis */
			element.innerHTML = xmlhttp.responseText;
			ajax_done = true;
			myOnAjaxLoad(element_id, notify);
		}
	}
	xmlhttp.send(null);
}


//////////////////////////////////////////////////////////////

function myPreAjaxLoad(element_id, baseurl) {
	if (element_id !='ogone_code_container' && baseurl!='') {
		var element = document.getElementById(element_id);
		element.innerHTML = '<img src="'+baseurl+'imgs/bg/waiting.gif" border="0" alt="">';
	}
}

function myOnAjaxLoad(element_id, notify) {
	/*
	if (element_id == 'ogone_code_container') {
		insert_Temporary_Booking_Entries();
	}
	if (element_id == 'dummy_blank_area') {
		enableBookButton();
	}
	*/
	if (element_id == 'ogone_code_container') {
		enableBookButton();
	}
}

function onLoadHandler() {
	fixOutlinedLinks();
}

function fixOutlinedLinks () {
	/* Set all hyperlink's outline styles to "none", 'cause we don't want border box around link to appear when following the hyperlink (RashA) */
	var st1, st2, stfix = "outline-style: none; outline: none;";
	var ahrefs = document.getElementsByTagName('A');
	for (var i = 0; i < ahrefs.length; i++)
	{
		st1 = ahrefs[i].getAttribute("style");
		if (typeof st1 == 'string' && st1.length)
			st2 = st1+"; "+stfix;
		else
			st2 = stfix;
		ahrefs[i].setAttribute("style", st2);
	}
	/* End of correcting hyperlink styles */
}

function myDateHandler (input_object) {
	/*
		Well, I've written this function to enable myself cathing event when date is selected in calendar.js, so this function is only related to calendar.js
		So far I have 2 good reasons to catch this event:
			1. I can validate dates as soon as they are selected in calendar
			2. I can use that event to trigger some other operation, like invoking some Ajax module to fill in other dependent form elements
			
			NOTICE:	If I set onblur="myDateHandler(this);" as calendar's html input parameter, I'll get the same stuff even if I change input field by hand,
				as soon as I move focus to some other element
				
		That's all for the moment... (RashA)
	*/
	if (input_object.id == 'b_date_b') {
		// Exception for birth date
		validateBirthDate (input_object.value);
	}
	else {
		// Handling departure and return date
		var return_date = document.getElementById('g_date_b') && document.getElementById('g_date_b').value;
		validateDate (input_object.value);
		if (input_object.id == 'g_date_b')
			myIsBefore (input_object.value, document.getElementById('f_date_b').value);
		else if (input_object.id == 'f_date_b' && return_date)
			myIsBefore (document.getElementById('g_date_b').value, input_object.value);
		reload_departure_return_table();
		/*clean_price_n_discount();*/
	}
	return 0;
}

function validateEmail (email) {
	// Fix for default parameter, we want default value for parameter 'email' to be ''
	var email = typeof(email) != 'undefined' ? email : '';
	
	if (email=='')
		return false;
	
	var good_email = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.info)|(\.biz)|(\.org)|(\.mobi)|(\.name)|(\..{2,2}))$)\b/gi);
	if (good_email)
		return true;
	else
		return false;
}

