var a_errorfields = new Array();
function highlight_errors(pa_errors) {
	if (pa_errors) {
		a_errorfields = pa_errors;
	}
	if (a_errorfields.length == 0) {
		return;
	}
	
	for (var i=0; i < a_errorfields.length; i++) {
		document.getElementById("c_" + a_errorfields[i]).className = "error_container";
	}	
	
	document.getElementById("f_" + a_errorfields[0]).focus();
}

function f_syncFields(ps_source, ps_target) {
	if (!ps_source && !ps_target) {
		return;
	}
	
	oSource = document.getElementById(ps_source);
	oTarget = document.getElementById(ps_target);
	
	if (oTarget.value == "") {	
		if (oSource && oTarget) {
			oTarget.value = oSource.value;
		}
	}
}

function c_browser() {
	var type = null;
	var os = null;
	var dom = null;
	var ie4 = null;
	var ns4 = null;
	var detect = null;
	this.check = function() {
		this.detect = navigator.userAgent.toLowerCase();
		this.dom = (document.getElementById)? true : false;
		this.ie4 = (document.all)? true : false;
		this.ns4 = (document.layers)? true : false;
		this.fnCheck();
	};
	this.fnCheck = function() {
		if (this.fnCheckIt('konqueror')) {
			this.type = "Konqueror";
			this.os = "Linux";
		}
		else if (this.fnCheckIt('safari')) this.type = "safari"
		else if (this.fnCheckIt('omniweb')) this.type = "omniweb"
		else if (this.fnCheckIt('opera')) this.type = "opera"
		else if (this.fnCheckIt('webtv')) this.type = "webtv";
		else if (this.fnCheckIt('icab')) this.type = "icab"
		else if (this.fnCheckIt('msie')) this.type = "internet_explorer"
		else if (this.fnCheckIt('firefox')) this.type = "firefox"
		else if (this.fnCheckIt('netscape')) this.type = "netscape_navigator"
		else if (!this.fnCheckIt('compatible')) {
			this.type = "netscape_navigator"
		} else 
			this.type = "unknown";
		
		if (this.fnCheckIt('linux')) this.os = "linux";
		else if (this.fnCheckIt('x11')) this.os = "unix";
		else if (this.fnCheckIt('mac')) this.os = "mac"
		else if (this.fnCheckIt('win')) this.os = "windows"
		else this.os = "unknown";
	};
	this.fnCheckIt = function(psString) {
		return this.detect.indexOf(psString) + 1;
	};
}
var browser = new c_browser();
browser.check();

function $(psId) {
	return fnGetElement(psId);
}

function fnGetElement(psId) {
	if (!psId) {
		return;
	}
	var oId = 0;
	if (browser.dom) {
		oId = document.getElementById(psId);
	} else if (browser.ie4) {
		oId = document.all[psId];
	} else if (browser.ns4) {
		oId = document.layers[psId];
	}
	return oId;
}
var a_close = Array();
function fnToggleAll(psId) {
	for (i = 0; i < a_close.length; i++) {
		fnToggleOff(a_close[i]);
	}
	fnToggleOn(psId);
}

function fnToggleOn(psId) {
	var oId = fnGetElement(psId);
	oId.style.display = 'block';
}

function fnToggleOff(psId) {
	var oId = fnGetElement(psId);
	oId.style.display = 'none';
}

function fnToggleState(psId) {
	var oID = fnGetElement(psId);
	if (oID.style.display == 'none') {
		return 'hidden';
	} else if (oID.style.display == 'block') {
		return 'visible';
	} else {
		return 'unknown';
	}
}

function fnToggle(psEl) {
	if (fnToggleState(psEl) == 'hidden') {
		fnToggleOn(psEl);
	} else {
		fnToggleOff(psEl);
	}
}

function fnHideHidden() {
	var oEl = document.getElementsByTagName("INPUT");
	
	var el = null;
	for(var i = 0; i < oEl.length; i++) {
		el = oEl[i];
		if (el.type.toLowerCase() == 'hidden') {
			el.style.visibility = 'hidden';
			el.style.display = 'none';
		}
	}	
}

function fnToggleText(poEl, psEl) {
	if (fnToggleState(psEl) == 'hidden') {
		poEl.innerHTML = 'customize';
	} else {
		poEl.innerHTML = 'close';
	}
}

