/* 
JavaScript Document For Simple Cover

Author : Adam Collison [adam.collison@soup.co.uk]
Client : Norwich Union
Project : Simple Cover

Last Modified : 10-04-2006

*/

function roll_over(id, flag, png_span)
{
	var element;

	if (typeof(id) == 'string')
	{
		element = document.getElementById(id);
	}
	else
	{
		element = id;	
	}

	var source = element.src;

	// get the extension of the file so we can deal with all types

	var extension = source.substr(source.length - 3, 3);

	// add in the _f2 to the filename

	if (flag)
	{
		source = source.substr(0, source.length - 4) + '_f2.' + extension;
	}
	else
	{
		source = source.substr(0, source.length - 7) + '.' + extension;
	}

	element.src = source;
	
	if (png_span != null)
	{
		document.getElementById(png_span).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + source + "')";
	}
}

function getPosition(e){
    var r=new Array(0,0);
    while(e){
        r[0]+=e.offsetLeft;
        r[1]+=e.offsetTop;
        e=e.offsetParent;
    }
    return r;
}

function form_functions(hide_elements) {
		do_hide(hide_elements);
}


// this function is called on load to hide all of our micro help divs and text links.
function do_hide(hide_elements) {
	// get user agent used if safari or opera is present.
	//detect = navigator.userAgent.toLowerCase();
	// check to see if its opera
	//if(detect.indexOf('opera') +1) return;

	for(h=0; h<hide_elements.length; h++) {
		var hide_id = hide_elements[h];
		document.getElementById(hide_id).className = "hide";
	}
}

function show_help(form_id,help_id) {
	
	// get user agent used if safari or opera is present.
	detect = navigator.userAgent.toLowerCase();
	// check to see if its opera then turn iframe off!
	if(detect.indexOf('opera') +1) {
		var i_frames=document.getElementsByTagName("iframe");
			for(x=0; x<i_frames.length; x++) {
				i_frames[x].style.display="none";
			}
	}
	
	// hide all other elements that may be showing
	do_hide(hide_elements);
	
	var coords=getPosition( document.getElementById(form_id) );
	var helpElement=document.getElementById(help_id);
	helpElement.className="help_visable";
	
	// alter position for safari
	if(detect.indexOf('safari') +1) coords[1] = coords[1] + 200;
	
	// set position
	helpElement.style.top=coords[1]+'px';
	
	// toggle correct links to show
	var innerLinks = helpElement.getElementsByTagName("a");
	innerLinks[0].className = "help_link";
	innerLinks[0].focus();
	innerLinks[1].className = "hide";
}