function PageProfile(initObj) {
	if (initObj.mainNavSelected != undefined) {
		this.mainNavSelected = initObj.mainNavSelected;
	} else {
		this.mainNavSelected = -1;
	}
	
	if (initObj.userId != undefined) {
		this.userId = initObj.userId;
	} else {
		this.userId = "guest";
	}
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0)  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1) {
	    c_start=c_start + c_name.length+1;
    	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 "";
}

function writeHunuVoteBox(initObj) {
	document.write(getHunuVoteBox(initObj));
}

function getHunuVoteBox(initObj) {
	var date = new Date();
	var hunuVoteBoxId = "hunuVoteBox" + date.getTime();
	var hunuVoteBox = "";
	//var encodedTargetUrl = encodeURIComponent(initObj.targetUrl);

	hunuVoteBox += '<form style="margin:0; padding:0" name="' + hunuVoteBoxId + '" id="' + hunuVoteBoxId + '">';
	hunuVoteBox += '	<div class="voteBox">';
	var badgeClass = "";
	var badgeLabel = "";
	var badgeLabelLink = "";
	if (initObj.category == "games") {
		badgeClass = initObj.demographic;
		badgeLabel = initObj.demographic;
		badgeLabelLink = "http://www.hunu.com/kids-games/" + badgeClass;
	} else {
		badgeClass = initObj.category;
		badgeLabel = initObj.category;
		badgeLabelLink = "http://www.hunu.com/" + badgeClass;
	}

	hunuVoteBox += '		<p id="pvote' + initObj.articleId + '" class="votes ' + badgeClass + '"><b>' + initObj.votecount + '</b><br />votes<br/><label><a href="' + badgeLabelLink + '">' + badgeLabel + '</a></label></p>';
	hunuVoteBox += '		<p class="voteBtn">';
	hunuVoteBox += '			<a href="javascript:submitVote(\'http://www.hunu.com/controller?action=recommendItem\',' + initObj.articleId + ',1);"><img src="http://www.hunu.com/i/vote/vote_up.gif" alt="" /></a> <a href="javascript:submitVote(\'http://www.hunu.com/controller?action=recommendItem\',' + initObj.articleId + ',-1);"><img src="http://www.hunu.com/i/vote/vote_down.gif" alt="" /></a>';
	hunuVoteBox += '		</p>';
	hunuVoteBox += '	</div>';
	hunuVoteBox += '</form>';	

	return hunuVoteBox;
}

