/* to check the users email, alphabets, name, password, remove spaces form the Name through trim() etc..*/
function trim (strVar) { 
	if(strVar.length >0)
	{
		while(strVar.charAt(0)==" ")			//remove left spaces
			strVar=strVar.substring(1,strVar.length);
		while(strVar.charAt(strVar.length-1)==" ")			//remove right spaces
			strVar=strVar.substring(0,strVar.length-1);
	}
	return strVar;
}

function textLimitCheck(thisArea, maxLength, msg)
{
    if (thisArea.value.length > maxLength)
    {
        alert(maxLength + ' characters limit. \rExcessive data will be truncated.');
        thisArea.value = thisArea.value.substring(0, maxLength);
        thisArea.focus();
    }
	document.getElementById(msg).innerText = thisArea.value.length;
	//document.getElementById(msg).innerText = maxLength-thisArea.value.length;
}
function checkLogin(chk)
{
	if(chk.userName.value.length==0)
	{
		alert("User Name can not be left blank");
		chk.userName.focus();
		return false;
	}
	if(chk.password.value.length==0)
	{
		alert("Password can not be left blank");
		chk.password.focus();
		return false;
	}
	return true;
}

function checkValidity(theForm)
{
	var schemeName = theForm.schemeName.value;
	var schemeDetail = theForm.schemeDetail.value;
	var meta_title = theForm.meta_title.value;
	
	if(schemeName.length==0)
	{
		alert("Please enter Scheme Name.");
		theForm.schemeName.focus();
		return false;
	}
	if(schemeDetail.length==0)
	{
		alert("Please enter Scheme Detail.");
		theForm.schemeDetail.focus();
		return false;
	}
	if(meta_title.length==0)
	{
		alert("Please enter Meta tilte.");
		theForm.meta_title.focus();
		return false;
	}
	return true;
}

function checkSchemeForm(theForm)
{
	var fundID = theForm.fundID.value;
	var schemeName = theForm.schemeName.value;
	var meta_title = theForm.meta_title.value;
	var objective = theForm.objective.value;
	var planDescription = theForm.planDescription.value;
	var schemeType = theForm.schemeType.value;
	var navName = theForm.navName.value;
	if(fundID.length==0)
	{
		alert("Please select Mutual Fund Name.");
		theForm.fundID.focus();
		return false;
	}
	if(schemeName.length==0)
	{
		alert("Please enter Scheme Name.");
		theForm.schemeName.focus();
		return false;
	}
		if(navName.length==0)
	{
		alert("Please enter Scheme Name (Temp).");
		theForm.navName.focus();
		return false;
	}
	if(schemeType.length==0)
	{
		alert("Please select Scheme Type.");
		theForm.schemeType.focus();
		return false;
	}
	if(objective.length==0)
	{
		alert("Please enter Objective.");
		theForm.objective.focus();
		return false;
	}
/*	if(planDescription.length==0)
	{
		alert("Please enter Option/Plan.");
//		theForm.planDescription.focus();
		return false;
	}
	*/
	if(meta_title.length==0)
	{
		alert("Please enter Meta tilte.");
		theForm.meta_title.focus();
		return false;
	}
	return true;
}

 function checkSearchValidity()
 {
	var keyword=document.form_search.keyword.value; 
	if(keyword.length==0)
	{
		alert("Please enetr keyword field.");
		document.form_search.keyword.focus();
		return false;
	}
	else
	{
		return true;
	}
 }
 
  function checkSearchValidity1()
 {
	var fundID = document.form_search.fundID.value; 
	var keyword = document.form_search.keyword.value; 
	var schemeType = document.form_search.schemeType.value; 
	if(fundID.length==0 && keyword.length==0 && schemeType.length==0)
	{
		alert("Please choose at least one search field.");
		document.form_search.keyword.focus();
		return false;
	}
	else
	{
		return true;
	}
 }
 
 
 function deleteAlert1()
{
	
	var records = document.removeForm.records.value;
	var total = 0;
	var msg = "";
    
	if(records>0)
	{
		for(i=0; i<document.removeForm.length; i++)
		{
			e=document.removeForm.elements[i];
			if (e.type=='checkbox')
			{
				
				if(eval('e.checked') == true)
				{
					total= total+1;
				}
			}
		}
		if(total >0)
		{
			msg = msg + 'Do You Like to remove ' + total +' records ?';
			//document.removeForm.totalchecked.value=total;
		}
		else
		{
			alert("Please check the items to remove !");
			return false;
		}
		if(msg.length >0)
		{
			var flag;
			flag = confirm(msg + " If Yes Press \"OK\" else Press \"Cancel\".");
			if(flag == true)
				return true;
		}
	}
	return false;
}
var pop='';

function openwin(nm,width,height) {
	var name=nm;
	if (pop && !pop.closed) {
		pop.close();
	}
	pop=eval("window.open('"+name+"','NewWIN','chrome[4],toolbar=no,left=5,top=5,width="+width+",height="+height+",directories=no,menubar=no,SCROLLBARS=yes,left=2,right=2')");
	if (!pop.opener) popUpWin.opener = self;
}

function closewin()
{
	window.close();
}
function setTitle(val, title, desc)
{
	title = document.getElementById(title);
	desc = document.getElementById(desc);
	title.value = val;
	desc.value = val;
}
/*Used in All Cp Modules*/
function checkAll(checked)
{
	for(var i=0;i<document.removeForm.elements.length;i++)
	{
		var e = document.removeForm.elements[i];
		if(e.type == "checkbox") e.checked = checked;
	}
}

function dateValid(dd, mm, yyyy)
{
	if(dd.length==0 || mm.length==0 || yyyy.length==0)
		return false;
	if(isNaN(dd)) 
		return false;
	if(isNaN(mm)) 
		return false;
	if(isNaN(yyyy)) 
		return false;
	if(yyyy.length<4)
	{
		alert("Please Enter Year in four digit!");
		return false;
	}
	if(mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)
	{
		if(dd>31)
			return false;
	}
	else 
	{
		if(mm==4 || mm==6 || mm==9 || mm==11)
		{
			if(dd>30)
				return false;
		}
		else
		{
			var f_day=isLeap(yyyy);
			if(dd>f_day) return false;
		}
	}
	return true;
}
//CHECK DAY IN FEBRUARY MONTH
function isLeap(year)
{
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function getCurrentDate()
{
	currentTime = new Date();
	
	dd=currentTime.getDate();
	mm=currentTime.getMonth();
	yy=currentTime.getYear();
	mm=mm+1;
	if(dd<10) dd="0"+dd;
	if(mm<10) mm="0"+mm;
	currDate=yy+"-"+mm+"-"+dd;

	return currDate;
}
