function confirmAction( str)
{
	var retVal = confirm(str);
	return retVal;
}

function getPath()
{
	//todo - improve this to work on windows and mac!
	
	//strip path 
	var endString =  document.forms.edit_member_form.photo_file.value.split('/');
	document.forms.edit_member_form.photo_path.value = endString[endString.length-1];
}

function go_to(url)
{
	window.location = url;
	
}

function add_string(query, url, encode)
{
	var str = prompt (query,"");
	if((str!='') && (str!=null))
	{
		go_to(url+"&"+encode+"="+str); 
	}
}

function numbersonly(myfield, e, dec,space,forslash)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;

//cursor keys
if ((key>36) && (key< 41))
   return true;

//mac cursor keys
if ((key>63231) && (key< 63236))
   return true;

//mac delete
if ((key==63272) )
   return true;

// numbers
else if (space && (keychar == " "))
   return true;

// numbers
else if (forslash && (keychar == "/"))
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   return true;
   }
else
   return false;
}

function validateDate(dtStr)
{
	function daysInFebruary (year)
	{
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}

	function DaysArray(n) 
	{
		var retVal = new Array();
		for (var i = 1; i <= n; i++) 
		{
			retVal[i] = 31;
			if (i==4 || i==6 || i==9 || i==11) 
			{
				retVal[i] = 30;
			}
			if (i==2) 
			{
				retVal[i] = 29;
			}
	   } 
	   return retVal;
	}
	
	// Declaring valid date character, minimum year and maximum year
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var error_in_slashes = dtStr.indexOf(dtCh,pos2+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;


	if(strMonth.length>2 || strDay.length>2 || strYear.length != 4)
	{
			alert("Please Enter Valid Date");
			return false;
	}

	if (strDay.charAt(0)=="0" && strDay.length>1) 
		strDay=strDay.substring(1);
		
	if (strMonth.charAt(0)=="0" && strMonth.length>1) 
		strMonth=strMonth.substring(1);
		
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) 
			strYr=strYr.substring(1);
	}
	
	if (pos1==-1 || pos2==-1 || error_in_slashes!=-1){
		alert("The date format should be : dd/mm/yyyy");
		return false;
	}

	if (strMonth.length<1 ||  strMonth<1 || strMonth>12)
	{
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || strDay.length>2|| strDay<1 || strDay>31 || 
		(strMonth==2 && strDay>daysInFebruary(strYear)) || strDay > daysInMonth[strMonth])
	{
		alert("Please enter a valid day");
		return false;
	}
	
	if ( strYear==0 || strYear<minYear || strYear>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}

return true;	
	
}

function isMoney(amount)
{
 	var pointFind=amount.indexOf('.');
	var pos2=amount.indexOf('.',pointFind+1);
	if(pos2 != -1)
	{
		alert("invalid money amount entered");
		return false;
	}
     if (pointFind >0)
	 {
          var decPart=amount.substr(parseInt(pointFind)+1,amount.length);
          if (parseInt(decPart) > 99)
		{
               alert("invalid money amount entered");
               return false;
          }
     }
	return true;
}

function isNull(str)
{
	if(typeof str == 'object' && !str)
		return true;
	else if( typeof str == 'undefined')
		return true;
	else if( typeof str == 'number' && str == 0)
		return true;
	else if( typeof str == 'string' && str.length == 0)
		return true;
		
	return false;
}

function checkCompulsory(element)
{
	var children = element.childNodes;
	for(var i = 0; i < children.length;++i)
	{
		if( !checkCompulsory(children[i]))
			return false;
		if(children[i].className == "compulsory" && isNull(children[i].value))
		{
			alert("Compulsory field empty!");
			children[i].focus();
			return false;
		}
	}
	return true;
}

function toggleBlock(obj) 
{
	var el = document.getElementById(obj);
	if(!el)
		return;
	//change icon as well
	var img = document.getElementById("img_"+obj);

	if(navigator.appName.indexOf("Microsoft") > -1){
	var canSee = 'block'
	} else {
	var canSee = '';
	}

	if (el.style.display && el.style.display != canSee) 
	{
		el.style.display = canSee;
		img.src = "img/bullet_arrow_bottom.png";
	}
	else 
	{
			
		el.style.display = "none";
		img.src = "img/bullet_arrow_top.png";
	}
	
	
}