function limitChars(textid, limit, infodiv) {
	var text = $('#'+textid).val(); 
	var textlength = text.length;
	if(textlength > limit) {
		$('#' + infodiv).html('<span class="callout">You cannot write more then '+limit+' characters.</span>');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	} else {
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

function prepareForInput(theTextArea) {
	$(theTextArea).focus(function() {
		if (!($(this).hasClass("inputReadyTextArea"))) {
			$(this).addClass("inputReadyTextArea");
			$(this).val("");
		}
	});
}

// begin ARTICLE LISTINGS --------------------
function writeArticleListing(htmlContainer,initObj,listType,atPageBuild) {
	var atPageBuid = false;
	if (typeof(htmlContainer) == "string") {
		if (htmlContainer == "pageBuild") {
			atPageBuild = true;
			htmlContainer = new PageBuildContainer();
		}
	}
	var theListType = listType;
	htmlContainer.listHtml += '<div class="articleWrap">';
	htmlContainer.listHtml += getHunuVoteBox(initObj);
	htmlContainer.listHtml += '<div class="detail">';
	if (theListType == "detail") {
		htmlContainer.listHtml += '<p class="title"><a href="'+ initObj.targetUrl + '" target="_new">' + initObj.title + '</a></p>';
	} else {
		htmlContainer.listHtml += '<p class="title"><a href="' + initObj.encodedMappedUrl + '">' + initObj.title + '</a></p>';
	}
	if (theListType == "side") {
		htmlContainer.listHtml += '<p>' + initObj.tinybodytext + '&nbsp;&nbsp;<a href="' + initObj.encodedMappedUrl + '">' + initObj.tinyelipsis + '</a></p>';
	} else {
		htmlContainer.listHtml += '<p>' + initObj.bodytext + '&nbsp;&nbsp;<a href="' + initObj.encodedMappedUrl + '">' + initObj.elipsis + '</a></p>';
	}
	if (theListType != "side") {
		var commentLink = "";
		if (parseInt(initObj.commentCount) > 0) {
			var commentLabel = "";
			if (parseInt(initObj.commentCount) == 1) {
				commentLabel = "comment";
			} else {
				commentLabel = "comments";
			}
			commentLink = '<a href="' + initObj.encodedMappedUrl + '#commentAnchor">' + initObj.commentCount + ' ' + commentLabel + '</a>  |  ';
		} else {
			commentLink = '<a href="' + initObj.encodedMappedUrl + '#commentAnchor">Be the first to comment!</a>  |  ';
		}
		htmlContainer.listHtml += '<p class="detailLinks">' + commentLink + '<b>' + initObj.submissionDate + '</b>';
		
		if (initObj.isNew == "true") {
			htmlContainer.listHtml += '<span style="background-color:#ff0;color:#000;font-weight:bold;font-size:8px;border:1px solid #000;padding:1px 3px;margin-left:4px;">NEW!</span>';
		}
		
		var formattedUsername= initObj.username;
		if (formattedUsername.length > 12) {
			formattedUsername = formattedUsername.substring(0,9) + "...";
		}
		htmlContainer.listHtml += '&nbsp;&nbsp;|&nbsp;&nbsp;<span class="usernameLink">Submitted by: <a href="http://www.hunu.com/parent/' + initObj.userId + '">' + formattedUsername + '</a></span></p>';
	}
	htmlContainer.listHtml += '</div>';
	htmlContainer.listHtml += '<div class="col3">';
	htmlContainer.listHtml += '<a href="' + initObj.encodedMappedUrl + '"><img src="' + initObj.imageUrl + '" class="pic" alt="" /></a>';
	htmlContainer.listHtml += '</div>';
	htmlContainer.listHtml += '<br clear="all" />';
	htmlContainer.listHtml += '</div><!--end articleWrap-->';
	if (atPageBuild) {
		document.write(htmlContainer.listHtml);
	}
}

function writeArticleList(tabindex1,tabindex2,theArticleList,listType) {
	var theListType = "default";
	if (listType != undefined) {
		theListType = listType;
	}
	theArticleList.setTabRowIndex(tabindex1,tabindex2);
	var theTab = theArticleList.getTab(theArticleList.getTabRowIndex(0),theArticleList.getTabRowIndex(1));
	var setTabInitObj = {
		tab1class:"tab" + theArticleList.getTabRowIndex(0),
		tab2class:"filterTab" + theArticleList.getTabRowIndex(1),
		parentDiv:theArticleList.parentDiv
	}
	if (!theTab.isPopulated) {
		var listXmlRequest = $.ajax({
			type: "GET",
			url: theTab.requestUrl,
			dataType: "xml",
			cache:false,
			success: function(xml) {
				var listIsEmpty = "yes";
				if ($(xml).find('article').length > 0) {
					$(xml).find('article').each(function(){
						var articleId = parseInt($(this).find('articleId').text());
						if (articleId > 0) {
							listIsEmpty = "no";
							writeArticleListing(theTab,
								{
									title:$(this).find('title').text(),
									category:$(this).find('category').text(),
									demographic:$(this).find('demographic').text(),
									bodytext:$(this).find('bodytext').text(),
									tinybodytext:$(this).find('tinybodytext').text(),
									elipsis:$(this).find('elipsis').text(),
									tinyelipsis:$(this).find('tinyelipsis').text(),
									votecount:$(this).find('votecount').text(),
									imageUrl:$(this).find('imageUrl').text(),
									targetUrl:$(this).find('targetUrl').text(),
									submissionDate:$(this).find('submissionDate').text(),
									articleId:$(this).find('articleId').text(),
									commentCount:$(this).find('commentCount').text(),
									userId: $(this).find('userId').text(),
									username: $(this).find('username').text(),
									isNew: $(this).find('newForUser').text(),
									encodedMappedUrl: $(this).find('encodedMappedUrl').text()
								},
								theListType
							);
						}
					}); 
					}
					$("#" + theArticleList.targetDiv).removeClass("listErrorMessage");
					var listHtml = "";
					if (listIsEmpty == "no") {
						listHtml = theTab.listHtml;
					} else {
						listHtml = theArticleList.emptyListMessage;
					}
					$("#" + theArticleList.targetDiv).html(listHtml);
					setTabSelection(setTabInitObj);
					theTab.isPopulated = true;
			},
			error: function(XMLHttpRequest, textStatus) {
				setTabSelection(setTabInitObj);
				$("#" + theArticleList.targetDiv).html("<div style='color:#ff0000;'>request URL:<br />" + theTab.requestUrl + "<br /><br />" + textStatus + "</div>");
			}
			});
	} else {
		$("#" + theArticleList.targetDiv).html(theTab.listHtml);
		setTabSelection(setTabInitObj);
	}
}

function setTabSelection(initObj) {
	var parentDivId = "#" + initObj.parentDiv;
	$(parentDivId + " .filterTab").removeClass("selected");
	$(parentDivId + " .tab").removeClass("selected");
	$(parentDivId + " ." + initObj.tab1class).addClass("selected");
	$(parentDivId + " ." + initObj.tab2class).addClass("selected");
}

function ListTab(i,j,theTabListSetupData) {
	this.dataSrc = theTabListSetupData.dataSrc;
	this.listHtml = "";
	this.isPopulated = false;
	this.selected = false;
	this.requestUrl = "";
	
	// Begin required params
	this.category = "";
	this.demographic = "";
	this.time = "";
	// End required params
	
	switch(theTabListSetupData.mainGrouping) {
		case "category":
			this.category = theTabListSetupData.mainGroupingValue;
			break;
		case "demographic":
			this.demographic = theTabListSetupData.mainGroupingValue;
			break;
		case "time":
			this.time = theTabListSetupData.mainGroupingValue;
			break;
	}
	
	switch(theTabListSetupData.row1Tabs[i].param) {
		case "dem":
			this.demographic = theTabListSetupData.row1Tabs[i].value;
			break;
		case "cat":
			this.category = theTabListSetupData.row1Tabs[i].value;
			break;
		case "time":
			this.time = theTabListSetupData.row1Tabs[i].value;
			break;
	}
	
	switch(theTabListSetupData.row2Tabs[j].param) {
		case "dem":
			this.demographic = theTabListSetupData.row2Tabs[j].value;
			break;
		case "cat":
			this.category = theTabListSetupData.row2Tabs[j].value;
			break;
		case "time":
			this.time = theTabListSetupData.row2Tabs[j].value;
			break;
	}

	this.requestUrl = this.dataSrc;
	if (this.category != "") {
		this.requestUrl += "&cat=" + encodeURIComponent(this.category);
	}
	if (this.demographic != "") {
		this.requestUrl += "&dem=" + encodeURIComponent(this.demographic);
	}
	if (this.time != "") {
		this.requestUrl += "&time=" + encodeURIComponent(this.time);
	}
	this.requestUrl += theTabListSetupData.urlTip;
}

function ArticleList(theTabListSetupData) {
	// Initialize data
	for (var i=0; i<theTabListSetupData.row1Tabs.length; i++) {
		theTabListSetupData.tabs[i] = new Array();
		for (var j=0; j<theTabListSetupData.row2Tabs.length; j++) {
			theTabListSetupData.tabs[i][j] = new ListTab(i,j,theTabListSetupData);
		}
	}
	this.targetDiv = theTabListSetupData.targetDiv;
	this.rowsArray = new Array();
	this.tabsArray = theTabListSetupData.tabs;
	this.parentDiv = theTabListSetupData.parentDiv;
	this.emptyListMessage = theTabListSetupData.emptyListMessage;
	for (var i=0; i<theTabListSetupData.numberOfRows; i++) {
		this.rowsArray.push(0);
	}
	delete theTabListSetupData;

	// Function definitions
	this.setTabRowIndex = function() {
		for(var i=0; i<arguments.length; i++){
			if (arguments[i] != -1) {
				this.rowsArray[i]=arguments[i];
			}
		}
	}
	this.getTabRowIndex = function(theIndex) {
		return(this.rowsArray[theIndex]);
	}

	this.getTab = function(index1,index2) {
		return(this.tabsArray[index1][index2]);
	}
}

function TabListSetupData() {
	// create master array of all tabs in the menu
	this.tabs = new Array();
	// create row 1 tabs array
	this.row1Tabs = new Array();
	// create row 2 tabs array
	this.row2Tabs = new Array();
	// set the url of the data source
	this.dataSrc = "";
	// set the target div for the article listing
	this.targetDiv = "";
	// set which tabs are selected by default
	this.tab1default = 0;
	this.tab2default = 0;
	// set the number of rows (filters)
	this.numberOfRows = 0;
	// set the name of the div containing the entire list and interface
	this.parentDiv = "";
	// optional string added to the end of the request, must be uri encoded before passing in here
	this.urlTip = "";
	this.emptyListMessage = "";
}
// end ARTICLE LISTINGS --------------------------

function MixedTabRow(tabTotal,parentDiv) {
	this.tabTotal = tabTotal;
	this.parentDiv = parentDiv;
	
	this.setSelected = function(theIndex) {
		for (var i=0; i<tabTotal; i++) {
			if (i == theIndex ) {
				$("#" + parentDiv + " .tab" + i).addClass("tabNormalSelected");
				$("#" + parentDiv + " .tab" + i).removeClass("selected");
				$("#" + parentDiv + " .tab" + i + "content").css({display:"block"});
			} else {
				$("#" + parentDiv + " .tab" + i).removeClass("tabNormalSelected");
				$("#" + parentDiv + " .tab" + i).removeClass("selected");
				$("#" + parentDiv + " .tab" + i + "content").css({display:"none"});
			}
		}
	}
}

function editField(formId,theField) {
	$("#" + formId + " #" + theField + "Edit").css({display:"block"});
	$(".editLinks").css({display:"none"});
	$("#" + formId + "Hide").css({display:"block"});
}

function InputGroup(formId,inputArray) {
	this.formId = formId;
	this.inputArray = inputArray;
	
	this.clearGroup = function() {
		
		for (var i=0; i<this.inputArray.length; i++) {
			cancelEdit(this.formId,this.inputArray[i]);
		}
		
		$("#" + this.formId + " .editEnabled").css({display:"none"});
		$(".editLinks").css({display:"inline"});
		$("#" + this.formId + "Hide").css({display:"none"});
		$("#" + this.formId + " label").css({display:"none"});
		
	}
}

function cancelEdit(formId,theField) {
	theField = document.getElementById(theField);
	
	if(theField == null)
		return;
	
	theFieldTag = theField.tagName;
	theFieldTag = theFieldTag.toUpperCase();
	
	//reset form fields to default states
	switch(theField.tagName) {
		case "INPUT":
			$("#" + formId + " #" + theField.id).val("");
			$("#" + formId + " #" + theField.id).removeAttr("checked");
			$("#" + formId + " #" + theField.id).removeAttr("CHECKED");
			break;
		case "TEXTAREA":
			$("#" + formId + " #" + theField.id).val("");
			break;
		case "SELECT":
			$("#" + formId + " #" + theField.id).val("");
			theField.selectedIndex = 0;
			break;
	}
}

function submitUserStatus(theForm) {
	var userStatus = $.trim($("#userStatus").val());
	if (userStatusModified && (userStatus != "")) {
		$("#userStatusForm").submit();
	}
}

function PageBuildContainer() {
	this.listHtml="";
}

function ChildFormCollection(parentDiv) {
	this.formModified = false;
	this.parentDiv = parentDiv;
	this.elementArray = new Array();
	this.addElement = function(initObj) {
		this.formModified = true;
		this.elementArray.push(new ChildFormElement(initObj));
		var currentIndex = this.elementArray.length-1;
		this.elementArray[currentIndex].currentIndex = currentIndex;
		$("#kidCount").val(this.elementArray.length);
	}
	this.removeElement = function(theIndex) {
		this.formModified = true;
		$("#kidBirthMonth" + theIndex).rules("remove");
		$("#kidBirthYear" + theIndex).rules("remove");
		$("#kidGender" + theIndex).rules("remove");

		this.elementArray.splice(theIndex,1);
		$("#kidCount").val(this.elementArray.length);
		this.showEditState();
	}
	this.showDisplayState = function() {
		var htmlBlock = "";
		for (var i=0; i<this.elementArray.length; i++) {
			this.elementArray[i].currentIndex = i;
			htmlBlock += this.elementArray[i].getDisplayState() + "\n";
		}
		$("#" + parentDiv).html(htmlBlock);
	}
	this.showEditState = function() {
		$("#allKidsEdit").css({visibility:"hidden"});
		var htmlBlock = "";
		
		if (this.elementArray.length < 1) {
			htmlBlock += "&nbsp;No kids<br />";
		} else {
			htmlBlock += "&nbsp;kids:<br />";
		}
		
		for (var i=0; i<this.elementArray.length; i++) {
			this.elementArray[i].currentIndex = i;
			htmlBlock += this.elementArray[i].getEditState() + "\n";
		}
		
		$("#" + parentDiv).html(htmlBlock);
		
		for (var i=0; i<this.elementArray.length; i++) {
			this.elementArray[i].setEditState();
		}
		
		$("#allKidsEdit").css({visibility:"visible"});
	
	}
	this.addKid = function() {
		if ( ($("#addKidGender").val() == "") || ($("#addKidBirthYear").val() == "") || ($("#addKidBirthYear").val() == "") ) {
			$("#addKidError").html("Please select birth date, month and gender.");
		} else {
			$("#addKidError").html("");
			this.addElement({
				gender : $("#addKidGender").val(),
				birthYear : $("#addKidBirthYear").val(),
				birthMonth : $("#addKidBirthMonth").val()
			});
			document.getElementById("addKidBirthMonth").selectedIndex = 0;
			document.getElementById("addKidBirthYear").selectedIndex = 0;
			document.getElementById("addKidGender").selectedIndex = 0;
			this.showEditState();
		}
	}
}

function ChildFormElement(initObj) {
	this.gender = initObj.gender;
	this.birthYear = initObj.birthYear;
	this.birthMonth = initObj.birthMonth;
	this.currentIndex = -1;

	this.getEditState = function() {
		var displayHtml = "";
		displayHtml += "<div id='kidEditGroup" + this.currentIndex + "' class='kidEditGroup'>";
		displayHtml += "<table border='0' cellpadding='0' cellspacing='0'><tr><td valign='middle' width='30' align='right'>&nbsp;" + (this.currentIndex+1) + "&nbsp;</td><td valign='middle'>";
		displayHtml += "<select id='kidBirthMonth" + this.currentIndex + "' name='kidBirthMonth" + this.currentIndex + "' onchange='childFormCollection.elementArray[" + this.currentIndex + "].birthMonth=this.value;childFormCollection.formModified = true;'>";
		displayHtml += "<option value=''>Month</option>";
		displayHtml += "<option value='1'>Jan</option>";
		displayHtml += "<option value='2'>Feb</option>";
		displayHtml += "<option value='3'>Mar</option>";
		displayHtml += "<option value='4'>Apr</option>";
		displayHtml += "<option value='5'>May</option>";
		displayHtml += "<option value='6'>Jun</option>";
		displayHtml += "<option value='7'>Jul</option>";
		displayHtml += "<option value='8'>Aug</option>";
		displayHtml += "<option value='9'>Sep</option>";
		displayHtml += "<option value='10'>Oct</option>";
		displayHtml += "<option value='11'>Nov</option>";
		displayHtml += "<option value='12'>Dec</option>";
		displayHtml += "</select>";
		displayHtml += "&nbsp;";
		displayHtml += "<select id='kidBirthYear" + this.currentIndex + "' name='kidBirthYear" + this.currentIndex + "' onchange='childFormCollection.elementArray[" + this.currentIndex + "].birthYear=this.value;childFormCollection.formModified = true;'>";
		displayHtml += "<option value='none'>Year</option>";
		displayHtml += "<option value='2009'>2009</option>";
		displayHtml += "<option value='2008'>2008</option>";
		displayHtml += "<option value='2007'>2007</option>";
		displayHtml += "<option value='2006'>2006</option>";
		displayHtml += "<option value='2005'>2005</option>";
		displayHtml += "<option value='2004'>2004</option>";
		displayHtml += "<option value='2003'>2003</option>";
		displayHtml += "<option value='2002'>2002</option>";
		displayHtml += "<option value='2001'>2001</option>";
		displayHtml += "<option value='2000'>2000</option>";
		displayHtml += "<option value='1999'>1999</option>";
		displayHtml += "<option value='1998'>1998</option>";
		displayHtml += "<option value='1997'>1997</option>";
		displayHtml += "<option value='1996'>1996</option>";
		displayHtml += "<option value='1995'>1995</option>";
		displayHtml += "<option value='1994'>1994</option>";
		displayHtml += "<option value='1993'>1993</option>";
		displayHtml += "<option value='1992'>1992</option>";
		displayHtml += "<option value='1991'>1991</option>";
		displayHtml += "<option value='1990'>1990</option>";
		displayHtml += "<option value='1989'>1989</option>";
		displayHtml += "<option value='1988'>1988</option>";
		displayHtml += "<option value='1987'>1987</option>";
		displayHtml += "<option value='1986'>1986</option>";
		displayHtml += "<option value='1985'>1985</option>";
		displayHtml += "<option value='1984'>1984</option>";
		displayHtml += "<option value='1983'>1983</option>";
		displayHtml += "<option value='1982'>1982</option>";
		displayHtml += "<option value='1981'>1981</option>";
		displayHtml += "<option value='1980'>1980</option>";
		displayHtml += "<option value='1979'>1979</option>";
		displayHtml += "<option value='1978'>1978</option>";
		displayHtml += "<option value='1977'>1977</option>";
		displayHtml += "<option value='1976'>1976</option>";
		displayHtml += "<option value='1975'>1975</option>";
		displayHtml += "<option value='1974'>1974</option>";
		displayHtml += "<option value='1973'>1973</option>";
		displayHtml += "<option value='1972'>1972</option>";
		displayHtml += "<option value='1971'>1971</option>";
		displayHtml += "<option value='1970'>1970</option>";
		displayHtml += "<option value='1969'>1969</option>";
		displayHtml += "<option value='1968'>1968</option>";
		displayHtml += "<option value='1967'>1967</option>";
		displayHtml += "<option value='1966'>1966</option>";
		displayHtml += "<option value='1965'>1965</option>";
		displayHtml += "<option value='1964'>1964</option>";
		displayHtml += "<option value='1963'>1963</option>";
		displayHtml += "<option value='1962'>1962</option>";
		displayHtml += "<option value='1961'>1961</option>";
		displayHtml += "<option value='1960'>1960</option>";
		displayHtml += "<option value='1959'>1959</option>";
		displayHtml += "<option value='1958'>1958</option>";
		displayHtml += "<option value='1957'>1957</option>";
		displayHtml += "<option value='1956'>1956</option>";
		displayHtml += "<option value='1955'>1955</option>";
		displayHtml += "<option value='1954'>1954</option>";
		displayHtml += "<option value='1953'>1953</option>";
		displayHtml += "<option value='1952'>1952</option>";
		displayHtml += "<option value='1951'>1951</option>";
		displayHtml += "<option value='1950'>1950</option>";
		displayHtml += "<option value='1949'>1949</option>";
		displayHtml += "<option value='1948'>1948</option>";
		displayHtml += "<option value='1947'>1947</option>";
		displayHtml += "<option value='1946'>1946</option>";
		displayHtml += "<option value='1945'>1945</option>";
		displayHtml += "<option value='1944'>1944</option>";
		displayHtml += "<option value='1943'>1943</option>";
		displayHtml += "<option value='1942'>1942</option>";
		displayHtml += "<option value='1941'>1941</option>";
		displayHtml += "<option value='1940'>1940</option>";
		displayHtml += "<option value='1939'>1939</option>";
		displayHtml += "<option value='1938'>1938</option>";
		displayHtml += "<option value='1937'>1937</option>";
		displayHtml += "<option value='1936'>1936</option>";
		displayHtml += "<option value='1935'>1935</option>";
		displayHtml += "<option value='1934'>1934</option>";
		displayHtml += "<option value='1933'>1933</option>";
		displayHtml += "<option value='1932'>1932</option>";
		displayHtml += "<option value='1931'>1931</option>";
		displayHtml += "<option value='1930'>1930</option>";
		displayHtml += "<option value='1929'>1929</option>";
		displayHtml += "<option value='1928'>1928</option>";
		displayHtml += "<option value='1927'>1927</option>";
		displayHtml += "<option value='1926'>1926</option>";
		displayHtml += "<option value='1925'>1925</option>";
		displayHtml += "<option value='1924'>1924</option>";
		displayHtml += "<option value='1923'>1923</option>";
		displayHtml += "<option value='1922'>1922</option>";
		displayHtml += "<option value='1921'>1921</option>";
		displayHtml += "<option value='1920'>1920</option>";
		displayHtml += "<option value='1919'>1919</option>";
		displayHtml += "<option value='1918'>1918</option>";
		displayHtml += "<option value='1917'>1917</option>";
		displayHtml += "<option value='1916'>1916</option>";
		displayHtml += "<option value='1915'>1915</option>";
		displayHtml += "<option value='1914'>1914</option>";
		displayHtml += "<option value='1913'>1913</option>";
		displayHtml += "<option value='1912'>1912</option>";
		displayHtml += "<option value='1911'>1911</option>";
		displayHtml += "<option value='1910'>1910</option>";
		displayHtml += "<option value='1909'>1909</option>";
		displayHtml += "<option value='1908'>1908</option>";
		displayHtml += "<option value='1907'>1907</option>";
		displayHtml += "<option value='1906'>1906</option>";
		displayHtml += "<option value='1905'>1905</option>";
		displayHtml += "<option value='1904'>1904</option>";
		displayHtml += "<option value='1903'>1903</option>";
		displayHtml += "<option value='1902'>1902</option>";
		displayHtml += "<option value='1901'>1901</option>";
		displayHtml += "<option value='1900'>1900</option>";
		displayHtml += "</select>";
		displayHtml += "&nbsp;";
		displayHtml += "<select id='kidGender" + this.currentIndex + "' name='kidGender" + this.currentIndex + "' onchange='childFormCollection.elementArray[" + this.currentIndex + "].gender=this.value;childFormCollection.formModified = true;'>";
		displayHtml += "<option value=''>Gender</option>";
		displayHtml += "<option value='Boy'>Boy</option>";
		displayHtml += "<option value='Girl'>Girl</option>";
		displayHtml += "</select>";
		displayHtml += "</td><td valign='middle'>&nbsp;<a href='javascript:childFormCollection.removeElement(" + this.currentIndex + ")'><img src='i/btns/kid_edit_del.gif' border='0' /></a>";
		displayHtml += "</td></tr></table>";
		displayHtml += "<div class='kidError'></div>";
		displayHtml += "</div>";
		return displayHtml;
	}
	this.setEditState = function() {
		
		if (this.gender == 'Boy') {
			document.getElementById("kidGender" + this.currentIndex).selectedIndex = 1;
		} else if (this.gender == 'Girl') {
			document.getElementById("kidGender" + this.currentIndex).selectedIndex = 2;
		}
		
		$("#kidBirthMonth" + this.currentIndex + " option[value='" + this.birthMonth + "']").attr({selected:"selected"});
		$("#kidBirthYear" + this.currentIndex + " option[value='" + this.birthYear + "']").attr({selected:"selected"});
		/*
		$("#kidBirthMonth" + this.currentIndex).rules("add", {
			 required: true,
			 digits: true,
			 messages: {
			   digits: "Please select month",
			   required: "Please select month"
			 }
		});
		*/
		$("#kidBirthYear" + this.currentIndex).rules("add", {
			 required: true,
			 digits: true,
			 messages: {
			   digits: "Please select year",
			   required: "Please select year"
			 }
		});
		$("#kidGender" + this.currentIndex).rules("add", {
			 required: true,
			 messages: {
			   required: "Please select gender"
			 }
		});
	}
	this.getDisplayState = function() {
		var displayHtml = "";
		displayHtml += "<div>gender:" + this.gender + "</div>";
		displayHtml += "<div>birthYear:" + this.birthYear + "</div>";
		displayHtml += "<div>birthMonth:" + this.birthMonth + "</div>";
		return displayHtml;
	}
}

function submitVote(url, itemid, score)
{
	$.get("controller?action=recommendItem",
		  {itemId:itemid, score:score},
		  function(xml){
			  jsonVote = $.xml2json(xml); 		
			  $('#pvote' + jsonVote.item.id + ' b').text(jsonVote.item.votecount);
			  
		  });
}

function trim(str) 
{
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);

  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);

  return str;
}

