

function fixLines()
{
	var cells = document.getElementsByClassName('tdHalfHeight');
	for (var i = 0; i < cells.length; i++) {
		var cell = cells[i];
		var p = cell.parentNode.parentNode;
		if(p != null){
			var height = document.defaultView.getComputedStyle(p,"").getPropertyValue("height");
			if(height != null){
				height = height.replace("px", "");
				cell.style.height = Math.round(height / 2)+'px';
			}
		}
	}
}
		

// Pops Window
function popupWindow(URL,width,height) {
  day = new Date();
  id = day.getTime();
  var left = (screen.width-width)/2;
  var top = (screen.height-height)/2;
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "');");
}

// Pops Window
function popupStaticWindow(name,URL,width,height) {
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	var popup = window.open(URL, name, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
	if(popup.opener) popup.opener = self;
}

// restore tell friend text
function setInputText(field,text) {
	if (field.value == "") {
		field.value = text;
	}
}

// hide tell friend text
function clearInputText(field,text) {
	if (field.value == text) {
		field.value = "";
	}
}

function SetFactDate(BY,BM,BD,DY,DM,DD){
	if(document.ContactAddFact.facttypeid.options[document.ContactAddFact.facttypeid.selectedIndex].value == '7'){
	    if(BM){ document.ContactAddFact.month1.value = BM; }
		if(BD){ document.ContactAddFact.day1.value = BD; }
		if(BY){ document.ContactAddFact.year1.value = BY; }
	}else if(document.ContactAddFact.facttypeid.options[document.ContactAddFact.facttypeid.selectedIndex].value == '15'){
	    if(DM){ document.ContactAddFact.month1.value = DM; }
		if(DD){ document.ContactAddFact.day1.value = DD; }
		if(DY){ document.ContactAddFact.year1.value = DY; }
	}else{
		document.ContactAddFact.month1.value = 'mm';
		document.ContactAddFact.day1.value = 'dd';
		document.ContactAddFact.year1.value = 'yyyy';
	}
}

// navigates using menu
function menu_nav(url) {
  if(url!=""){window.location.href=url;}
}

// navigates using menu
function delete_warning(type,url) {
	if(type=="forum"){
		resp1 = confirm("Are you sure you want to permanently delete this forum? All topics and posts will be lost.");
	}
	if(type=="family"){
		resp1 = confirm("Are you sure you want to delete this family page? All information, news, guestbook entries, and photo galleries for this page will be lost.");
	}
	if(type=="gallery"){
		resp1 = confirm("Are you sure you want to delete this photo gallery? All photos and information will be lost.");
	}
	if(type=="contact"){
		resp1 = confirm("Are you sure you want to permanently delete this family member? All information and photos will be lost.");
	}
	if(type=="fact"){
		resp1 = confirm("Are you sure you want to permanently delete this fact? All information and photos attached to this fact only will be lost.");
	}
	if(type=="wordlist"){
		resp1 = confirm("Are you sure you want to permanently delete this word list? All words in your word search will be lost.");
	}
	if (resp1 == true){
		resp2 = confirm("Are you sure?");
		if(resp2 == true){
			window.location.href=url;
		}
	}
}

// check all approve boxes
function CheckAll(FormName,InputName,Max) {
  for(i=1; i <= Max; i++){
  	eval("document."+FormName+"."+InputName+"_" + i + ".checked = true;");
  }
}

// uncheck all approve boxes
function UncheckAll(FormName,InputName,Max) {
  for(i=1; i <= Max; i++){
  	eval("document."+FormName+"."+InputName+"_" + i + ".checked = false;");
  }
}

function array2json(arr) {
    var parts = [];
    var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');

    for(var key in arr) {
    	var value = arr[key];
        if(typeof value == "object") { //Custom handling for arrays
            if(is_list) parts.push(array2json(value)); /* :RECURSION: */
            else parts[key] = array2json(value); /* :RECURSION: */
        } else {
            var str = "";
            if(!is_list) str = '"' + key + '":';

            //Custom handling for multiple data types
            if(typeof value == "number") str += value; //Numbers
            else if(value === false) str += 'false'; //The booleans
            else if(value === true) str += 'true';
            else str += '"' + value + '"'; //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)

            parts.push(str);
        }
    }
    var json = parts.join(",");
    
    if(is_list) return '[' + json + ']';//Return numerical JSON
    return '{' + json + '}';//Return associative JSON
}
/**
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'http://code.jquery.com/jquery-latest.js';
head.appendChild(script);
$.noConflict();
**/
