//alert when delete
function delete_selected(form) 
{ 
	if(form.elements.length)
    {
      	nChecked=0;
        for(var j=2;j<form.elements.length;j++)
        {
         	if(form.elements[j].checked)
                nChecked++;
        }
	}
	if(nChecked > 1)
	{
		if(confirm('Are you sure?\nDo you really want to delete the selected records?'))
			return true;
		else
			return false;
	}
	else if(nChecked == 1)
	{ 
		if(confirm('Are you sure?\nDo you really want to delete the selected record?'))
			return true;
		else
			return false;
	}
	else if(nChecked == 0)
	{ 
		alert("Please select one or more records to delete.");
		return false;
	}
}

// alert when single delete
function del(name) 
{ 
	if(confirm('Are you sure?\nDo you really want to delete this '+ name +'.'))
		return true;
	else
		return false;
}

// check all/uncheck all  
function toggleChecked(oElement) 
{
  oForm = oElement.form;
  oElement = oForm.elements[oElement.name];
  if(oElement.length)
  {
    bChecked = oElement[0].checked;
    for(i = 1; i < oElement.length; i++)
      oElement[i].checked = bChecked;
  }
}

//  check/uncheck  checkall checkbox
function toggleController(oElement) 
{
	oForm=oElement.form;
	oElement=oForm.elements[oElement.name];
	if(oElement.length)
	{	
		bChecked=true;
		nChecked=0;
		for(i=1;i<oElement.length;i++)
		if(oElement[i].checked)
			nChecked++;
		

		if(nChecked<oElement.length - 1)
			bChecked=false;
		oElement[0].checked=bChecked;
	}
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
 
// email address validation
function echeck(str)  
{ 

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter valid email-Id.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter valid email-Id.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter valid email-Id.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter valid email-Id.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter valid email-Id.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter valid email-Id.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter valid email-Id.")
		    return false
		 }

 		 return true					
	}
	

// open new window for view records page.
var win = null;
function NewWindow(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+''
	win = window.open(mypage,myname,settings)
}

//verify whether any records are selected or not or records are available or not for delte
function verify(form)
{ 
	if(form.elements.length)
    {
      	nChecked=0;
        for(var j=2;j<form.elements.length;j++)
        {
         	if(form.elements[j].checked)
                nChecked++;
        }
	}
	if(nChecked == 0)
	{ 
		alert("Please select one or more records to delete.");
		return false;
	}

}

//Reset FCKEditor Value.
function resetEditors()
{
    // If the editor API does not exist, there are no editors
    if (typeof FCKeditorAPI == "undefined") return;

    // Loop through all FCK instances, in case there are several editors
    for (var sEditorName in FCKeditorAPI.__Instances)
    {
        // The initial value that was set when the form was created
        // is stored in a hidden <INPUT> with the same name as the
        // editor (the editor itself is in an <IFRAME> with ___Frame
        // appended to the name.  Check whether that INPUT exists
        if (document.getElementById(sEditorName))
        {
            // Get the initial value
            var sInitialValue = document.getElementById(sEditorName).value;

            // Overwrite the editor's current value
            FCKeditorAPI.__Instances[sEditorName].SetHTML(sInitialValue);
        }
    }
} 

