

var WFIE = {}; //WFIE = WireFrame Inside Edition.

WFIE.SpecialReport = {}; //Special Report Pages.

WFIE.SpecialReport.deleteGridItem = function( tag )
{
	var hidden = tag.parentNode.getElementsByTagName( "INPUT" )[ 0 ];
	hidden.value = "false";
	
	var row = tag.parentNode.parentNode;
	row.style.display = "none";
	
	var txt = row.cells[ 3 ].getElementsByTagName( "INPUT" )[ 0 ];
	txt.value = "";
	txt.setAttribute( "currentvalue", "" );
	
	return false;
}

WFIE.SpecialReport.updateOrder = function( tag )
{
	var txt, lastValue, table = tag.parentNode.parentNode.parentNode;
	tag.value = WFIE.trim( tag.value );
	
	if( tag.value.length > 0 )
	{
		var value = "";
		for( var i = 0; i < tag.value.length; i++ )
		{
			for( var j = 0; j <= 9; j++ )
			{
				if( tag.value.charAt( i ) == j.toString( ) )
				{
					value += j.toString( );
					break;
				}
			}
		}
		lastValue = tag.getAttribute( "currentvalue" );
		tag.value = value;
		tag.setAttribute( "currentvalue", value );
		
		for( var i = 1; i < table.rows.length; i++ )
		{
			txt = table.rows[ i ].cells[ 3 ].getElementsByTagName( "INPUT" )[ 0 ];
			if( txt != tag && tag.value == txt.value )
			{
				txt.value = lastValue;
				txt.setAttribute( "currentvalue", lastValue );
			}
		}
	}
}

WFIE.Poll = {}; //Poll Pages.

WFIE.Poll.initialize = function( )
{
	WFIE.Poll.tblAnswers = document.getElementById( "tblAnswers" );
	WFIE.Poll.hidAnswersLength = document.getElementById( "hidAnswersLength" );
	WFIE.Poll.lnkAddAnswer = document.getElementById( "lnkAddAnswer" );
	
	WFIE.Poll.disableCheckbox( 0 );
	WFIE.Poll.disableCheckbox( 1 );
}

WFIE.attachSubwindow = function( tag, url, height, scrollbars )
{
	tag = document.getElementById( tag );
	if( tag )
	{
		tag.onclick = function( )
		{
			var halfWidth = screen.availWidth / 2, halfHeight = screen.availHeight / 2;
			var left = halfWidth - 425, top = halfHeight - ( height / 2 );
			
			window.open( url, "", "resizable=no,scrollbars=" + scrollbars + ",width=780,height=" + height + ",top=" + top + ",left=" + left );
			return false;
		}
	}
}

WFIE.Poll.vote = function( tag )
{
	var inputs = document.getElementsByName( "Answer" );
	for( var i = 0; i < inputs.length; i++ )
	{
		if( inputs[ i ].checked == true )
		{
			return true;
		}
	}
	
	alert( "Please select an answer." );
	return false;
}

WFIE.Poll.addAnswer = function( )
{
	var table = WFIE.Poll.tblAnswers;
	var row;
	
	for( var i = 0; i < table.rows.length; i++ )
	{
		if( table.rows[ i ].style.display == "none" )
		{
			row = table.rows[ i ];
			break;
		}
	}
	
	if( row == null )
	{
		alert( "You have already entered the maximum of answers allowed." );
	}
	else
	{
		var hidden = WFIE.Poll.hidAnswersLength;
		hidden.value = parseInt( hidden.value ) + 1;
		row.style.display = "";
		WFIE.Poll.clearContent( row );
		
		if( row.rowIndex < 2 )
		{
			WFIE.Poll.disableCheckbox( row.rowIndex );
		}
	}
}

WFIE.Poll.deleteAnswer = function( tag )
{
	while( tag.tagName.toUpperCase( ) != "TABLE" )
	{
		tag = tag.parentNode;
	}
	
	var hidden = WFIE.Poll.hidAnswersLength;
	var table = WFIE.Poll.tblAnswers;
	var fromIndex = tag.parentNode.parentNode.rowIndex;
	
	tag.parentNode.parentNode.style.display = "none";
	hidden.value = parseInt( hidden.value ) - 1;
	
	table.tBodies[ 0 ].appendChild( table.rows[ fromIndex ] );
	WFIE.Poll.updateAnswerText( );
}

WFIE.Poll.disableCheckbox = function( index )
{
	var table = WFIE.Poll.tblAnswers;
	if( table.rows.length - 1 > index )
	{
		var input = table.rows[ index ].cells[ 0 ].getElementsByTagName( "TABLE" )[ 0 ].rows[ 0 ].cells[ 0 ].getElementsByTagName( "INPUT" )[ 0 ];
		input.checked = true;
		input.disabled = true;
	}
}

WFIE.Poll.clearContent = function( row )
{
	var nodes = row.cells[ 0 ].getElementsByTagName( "INPUT" );
	var img = row.cells[ 0 ].getElementsByTagName( "IMG" );
	
	if( img.length > 0 )
	{
		img.parentNode.removeChild( img );
	}
	
	for( var i = 0; i < nodes.length; i++ )
	{
		if( nodes[ i ].type.toUpperCase( ) == "CHECKBOX" )
		{
			nodes[ i ].checked = false;
		}
		else
		{
			nodes[ i ].value = "";
		}
	}
}

WFIE.Poll.updateAnswerText = function( )
{
	var table = WFIE.Poll.tblAnswers;
	for( var i = 0; i < table.rows.length; i++ )
	{
		var span = table.rows[ i ].cells[ 0 ].getElementsByTagName( "TABLE" )[ 0 ].rows[ 0 ].cells[ 0 ].getElementsByTagName( "SPAN" )[ 0 ];
		span.innerHTML = "Answer " + ( i + 1 );
	}
}

WFIE.Poll.updateNames = function( )
{
	var table = WFIE.Poll.tblAnswers;
	for( var i = 0; i < table.rows.length; i++ )
	{
		var nodes = table.rows[ i ].cells[ 0 ].getElementsByTagName( "INPUT" );
		for( var j = 0; j < nodes.length; j++ )
		{
			var start = nodes[ j ].name.indexOf( ":" );
			var end = nodes[ j ].name.lastIndexOf( ":" );
			var sub = nodes[ j ].name.substring( start, end );
			var name = nodes[ j ].name.replace( sub, ":_ctl" + i );
			nodes[ j ].name = name;
		}
	}
}

WFIE.EmailThis = {}; //Email Popups.

WFIE.EmailThis.validate = function( )
{
	var to = document.getElementById( "emailto" );
	var from = document.getElementById( "emailfrom" );
	var message = document.getElementById( "message" );
	var objRegExp = /(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z0-9]{3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)(\.[a-z0-9]{3})(\.[a-z0-9]{2})*$)/i;
	
	if( !objRegExp.test( to.value ) )
	{
		alert( "The recipient's e-mail address is not valid." );
		return false;
	}
	
	if( !objRegExp.test( from.value ) )
	{
		alert( "Your e-mail address is not valid." );
		return false;
	}
	
	return true;
}

WFIE.APContent = {}; //APContent Page.

WFIE.APContent.validateSave = function( radioID, fileID, urlID, imageID )
{
	var radio = document.getElementById( radioID );
	if( radio.checked == true )
	{
		var label = document.getElementById( "lblValidator" );
		var fileInput = document.getElementById( fileID );
		var urlInput = document.getElementById( urlID );
		var imageInput = document.getElementById( imageID );
		label.className = "spanvalidator_valid";
		
		if( ( WFIE.trim( fileInput.value ).length < 1 && WFIE.trim( imageInput.value ).length < 1 ) || WFIE.trim( urlInput.value ).length < 1 )
		{
			label.className = "spanvalidator_invalid";
			return false;
		}
	}
	
	return true;
}

