var oldHTML = "";

function hideText( id ) {
	grabElement( id ).value = "";
	grabElement( id )
}

function initBoxes() {
	initHiddenText( grabElement( "searchReports" ), "Search our reports" );
	initHiddenText( grabElement( "userName" ), "User Name" );
	initHiddenPassword( grabElement( "passwordtext" ), "Password" );
}

function swapFlashMovie( name ) {
	var MyObjRewrite = new ObjectRewrite('/mkt/home/flash/'+name+'Banner.swf', 961, 265, 7);
	MyObjRewrite.prepForFlash();
	oldHTML = grabElement( "slider2" ).innerHTML;
	grabElement( "slider2" ).innerHTML = MyObjRewrite.getHTML();
}

function restoreMainBanner() {
	if( oldHTML != "" ) {
		grabElement( "slider2" ).innerHTML = oldHTML;
	}
}

function initHiddenPassword( obj, value ) {

	if (obj == null) {
		return;
	}
	
	obj.value = value;
        obj.readonly=false;
}

function showPwd (obj) {

	if (obj == null) {
		return;
	}
	if( obj.value == "Password" ) {
		hideText( obj );
		try {
			obj.type = "password";
		}  catch (e) {
		var newElement = null;
		try {
newElement = document.createElement("<input class=\"text\" type=\"password\" id=\"password\" name=\"password\" value=\"\" onfocus=\"JavaScript:showPwd(this);\"  onblur=\"JavaScript:hidePwd(this);\" />");
		} catch (e) {}
		if (!newElement) {
			newElement = document.createElement("input");
		}
		obj.parentNode.replaceChild(newElement, obj);
		newElement.focus();
		newElement.select();
		}
	}
}
	
function hidePwd (obj) {

	if (obj == null) {
		return;
	}
	if( obj.value == "" ) 
	{
		try {
			obj.type = "text";
		}  catch (e) {
		var newElement = null;
		try {
newElement = document.createElement("<input class=\"text\" type=\"text\" id=\"password\" name=\"password\" value=\"Password\" onfocus=\"JavaScript:showPwd(this);\"  onblur=\"JavaScript:hidePwd(this);\" />");
		} catch (e) {}
		if (!newElement) {
			newElement = document.createElement("input");
		}
		obj.parentNode.replaceChild(newElement, obj);
		}	
	}
}

function initHiddenText( obj, value ) {

	if (obj == null) {
		return;
	}

	obj.value = value;

	obj.onfocus = function() {
		if( obj.value == value ) {
			hideText( this );
		}
	}

	obj.onblur = function() {
		if( obj.value == "" ) {
			obj.value = value;
		}
	}
        obj.readOnly=false;
}

function filter( form ) {

	if ( form.keywords.value == 'Search our reports' ) {
		form.keywords.value = '';
	} 
	
	return true;
}

windowObject.addLoadFunction( initBoxes );
