// Function to Check all the Checkbox's present before the records listed
function checkFunc(CheckBoxControl)
{	  
	if (CheckBoxControl.checked == true) {
		var a = 0;
		for (i=0; i<document.listView.elements.length; i++) {
			if (document.listView.elements[i].type == "checkbox") {
				document.listView.elements[i].checked=true;
				a = a + 1;
			}
		}
		a = a - 1;
		document.getElementById("selectCount").innerHTML = a;		
		document.getElementById("selectCount1").innerHTML = a;				
	} else {
		for (i=0; i<document.listView.elements.length; i++) {
			if (document.listView.elements[i].type == "checkbox") {
				document.listView.elements[i].checked = false;
			}
		}
		document.getElementById("selectCount").innerHTML = 0;
		document.getElementById("selectCount1").innerHTML = 0;
	}
}	

// Function to generate the selected Checkbox's Count	
function select_count()
{
	var a = 0;
	for (i=0; i<document.listView.elements.length; i++) {
		if (document.listView.elements[i].type == "checkbox") {
			if (document.listView.elements[i].checked == true)
				a = a + 1;
		}
	}
	document.getElementById("selectCount").innerHTML = a;
	document.getElementById("selectCount1").innerHTML = a;
	if (document.listView.checkAll.checked == true)	{
		document.getElementById("selectCount").innerHTML = a-1;
		document.getElementById("selectCount1").innerHTML = a-1;
	}
	document.listView.checkAll.checked = false;			
}

// Function to Clear all the Checkbox selected
function clearfunc()
{
	for (i=0; i<document.listView.elements.length; i++) {
		if (document.listView.elements[i].type == "checkbox") {
			document.listView.elements[i].checked = false;
		}
	}
	document.getElementById("selectCount").innerHTML = 0;
	document.getElementById("selectCount1").innerHTML = 0;
}

// Function to confirm before delete
function isActionValid(action)
{
	var msg1 = "Are you sure to "+action+" ? ";
	
	var isValid = window.confirm(msg1);
		
	return isValid;
}

// Function to validate the form before delete operation executes
function formValidator(frmName, actn)
{	
	var a=0;	
	for(i=0; i<document.listView.elements.length; i++)
	{
		if(document.listView.elements[i].type=="checkbox"  && document.listView.elements[i].name != "checkAll")
		 {			    
			if (document.listView.elements[i].checked == true)
			a = a + 1;
		 }			
	}				

	if (a < 1) {
		alert("Select at least one record to "+actn+" ?");
		return false;
	}
	else
	{		  
			var z = window.confirm("Are you sure to "+actn+" "+a+" record(s) ?");
    
			return z;
	}
	return true;
}

function validateCheckbox(frmName,action)
{
	var a=0;		
	if(frmName!='') {
		for(i=0; i<frmName.elements.length; i++) {
			if(frmName.elements[i].type=="checkbox"  && frmName.elements[i].name != "checkAll"){			    
				if (frmName.elements[i].checked == true)
				a = a + 1;
			}			
		}		
		if(a < 1)  {
			alert("Select at least one record to "+action);
			return false;
		}
		else {
			var z = window.confirm("Are you sure to "+action+" "+a+" record(s) ?");
			return z;
		}
		return true;
	}
}

function validateRadioButton(frmName,action)
{
	var a=0;		
	if(frmName!='') {
		for(i=0; i<frmName.elements.length; i++) {
			if(frmName.elements[i].type=="radio" ){			    
				if (frmName.elements[i].checked == true)
				a = a + 1;
			}			
		}		
		if(a < 1)  {
			alert("Select at least one "+action);
			return false;
		}
		return true;
	}
}

//Function to reset values and clear error messages
function resetValues(formName)
{  	
        var x;
        formName.reset();
        //Reset the values of editor
        var editor = document.getElementsByTagName('iframe');
        for (count = 0 ; count < editor.length; count++){
	        if(editor[count]){
	            if(editor[count].id.indexOf('wysiwyg')>=0){
		            elementId = editor[count].id.substr(7);
		        	txtArea = document.getElementById(elementId);
		            doc = editor[count].contentWindow.document;     
		            doc.open();
		  			doc.write(txtArea.value);
		  			doc.close();
	            }
	        }
        }
        var errSpan = document.getElementsByTagName("span");   
        for(x=0;x<errSpan.length;x++){
            if(! errSpan[x].id) continue;
            if(errSpan[x].id.indexOf("Err")>0){
               if(errSpan[x].innerHTML)
                errSpan[x].innerHTML= "";
            }
        }
       
}   