function onSendAdv()
{
    a = '';
    if (!document.form.elements['info'].value) a = 'Please enter information about company';
    if (!document.form.elements['country'].value) a = 'Please enter country';
    if (!document.form.elements['telephone'].value) a = 'Please enter telephone';
    if (!document.form.elements['email'].value) a = 'Please enter email';
    if (!document.form.elements['contact_person'].value) a = 'Please enter contact person';
    if (!document.form.elements['company_name'].value) a = 'Please enter company name';
    if (a) alert(a); else document.form.submit();
}

function anyPopup(title, url) {
	obj=window.open(url, title, "width=512,height=768,left=384,top=0,scrollbars=1,location=0,menubar=0,resizable=1");
}

function popupNews(){
   	obj=window.open("/news/","_news","width=700,height=450,left=269,top=269,scrollbars=1,location=0,menubar=0,resizable=0");
}

function certificatePopup(id, print, popupWidth, popupHeight) {
	
	if (print) {
		
		var popupWidth  = popupWidth  || 1024;
		var popupHeight = popupHeight || 768;
		
		var win = window.open('/get_certificate/?ModuleID=' + id + '&print', 'Certificate', 'scrollbars=yes,width=' + popupWidth + ',height=' + popupHeight);
	} else {
		var win = window.open('/get_certificate/?ModuleID=' + id, 'Certificate', 'scrollbars=yes,width=1024,height=768');
	}
}

function booking () {
	var obj = window.open('/manage/booking/','Booking','width=1000,height=650,scrollbars=1,location=0,menubar=0,resizable=0');
	obj.focus();
}

function paramGet(url, paramName)
{
	var paramsGet = new Array();
	var str = String(url);
	str = str.split('?');
	params = str[1].split('&');
	for(i = 0; i < params.length; i++) {
		var tmp = params[i].split('=');
		paramsGet[tmp[0]] = tmp[1];
	}
	return paramsGet[paramName];
}

