function popup(theURL,winName,width,height,features) {
 
var window_width = width;
var window_height = height;
var newfeatures= features;
var window_top = (screen.height-window_height)/2;
var window_left = (screen.width-window_width)/2;
newWindow=window.open(''+ theURL + '','Window','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',' + newfeatures + '');
newWindow.focus();
}

function setHomePage() { 
	if (window.external) 
	{ 
		document.body.style.behavior='url(#default#homepage)';
   		document.body.setHomePage(window.location.href);
	} 
	else 
	{ 
		alert("To set this page as your Home Page drag the Bookmark icon over the home icon in the toolbar");
	} 
}


function nu_create_window(w,h,url)
{

var options = "width=" + w + ",height=" + h + ",resizable=no";
var new_window = window.open(url, "new_window", options);

}

function nu_changeText(id,newtext)
{
	var f, obj;
	if ((obj=findObj(id))!=null)
	{
		
		obj.innerHTML=newtext;
	}

}
function nu_hideObject(id)
{
	var f, obj;
	if ((obj=findObj(id))!=null)
	{
		
		obj.visible=newtext;
	}

}


var validNums = '0123456789.'; 
var validInt = '0123456789'; 
var validLetters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 

function nu_validateKeyPress(e, validSet) 
{ 
    var key; 
    var keychar; 
         
    if(window.event || !e.which) // IE 
        key = e.keyCode; // IE 
    else if(e) 
        key = e.which;   // Netscape 
    else 
        return true;     // no validation 

    keychar = String.fromCharCode(key); 
    validSet += String.fromCharCode(8); 

    if (validSet.indexOf(keychar) < 0) 
      return false; 

    return true; 
} 
function nu_changeMeasure(f, imperial)
{
	//this will change the measures to the 
	//required labels
	//the label ids on the page must match these setup
	var obj;
	
	if(!imperial)
	{
		nu_changeText('heightlabel1','ft');
		nu_changeText('heightlabel2','ins');			
		nu_changeText('weightlabel1','st');			
		nu_changeText('weightlabel2','lbs');			
		showHideLayers('weightlabel2','show');
		showHideLayers('txtweight2','show');
		nu_changeText('measurechange','Click here to change to metric');			
		nu_changeText('weightloss1','1/2 lb');			
		nu_changeText('weightloss2','1 lb');			
		nu_changeText('weightloss3','1 1/2 lb');			
		nu_changeText('weightloss4','2 lb');			
		f.ismetric.value="0"
	}
	else
	{
		nu_changeText('heightlabel1','m');
		nu_changeText('heightlabel2','cm');			
		nu_changeText('weightlabel1','kg');			
		showHideLayers('weightlabel2','hide');
		showHideLayers('txtweight2','hide');
//		nu_changeText('weightlabel2','&nbsp;g&nbsp;');			
		nu_changeText('measurechange','Click here to change to imperial');			
		nu_changeText('weightloss1','0.23 kg');			
		nu_changeText('weightloss2','0.46 kg');			
		nu_changeText('weightloss3','0.69 kg');			
		nu_changeText('weightloss4','0.92 kg');		
		
		
		f.ismetric.value="1"
	}

	
}


function isDate(DateToCheck){
if(DateToCheck==""){return false;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function


function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}
function showHideLayers(name,visStr)
{ 
 
  var i, visStr, obj, args = showHideLayers.arguments;


    if ((obj = findObj(name)) != null)
    {

      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }

}
function createYESNO(text, image,yesfunction)
{
	var box = document.createElement("div");
	box.id = "YESNO";
	box.innerHTML="<div style=\"position:absolute;left:12px;top:17px;width:150px\"><img border=\"0\" src=\"" + image + "\" ></div><div style=\"position:absolute;left:80px;top:15px;width:150px\"><p>" + text + "</p></div><div style=\"position:absolute;left:60px;top:55px;width:150px\"><a href=\"javascript:" + yesfunction + "()\"><img class=\"yesno_yes\" border=\"0\" src=\"/media/images/2/buttons/deletepanelyes.gif\" ></a><a href=\"javascript:removeYESNO();\"><img class=\"yesno_no\" border=\"0\"  src=\"/media/images/2/buttons/deletepanelno.gif\" ></a></div>";
	if( typeof( window.innerWidth ) == 'number') {
		box.style.top = (window.innerHeight/2 - 50) + "px";
		box.style.left = (window.innerWidth/2 - 118)  + "px";
	}
	else{
	 box.style.top = (document.documentElement.clientHeight/2 - 50) + "px";
     box.style.left = (document.documentElement.clientWidth/2 - 118) + "px";		
	}
	document.body.appendChild(box);
}
function removeYESNO()
{
	var box = document.getElementById("YESNO");
	if(box)
	{
		document.body.removeChild(box);
	}
}

