//-------------------------------Delete All (checkbox)-------------------------------
function checkCheckBox(str,errorMessage)
{
	
//Check if the items are selected
		var flag=0;
	 elmlen = document.forms[str].elements.length;
		  for(var j=0;j<elmlen;j++)
		  {
			if(document.forms[str].elements[j].type == "checkbox")
			{	
				if(document.forms[str].elements[j].checked == true)
				{
					flag=1
				}
			}
		  }
		  
		  if(flag==0)
		  {
			  alert(errorMessage);
			  return false
		  }
		  else
		  {
			  return true
		  }
}

function deleteAll(formname,page_name,itemname)
{
	if(checkCheckBox(formname,'Please select at least one '+itemname+' to delete.'))
	{
		if(confirm('Are you sure you want to delete selected '+itemname+'(s)?'))
		{
					var actionval="'delete'";
					var redirectPage="'"+page_name+"'";
					eval('document.'+formname+'.step.value='+actionval);
					eval('document.'+formname+'.action='+redirectPage);
					eval('document.'+formname+'.submit();'); 
		}
	}		
}

//-------------------------------Delete All (checkbox)-------------------------------
function deleteSingle(delete_id,formname,page_name,itemname)
{
	//hidden field is compulsory as name id
	//alert(delete_id+" "+formname+" "+page_name+" "+itemname);
	if(confirm('Are you sure you want to delete this '+itemname+'?'))
	{
					var actionval="'delete'";
					var delete_id="'"+delete_id+"'";
					var redirectPage="'"+page_name+"'";
					eval('document.'+formname+'.step.value='+actionval);
					eval('document.'+formname+'.id.value='+delete_id);
					eval('document.'+formname+'.action='+redirectPage);
					eval('document.'+formname+'.submit();'); 
	}
}
function activeInactive(AIID,status,itemname,page_name,formname)
{
	var result = status.indexOf(",");
	if(result!=-1)
	{
			var col_array=status.split(",");
			statusvalue=col_array[0];
	}
	else
	{
			statusvalue=status;
	}
	//alert(AIID+" "+status+" "+itemname+" "+page_name+" "+formname);
	// two hidden variables are required id,step
	var currentStatus = (statusvalue=='A') ? 'Inactivate' : 'Activate';
	if(confirm('Are you sure you want to '+ currentStatus +' this '+itemname+'?'))
	{
					var actionval="'ActiveInactive'";
					var active_inactive_id="'"+AIID+"'";
					var redirectPage="'"+page_name+"'";
					var status_val="'"+status+"'";
					eval('document.'+formname+'.status.value='+status_val);
					eval('document.'+formname+'.step.value='+actionval);
					eval('document.'+formname+'.id.value='+active_inactive_id);
					eval('document.'+formname+'.action='+redirectPage);
					eval('document.'+formname+'.submit();'); 
	}
}
// REQUIRES TWO PARAMETER PAGENAME & FOLDER NAME (IF FOLDER NOT EXIST THE PASS BLANK ARGUMENT) 
function gobackHome(page_name,folder)
{
	if(folder=='')
     {
			window.location=page_name;
	 }
	 else
	 {
		 window.location=folder+page_name;
	 }
}
//this function require one hidden varible call id.
function editSingle(edit_id,formname,page_name)
{
		var actionval="'edit'";
		var delete_id="'"+edit_id+"'";
		var redirectPage="'"+page_name+"'";
		eval('document.'+formname+'.step.value='+actionval);
		eval('document.'+formname+'.id.value='+delete_id);
		eval('document.'+formname+'.action='+redirectPage);
		eval('document.'+formname+'.submit();');
}

function validateCombo(ctrlid,message)
{
		selectedval=eval('document.getElementById("'+ctrlid+'").selectedIndex');
		if (selectedval==0) 
			{
				 alert (message);
				 eval('document.getElementById("'+ctrlid+'").focus()');
				 return false;
		}
		return true;
}



function newUser(user_id,formname,page_name,itemname)
{
	if(confirm('Are you sure you want to approve this user?'))
	{
					var actionval="'Approve'";
					var user_id="'"+user_id+"'";
					var redirectPage="'"+page_name+"'";
					eval('document.'+formname+'.step.value='+actionval);
					eval('document.'+formname+'.id.value='+user_id);
					eval('document.'+formname+'.action='+redirectPage);
					eval('document.'+formname+'.submit();'); 
	}
}

function activateUser(user_id,formname,page_name,itemname)
{
	if(confirm('Are you sure you want to activate cancelled account?'))
	{
					var actionval="'Activateuser'";
					var user_id="'"+user_id+"'";
					var redirectPage="'"+page_name+"'";
					eval('document.'+formname+'.step.value='+actionval);
					eval('document.'+formname+'.id.value='+user_id);
					eval('document.'+formname+'.action='+redirectPage);
					eval('document.'+formname+'.submit();'); 
	}
}

function trim(inputString) 
{
		   if (typeof inputString != "string") { return inputString; }
		   var retValue = inputString;
		   var ch = retValue.substring(0, 1);
		   while (ch == " ") { // Check for spaces at the beginning of the string
			  retValue = retValue.substring(1, retValue.length);
			  ch = retValue.substring(0, 1);
		   }
		   ch = retValue.substring(retValue.length-1, retValue.length);
			while (ch == " ") { // Check for spaces at the end of the string
			  retValue = retValue.substring(0, retValue.length-1);
			  ch = retValue.substring(retValue.length-1, retValue.length);
		   }
		   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
			  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		   }
		   return retValue; 
}

function popupWindow(url) 
{
	 mywindow=window.open(url,'popupWindow','toolbar=no,location=0,directories=no,statusbar=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=500,height=300')
	  mywindow.moveTo(300,250);
}

function popupWindowVideo(url) 
{
	 mywindow=window.open(url,'popupWindow','toolbar=no,location=0,directories=no,statusbar=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=580,height=340')
	  mywindow.moveTo(500,250);
}

function popupimage(url) 
{
	 mywindow=window.open(url,'popupWindow','toolbar=no,location=0,directories=no,statusbar=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=900,height=700')
	  mywindow.moveTo(0,0);
}