function paramsGet(url)
{
	var paramsGet = new Array();
	var str = String(url);
	if (str.search('/?/')) {
		str = str.split('?');
		tmpString = String(str[1]);
		if (tmpString.search('/&/')) {
			params = tmpString.split('&');
			for(i = 0; i < params.length; i++) {
				var tmp = params[i].split('=');
				paramsGet[tmp[0]] = tmp[1];
			}
			return paramsGet;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function popup()
{
    obj=window.open("/manage/users_export_1/","","width=370,height=100,left=269,top=269,scrollbars=1,location=0,menubar=0,resizable=0");
    obj.focus();
}

function popupExport(courseId)
{
    if (courseId) {
        obj=window.open("/manage/users_export_select/?CourseID=" + courseId,"","width=700,height=700,left=269,top=269,scrollbars=1,location=0,menubar=0,resizable=0");
    } else {
        obj=window.open("/manage/users_export_select/","","width=700,height=700,left=269,top=269,scrollbars=1,location=0,menubar=0,resizable=0");
    }
    obj.focus();
}

function parse_url (str, component) {
    // Parse a URL and return its components  
    // 
    // version: 905.3122
    // discuss at: http://phpjs.org/functions/parse_url
    // +      original by: Steven Levithan (http://blog.stevenlevithan.com)
    // + reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: blog post at http://blog.stevenlevithan.com/archives/parseuri
    // %          note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
    // %          note: Does not replace invaild characters with '_' as in PHP, nor does it return false with
    // %          note: a seriously malformed URL.
    // %          note: Besides function name, is the same as parseUri besides the commented out portion
    // %          note: and the additional section following, as well as our allowing an extra slash after
    // %          note: the scheme/protocol (to allow file:/// as in PHP)
    // *     example 1: parse_url('http://username:password@hostname/path?arg=value#anchor');
    // *     returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'}
    var  o   = {
        strictMode: false,
        key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
        q:   {
            name:   "queryKey",
            parser: /(?:^|&)([^&=]*)=?([^&]*)/g
        },
        parser: {
            strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
            loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-protocol to catch file:/// (should restrict this)
        }
    };
    
    var m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
    uri = {},
    i   = 14;
    while (i--) {uri[o.key[i]] = m[i] || "";}
    // Uncomment the following to use the original more detailed (non-PHP) script
    /*
        uri[o.q.name] = {};
        uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
        });
        return uri;
    */

    switch (component) {
        case 'PHP_URL_SCHEME':
            return uri.protocol;
        case 'PHP_URL_HOST':
            return uri.host;
        case 'PHP_URL_PORT':
            return uri.port;
        case 'PHP_URL_USER':
            return uri.user;
        case 'PHP_URL_PASS':
            return uri.password;
        case 'PHP_URL_PATH':
            return uri.path;
        case 'PHP_URL_QUERY':
            return uri.query;
        case 'PHP_URL_FRAGMENT':
            return uri.anchor;
        default:
            var retArr = {};
            if (uri.protocol !== '') {retArr.scheme=uri.protocol;}
            if (uri.host !== '') {retArr.host=uri.host;}
            if (uri.port !== '') {retArr.port=uri.port;}
            if (uri.user !== '') {retArr.user=uri.user;}
            if (uri.password !== '') {retArr.pass=uri.password;}
            if (uri.path !== '') {retArr.path=uri.path;}
            if (uri.query !== '') {retArr.query=uri.query;}
            if (uri.anchor !== '') {retArr.fragment=uri.anchor;}
            return retArr;
    }
}

function in_array(needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 905.3120
    // discuss at: http://phpjs.org/functions/in_array
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

function getElementPosition(obj) {
    var x = y = 0;
    while(obj) {
          x += obj.offsetLeft;
          y += obj.offsetTop;
          obj = obj.offsetParent;
    }
    return {"left":x, "top":y};
}

function addEvent(nameEvent, event, add) {
	var tmp = new String(event);
	eval(nameEvent + ' = ' + tmp.substr(0, tmp.length-1) + add + '}');
}

function setCookie (name, value) {
    document.cookie = name + "=" + escape(value);
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function deleteCookie(name) {
      if (getCookie(name)) {
              document.cookie = name + "=";
      }
}

function checkSetCookie(courseId) {
	setCookie('test', '1');
	var cookie = getCookie('test');
	
	if (!cookie) {
		popupErrorCookie();
	} else {
		$j('form[name=login_form]').submit();
	}
}

function checkSetCookieJoin(courseId) {
	setCookie('test', '1');
	var cookie = getCookie('test');
	if (!cookie) {
		popupErrorCookie();
	} else {
		window.location = '/join/';
	}
}

function checkSetCookieJoinSilversea(regionId) {
	setCookie('test', '1');
	var cookie = getCookie('test');
	
	if (!cookie) {
		popupErrorCookie();
	} else {
		window.location = '/loginForm2/?region=' + regionId;
	}
}

function checkSetCookieJoinAdventure(regionId) {
	setCookie('test', '1');
	var cookie = getCookie('test');
	
	if (!cookie) {
		popupErrorCookie();
	} else {
		window.location = '/loginForm2/?region=' + regionId;
	}
}

function popupErrorCookie() {
	var popup = new Window('errorCookie',
            {
              className: 'errorCookie',
              title: '<div style="color: #a20000; text-align: left; margin: -3px 0 0 0; font-weight: bold; font-size: 14px; font-family: sans serif;">Cookies are disabled</div>',
              width: 400,
              height: 145,
              top: 300,
              left: 100,
              zIndex: 10000,
              destroyOnClose: true,
              resizable: false,
              closable: false,
              minimizable: false,
              maximizable: false,
              draggable: false
            });
	var content = '<div style="margin: 10px 8px 0 8px; text-align: justify; font-weight: bold; font-size: 13px; font-family: Arial;">' +
				  	 'Sorry, but it would appear you have cookies disabled in your browser: to view this site you will need to enable cookies. For more information about cookies, including how to enable them, please refer to your web browser\'s help menu or visit this helpful <a style="color: #a20000;" href="http://www.google.com/support/accounts/bin/answer.py?ctx=ch&answer=61416" target="_blank">page</a> on Google.' + 
				  '</div>' +
				  '<div style="text-align: center; margin: 10px 0 0 165px;">' +
					  '<div class="buttonErrorCookie" id="closeErrorCookie">' +
					  '</div>' +
				  '</div>';
	
	popup.getContent().innerHTML = content;
	
	popup.close();
	
	$j('#errorCookie').css({position: 'absolute'});
	
	$j('#closeErrorCookie').click( function () { popup.destroy() } );
	
	popup.showCenter();
}