WFIE.APContent.centerContent = function( )
{
	var header = document.getElementById( "apvideo_container_header" );
	var container = document.getElementById( "apvideo_container" );
	var ap = document.getElementById( "apvideo" );
	
	container.style.height = ( ap.offsetHeight + 20 ) + "px";
	container.style.width = ( ap.offsetWidth + 20 ) + "px";
	
	ap.style.left = ( container.offsetLeft + 10 ) + "px";
	ap.style.top = ( container.offsetTop + 10 ) + "px";
	
	header.style.width = container.offsetWidth + "px";
}

WFIE.MostEmailedStories = {} //Most Emailed Stories Page.

WFIE.MostEmailedStories.validate = function( )
{
	var isValid = true;
	
	for( var i = 1; i < 6; i++ )
	{
		var radio = document.getElementById( "optURL" + i );
		var span = document.getElementById( "valStory" + i );
		span.className = "spanvalidator_valid";
		
		if( radio.checked )
		{
			var caption = document.getElementById( "txtCaption" + i );
			var url = document.getElementById( "txtURL" + i );
			
			if( WFIE.trim( caption.value ).length < 1 || WFIE.trim( url.value ).length < 1 )
			{
				isValid = false;
				span.className = "spanvalidator_invalid";
			}
		}
	}
	
	return isValid;
}

WFIE.Newswire = {}; //newsletter.aspx.

WFIE.Newswire.validate = function( )
{
	var tag;
	
	tag = document.getElementById( "firstnamebox" );
	if( WFIE.trim( tag.value ).length < 1 )
	{
		alert( "Please provide your First Name." );
		return false;
	}
	
	tag = document.getElementById( "lastnamebox" );
	if( WFIE.trim( tag.value ).length < 1 )
	{
		alert( "Please provide your Last Name." );
		return false;
	}
	
	tag = document.getElementById( "citybox" );
	if( WFIE.trim( tag.value ).length < 1 )
	{
		alert( "Please provide your City Name." );
		return false;
	}
	
	tag = document.getElementById( "zipbox" );
	if( WFIE.trim( tag.value ).length < 1 )
	{
		alert( "Please provide your Zipcode." );
		return false;
	}
	
	tag = document.getElementById( "emailbox" );
	var objRegExp = /(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z0-9]{3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)(\.[a-z0-9]{3})(\.[a-z0-9]{2})*$)/i;
	var valid = objRegExp.test(tag.value);
	if( !valid )
	{
		alert( "Please provide a valid Email Address." );
		return false;
	}
	
	var month;
    var day;
    var year;
    month = document.getElementById( "dobmonthbox" ).value;
    day = document.getElementById( "dobdaybox" ).value;
    year = document.getElementById( "dobyearbox" ).value;
       

    if(document.implementation.createDocument)
    {
        if(month!="Month" && day!="Day" && year!="Year" )
        {
    	    var min_age = 13;
    	    month= parseInt(month);
    	    day= parseInt(day);
    	    year = parseInt(year);
            
            var theirDate = new Date((year + min_age), month, day);   
	        var today = new Date;
     	    
	        if ( (today.getTime() - theirDate.getTime()) < 0) 
	            {
		            alert( "User should be above 13 to use newsletter subscribtion." );
		            return false;
	            }
        }
        else
        {
            alert( "Please select proper date of birth." );
		    return false;
        }
    }
    else
    {
        if(month!="" && day!="" && year!="" )
        {
    	    var min_age = 13;
    	    month= parseInt(month);
    	    day= parseInt(day);
    	    year = parseInt(year);
            
            var theirDate = new Date((year + min_age), month, day);   
	        var today = new Date;
     	    
	        if ( (today.getTime() - theirDate.getTime()) < 0) 
	            {
		            alert( "User should be above 13 to use newsletter subscribtion." );
		            return false;
	            }
        }
        else
        {
            alert( "Please select proper date of birth." );
		    return false;
        }
    }
    
	tag = document.getElementById( "agecheck" );
	if( !tag.checked )
	{
		alert( "Please agree to Terms and Condition to proceed." );
		return false;
	}
	
	tag = document.getElementById( "hidRegister" );
	tag.value = "YES";
	return true;
}

WFIE.FeaturedScrollers = {};//Featured Scrollers Page.

WFIE.FeaturedScrollers.isValidHideShow = function( )
{
	var inputs, tag, grid = document.getElementById( "tblFeatures" );
	
	for( var i = 0; i < grid.rows.length; i++ )
	{
		inputs = grid.rows[ i ].getElementsByTagName( "input" );
		for( var j = 0; j < inputs.length; j++ )
		{
			tag = inputs[ j ];
			if( tag.type.toUpperCase( ) == "CHECKBOX" && tag.checked )
			{
				return true;
			}
		}
	}
	
	alert( "Please select at least one Feature." );
	return false;
}

WFIE.SubmitStory = {}; //Submit Your Story Page.

WFIE.SubmitStory.loadFields = function( )
{
	WFIE.SubmitStory.fields =
	{
		firstName: { tag: document.getElementById( "firstname" ), required: true, message: "First Name" },
		lastName: { tag: document.getElementById( "lastname" ), required: true, message: "Last Name" },
		month: { tag: document.getElementById( "month" ), required: true, message: "Age - month" },
		day: { tag: document.getElementById( "day" ), required: true, message: "Age - day" },
		year: { tag: document.getElementById( "year" ), required: true, message: "Age - year" },
		email: { tag: document.getElementById( "email" ), required: true, message: "Email Address" },
		street1: { tag: document.getElementById( "address" ), required: true, message: "Street Address" },
		street2: { tag: document.getElementById( "address2" ), required: false, message: "Street Address 2" },
		city: { tag: document.getElementById( "city" ), required: true, message: "City" },
		state: { tag: document.getElementById( "state" ), required: true, message: "State" },
		province: { tag: document.getElementById( "province" ), required: false, message: "Province/Region" },
		zip: { tag: document.getElementById( "zip" ), required: false, message: "Zip Code", isNumeric: true },
		country: { tag: document.getElementById( "country" ), required: true, message: "Country" },
		dayArea: { tag: document.getElementById( "dayarea" ), required: true, message: "Daytime Phone - area code", minLength: 3, isNumeric: true, group: "Daytime" },
		dayPrefix: { tag: document.getElementById( "dayprefix" ), required: true, message: "Daytime Phone - 3 first digits", minLength: 3, isNumeric: true, group: "Daytime" },
		dayNumber: { tag: document.getElementById( "daynumber" ), required: true, message: "Daytime Phone - 4 last digits", minLength: 4, isNumeric: true, group: "Daytime" },
		eveArea: { tag: document.getElementById( "evearea" ), message: "Evening Phone - area code", minLength: 3, isNumeric: true, group: "Evening" },
		evePrefix: { tag: document.getElementById( "eveprefix" ), message: "Evening Phone - 3 first digits", minLength: 3, isNumeric: true, group: "Evening" },
		eveNumber: { tag: document.getElementById( "evenumber" ), message: "Evening Phone - 4 last digits", minLength: 4, isNumeric: true, group: "Evening" },
		cellArea: { tag: document.getElementById( "cellarea" ), message: "Cell Phone - area code", minLength: 3, isNumeric: true, group: "Cellphone" },
		cellPrefix: { tag: document.getElementById( "cellprefix" ), message: "Cell Phone - 3 first digits", minLength: 3, isNumeric: true, group: "Cellphone" },
		cellNumber: { tag: document.getElementById( "cellnumber" ), message: "Cell Phone - 4 last digits", minLength: 4, isNumeric: true, group: "Cellphone" },
		//altArea: { tag: document.getElementById( "altarea" ), message: "Alternate Phone - area code", minLength: 3, isNumeric: true, group: "Alternate Contact" },
		//altPrefix: { tag: document.getElementById( "altprefix" ), message: "Alternate Contact Phone - 3 first digits", minLength: 3, isNumeric: true, group: "Alternate Contact" },
		//altNumber: { tag: document.getElementById( "altnumber" ), message: "Alternate Contact Phone - 4 last digits", minLength: 4, isNumeric: true, group: "Alternate Contact" },
		//alternate: { tag: document.getElementById( "alternate" ), required: false, message: "Alternate Contact", group: "Alternate Contact" },
		story: { tag: document.getElementById( "story" ), required: true, message: "Story" }
	};
	
	WFIE.SubmitStory.fields2 = 
	{
		terms_agree: document.getElementById( "terms_agree" ),
		submitButton: document.getElementById( "submitbutton" ),
		cancelButton: document.getElementById( "cancelbutton" )
	};
};

