//Reset the Text on focus.
function resetText(obj, text)
{
	if (obj.value == text)
	obj.value= '';
}

// Set the Text on Blur
function setText(obj, text)
{
	if (trim(obj.value) == '')
	obj.value = text;
}

//Trim the Specified String
function trim(str)
{
	str = str.replace(/^\s*|\s*$/g,'');
	return str;
}
//Funciton to open Popup windows
function openPopUp(url, windowName, w, h, scrollbar) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar+',resizable=1';
	win = window.open(url, windowName, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

// Function to Check all the Checkbox's present before the records listed
function checkFunc(CheckBoxControl)
{	  
	var a = 0;
	for (i=0; i<document.listView.elements.length; i++) {
		if (document.listView.elements[i].type == "checkbox" && document.listView.elements[i].id.indexOf('chkOffer') < 0) {
			document.listView.elements[i].checked=CheckBoxControl.checked;
			a = a + 1;
		}
	}
	if (CheckBoxControl.checked == true) {
		a = a - 1;
	} else {
		a = 0;
	}
	
	document.getElementById("selectCount").innerHTML = a;		
	if(document.getElementById("selectCount1")) {
		document.getElementById("selectCount1").innerHTML = a;
	}
}	

// 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 && document.listView.elements[i].id.indexOf('chkOffer') < 0)
				a = a + 1;
		}
	}
	if (document.listView.checkAll.checked == true)	{
		a = a-1;
	}
	document.getElementById("selectCount").innerHTML = a;
	if(document.getElementById("selectCount1")) {
		document.getElementById("selectCount1").innerHTML = a;
	}
	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 action
function confirmAction(msg1, msg2, href) {
	var answer = confirm(msg1)
	if (answer) window.location = href;
	else alert(msg2);
}

// 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 convert Date to Ymd Format from dmy format
function convertDateToYMDFromDMY( inputDate )
{
    var dateArr = inputDate.split(/-|\/|\./);
    var day = dateArr[0];
    var month = dateArr[1];
    var year = dateArr[2];
    var ymdFormat = year + "/" + month + "/" + day;
    return ymdFormat;
}

//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= "";
            }
        }
       
}