// JavaScript Document


/***********************************************
* Extra styling for mac to overwrite pc specific fontsizing..
**********************************************

var mac_css='assets/templates/smi/macstyles.css' // specify Mac css file here
var mactest=navigator.userAgent.indexOf("Mac")!=-1
if(mactest) {
	document.write('<link rel="stylesheet" type="text/css" href="'+ mac_css +'" />')
}
*/



function popUp(URL){
	var w=500;
	var h=600;
	leftPos = (screen.width) ? (screen.width-w)/2 : 0;
	topPos = (screen.height) ? (screen.height-h)/2 : 0;
	popup = window.open(URL,'GoogleMap','height='+h+',width='+w+',menubar=0,scrollbars,resizable=0, status=0,titlebar=0,toolbar=0,left='+leftPos+',top='+topPos+'');
	popup.focus();
}

// JavaScript Document
function setBackgroundImage (id, imageURL) {
  if (document.layers)
    document[id].background.src = imageURL == 'none' ? null : imageURL;
  else if (document.all)
    document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
  else if (document.getElementById)
    document.getElementById(id).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
}

function addEvent(elm, evType, fn, useCapture){
	if(elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}else if (elm.attachEvent){
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}else{
		elm['on' + evType] = fn;
	}
}

function getEvent()
{
	if(window.event) {
		return this.window.event;
	}else{
		return getEvent.caller.arguments[0];
	}
}
/*/////////////
	Set value of input fields which need labelling.
	the toLabel key relates to <key>field in the input id
	value is used as the placeholder for safari
	other browsers use a background image referenced <key>bglbl.gif
*/////////////
var toLabel = new Object();
toLabel['username'] = 'email address';
toLabel['password'] = 'password';
	
///functions for labelling

function toggleInputBG()
{
	var oEvent = getEvent();
	var oTarget = (oEvent.target || oEvent.srcElement);
	//alert(oTarget.id);
	if(oTarget.id){
		if(oEvent.type=="blur" && oTarget.value==''){
			for ( keyVar in toLabel ) {
				if( oTarget.id.indexOf(keyVar)==0){
					//found key to image
					setBackgroundImage (oTarget.name, 'assets/templates/smi/images/' + keyVar + '-bg.gif');
				}
			}
		
		}else if(oEvent.type=="focus" || oEvent.type=="keypress"){
			//alert(oTarget.id);
			setBackgroundImage (oTarget.name, 'none');
		}
	}
}

function setInputs()
{
	// Label all the input text fields with background image
	for ( keyVar in toLabel ) {
		var tt_input = document.getElementById(keyVar);
		if(tt_input){
			addEvent(tt_input, 'focus', toggleInputBG, false);
			addEvent(tt_input, 'blur', toggleInputBG, false);
			addEvent(tt_input, 'keypress', toggleInputBG, false);
			
			//tt_input.setAttribute("placeholder", toLabel[keyVar]);
			
			if(tt_input.value == '') {
				setBackgroundImage (keyVar, 'assets/templates/smi/images/' + keyVar + '-bg.gif');
			}else{
				setBackgroundImage (keyVar, 'none');
			}
		}
	}
}
addEvent(window, 'load', setInputs, false);