WFIE.SubmitStory.reset = function( )
{
	var tag, fields = WFIE.SubmitStory.fields;
	
	for( var prop in fields )
	{
		tag = fields[ prop ].tag;
		
		if( tag.tagName.toUpperCase( ) == "SELECT" )
		{
			tag.selectedIndex = 0;
		}
		else
		{
			tag.value = "";
		}
	}
}

WFIE.SubmitStory.validate = function( )
{
	if(WFIE.SubmitStory.fields2.terms_agree.checked) {
		if( WFIE.SubmitStory.validateRequireds( ) )
		{
			if( WFIE.SubmitStory.validateMinLength( ) )
			{
				if( WFIE.SubmitStory.validateNumerics( ) )
				{
					if( WFIE.SubmitStory.validateGroups( ) )
					{
						if( WFIE.SubmitStory.validateEmail( ) )
						{
							if( WFIE.SubmitStory.validateStory( ) )
							{
								if(WFIE.SubmitStory.validateAge( ) ) 
								{
									return true;
								}
							}
						}
					}
				}
			}
		}
	}
	return false;
};

WFIE.SubmitStory.validateStory = function( )
{
	var message = "Please provide a story text.", tag = WFIE.SubmitStory.fields.story.tag;
	var value = WFIE.trim( tag.value );
	tag.value = value;
	
	var valid = ( value.length > 2000 )? false: true;
	if( !valid )
	{
		alert( "Story must not exceed 2000 characters." );
	}
	
	return valid;
}

WFIE.SubmitStory.validateGroups = function( )
{
	var checked, field, valid = true, message = "Following information must be filled completely (not partially):\n";
	var fields = WFIE.SubmitStory.fields, invalidGroups = new Array( );
	
	for( var prop in fields )
	{
		field = fields[ prop ];
		if( field.group != null )
		{
			var check = true;
			for( var i = 0; i < invalidGroups.length; i++ )
			{
				if( invalidGroups[ i ] == field.group )
				{
					check = false;
					break;
				}
			}
			if( check )
			{
				var field2;
				for( var prop2 in fields )
				{
					field2 = fields[ prop2 ];
					if( field2 != field && field2.group == field.group )
					{
						var v1 = WFIE.trim( field.tag.value ).length, v2 = WFIE.trim( field2.tag.value ).length;
						if( ( v1 < 1 && v2 > 0 ) || ( v1 > 0 && v2 < 1 ) )
						{
							message += "-" + field.group + ".\n";
							invalidGroups[ invalidGroups.length ] = field.group;
							valid = false;
							break;
						}
					}
				}
			}
		}
	}
	
	if( !valid )
	{
		alert( message );
	}
	
	return valid;
}

WFIE.SubmitStory.validateNumerics = function( )
{
	var value, field, valid = true, message = "Following information must be numeric:\n", fields = WFIE.SubmitStory.fields;
	
	for( var prop in fields )
	{
		field = fields[ prop ];
		if( field.isNumeric != null )
		{
			value = WFIE.trim( field.tag.value );
			if( !field.tag.tagName.toUpperCase( ) == "SELECT" )
			{
				field.tag.value = value;
			}
			if( value.length > 0 && !WFIE.isNumeric( value ) )
			{
				message = message + " -" + field.message + ".\n";
				valid = false;
			}
		}
	}
	
	if( !valid )
	{
		alert( message );
	}
	
	return valid;
}

WFIE.SubmitStory.validateMinLength = function( )
{
	var value, field, valid = true, message = "Following information must match specified chars length:\n", fields = WFIE.SubmitStory.fields;
	
	for( var prop in fields )
	{
		field = fields[ prop ];
		if( field.minLength != null )
		{
			value = WFIE.trim( field.tag.value );
			if( !field.tag.tagName.toUpperCase( ) == "SELECT" )
			{
				field.tag.value = value;
			}
			if( value.length > 0 && value.length < field.minLength )
			{
				message = message + " -Field: '" + field.message + "', length: " + field.minLength + ".\n";
				valid = false;
			}
		}
	}
	
	if( !valid )
	{
		alert( message );
	}
	
	return valid;
}

WFIE.SubmitStory.validateEmail = function( )
{
	var valid = true, message = "Please provide a valid email address.", value = WFIE.SubmitStory.fields.email.tag.value;
	
	var objRegExp = /(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)([.][a-z0-9]{3})$)|(^[a-z0-9]([a-z0-9_\.]*)@([a-z0-9_\.]*)(\.[a-z0-9]{3})(\.[a-z0-9]{2})*$)/i;
	valid = objRegExp.test(value);
	
	if( !valid )
	{
		alert( "Please provide a valid email address." );
	}
	
	return valid;
}	

WFIE.SubmitStory.validateRequireds = function( )
{
	var value, field, valid = true, message = "The following information is required:\n", fields = WFIE.SubmitStory.fields;
	
	for( var prop in fields )
	{
		field = fields[ prop ];
		if( field.required === true )
		{
			value = WFIE.trim( field.tag.value );
			if( !field.tag.tagName.toUpperCase( ) == "SELECT" )
			{
				field.tag.value = value;
			}
			if( value.length < 1 )
			{
				message = message + " -" + field.message + ".\n";
				valid = false;
			}
		}
	}
	
	if( !valid )
	{
		alert( message );
	}
	
	return valid;
}

WFIE.SubmitStory.validateAge = function() {
	var cookie, age, valid = true;
	var message = "We're sorry, but you do not meet the eligibility requirements to register with this Site.";
	var fields = WFIE.SubmitStory.fields;

	cookie = WFIE.cookies.getCookie("underage");
	if(!cookie || cookie === "") {
		age = getAge(fields.year.tag.value, fields.month.tag.value - 1, fields.day.tag.value);
		if(age < 13) {
			WFIE.cookies.setCookie("underage", age, 1);
			valid = false;
		}
	}
	else {
		valid = false;
	}

	if( !valid )
	{
		alert( message );
	}
	return valid;
};
WFIE.SubmitStory.termsOnCheck = function() {
	var fields = WFIE.SubmitStory.fields2;
	if(fields.terms_agree.checked) 
	{
		fields.submitButton.src = "images/submit_submit.jpg";
		fields.submitButton.style.cursor = "pointer";
	}
	else
	{
		fields.submitButton.src = "images/submit_submit_disabled.gif";
		fields.submitButton.style.cursor = "default";
	}
};

WFIE.Search = {}; //Search Control.

WFIE.Search.search = function( )
{
	var txt = document.getElementById( "txtSearch" );
	if( !WFIE.isEmpty( txt ) )
	{
		document.location = "search.aspx?search=" + txt.value ;
	}
	
	return false;
}

