
function dataMediaFullViewFromHiddenItem(itemID, sectionID, width, height)
{
	var tempObj = document.getElementById(itemID);
	pmPop('http://www.kidzango.com/pm/' + sectionID + '/dataID' + tempObj.value, width, height);	
}
function openDiv(divID)
{
	var tempObj = document.getElementById(divID);
	tempObj.style.visibility = 'visible';
	return false;
}
function deleteData(rowID, tableName)
{
	if(confirm("Are you sure that you want to delete this piece of data?"))
	{
		var tempObj = document.getElementById('delete_rowID');
		tempObj.value = rowID;
		
		tempObj = document.getElementById('delete_tableName');
		tempObj.value = tableName;
		
		tempObj = document.getElementById('refreshForm_deleteDataForm');
		tempObj.submit();
	}
	return false;
}

function deleteCartData(tableName, rowID)
{
	if(confirm("Are you sure that you want to remove this item?"))
	{
		var tempObj = document.getElementById('delete_CartSysRowID');
		tempObj.value = rowID;
		tempObj = document.getElementById('delete_CartTableName');
		tempObj.value = tableName;
		tempObj = document.getElementById('refreshForm_deleteCartDataForm');
		tempObj.submit();
	}
	return false;
}

function exportDataPage()
{
	pmPop('/include/dataExport.aspx?isFullPage=0', 530, 200);
	return false;
}

function exportDataSet()
{
	pmPop('/include/dataExport.aspx?isFullPage=1', 530, 200);
	return false;
}

function refreshPageIsDate(formID, currentPage, theItem)
{
	if(isDate(theItem) == false)
	{
	}
	else
	{
		var tempObj = document.getElementById(formID);
		tempObj.action = currentPage;
		tempObj.submit();
	}
}

function refreshPage(formID, currentPage)
{
	var tempObj = document.getElementById(formID);
	tempObj.action = currentPage;
	tempObj.submit();
}

function refreshCapturePage(formID, currentPage)
{	
	var tempObj = document.getElementById('isRefresh');
	tempObj.value = '1';

	tempObj = document.getElementById(formID);
	tempObj.action = currentPage;
	
	tempObj.submit();
}
function refreshSearchPage(formID)
{
	var tempObj = document.getElementById(formID);
	tempObj
}

function resizeScreen(resizeX, resizeY)
{
	window.resizeTo(resizeX,resizeY);
}


function checkFormItems(requiredColumnNames, requiredColumnDisplayNames, isExistingUser, formID)
{
	// split them into an array and check...
	arrayOfColumnNames = requiredColumnNames.split(',');
	arrayOfDisplayName = requiredColumnDisplayNames.split(',');
	
	var tempFlag = false;
	var columnName = ''
	for (var i=0; i < arrayOfColumnNames.length; i++) 
	{
		var tempObj = document.getElementById(arrayOfColumnNames[i]);
		var pos = arrayOfColumnNames[i].indexOf('_');
		columnName = arrayOfColumnNames[i].substring(pos+1);
		
		if(tempObj)
		{
			if(isExistingUser && columnName == 'password')
			{
				if(tempObj.value != '')
				{
					var confirmNewPass = prompt("Please confirm your new password:", "");
					if(confirmNewPass != tempObj.value)
					{
						alert('You have not correctly confirmed your new password!\nPlease try again.');
						tempObj.select();
						tempObj.focus();
						return false;
					}
				}				
			}
			else
			{
				switch(tempObj.type)
				{
					case 'checkbox' :
						// if checkbox is required then must be checked....
						if(tempObj.checked)
						{}
						else
						{
							checkFormItemsError(arrayOfDisplayName[i]);
							tempObj.select();
							tempObj.focus();
							return false;
						}
						break;
					case 'select-one' :
						if(tempObj.options[tempObj.selectedIndex].value == '')
						{
							checkFormItemsError(arrayOfDisplayName[i]);
							tempObj.focus();
							return false;
						}
						break;
					case 'select-multiple' :
						if(tempObj.type == 'select-multiple')
						{
							tempFlag = false;
							for(c=0; c< tempObj.options.length; c++)
							{
								if(tempObj.options[c].selected && tempObj.options[c].value != '')
								{
									tempFlag = true;
								}
							}
							
							if(tempFlag == false)
							{
								checkFormItemsError(arrayOfDisplayName[i]);
								tempObj.focus();
								return false;
							}
						}
						break;
					case 'hidden' :
						break;
						
					default :
						if(tempObj.value == '')
						{
							checkFormItemsError(arrayOfDisplayName[i]);
							tempObj.select();
							tempObj.focus();
							return false;
						}
					
				}
			}
		}
	}

	// need to disable the all submit buttons...
	tempObj = document.getElementsByName('submitItem');
	for(c=0;c<tempObj.length;c++)
	{
		tempObj[c].disabled=true;
	}
	

	// return true if all passed
	return true;
}
function checkFormItemsError(message)
{
	alert('Please complete:\n\n' + message);
	return false;
}