function regularExpression(value, expression)
{
	if(expression.test(value)) return true;

	return false;
}

function isValidURL(value)
{
	return regularExpression(value, 
		/^([hH][tT][tT][pP]s?)\:\/\/([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?\/?([a-zA-Z0-9\-\._\?\,\/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$/);
}

function isValidEmail(value)
{
	//return false;
	return regularExpression(value,/^[a-zA-Z0-9.%_\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,6}$/);
}

function activateKidEditor() {
	$('#profileAllKidsDiv').css({backgroundColor:'#DDDDDD'});
	editField('profileAllKids','allKids');
	childFormCollection.showEditState();
	childFormCollection.formModified = false;
	$('#addKid').css({display:'block'});
}

function deactivateKidEditor() {
	$('#profileAllKidsDiv').css({backgroundColor:'#FFFFFF'});
	$('#allKidsEdit').css({display:'none'});
	$('#addKid').css({display:'none'});
	$('.kidError').html("");
	$('#addKidError').html("");
	$("#profileAllKidsHide").css({display:"none"});
	$(".editLinks").css({display:"inline"});
	childFormCollection.elementArray.length = 0;
	initKidData();
	document.getElementById("addKidBirthMonth").selectedIndex = 0;
	document.getElementById("addKidBirthYear").selectedIndex = 0;
	document.getElementById("addKidGender").selectedIndex = 0;	
	
}

function handleKidSubmit(theFormCollection,theFormId) {
//	if (theFormCollection.formModified == true) {
//		$('#profileAllKids').submit();
		$('#addKid').submit();
//	} else {
//		deactivateKidEditor();
//	}
}