
function changeImg(imgold,imgnew)
{
	//alert(imgold.src);
	imgold.src = imgnew;
}

function pause(numberMillis)
{
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true)
    {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

//  check for unacceptable characters
function NonAcceptableChars(strString)
{
	// strValidChars copntains list of unacceptable characters
	var strValidChars = " ";
	var strChar;
	var blnResult = true;

	//  test strString consists of unacceptable characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == 0)
	 	{
	 		blnResult = false;
	 	}
  }
	return blnResult;
}

function IsNumeric(strString)
//  check for valid numeric strings
{
	var strValidChars = "0123456789 ";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	 {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
		 	blnResult = false;
		}
	 }
	return blnResult;
}


function NewImage(arg)
{
	if (document.images)
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function ChangeImage()
{
	if (document.images && (preloadFlag == true))
	{
		for (var i=0; i<ChangeImage.arguments.length; i+=2)
		{
			document[ChangeImage.arguments[i]].src = ChangeImage.arguments[i+1];
		}
	}
}

function HighlightField(objField)
{
	objField.style.border = "1px solid #ff0000";
	objField.style.padding = "1px";
	objField.style.margin = "1px 0 1px 0";
	objField.select();
	objField.focus();
}

function FlashManager(strFile, intWidth, intHeight, strBackgroundColour)
{
	//
	// location.protocol added to cover http and https
	//
	var window_mode = 'transparent' //set this to transparent to make flash movie sit in the document order correctly

	document.write('<object\n');
	document.write('id="RokVSA"\n');
	document.write('classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n');
	document.write('codebase="'+location.protocol+'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"\n');
	document.write('width="'+intWidth+'"\n');
	document.write('height="'+intHeight+'"\n');
	document.write('align="center">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="'+strFile+'" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="bgcolor" value="'+strBackgroundColour+'" />\n');
	document.write('<param name="wmode" value="'+window_mode+'" />\n');
	document.write('<embed\n');
	document.write('src="'+strFile+'"\n');
	document.write('quality="high"\n');
	document.write('bgcolor="'+strBackgroundColour+'"\n');
	document.write('width="'+intWidth+'"\n');
	document.write('height="'+intHeight+'"\n');
	document.write('name="ROK TV"\n');
	document.write('align="left"\n');
	document.write('wmode="'+window_mode+'"\n');
	document.write('allowScriptAccess="sameDomain"\n');
	document.write('type="application/x-shockwave-flash"\n');
	document.write('pluginspage="'+location.protocol+'//www.macromedia.com/go/getflashplayer"\n');
	document.write('/>\n');
	document.write('</object>\n');
}

// var objWidth = new Object();
// objWidth["stringValue"] = "mystring";

//
// Creates an editable row
// Implementation:
// Ensure the table is nested inside a form tag and
// ...each td tag has a width setting
// The edit field must have an id of 'updateurl'
// The delete field must have an id of 'deleteurl'
// arg 1: The name/id of the form
// arg 2: The name/id of the database id
// arg 3: The id value of this particularly row
// arg 4: csv list of fields needing text area
// arg 5: the number of rows needed for the text field
//
var blnEdit = false;
function EditRow(strIdFieldName, intIdValue, csvTextAreaList, intTextAreaRows, strRequiredQueryStringItem)
{
	if (blnEdit)
	{
		alert(_TXT1); // Another row already being edited
		return false;
	}
	else
	{
		blnEdit = true;
	}

	// Create array of the fields needing text areas, otherwise defauts to normal text field
	arrTextAreaList = csvTextAreaList.split(",");

	// Get the row
	var objRow = document.getElementById(intIdValue);
	var rowId = null;

	// Get cells from the row
	if (objRow)
	{
		var objCell = objRow.getElementsByTagName("td");
		var strOutput = "";

		for(var i = 0; i < objCell.length; i++)
		{
			var arrTmp = objCell[i].id.split("-");
			var strFieldName = arrTmp[0];

			// Sort out the columns
			if (strFieldName == null || strFieldName == "") continue;
			else if(strFieldName == strIdFieldName) // The hidden non-editable field with the row id
			{
				objCell[i].innerHTML = objCell[i].innerHTML+' <input type="hidden" name="'+strFieldName+'" value="'+objCell[i].innerHTML+'" />';
			}
			else if(strFieldName == "deleteurl") // The delete cell, converted to a cancel button
			{
				objCell[i].innerHTML = '<a href="'+location.pathname+'?'+strRequiredQueryStringItem+'">'+_TXT2+'</a>'; // Cancel
			}
			else if(strFieldName == "updateurl") // The edit cell, converted to save button
			{
				objCell[i].innerHTML = '<input type="submit" value="'+_TXT3+'" style="width:'+(objCell[i].width-6)+'px;margin:0;cursor:pointer" />'; // Save
			}
			else if (InArray(strFieldName, arrTextAreaList)) // an editable field. uses text area
			{
				if (intTextAreaRows == undefined) intTextAreaRows = 3;
				objCell[i].innerHTML = '<textarea name="'+strFieldName+'" rows="'+intTextAreaRows+'" style="width:'+(objCell[i].width-8)+'px;">'+objCell[i].innerHTML+'</textarea>';
			}
			else // an editable field
			{
				var objCellChild = objCell[i].getElementsByTagName("Select");
				if (objCellChild.length > 0) objCellChild[0].disabled = false; // Only concerned with first element
				else objCell[i].innerHTML = '<input type="text" name="'+strFieldName+'" value="'+objCell[i].innerHTML+'" style="width:'+(objCell[i].width-8)+'px;" />';
			}
		}

		// For debugging
		// alert(strOutput);
	}
	return false;
}

// Typical usage
// var messages = new makeArray(COMMA SEPARATED LIST AS ARGUMENTS HERE);
function CsvToArray()
{
	arrTmp = new Array();
	for (var i = 0; i < CsvToArray.arguments.length; i++)
		arrTmp[i] = CsvToArray.arguments[i];
	return arrTmp;
}

function InArray(strSource, arrTarget)
{
	if (strSource == "") return false;
	else if (arrTarget.length == 0) return false;

	for (var i = 0; i < arrTarget.length; i++)
	{
		if (arrTarget[i] == undefined) continue;
	  	else if (arrTarget[i] == strSource) return true;
	}
	return false;
}

function DropDownGoTo(strName, selObj)
{
	var strDestination = location.pathname + "?"+strName+"="+selObj.options[selObj.selectedIndex].value;
	location.href = strDestination.substr(1); // Remove forward slash
}

function OpenWin(theURL,winName, wWidth, wHeight, withScrollbars, withResizeable, horzPos, vertPos, boolSetCookie)
{
	winHandle = '';
	vAdjustment = -50;
	if (horzPos == "" && vertPos == "")
	{
		if (screen)
		{
			horzPos = Math.ceil((screen.width - wWidth)/2);
			vertPos = Math.ceil((screen.height - wHeight)/2) + vAdjustment;
		}
		else
		{
			horzPos = 0;
			vertPos = 0;
		}
	}
	winChild = window.open(theURL, winName,'toolbar=no,location=no,scrollbars='+withScrollbars+',resizable='+withResizeable+',width='+wWidth+',height='+wHeight+', left='+horzPos+', top='+vertPos+'');
	setTimeout("winChild.focus()", 500);
	if (boolSetCookie) SetCookie("childWinUrl", theURL, 24);
}

function ShowHideObj(linkObj, objId, strShowText, strHideText)
{
	var objItem = document.getElementById(objId);

	if (objItem.style.display == "none")
	{
		objItem.style.display = "block";
		linkObj.innerHTML = strHideText;
	}
	else
	{
		objItem.style.display = "none";
		linkObj.innerHTML = strShowText;
	}

	return false;
}

function GoTo(strLocation)
{
	location.href = strLocation;
	return false;
}

function ManageCss(strObName, strNewClassName)
{
	var objMenu = document.getElementById(strObName);
	if(objMenu != null)
	{
		var strCurrUri = window.location.pathname.toLowerCase().replace("/", "");

		// Check for parent menu to override
		if (parentUrl != "")
		{
			if (parentUrl != strCurrUri) strCurrUri = parentUrl;
		}

		var arrA = objMenu.getElementsByTagName("a");
		var strAnchorHref = null;
		for(var i=0; i< arrA.length;i++)
		{
			strAnchorHref = arrA[i].href.toLowerCase().replace("//", "").replace("/", "").replace(window.location.hostname, "").replace(window.location.protocol, "");
			// alert(strAnchorHref +" : " + strCurrUri);
			if (strAnchorHref == strCurrUri)
			{
				arrA[i].className = strNewClassName;
			}
		}
	}
}

function InArray(strValue, arrArray)
{
	for(i = 0; i < arrArray.length; i++)
	{
		if (strValue == arrArray[i]) return true;
	}
	return false;
}

function AddSlashes(str)
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function StripSlashes(str)
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

//
// Typical Usage
//
/*
var page = new PageQuery(location.search);
var myValue = page.getValue("a");
if (myValue == "-1") myValue = "history.html";
*/
function PageQuery(q)
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q)
	{
		for(var i=0; i < this.q.split("&").length; i++)
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return -1;
	}
	this.getParameters = function()
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
     this.getLength = function() { return this.keyValuePairs.length; }
}

function IsUsernameType(arg1)
{
	var re = /^[a-z0-9_]{6,12}$/;
	if (re.test(arg1)) return true;
	return false;
}

// Button should be verdana and have a width of at least 100px
function DisableButton(btnObj, strTxt)
{
	if (btnObj != null)
	{
		btnObj.disabled = true;
		// btnObj.style.fontFamily = "Verdana";
		if (strTxt == "") btnObj.value = "One moment ...";
		else btnObj.value = strTxt;
		btnObj.style.cursor = "wait";
	}
}