function gotoDataPage(dataMedia_searchResults_screen_id, pageNum)
{
	//var tempObj= document.getElementById('dataPage_' + dataMedia_searchResults_screen_id)
	//tempObj.value = pageNum;

	tempObj = document.getElementsByName('dataPage_' + dataMedia_searchResults_screen_id);
	for(c=0;c<tempObj.length;c++)
	{
		tempObj[c].value = pageNum;
	}


	var tempObj = document.getElementById('dataMediaSearchResultsScreen_' + dataMedia_searchResults_screen_id);
	tempObj.submit();
	return false;
}


var storeID;
function launchCal(dropItem)
{

	var tempObj = document.getElementById(dropItem);
	var selectedDate = '';
	if(checkDate(tempObj.value))
	{
		// is a valid date
		selectedDate = tempObj.value;
	}	
	storeID = dropItem;
	var width = 165;
	var height = 175;

	var pmCal = window.open('/include/calendar.aspx?currentDate=' + escape(selectedDate), "pmCal",
			      "toolbar=no,menubar=no,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=no,resizable=no");
	return false;
}

function calendarCallback(day, month, year)
{
	var tempObj = document.getElementsByName(storeID);
	for(c=0;c<tempObj.length;c++)
	{
		tempObj[c].value = day + '/' + month + '/' + year;
	}
}

function printFriendly(section_id, title, article_id, sessionID)
{
	var width = 600;
	var height = 550;

	var pmPrint = window.open('/print/' + section_id + '/' + escape(title) + '/' + article_id, "pmPrint",
			      "toolbar=yes,menubar=yes,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=yes,resizable=no");
	return false;
}

function emailFriend(title, article_id)
{
	var width = 400;
	var height = 350;

	var pmEmailArticle = window.open('/util_email_article.aspx?article_title=' + escape(title) + '&article_id=' + article_id, "pmEmailArticle",
			      "toolbar=no,menubar=no,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=yes,resizable=no");
	return false;
}
function submitForm(formID)
{
	eval('document.' + formID + '.submit();');
	return false;
}
function submitFormWithPopup(formID, width,height)
{
	var formPop = window.open("about:blank", "formPop",
			      "toolbar=no,menubar=no,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=no,resizable=yes");
	eval('document.' + formID + '.submit();');
	return false;
}
function register(formID)
{
	eval('document.' + formID + '.submit();');
	return false;
}
function logon(formID)
{
	eval('document.' + formID + '.submit();');
	return false;
}
function pmPop(url, width, height)
{
	var pmPop = window.open(url, "pmPop",
			      "toolbar=no,menubar=no,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=yes,resizable=yes");
	return false;
}
function pmPopForm(theForm, width, height)
{
	var formPop = window.open("about:blank", "formPop",
			      "toolbar=no,menubar=no,personalbar=no,width=" + width + ",height=" + height + "," +
			      "scrollbars=no,resizable=yes");
	return true;
}
function pmPopForm2(theFormID)
{
	var tempObj = document.getElementById(theFormID);
	tempObj.submit();
	return false;
}

function menuMouseAction(theItem, theAction, menuItemID)
{
	if(theAction == 'DOWN')
	{
		theItem.src = eval('menuItem' + menuItemID + '_down.src');
	}
	if(theAction == 'OVER')
	{
		theItem.src = eval('menuItem' + menuItemID + '_over.src');
	}
}


function alphaClick(theLetter, resultsID)
{
	var tempObj = document.getElementById("article_results_alpha_" + resultsID);
	tempObj.value = theLetter;

	var tempObj = document.getElementById("article_results_page_" + resultsID);
	tempObj.value = '1';

	var tempObj = document.getElementById("article_results_form_" + resultsID);
	tempObj.submit();

	return false;	
}

function nextPage(maxPages, pageNum, resultsID)
{
	if(Number(maxPages) < Number(pageNum)+1)
	{
		alert("There are no more results!");
	}
	else
	{
		var tempObj = document.getElementById("article_results_page_" + resultsID);
		tempObj.value = Number(pageNum)+1;

		var tempObj = document.getElementById("article_results_form_" + resultsID);
		tempObj.submit();

	}
	return false;
}