WFIE.PhotoGallery = {}; //SearchResults Control.

WFIE.PhotoGallery.loadPhotoGallery = function()
{
	var child, details = document.getElementById( "divDetailsStatus" );
	for( var i = 0; i < details.childNodes.length; i++ )
	{
		child = details.childNodes[ i ];
		if( child.nodeType == 1 && child.id.indexOf("group-box-") == 0 )
		{
			WFIE.format( child, "p",15,1,6,30 );
		}
	}
	
	WFIE.PhotoGallery.currentPage = parseInt(document.getElementById("divDetailsStatus").getAttribute("currentpage"));
	WFIE.PhotoGallery.totalPages = parseInt(document.getElementById("divDetailsStatus").getAttribute("totalpages"));

	WFIE.PhotoGallery.photoGroups = document.getElementById("photogroups");
	WFIE.PhotoGallery.span = document.getElementById("pagination");
	WFIE.PhotoGallery.slideShowScript = document.getElementById("slideShowScript");
	WFIE.slideshow.currentphotoGalleryID = parseInt(document.getElementById("divDetailsStatus").getAttribute("currentphotogalleryid"));
	
	if(WFIE.slideshow.currentphotoGalleryID >0)
	{
		WFIE.PhotoGallery.currentDivGallery = document.getElementById( "group_box_" + WFIE.slideshow.currentphotoGalleryID );
		var source = document.getElementById( "view-" + WFIE.slideshow.currentphotoGalleryID );
		source.src = "/images/gallery_group_view_active.jpg";
		WFIE.PhotoGallery.currentImg = source;
	}
	
	
	WFIE.PhotoGallery.span.innerHTML = document.getElementById("divDetailsStatus").getAttribute("statusText");
	WFIE.slideshow.currentIndex = 1;
	WFIE.slideshow.prev();
}

WFIE.PhotoGallery.previousPage = function( )
{
	var current = WFIE.PhotoGallery.currentPage;
	
	if( current > 0 )
	{
		WFIE.PhotoGallery.currentPage = current - 1;
		WFIE.PhotoGallery.pagine( );
	}
}

WFIE.PhotoGallery.nextPage = function( )
{
	var current = WFIE.PhotoGallery.currentPage;
	var total = WFIE.PhotoGallery.totalPages;
	
	if( current < ( total - 1 ) )
	{
		WFIE.PhotoGallery.currentPage = current + 1;
		WFIE.PhotoGallery.pagine( );
	}
}

WFIE.PhotoGallery.displayPhotoGalleryItems = function(response)
{
	if( response != null )
	{
		WFIE.PhotoGallery.photoGroups.innerHTML = response.responseText;
	}
	
	var child, details = document.getElementById( "divDetailsStatus" );
	for( var i = 0; i < details.childNodes.length; i++ )
	{
		child = details.childNodes[ i ];
		if( child.nodeType == 1 && child.id.indexOf("group-box-") == 0 )
		{
			WFIE.format( child, "p",15,1,4,30 );
		}
	}
	
	var span = WFIE.PhotoGallery.span;
	var div = details;
	
	if( span && div )
	{
		span.innerHTML = div.getAttribute( "statustext" );
		WFIE.PhotoGallery.currentPage = parseInt(div.getAttribute( "currentpage" ));
		WFIE.PhotoGallery.totalPages = parseInt(div.getAttribute( "totalpages" ));
	}
}

WFIE.PhotoGallery.pagine = function( )
{
	var url = "CallbackManager.aspx?action=loadphotogallery";
	url += "&currentpage=" + WFIE.PhotoGallery.currentPage;
	url += "&itemsByPage=4";
	WFIE.callbackRequest( url, "GET", null, WFIE.PhotoGallery.displayPhotoGalleryItems );
}

WFIE.PhotoGallery.displaySlideShow = function( response )
{
	if( response != null )
	{
		var div = WFIE.PhotoGallery.slideShowScript;
		var script = div.getElementsByTagName( "script" )[ 0 ];
		
		if( document.all )
		{
			script.text = response.responseText;
		}
		else
		{
			script.text = eval( response.responseText );
		}
		
		WFIE.slideshow.currentIndex = 1;
		WFIE.slideshow.prev();
	}
}

WFIE.PhotoGallery.loadSlideShow = function(photoGalleryID)
{
	if( WFIE.slideshow.currentphotoGalleryID != photoGalleryID )
	{
		WFIE.slideshow.currentphotoGalleryID = photoGalleryID;
		var url = "CallbackManager.aspx?action=loadslideshow";
		url += "&photogalleryid=" + photoGalleryID;
		WFIE.callbackRequest( url, "GET", null, WFIE.PhotoGallery.displaySlideShow );
		
		WFIE.PhotoGallery.switchBackground( photoGalleryID );
	}
}

WFIE.PhotoGallery.switchBackground = function( photoGalleryID )
{
	if( WFIE.PhotoGallery.currentImg)
	{
		WFIE.PhotoGallery.currentImg.src = "/images/gallery_group_view.jpg";
	}
	if( WFIE.PhotoGallery.currentDivGallery )
	{
		WFIE.PhotoGallery.currentDivGallery.className = "groupbox";
	}
	
	var source = document.getElementById( "view-" + photoGalleryID );
	source.src = "/images/gallery_group_view_active.jpg";
	WFIE.PhotoGallery.currentImg = source;
	var div = document.getElementById( "group_box_" + photoGalleryID );
	div.className = "groupboxactive";
	WFIE.PhotoGallery.currentDivGallery = div;
}

WFIE.Listings = {};

WFIE.Listings.IsValidListing = function( )
{
	var tag, inputs = document.getElementById( "tblAddListing" ).rows[ 0 ].getElementsByTagName( "input" );
	for( var i = 0; i < inputs.length; i++ )
	{
		tag = inputs[ i ];
		if( tag.type.toUpperCase( ) == "TEXT" )
		{
			var value = WFIE.trim( tag.value );
			if( value.length < 1 )
			{
				alert( "All fields are required." );
				return false;
			}
		}
	}
	
	return true;
}

WFIE.Listings.IsValidState = function( link, comboId )
{
	var combo = document.getElementById( comboId );
	if( combo.selectedIndex > 0 )
	{
		return true;
	}
	else
	{
		alert( "Please select a state." );
		link.href = "";
		return false;
	}
}

WFIE.Video = {}; //Video Control.

WFIE.Video.loadCategories = function( categoryID )
{
	var div = document.getElementById( "videogroups" );
	var links = div.getElementsByTagName( "A" );
	var link, categoryIndex = 0;
	
	for( var i = 0; i < links.length; i++ )
	{
		link = links[ i ];
		link.link_images = link.parentNode.getElementsByTagName( "IMG" );
		
		if( link.getAttribute( "category" ).toUpperCase( ) == categoryID )
		{
			categoryIndex = i;
		}
	}
	
	WFIE.Video.divDetails = document.getElementById( "divDetails" );
	WFIE.Video.divStatus = document.getElementById( "videodisplaystatus" );
	WFIE.Video.divData = document.getElementById( "videosdata" );
	WFIE.Video.loadCategory( links[ categoryIndex ] );
	WFIE.Video.displayCategory( null );
	WFIE.format( "videosdata", "DIV", 15, 1, 12, 50 );//12 lines, 50 chars
}

WFIE.Video.loadCategory = function( link )
{
	if( link != WFIE.Video.activeGroup )
	{
		var active = WFIE.Video.activeGroup;
		if( active )
		{
			active.link_images[ 0 ].style.visibility = 'visible';
			active.link_images[ 1 ].style.visibility = 'hidden';
			active.link_images[ 2 ].style.visibility = 'hidden';
			WFIE.Video.pagine( link );
		}
		
		link.link_images[ 0 ].style.visibility = 'hidden';
		link.link_images[ 1 ].style.visibility = 'visible';
		link.link_images[ 2 ].style.visibility = 'visible';
		WFIE.Video.activeGroup = link;
	}
}

