/*********************************************************

	This document contains [JavaScript] that is crucial for the
	PhotoVoice web-site to function.

*********************************************************/

function get_image(strImage) {
	var getCurrentImage = window.open('get_current_image.html?current=' + strImage, 'getCurrentImage', 'width=850, height=650, status=yes, scrollbars=yes, resizable=yes'); 
}

function build_controls(strSource, strValid) {
	var strLanguage = '';
		
	if (document.getElementById) {
		strLanguage = document.getElementById('hhdnControl').getAttribute('value');
		if (strLanguage == null) {
			strLanguage = '';
		}
		delay_image();			
		if ((strLanguage != '') && (strLanguage == 'spanish')) {		//Build all controls using [Spanish].
			if (strValid == '0') {
				document.getElementById('himgLogo').src = 'Images/pv_logo2.gif'; 
			} else {
				document.getElementById('himgLogo').src = '../Images/pv_logo2.gif'; 
			}
			if (document.getElementById('hdivEnglishHead')) {
				document.getElementById('hdivEnglishHead').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishHead')) {
				document.getElementById('hdivSpanishHead').style.display = 'block';
			}
			if (document.getElementById('hdivEnglishULinks')) {
				document.getElementById('hdivEnglishULinks').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishULinks')) {
				document.getElementById('hdivSpanishULinks').style.display = 'block';
			}
			if (document.getElementById('hdivEnglishLinks')) {
				document.getElementById('hdivEnglishLinks').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishLinks')) {
				document.getElementById('hdivSpanishLinks').style.display = 'block';
			}
			if (document.getElementById('hdivEnglishBLinks')) {
				document.getElementById('hdivEnglishBLinks').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishBLinks')) {
				document.getElementById('hdivSpanishBLinks').style.display = 'block';
			}
			if (document.getElementById('hdivEnglishContent')) {
				document.getElementById('hdivEnglishContent').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishContent')) {
				document.getElementById('hdivSpanishContent').style.display = 'block';
			}
			if (document.getElementById('hdivEnglishStake')) {
				document.getElementById('hdivEnglishStake').style.display = 'none';
			}
			if (document.getElementById('hdivSpanishStake')) {
				document.getElementById('hdivSpanishStake').style.display = 'block';
			}
			switch (strSource) {
				case 'home':
					document.title = 'Clarendon/Portsmouth FotoVoz Project';
					if (document.getElementById('hdivSpanishHome')) {
						document.getElementById('hdivSpanishHome').style.display = 'block';
					}
					if (document.getElementById('hdivEnglishHome')) {
						document.getElementById('hdivEnglishHome').style.display = 'none';
					}
					break;                     
				case 'photo':
					document.title = 'FotoVoz Photos';
					break;	
				case 'map':
					document.title = 'FotoVoz Maps';
					break;	
				case 'report':
					document.title = 'FotoVoz Report';
					break;	
				case 'about':
					document.title = 'About Us';
					break;		
				case 'contact':
					document.title = 'Contact Us';
					break;	
				case 'slide':
					document.title = 'FotoVoz Slide Show';	
					if (document.getElementById('hdivSpanishSlide')) {
						document.getElementById('hdivSpanishSlide').style.display = 'block';
					}
					if (document.getElementById('hdivEnglishSlide')) {
						document.getElementById('hdivEnglishSlide').style.display = 'none';
					}
					setSlideControl();
					setContentSlide();
					ap(' Stop ');
					first();
					break;
			}

		} else {				//Build all controls using [English].
			if (strValid == '0') {
				document.getElementById('himgLogo').src = 'Images/pv_logo1.gif'; 
			} else {
				document.getElementById('himgLogo').src = '../Images/pv_logo1.gif'; 
			}			
			if (document.getElementById('hdivEnglishHead')) {
				document.getElementById('hdivEnglishHead').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishHead')) {
				document.getElementById('hdivSpanishHead').style.display = 'none';
			}
			if (document.getElementById('hdivEnglishULinks')) {
				document.getElementById('hdivEnglishULinks').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishULinks')) {
				document.getElementById('hdivSpanishULinks').style.display = 'none';
			}
			if (document.getElementById('hdivEnglishLinks')) {
				document.getElementById('hdivEnglishLinks').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishLinks')) {
				document.getElementById('hdivSpanishLinks').style.display = 'none';
			}
			if (document.getElementById('hdivEnglishBLinks')) {
				document.getElementById('hdivEnglishBLinks').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishBLinks')) {
				document.getElementById('hdivSpanishBLinks').style.display = 'none';
			}
			if (document.getElementById('hdivEnglishContent')) {
				document.getElementById('hdivEnglishContent').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishContent')) {
				document.getElementById('hdivSpanishContent').style.display = 'none';
			}
			if (document.getElementById('hdivEnglishStake')) {
				document.getElementById('hdivEnglishStake').style.display = 'block';
			}
			if (document.getElementById('hdivSpanishStake')) {
				document.getElementById('hdivSpanishStake').style.display = 'none';
			}
			switch (strSource) {
				case 'home':
					document.title = 'Clarendon/Portsmouth PhotoVoice Project';
					if (document.getElementById('hdivEnglishHome')) {
						document.getElementById('hdivEnglishHome').style.display = 'block';
					}
					if (document.getElementById('hdivSpanishHome')) {
						document.getElementById('hdivSpanishHome').style.display = 'none';
					}
					break;                     
				case 'photo':
					document.title = 'PhotoVoice Photos';
					break;	
				case 'map':
					document.title = 'PhotoVoice Maps';
					break;	
				case 'report':
					document.title = 'PhotoVoice Report';
					break;	
				case 'about':
					document.title = 'About Us';
					break;		
				case 'contact':
					document.title = 'Contact Us';
					break;	
				case 'slide':
					document.title = 'PhotoVoice Slide Show';	
					if (document.getElementById('hdivEnglishSlide')) {
						document.getElementById('hdivEnglishSlide').style.display = 'block';
					}
					if (document.getElementById('hdivSpanishSlide')) {
						document.getElementById('hdivSpanishSlide').style.display = 'none';
					}
					setSlideControl();
					setContentSlide();
					ap(' Stop ');
					first();
					break; 
			}
		}
	}
}