function previousPage(maxPages, pageNum, resultsID)
{
	if(pageNum == '1')
	{
		alert("You are already at the first page of results!");
	}
	else
	{
		var tempObj = document.getElementById("article_results_page_" + resultsID);
		tempObj.value = Number(pageNum)-1;
		
		var tempObj = document.getElementById("article_results_form_" + resultsID);
		tempObj.submit();
	}
	return false;	
}

function articleSimpleListViewer(theItem)
{
	if(theItem.value == '')
	{}
	else
	{
		viewArticle(theItem.value);
	}
}

function viewArticle(aritcleID)
{
	document.location.href=("/pma/" + aritcleID);
}

// validation routines...

function isDate(theItem)
{

	if(checkDate(theItem.value))
	{
	}
	else
	{
		alert("Please enter a valid Date for this item in DD/MM/YY format!");
		theItem.select();
		theItem.focus();
		return false;
	}	
}

function isEmail(theItem)
{
	if(isEmailAddr(theItem.value))
	{
	}
	else
	{
		alert("Please enter a valid e-Mail address for this item");
		theItem.select();
		theItem.focus();
		return false;
	}
	
}


function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}



function checkDate(dateVal)
{
	if(dateVal == '')
	{
		return true;
	}
	
	arrayOfStrings = dateVal.split("/");


	if(arrayOfStrings.length < 3)
	{
		return false;
	}

	if(isNaN(arrayOfStrings[0]) || isNaN(arrayOfStrings[1]) || isNaN(arrayOfStrings[2]))
	{
		return false
	}

	if(arrayOfStrings[0] > 31 || arrayOfStrings[1] > 12 )
	{
		return false;
	}

	maxDays = getDays(new Number(arrayOfStrings[1]), new Number(arrayOfStrings[2]));

	if(arrayOfStrings[0] > maxDays)
	{
		return false;
	}

	return true;
}

function getDays(month, year) {
  // create array to hold number of days in each month
  var ar = new Array(12);
  ar[1] = 31; // January
  ar[2] = (leapYear(year)) ? 29 : 28; // February
  ar[3] = 31; // March
  ar[4] = 30; // April
  ar[5] = 31; // May
  ar[6] = 30; // June
  ar[7] = 31; // July
  ar[8] = 31; // August
  ar[9] = 30; // September
  ar[10] = 31; // October
  ar[11] = 30; // November
  ar[12] = 31; // December

  // return number of days in the specified month (parameter)
  return ar[month];
}

function leapYear(year) {
  if (year % 4 == 0) {// basic rule
    return true; // is leap year
  }
  /* else */ // else not needed when statement is "return"
  return false; // is not leap year
}