WFIE.Video.loadCategorySSID = function( link, ssid )
{
	if( link != WFIE.Video.activeGroup )
	{
		var active = WFIE.Video.activeGroup;
		if( active )
		{
			active.link_images[ 0 ].style.visibility = 'visible';
			active.link_images[ 1 ].style.visibility = 'hidden';
			active.link_images[ 2 ].style.visibility = 'hidden';
			WFIE.Video.pagineSSID( link, ssid );
		}
		
		link.link_images[ 0 ].style.visibility = 'hidden';
		link.link_images[ 1 ].style.visibility = 'visible';
		link.link_images[ 2 ].style.visibility = 'visible';
		WFIE.Video.activeGroup = link;
	}
}

WFIE.Video.displayCategory = function( response )
{
	if( response != null )
	{
		WFIE.Video.divDetails.innerHTML = response.responseText;
	}
	
	var child, details = document.getElementById( "divDetailsStatus" );
	for( var i = 0; i < details.childNodes.length; i++ )
	{
		child = details.childNodes[ i ];
		if( child.nodeType == 1 && child.tagName.toUpperCase( ) == "A" )
		{
			WFIE.format( child, "SPAN", 15, 1, 4, 60 );
		}
	}
	
	var span = WFIE.Video.divStatus.getElementsByTagName( "SPAN" )[ 0 ];
	var div = WFIE.Video.divDetails.getElementsByTagName( "DIV" )[ 0 ];
	var link = WFIE.Video.activeGroup;
	
	if( span && div && link )
	{
		span.innerHTML = div.getAttribute( "statustext" );
		link.setAttribute( "currentpage", div.getAttribute( "currentpage" ) );
		link.setAttribute( "totalpages", div.getAttribute( "totalpages" ) );
	}
}

WFIE.Video.playVideo = function( videoArchiveID )
{
	var url = "CallbackManager.aspx?action=playvideo";
	url += "&videoid=" + videoArchiveID;
	WFIE.callbackRequest( url, "GET", null, WFIE.Video.logVideo );
}

WFIE.Video.playVideoSSID = function( videoArchiveID, ssid )
{
	var url = "CallbackManager.aspx?action=playvideo";
	url += "&videoid=" + videoArchiveID;
	WFIE.callbackRequestSSID( url, "GET", null, WFIE.Video.logVideoSSID, ssid);
}

WFIE.Video.logVideo = function( response )
{
	WFIE.Video.divData.innerHTML = response.responseText;
	WFIE.format( "videosdata", "DIV", 15, 1, 12, 50 );//12 lines, 50 chars
	
	var div = document.getElementById( "currentvideo_info" );
	var videoID = div.getAttribute( "videoarchiveid" );
	var videoUrl = div.getAttribute( "videourl" );
	
	var lnkEmail = document.getElementById( "lnkEmailVideo" );
	if( lnkEmail )
	{
		lnkEmail.href = ( parseInt( videoID ) > 0 )?"javascript:email('email_default_video.aspx?videoArchiveID=" + videoID + "');": "javascript:void( 0 );";
	}
	writeFlashVideo( 'flash/video.swf', 320, 280, 'videosvideo', 'docwrite', videoUrl );
}

WFIE.Video.logVideoSSID = function( response, ssid )
{
	WFIE.Video.divData.innerHTML = response.responseText;
	WFIE.format( "videosdata", "DIV", 15, 1, 12, 50 );//12 lines, 50 chars
	
	var div = document.getElementById( "currentvideo_info" );
	var videoID = div.getAttribute( "videoarchiveid" );
	var videoUrl = div.getAttribute( "videourl" );
	
	var lnkEmail = document.getElementById( "lnkEmailVideo" );
	if( lnkEmail )
	{
		lnkEmail.href = ( parseInt( videoID ) > 0 )?"javascript:email('email_default_video.aspx?videoArchiveID=" + videoID + "');": "javascript:void( 0 );";
	}
	//writeFlashVideoSSID( 'flash/video.swf', 320, 280, 'videosvideo', 'docwrite', videoUrl, ssid);
	writeFlashVideoSSID( 'flash/player.swf', 320, 280, 'videosvideo', 'docwrite', videoUrl + '&playerProfile=13043:cbstd_ie_commercial_break&videoAsset=' + videoID + '&renderersXML=http://adm.fwmrm.net/p/cbsie_live/renderers.xml&siteSection=' + ssid + '&networkId=13043&videoAssetNetworkId=13043&siteSectionNetworkAssetId=13043&cachebuster=1&disableFreewheel=false&responseUrl=http://32f3.v.fwmrm.net/ad/p/1&enableDomScan=true', ssid );

}

WFIE.Video.pagine = function( link )
{
	var url = "CallbackManager.aspx?action=loadcategoryvideos";
	url += "&category=" + link.getAttribute( "category" );
	url += "&currentpage=" + link.getAttribute( "currentpage" );
	url += "&itemsByPage=4";
	WFIE.callbackRequest( url, "GET", null, WFIE.Video.displayCategory );
}

WFIE.Video.pagineSSID = function( link, ssid )
{
	var url = "CallbackManager.aspx?action=loadcategoryvideos";
	url += "&category=" + link.getAttribute( "category" );
	url += "&currentpage=" + link.getAttribute( "currentpage" );
	url += "&itemsByPage=4";
	url += "&SSID=" + ssid;
	WFIE.callbackRequestSSID( url, "GET", null, WFIE.Video.displayCategory, ssid, null);
}


WFIE.Video.nextPage = function( )
{
	var link = WFIE.Video.activeGroup;
	var current = parseInt( link.getAttribute( "currentpage" ) );
	var total = parseInt( link.getAttribute( "totalpages" ) );
	
	if( current < ( total - 1 ) )
	{
		link.setAttribute( "currentpage", current + 1 );
		WFIE.Video.pagine( link );
	}
}

WFIE.Video.nextPageSSID = function(ssid)
{
	var link = WFIE.Video.activeGroup;
	var current = parseInt( link.getAttribute( "currentpage" ) );
	var total = parseInt( link.getAttribute( "totalpages" ) );
	
	if( current < ( total - 1 ) )
	{
		link.setAttribute( "currentpage", current + 1 );
		WFIE.Video.pagineSSID( link, ssid );
	}
}


WFIE.Video.previousPage = function( )
{
	var link = WFIE.Video.activeGroup;
	var current = parseInt( link.getAttribute( "currentpage" ) );
	
	if( current > 0 )
	{
		link.setAttribute( "currentpage", current - 1 )
		WFIE.Video.pagine( link );
	}
}

WFIE.Video.previousPageSSID = function(ssid)
{
	var link = WFIE.Video.activeGroup;
	var current = parseInt( link.getAttribute( "currentpage" ) );
	
	if( current > 0 )
	{
		link.setAttribute( "currentpage", current - 1 )
		WFIE.Video.pagine( link, ssid );
	}
}

WFIE.Video.swapCategoryImage = function( evt )
{
	var link = ( evt.target )? evt.target.parentNode: evt.srcElement.parentNode;
	if( link.tagName.toUpperCase( ) == "A" && link != WFIE.Video.activeGroup )
	{
		if( evt.type == "mouseover" )
		{
			link.link_images[ 0 ].style.visibility = 'hidden';
			link.link_images[ 1 ].style.visibility = 'visible';
		}
		else
		{
			link.link_images[ 1 ].style.visibility = 'hidden';
			link.link_images[ 0 ].style.visibility = 'visible';
		}
	}
}