var goOldClass = null;
function fnChangeClass(poEl, psClassName) {
	if (goOldClass != null) {
		goOldClass.className = '';
	}	
	poEl.className = psClassName;
	goOldClass = poEl;				
}

function isNum(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

var gOldContent = null;
function fnLoadContent(psNewContent) {
	if (gOldContent != null) {
		fnToggleOff(gOldContent);
	}
	oEl = $(psNewContent);
	fnToggleOn(oEl);
	
	gOldContent = oEl;
}

function introduction() {
	
	$('introduction').style.display = 'none';
	cookie.setCookie('introduction', 'true', 60*60*24*364);
	
}

function addselectoption(selectbox, value, text) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

var iphone = false;
var g_imgwidth_vert = 500;
var g_imgwidth_hori = 800;
var g_orientation = 'vert';
var g_faded = 0;
var previous_link = '';

function clickThumb(p_id, po_link, ps_orientation) {
	slideStartStop('stop');
	changeImage(p_id, po_link, ps_orientation);
}
function clickImage() {
	slideStartStop('stop');
	slideChangeImage();
}

function changeImage(p_id, po_link, ps_orientation) {
	if (ps_orientation == 'vert') {
		g_orientation = 'vert';
		updateWidth();
		updateShadow();
	} else {
		g_orientation = 'hori';
		updateWidth();
		updateShadow();
	}
	
	$('photo').src = preloadImage[p_id].src;
	
	if (previous_link == '') {
		previous_link = $('thumb_0');
	}
	previous_link.className = '';
	po_link.className = 'on';
	
	previous_link = po_link;
	
	slidePlace = p_id;
}

function updateWidth() {
	$('photo').width = eval("g_imgwidth_" + g_orientation);
}
function updateShadow() {
	$('shadow').src = '/images/shadow-' + g_orientation + '.gif';
	$('shadow').width = $('photo').width;
}


var g_viewportwidth;
var g_viewportheight;

function getViewPort() {
	if (typeof window.innerWidth != 'undefined') {
		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		g_viewportwidth = window.innerWidth,
		g_viewportheight = window.innerHeight
	} else if (
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		typeof document.documentElement != 'undefined' 
		&& typeof document.documentElement.clientWidth != 'undefined' 
		&& document.documentElement.clientWidth != 0) {
			g_viewportwidth = document.documentElement.clientWidth,
			g_viewportheight = document.documentElement.clientHeight
	} else {
		// older versions of IE
		g_viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		g_viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
}


function resizeImages(ps_orientation) {
	
	if (ps_orientation) {
		g_orientation = ps_orientation;
	}
	
	if (iphone == true) {
		g_imgwidth_hori = 940;
		g_imgwidth_vert = 700;	
	} else {
		getViewPort();
		//alert(g_viewportwidth);
		if (g_viewportwidth <= 1100) {
			g_imgwidth_hori = 600;
			g_imgwidth_vert = 400;
		} else if (g_viewportwidth > 1100 && g_viewportwidth <= 1500) {
			g_imgwidth_hori = 800;
			g_imgwidth_vert = 500;
		} else {
			g_imgwidth_hori = 1200;
			g_imgwidth_vert = 900;
		}
	}
	updateWidth();
	updateShadow();
}

function setPlayImage() {
	$('playpause').src = '/images/ico-play.gif';
}
function setPauseImage() {
	$('playpause').src = '/images/ico-pause.gif';	
}


var slideTimer = 0;
var slidePlace = 0;
var slideMax = 0;
var slideRun = 1;
var slideSpeed = 6; //seconds

function slideStartStop(ps_stop) {
	
	if (ps_stop || slideRun == 1) {
		slideRun = 0;
		slideShowStop();
		setPlayImage();
	} else {
		slideRun = 1;
		slideChangeImage();
		setPauseImage();
	}
}
function slideShowStop() {
	clearTimeout(slideTimer);
}
function slideShowRun() {
	if (slideRun == 1) {
		slideTimer = setTimeout("slideChangeImage()", (slideSpeed * 1000));
	}
}

function slideChangeImage() {
	slidePlace = (slidePlace == slideMax)? 0 : slidePlace+1;
	changeImage(slidePlace, $('thumb_' + slidePlace), imagePrefs[slidePlace]['orientation']);
	slideShowRun();
}