function validateKeypress(evnt,theItem,maxLength,validateType,maxLengthType)
{
	//
	// validateType:
	//
	//		ALL
	//		NUMERIC
	//		NOSPACE
	//		
	if(evnt.which)
	{
		// netscape/mozilla...
		var keyCode = evnt.which;
	}
	else
	{
		// ie...
		var keyCode = evnt.keyCode;
	}
	

	inValidItem = false;
	switch(validateType)
	{

		case 'NUMERIC':
			if((keyCode > 46 && keyCode < 59) || keyCode==8 || keyCode == 45  )
			{
			}
			else
			{
				inValidItem =  true;
			}
			break;
			
		case 'NUMERIC2':
			// allow the use of the '.' character
			if((keyCode > 46 && keyCode < 59) || keyCode==8 || keyCode==46 || keyCode == 45 )
			{
			}
			else
			{
				inValidItem = true;
			}
			break;

		case 'NOSPACE':
			if(keyCode == 32)
			{
				inValidItem = true;
			}
			break;
			
		case 'ALPHANUMERIC':
			
			if( (keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91) || (keyCode > 96 && keyCode < 123) || keyCode == 95 )
			{
			}
			else
			{
				inValidItem = true;
			}
			break;
	}
	theData = theItem.value

	if(inValidItem == false)	
	{

		if(maxLengthType == 1)
		{
			if(countWords(theData) > maxLength)
			{
				alert("The maximum number of words permitted for this item is: " + maxLength + ".");
				inValidItem = true;
			}
		}
		else
		{
			if(theData.length < maxLength)
			{
				inValidItem = false;
			}
			else
			{
				alert("The maximum size for this item is: " + maxLength + " characters!");
				inValidItem =  true;
			}
		}
	}

	if(inValidItem)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function inValidItem(theData,maxLength, validateType)
{	
}

function validatePaste(evnt,theItem, maxLength, validateType, maxLengthType)
{
	var theData = window.clipboardData.getData("Text");
	var isValid = true;

	switch(validateType)
	{
		case 'NUMERIC':
			if(isNaN(theData))
			{
				isValid = false;
			}
			else
			{
				if(theData.indexOf('.') > -1)
				{
					isValid = false;
				}
			}
			break;
			
		case 'NUMERIC2':
			// allow the use of the '.' character
			if(isNaN(theData))
			{
				isValid=false;
			}
			break;

		case 'NOSPACE':
			re = /[\s]/gi;
			var tempStr = theData.replace(re,"");
			theData = tempStr;
			window.clipboardData.setData("Text", tempStr);	
			break;								
	}

	if(isValid)
	{
		if(maxLengthType == 1)
		{	
			var wordCount = countWords(theData);
			if(wordCount > maxLength)
			{
				alert("The maximum number of words permitted for this item is: " + maxLength + ", the text you are trying to paste contains " + wordCount + " words.");
				return false;
			}
		}
		else
		{
			if(theData.length + theItem.value.length <= maxLength)
			{
			}
			else
			{
				alert("The maximum size for this item is: " + maxLength + " characters!");
				return false;
			}
		}
	}
	else
	{
		alert("The content in the clipboard is invalid for this item");
		return false;
	}
}


function countWords(theValue)
{
	var fullStr = theValue;
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length;
	return word_count;
}



// popup menus
var zindex=100
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
var opr=navigator.userAgent.indexOf("Opera")

function dropit(e,whichone)
{
	curmenuID=ns6? document.getElementById(whichone).id : eval(whichone).id;
	if (window.themenu&&themenu.id!=curmenuID)
	themenuStyle.visibility=ns4?"hide" : "hidden";

	themenu=ns6? document.getElementById(whichone): eval(whichone);
	themenuStyle=(ns6||ie4)? themenu.style : themenu;

	themenuoffsetX=(ie4&&opr==-1)? document.body.scrollLeft : 0;
	themenuoffsetY=(ie4&&opr==-1)? document.body.scrollTop : 0;

	themenuStyle.left=ns6||ns4? e.pageX-e.layerX+51 : themenuoffsetX+event.clientX-event.offsetX+50;
	themenuStyle.top=ns6||ns4? e.pageY-e.layerY+8 : themenuoffsetY+event.clientY-event.offsetY+4;

	hiddenconst=(ns6||ie4)? "hidden" : "hide";
	
	if (themenuStyle.visibility==hiddenconst)
	{
		themenuStyle.visibility=(ns6||ie4)? "visible" : "show";
		themenuStyle.zIndex=zindex++;
	}
	else
	{
		hidemenu();
	}
	
	return false
}

function hidemenu()
{
	if ((ie4||ns6)&&window.themenu)
		themenuStyle.visibility="hidden";
	else if (ns4)
		themenu.visibility="hide";
}

if (ie4||ns6)
document.onclick=hidemenu


// -----------  New menu functions
// --------------------------------------------------------------------------------------------

content = new Array ();

// Adjustable params
/*
content [0] = new Array (
false, 							// opening status in the first page viewing
new Array('sub_0_1','sub_0_2')  // subitems, note! the first index is the same as in content []
);
content [1] = new Array (
false, 							// opening status in the first page viewing
new Array('sub_1_1','sub_1_2')  // subitems, note! the first index is the same as in content []
);
content [2] = new Array (
false, 							// opening status in the first page viewing
new Array('sub_2_1','sub_2_2')  // subitems, note! the first index is the same as in content []
);
*/

isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
isIE    = (document.all && !isOPERA)? true : false;
isDOM   = (document.getElementById && !isIE && !isOPERA)? true : false;


function processTree (id)
{
	if (content [id][0])
	{
		for (i = 0; i < content [id][1].length; i++)
			hide (content [id][1][i]);

		content [id][0] = false;
	}
	else
	{
		for (i = 0; i < content [id][1].length; i++)
			show (content [id][1][i], 'table-row');

		content [id][0] = true;
	}

	return false;
}

function show (id, displayValue)
{
	if (isDOM)
		document.getElementById(id).style.display = (displayValue)? displayValue : "block";
		
	else if (isIE)
		document.all[id].style.display = "block";

}

function hide (id)
{
	if (isDOM)
		document.getElementById(id).style.display = "none";
	else if (isIE)
		document.all[id].style.display = "none";
}

if (isDOM || isIE)
{
	document.writeln('<style type="text/css">');
	document.writeln('.SubItemRow \{ display: none;  \}');
	document.writeln('</style>');
}

// --------------------------------------------------------------------------------------------