WFIE.VideoArchives = {};

WFIE.VideoArchives.formatPreview = function( )
{
	var child, details = document.getElementById( "divDetailsStatus" );
	for( var i = 0; i < details.childNodes.length; i++ )
	{
		child = details.childNodes[ i ];
		if( child.nodeType == 1 && child.tagName.toUpperCase( ) == "A" )
		{
			WFIE.format( child, "SPAN", 15, 1, 4, 60 );
		}
	}
}

WFIE.Sections = {}; //Sections control.

WFIE.Sections.change = function( tag )
{
	document.location = "featured_scrollers.aspx?sectionID=" + tag.options[ tag.selectedIndex ].value;
}

WFIE.States = {}; //States Control.

WFIE.States.selectState = function( )
{
	var combo = document.getElementById( 'cboStates' );
	if( combo.selectedIndex > 0 )
	{
		document.location = combo.value;
	}
	else
	{
		alert( "Please select a state." );
	};
	
	return false;
}

WFIE.format = function( parentId, childsTagName, lineHeight, childsByParent, linesByChild, charsByLine, maxLines )
{
	var parent = ( typeof( parentId ) == "string" )? document.getElementById( parentId ): parentId;
	if( parent )
	{
		var lines = 0;
		var linesTotal = ( maxLines )? maxLines:( childsByParent * linesByChild );
		var childs = parent.getElementsByTagName( childsTagName );
		
		for( var i = 0; i < childs.length; i++ )
		{
			if( i < childsByParent && lines < linesTotal )
			{
				var child = childs[ i ];
				WFIE.showFromChildToParent( child, parent );
				if( child.offsetHeight < lineHeight )
				{
					lines++;
				}
				else
				{
					var text = WFIE.getInnerText( child );
					if( text.length > ( linesByChild * charsByLine ) )
					{
						text = text.substr( 0, ( linesByChild * charsByLine ) );
					}
					
					child.innerHTML = text;
					if( lines <= ( linesTotal - linesByChild ) )
					{
						while( child.offsetHeight > ( linesByChild * lineHeight ) )
						{
							text = text.substr( 0, text.length - 5 ) + "...";
							child.innerHTML = text;
						}
						lines += linesByChild;
					}
					else
					{
						while( child.offsetHeight > lineHeight )
						{
							text = text.substr( 0, text.length - 5 ) + "...";
							child.innerHTML = text;
						}
						lines++;
					}
				}
			}
			else
			{
				break;
			}
		}
	}
	else
	{
		setTimeout( "WFIE.format('"+parentId+"','"+childsTagName+"','"+lineHeight+"','"+childsByParent+"','"+linesByChild+"','"+charsByLine+"');", 100 );
	}
}

WFIE.getInnerText = function( tag )
{
	//if( document.all )
	//{
		return tag.innerHTML;
	/*}
	else
	{
		var rng = document.createRange( );
		rng.selectNode( tag );
		return rng.toString( );
	}*/
}

WFIE.showFromChildToParent = function( child, parent )
{
	while( child != parent )
	{
		if( child.style.display == "none" )
		{
			child.style.display = "";
		}
		child = child.parentNode;
	}
}

WFIE.redirectEnter = function( e )
{
	if( e.keyCode == 13 )
	{
		e.cancelBubble = true;
		e.returnValue = false;
		
		if( e.stopPropagation )
		{
			e.stopPropagation();
		}
		if( e.preventDefault )
		{
			e.preventDefault();
		}
		
		var target = ( e.target )? e.target: e.srcElement;
		if( target )
		{
			var buttonID = target.getAttribute( "defaultbutton" );
			if( document.all )
			{
				document.getElementById( buttonID ).click( );
			}
			else
			{
				setTimeout( "document.getElementById( '" + buttonID + "' ).click( );", 50 );
			}
		}
		
		return false;
	}
	else
	{
		return true;
	}
};

WFIE.isEmpty = function( tag )
{
	if( typeof( tag ) == "string" )
	{
		tag = document.getElementById( tag );
	}
	
	if( tag == null || ( tag.value == null || tag.value.length < 1 ) )
	{
		return true;
	}
	
	return false;
};

WFIE.trim = function( value )
{
	var objRegExp = /^(\s*)$/;

	//check for all spaces
	if(objRegExp.test(value))
	{
		value = value.replace(objRegExp, '');
		if( value.length == 0)
		return value;
	}

	//check for leading &amp; trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(value))
	{
		//remove leading and trailing whitespace characters
		value = value.replace(objRegExp, '$2');
	}
	
	return value;
}

WFIE.isNumeric = function( value )
{
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
  var numeric = objRegExp.test(value);
  
  return numeric;
}

WFIE.callbackRequest = function( url, method, arguments, handler )
{
	url = url + "&random=" + Math.random( );
	_xmlHttpObject = getXmlHttpObject( receiveData, receiveError );
	_xmlHttpObject.open( method, url, true );
	_xmlHttpObject.send( arguments );
	
	function getXmlHttpObject( )
	{ 
		var objXmlHttp = null;
		var isIE7 = false;

		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			//alert("This example doesn't work in Opera")
			return null;
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{
			var strName="Msxml2.XMLHTTP";

			if (navigator.appVersion.indexOf("MSIE 7.0")>=0)
			{
				//alert("using Internet Explorer 7");
				strName=new XMLHttpRequest();
				isIE7 = true;
			}
			else if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			}

			try
			{
				if(!isIE7){
					objXmlHttp=new ActiveXObject(strName);
				}
				else
				{
					objXmlHttp=strName;
				}
				objXmlHttp.onreadystatechange=receiveData;
				return objXmlHttp;
			}
			catch(e)
			{
				alert(e.message);
				return null;
			}
		}
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest();
			objXmlHttp.onload=receiveData;
			objXmlHttp.onerror=receiveError;
			return objXmlHttp;
		}
	}
	
	function receiveData( )
	{
		if( _xmlHttpObject.readyState == 4 )
		{
			handler( _xmlHttpObject );
		}
	}

	function receiveError( xml )
	{
		alert( xml );
	}
}

WFIE.callbackRequestSSID = function( url, method, arguments, handler, ssid )
{
	url = url + "&random=" + Math.random( );
	_xmlHttpObject = getXmlHttpObject( receiveData, receiveError );
	_xmlHttpObject.open( method, url, true );
	_xmlHttpObject.send( arguments );
	
	function getXmlHttpObject( )
	{
		var objXmlHttp = null;
		var isIE7 = false;

		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			//alert("This example doesn't work in Opera")
			return null;
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{
			var strName="Msxml2.XMLHTTP";

			if (navigator.appVersion.indexOf("MSIE 7.0")>=0)
			{
				//alert("using Internet Explorer 7");
				strName=new XMLHttpRequest();
				isIE7 = true;
			}
			else if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			}

			try
			{
				if(!isIE7){
					objXmlHttp=new ActiveXObject(strName);
				}
				else
				{
					objXmlHttp=strName;
				}
				objXmlHttp.onreadystatechange=receiveData;
				return objXmlHttp;
			}
			catch(e)
			{
				alert(e.message);
				return null;
			}
		}
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest();
			objXmlHttp.onload=receiveData;
			objXmlHttp.onerror=receiveError;
			return objXmlHttp;
		}
	}
	
	function receiveData( )
	{
		if( _xmlHttpObject.readyState == 4 )
		{
			handler( _xmlHttpObject, ssid );
		}
	}

	function receiveError( xml )
	{
		alert( xml );
	}
}