function goto_page(strSender, strValid) {
	var strLanguage = '';
		
	if (document.getElementById) {
		strLanguage = document.getElementById('hhdnControl').getAttribute('value');        
	}
	if ((strLanguage == null) || (strLanguage == '')) {
		strLanguage = 'english';
	} 
	switch (strSender) {
		case 'home':
			if (strValid == '0') {
				window.location.href = 'index.html?lang=' + strLanguage;
			} else {
				window.location.href = '../index.html?lang=' + strLanguage;
			}
			break;                     
		case 'photo':
			if (strValid == '0') {
				window.location.href = 'Basepages/photo.html?lang=' + strLanguage;
			} else {
				window.location.href = 'photo.html?lang=' + strLanguage;
			}
			break;	
		case 'map':
			if (strValid == '0') {
				window.location.href = 'Basepages/map.html?lang=' + strLanguage;
			} else {
				window.location.href = 'map.html?lang=' + strLanguage;
			}
			break;	
		case 'report':
			if (strValid == '0') {
				window.location.href = 'Basepages/report.html?lang=' + strLanguage;
			} else {
				window.location.href = 'report.html?lang=' + strLanguage;
			}
			break;	
		case 'about':
			if (strValid == '0') {
				window.location.href = 'Basepages/about.html?lang=' + strLanguage;
			} else {
				window.location.href = 'about.html?lang=' + strLanguage;
			}
			break;		
		case 'contact':
			if (strValid == '0') {
				window.location.href = 'Basepages/contact.html?lang=' + strLanguage;
			} else {
				window.location.href = 'contact.html?lang=' + strLanguage;
			}
			break;	
		case 'slide':
			if (strValid == '0') {
				window.location.href = 'Basepages/slide_main.html?lang=' + strLanguage;
			} else {
				window.location.href = 'slide_main.html?lang=' + strLanguage;
			}		
			break;
	}
}

function setPageLanguage(strSource, strValid) {
	var strLanguage = '';		
	var cboLanguage;
	var i;
			
	strLanguage = get_lang();
	strLanguage = strLanguage.trim();
	if (strLanguage == null) {
		strLanguage = '';
	} 	
	if (strLanguage != '') {
		if (document.getElementById) {
			document.getElementById('hhdnControl').setAttribute('value', strLanguage);	
			cboLanguage = document.getElementById('hcboLang');
			for (i = 0; i < cboLanguage.length; i++) {	
				if (cboLanguage.options[i].value == strLanguage) {					    
					cboLanguage.selectedIndex = i;		 								
				}	
			}
		}	
	}
	build_controls(strSource, strValid);
}
		
function setControlLang(strSource, strValid) {
	var strLanguage = '';
	var cboLanguage;

	if (document.getElementById) {
		cboLanguage = document.getElementById('hcboLang');
		strLanguage = getComboValue(cboLanguage);
		document.getElementById('hhdnControl').setAttribute('value', strLanguage);       
	}
	build_controls(strSource, strValid);
}
		
function get_arguments() {
	var args;
	var query;
	var pairs;
	var argName;
	var argValue;
	var position;
	var i;
    
	args = new Object();
	query = window.location.search.substring(1);
	pairs = query.split('&');  
	for (i = 0; i < pairs.length; i++) {
		position = pairs[i].indexOf('=');
		if (position == -1) {
			continue;
		}
		argName = pairs[i].substring(0, position);
		argValue = pairs[i].substring(position + 1);
		args[argName] = unescape(argValue);
	}
	return args;
}

function get_lang() {
	var args;
	var argValue = '';
    
	args = get_arguments();
	if (args.lang) {
		argValue = args.lang.toString();
	}
	return argValue;
}
		
function getComboValue(cboCombo) {
	var returnValue;
	var i;

	for (i = 0; i < cboCombo.length; i++) {		
		if (cboCombo.selectedIndex == i) {						    
			returnValue = cboCombo.options[i].value;	 								
		}
	}
	return returnValue;       	    
} 

function delay_image() {
    if (document.getElementById) {
        document.getElementById('himgLogo').style.visibility = 'hidden';    
    }
    setTimeout('show_image()', 200);
}
		
function show_image() { 
    if (document.getElementById) {
        document.getElementById('himgLogo').style.visibility = 'visible';    
    }
} 
			
String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, '');		//Custom [trim] function used to trim input values from other functions.
}	
		
		
		
		
		
