var root = '';

function i_getRelativePath() {
	var pathname = location.pathname.substring(1).replace(root, '');
	var dir = "";
	for(var i=0; i<pathname.length; i++) {
		if(pathname.charAt(i) == "/") {
			dir += "../"
		}
	}
	return dir;
}

function i_getSection() {
	var pathname = location.pathname.substring(1).replace(root, '');
	var section = "";
	if(pathname.indexOf('/') > 0) {
		section = pathname.substring(0, pathname.indexOf('/'));
	}
	return section;
}

function i_getSubSection() {
	var pathname = location.pathname.substring(1).replace(root, '');
	var section = i_getSection();
	var subsection = "";
	if(section != "") {
		pathname = pathname.substring(section.length+1, pathname.length);
		subsection = pathname.substring(0, pathname.indexOf('/'));
	}
	return subsection;
}

function i_getRandomNumber(number) {
	day = new Date();
	seed = day.getTime();
	return parseInt(((seed - (parseInt(seed/1000,10) * 1000)) /10) /100 * number + 1,10);
}

function i_popUpWin(url, win, width, height, options, position) {
	var defaultPos = 20;
		
	if(position == "cs") {
		leftPos = (screen.width) ? (screen.width-width)/2 : defaultPos;
		topPos = (screen.height) ? (screen.height-height)/2 : defaultPos;
	} else if(position == "cw") {
		leftPos = (document.body.clientWidth) ? (document.body.clientWidth-width)/2 : defaultPos;
		topPos = (document.body.clientHeight) ? (document.body.clientHeight-height)/2 : defaultPos;
		leftPos += (window.screenLeft) ? window.screenLeft : window.screenX;
		if(leftPos.toString() == "NaN") {
			leftPos = (screen.width) ? (screen.width-width)/2 : defaultPos;			
		}
		topPos = (topPos < 100) ? 100 : topPos;
	} else {
		leftPos = defaultPos;
		topPos = defaultPos;
	}
	
	options += ((options != '') ? ',' : '') + 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	newWin = window.open(url, win, options);
	newWin.focus();
	
	return newWin;
}

/* submit functions */
function i_display_reqired(required) {
	var count = 0;
	var message = "The following fields are required:\n";
	for(var i=0; i<required.length; i++) {
		if(required[i] != "" || required[i] != null) {
			message = message + " - " + required[i] + "\n";
			count += 1;
		}
	}
	
	if(count > 0) {
		alert(message);
		return false;
	} else {
		return true;
	}
}


function i_display_error(errors) {
	var count = 0;
	var message = "The following errors have occured:\n";
	for(var i=0; i<errors.length; i++) {
		if(errors[i] != "" || errors[i] != null) {
			message = message + " - " + errors[i] + "\n";
			count += 1;
		}
	}
	
	if(count > 0) {
		alert(message);
		return false;
	} else {
		return true;
	}
}

var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length) {
	x = navigator.plugins["Shockwave Flash"];
	if (x) {
		flashinstalled = 2;
		if (x.description) {
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		flashinstalled = 1;
	}
	if (navigator.plugins["Shockwave Flash 2.0"]) {
		flashinstalled = 2;
		flashversion = 2;
	}
} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin) {
		flashinstalled = 2;
	} else {
		flashinstalled = 1;
	}
} else {
	MSDetect = "true";
}