WFIE.slideshow = {};
//WFIE.slideshow.images.src
//WFIE.slideshow.images.caption
WFIE.slideshow.currentIndex = 0;
WFIE.slideshow.init = function()
{
	WFIE.slideshow.fields =
	{
		prevarrow: document.getElementById('prevarrow'),
		nextarrow: document.getElementById('nextarrow'),
		photocaption: document.getElementById('photocaption'),
		photolink: document.getElementById('photolink'),
		photolinkWindow: document.getElementById('photolinkWindow'),
		photo: document.getElementById('photo'),
		photoposition: document.getElementById('photoposition')
	};
	
	WFIE.PhotoGallery.loadPhotoGallery();
};
WFIE.slideshow.next = function() {
	WFIE.slideshow.testLoad( );
	var index = WFIE.slideshow.currentIndex;
	var fields = WFIE.slideshow.fields;
	var total = WFIE.slideshow.images.src.length;
	if(index < total - 1) {
		index++;
	}
	else {
		index = 0;
	}
	
	if( WFIE.slideshow.images.src.length > 0 )
	{
		fields.photo.src =  "lib/images/photogallery/" + WFIE.slideshow.images.photoGalleryID[index] + "/" + WFIE.slideshow.images.src[index];
		fields.photocaption.innerHTML = WFIE.slideshow.images.caption[index];
		fields.photolink.innerHTML = WFIE.slideshow.images.link[index];
		fields.photolinkWindow.innerHTML = WFIE.slideshow.images.linkWindow[index];
		if (fields.photolink.innerHTML != "")
		{
		    if (fields.photolinkWindow.innerHTML == "True")
		        fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\">"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"><a target=\"_blank\" style=\"color: #ffffff\" href=\""+ fields.photolink.innerHTML+"\">Related Story" +"</a></td></tr></table>";
		    else
		        fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\">"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"><a style=\"color: #ffffff\" href=\""+ fields.photolink.innerHTML+"\">Related Story" +"</a></td></tr></table>";
		}
		else
		    fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\">"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"></td></tr></table>";    
	}
	else
	{
		fields.photo.src =  "";
		fields.photocaption.innerHTML = "";
		fields.photoposition.innerHTML = "There are no photos in this gallery.";
	}
	WFIE.slideshow.currentIndex = index;
};
WFIE.slideshow.prev = function() {
	WFIE.slideshow.testLoad( );
	var index = WFIE.slideshow.currentIndex;
	var fields = WFIE.slideshow.fields;
	var total = WFIE.slideshow.images.src.length;
	if(index == 0) {
		index = total -1;
	}
	else {
		index--;
	}
	
	if( WFIE.slideshow.images.src.length > 0 )
	{
		fields.photo.src =  "lib/images/photogallery/" + WFIE.slideshow.images.photoGalleryID[index] + "/" + WFIE.slideshow.images.src[index];
		fields.photocaption.innerHTML = WFIE.slideshow.images.caption[index];
		fields.photolink.innerHTML = WFIE.slideshow.images.link[index];
		fields.photolinkWindow.innerHTML = WFIE.slideshow.images.linkWindow[index];
		if (fields.photolink.innerHTML != "")
		{
		    if (fields.photolinkWindow.innerHTML == "True")
		        fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\" >"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"><a target=\"_blank\" style=\"color: #ffffff\" href=\""+ fields.photolink.innerHTML+"\">Related Story" +"</a></td></tr></table>";
		    else
		        fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\" >"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"><a style=\"color: #ffffff\" href=\""+ fields.photolink.innerHTML+"\">Related Story" +"</a></td></tr></table>";
        }
    	else
		    fields.photoposition.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"right\" width=\"55%\">"+(index+1) + " of " + total + "</td><td align=\"right\" width=\"45%\"></td></tr></table>";    

	}
	else
	{
		fields.photo.src =  "";
		fields.photocaption.innerHTML = "";
		fields.photoposition.innerHTML = "There are no photos in this gallery.";
	}
	
	WFIE.slideshow.currentIndex = index;
};

WFIE.slideshow.testLoad = function( )
{
	if( WFIE.slideshow.fields.photo == null )
	{
		WFIE.slideshow.init();
	}
}

WFIE.preventTextarea = function( evt )
{
	evt = ( evt )? evt: event;
	var tag = ( evt.target )? evt.target: evt.srcElement;
	var maxlength = tag.getAttribute( "cmaxlength" );
	
	if( tag.value.length >= maxlength && evt.keyCode != 8 )
	{
		return false;
	}
	
	return true;
}

WFIE.limitTextarea = function( evt )
{
	evt = ( evt )? evt: event;
	var tag = ( evt.target )? evt.target: evt.srcElement;
	var maxlength = tag.getAttribute( "cmaxlength" );
	
	if( tag.value.length >= maxlength )
	{
		var scrollTop = tag.scrollTop;
		tag.value = tag.value.substring( 0, maxlength );
		tag.scrollTop = scrollTop;
	}
}

WFIE.loadTextareaLimits = function( )
{
	var tags = document.getElementsByTagName( "TEXTAREA" );
	var maxlength;
	
	for( var i = 0; i < tags.length; i++ )
	{
		maxlength = tags[ i ].getAttribute( "cmaxlength" );
		if( maxlength )
		{
			tags[ i ].onkeydown = WFIE.preventTextarea;
			tags[ i ].onkeyup = WFIE.limitTextarea;
		}
	}
}

WFIE.onLoad_handlers = new Array( );
WFIE.onLoad = function( )
{
	var handler;
	for( var i = 0; i < WFIE.onLoad_handlers.length; i++ )
	{
		handler = WFIE.onLoad_handlers[ i ].handler;
		if( handler.length > 0 )
		{
			handler.apply( window, WFIE.onLoad_handlers[ i ].parameters );
		}
		else
		{
			handler.call( window );
		}
	}
}

WFIE.setFocus = function ( )
{
	if(typeof(setFocusControl)!="undefined")
	{
		//alert(setFocusControl);
		var control = document.getElementById(setFocusControl);	
		if(control!=null)
//			control.focus();
			control.scrollIntoView( true );
		//else 
			//alert('null control');
	}
}

function email(url) 
{
 var newWin = window.open (url, 'newWin', 'width=420,height=380,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no');
 newWin.focus();

}
function getAge(year,month,day) {
  var now = new Date();
  var yearNow = now.getFullYear();
  var monthNow = now.getMonth() + 1;
  var dayNow = now.getDate();

  var today = new Date(yearNow,monthNow,dayNow);

  var yearAge = yearNow - year;
	
  if (monthNow <= month) {
    if (monthNow < month) {
      yearAge--;		
    } else {
      if (dayNow < day) {
        yearAge--;
      }
    }
  }
  return yearAge;
};

//Cookies 
WFIE.cookies = {};
WFIE.cookies.setCookie = function(c_name, value, expiredays)
{
	c_name = "WFIE_" + c_name;
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value)+
	((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
};
WFIE.cookies.getCookie = function(c_name)
{
	c_name = "WFIE_" + c_name;
	if (document.cookie.length>0)
	{
		var c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length+1; 
			var c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	return "";
};

WFIE.trimdotted = function( parentId, childsTagName, lineWidth, lineHeight)
{
	var parent = ( typeof( parentId ) == "string" )? document.getElementById( parentId ): parentId;
	if( parent )
	{
		var childs = parent.getElementsByTagName( childsTagName );
		
		for( var i = 0; i < childs.length; i++ )
		{
			var child = childs[ i ];
			WFIE.showFromChildToParent( child, parent );
			var text = WFIE.getInnerText( child );
			if ( child.offsetWidth > lineWidth || child.offsetHeight > lineHeight )
			{
				while( child.offsetWidth > lineWidth || child.offsetHeight > lineHeight )
				{
					text = text.substr( 0, text.length - 5 ) + "...";
					child.innerHTML = text;
				}
			}
		}
	}
}

WFIE.trimWidthAndHeight = function( parentId, childsTagName, lineWidth, lineHeight)
{
	var parent = ( typeof( parentId ) == "string" )? document.getElementById( parentId ): parentId;
	if( parent )
	{
		var childs = parent.getElementsByTagName( childsTagName );
		
		for( var i = 0; i < childs.length; i++ )
		{
			var child = childs[ i ];
			WFIE.showFromChildToParent( child, parent );
			var text = WFIE.getInnerText( child );
			if ( child.offsetWidth > lineWidth || child.offsetHeight > lineHeight )
			{
				while( child.offsetWidth > lineWidth || child.offsetHeight > lineHeight )
				{
					text = text.substr( 0, text.length - 5 );
					child.innerHTML = text;
				}
			}
		}
	}
}

WFIE.DeborahLookALike = {};

WFIE.DeborahLookALike.termsOnCheck = function()
{
	if(WFIE.DeborahLookALike.buttons.terms_agree.checked) 
	{
		WFIE.DeborahLookALike.buttons.submitButton.src = "images/submit_submit.jpg";
		WFIE.DeborahLookALike.buttons.submitButton.style.cursor = "pointer";
		document.getElementById("submitdisabled").style.visibility = "hidden";
	}
	else
	{
		WFIE.DeborahLookALike.buttons.submitButton.src = "images/submit_submit_disabled.gif";
		WFIE.DeborahLookALike.buttons.submitButton.style.cursor = "default";
		document.getElementById("submitdisabled").style.visibility = "visible";
	}

}

WFIE.DeborahLookALike.loadFields = function( )
{
	WFIE.DeborahLookALike.fields =
	{
		firstName: { tag: document.getElementById( "txtFirstName" ), required: true, message: "First Name" },
		lastName: { tag: document.getElementById( "txtLastName" ), required: true, message: "Last Name" },
		month: { tag: document.getElementById( "ddMonth" ), required: true, message: "Age - month" },
		day: { tag: document.getElementById( "ddDay" ), required: true, message: "Age - day" },
		year: { tag: document.getElementById( "ddYear" ), required: true, message: "Age - year" },
		email: { tag: document.getElementById( "txtEmail" ), required: true, message: "Email Address" },
		street1: { tag: document.getElementById( "txtAddress1" ), required: true, message: "Street Address" },
		street2: { tag: document.getElementById( "txtAddress2" ), required: false, message: "Street Address 2" },
		city: { tag: document.getElementById( "txtCity" ), required: true, message: "City" },
		state: { tag: document.getElementById( "ddState" ), required: true, message: "State" },
		province: { tag: document.getElementById( "txtProvince" ), required: false, message: "Province/Region" },
		zip: { tag: document.getElementById( "txtZip" ), required: false, message: "Zip Code", isNumeric: true },
		country: { tag: document.getElementById( "txtCountry" ), required: true, message: "Country" },
		dayArea: { tag: document.getElementById( "txtArea" ), required: true, message: "Phone Number - area code", minLength: 3, isNumeric: true, group: "Daytime" },
		dayPrefix: { tag: document.getElementById( "txtPrefix" ), required: true, message: "Phone Number - 3 first digits", minLength: 3, isNumeric: true, group: "Daytime" },
		dayNumber: { tag: document.getElementById( "txtNumber" ), required: true, message: "Phone Number - 4 last digits", minLength: 4, isNumeric: true, group: "Daytime" },
		story: { tag: document.getElementById( "txtStory" ), required: true, message: "Story" }

	};
	
	WFIE.DeborahLookALike.buttons = 
	{
		terms_agree: document.getElementById( "terms_agree" ),
		submitButton: document.getElementById( "submitbutton" )
	};
	
	document.getElementById("submitbutton").style.visibility = "visible";
};

WFIE.DeborahLookALike.validate = function( )
{
	if(WFIE.DeborahLookALike.buttons.terms_agree.checked) 
	{
	    WFIE.SubmitStory.fields = WFIE.DeborahLookALike.fields;
		if( WFIE.SubmitStory.validateRequireds( ) )
		{
		    if ( WFIE.DeborahLookALike.validateRequireds( ) )
		    {
			    if( WFIE.SubmitStory.validateMinLength( ) )
			    {
				    if( WFIE.SubmitStory.validateNumerics( ) )
				    {
					    if( WFIE.SubmitStory.validateGroups( ) )
					    {
						    if( WFIE.SubmitStory.validateEmail( ) )
						    {
							    if( WFIE.SubmitStory.validateStory( ) )
							    {
								    if(WFIE.SubmitStory.validateAge( ) ) 
								    {
									    return true;
								    }
							    }
						    }
					    }
				    }
			    }
			}
		}
	}
	return false;
};


WFIE.DeborahLookALike.validateRequireds = function( )
{
    var photo = document.getElementById( "fuPhoto" );
    var video = document.getElementById( "fuVideo" );
    
    var photoTypes = new Array("JPG", "GIF");
    var videoTypes = new Array("SVI", "MOV", "WMV", "MP4");
    
    var message = "You need to upload a photo or a video.";
    var validExtension = new Boolean(false);

    if (photo.value == "" && video.value == "")
    {
        alert( message );
        return false;
    }
        
    if (photo.value != "")
    {
        var photoExtension = WFIE.GetExtension(photo.value);

        for (var x in photoTypes)
        {
            if ( photoTypes[x] == photoExtension )
            {
                validExtension = true;
            }
        }
        
        if ( validExtension == false )
        {
            message = "Your photo must be either a JPG or GIF";
            document.forms[0].fuPhoto.value = "";            
            alert( message );
            return false;
        }
	}
	
	if (video.value != "")
	{
        var videoExtension = WFIE.GetExtension(video.value);
        
        validExtension = false;
        
        for (var x in videoTypes)
        {
            if ( videoTypes[x] == videoExtension )
            {
                validExtension = true;
            }
        }
        
        if ( validExtension == false )
        {
            message = "Your video must be a SVI, MOV, WMV, or MP4";
            document.forms[0].fuVideo.value = "";
            alert( message );
            return false;
        }
	}
	
	return true;
}

WFIE.GetExtension = function( filename )
{
    return filename.toString().substring(filename.toString().lastIndexOf(".") + 1).toUpperCase();
}

WFIE.OpenPopUp = function (photo, height, width)
{
/*
	var w = 480, h = 340;

	if (document.all) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	else if (document.layers) {
		w = window.innerWidth;
		h = window.innerHeight;
	}
*/
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = width , popH = height;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;

	window.open('/admin/submitted-info-popup.aspx?photo=' + photo, '_blank', 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=0, width=' + width + ', height=' + height + ', left=' + leftPos + ', top=' + topPos); 
	
	return false;
}

WFIE.hidewinnerscrollers = function()
{
	if (hideWinnersScroll == 1)
	{
			document.getElementById('featured_winners_left').style.backgroundImage="none";
			document.getElementById('featured_winners_right').style.backgroundImage="none";
			document.getElementById('featured_winners_left').style.cursor="default";
			document.getElementById('featured_winners_right').style.cursor="default";
	}	
	
	if (hideWinnersScroll == 0)
	{
			document.getElementById('featured_winners_left').style.backgroundImage="url(../images/awards/featured_left_arrow.gif)";
			document.getElementById('featured_winners_right').style.backgroundImage="url(../images/awards/featured_right_arrow.gif)";
			document.getElementById('featured_winners_left').style.cursor="pointer";
			document.getElementById('featured_winners_right').style.cursor="pointer";
	}
}

// <MMR> Code needed for the generation of random number used on the MRM Tags 26/JAN/2009 </MMR>
var mrmRandomNumber = Math.floor(Math.random() * 100000) + 10000;
