function mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}
function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}
function telefone(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
	v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca hífen entre o quarto e o quinto dígitos
	if (v.length > 14){
			v=v.replace(/(\d)$/g,"")
	}
return v
}
function cpf(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos
	v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos
	//de novo (para o segundo bloco de números)
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
	return v
}
function somenteNumeros(v){
	v=v.replace(/\D/g,"")
	return v
}
function cnpj(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/^(\d{2})(\d)/,"$1.$2") //Coloca ponto entre o segundo e o terceiro dígitos
	v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
	v=v.replace(/\.(\d{3})(\d)/,".$1/$2") //Coloca uma barra entre o oitavo e o nono dígitos
	v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca um hífen depois do bloco de quatro dígitos
	if (v.length > 18){
			v=v.replace(/(\d)$/g,"")
	}
	return v
}
/* -------------------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------------------*/
function numericOnly(evnt)
{
	return v.replace(/\D/g,"")
}

/*This function have not allow space and  allow dot(.)*/
function numericWithDot(evnt)
{
	var unicode=evnt.charCode? evnt.charCode : evnt.keyCode
	if (unicode<=46 || unicode>57 || unicode==47 || unicode==32)
	{
		if(( unicode == 32 || unicode == 8 || unicode == 9 || unicode == 45 || unicode == 46) && (unicode!=32) && (unicode!=116)  && (unicode!=45) && (unicode!=43))
			return true;
		else
			return false;
	}
}
	
function alphaNumericOnly(evnt)
{
	var unicode=evnt.charCode? evnt.charCode : evnt.keyCode
	
	if((unicode>=65 && unicode<=90) ||(unicode>=97 && unicode<=122) || (unicode>=48 && unicode<=57) || unicode==8 || unicode==46) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
}

function mobileNumberValue(evnt)
{
	var unicode=evnt.charCode? evnt.charCode : evnt.keyCode
	if (unicode<47||unicode>57 || unicode==47)
	{
		if(unicode == 8 || unicode == 116 || unicode == 9)
			return true;
		else
			return false;
	}
}

function telNumberValue(evntb)
{
	var unicode=evnt.charCode? evnt.charCode : evnt.keyCode

	if (unicode<47||unicode>57 || unicode==47)
	{
		if(unicode == 8 || unicode == 116 || unicode == 9)
		{
			return true;
		}
		else
			return false;
	}
}

function checkValidNumber()
{
	val = event.keyCode;
	if(val<48)
	{
	  event.keyCode=0;
	
	}
	if(val>57)
	{
	  event.keyCode=0;	
	}
	return true;
}
/* -------------------------------------------------------------------------------------------------------------------------*/
function tagShowHide(tagId,type) 
{
	var theTag = document.getElementById(tagId);

	if (theTag) 
	{
		if (theTag.style.display == 'none') 
		{
			tagShow(tagId,type);
		} 
		else 
		{
			tagHide(tagId); 
		}
	}
}
function tagShow(tagId,type)
{
	var theTag = document.getElementById(tagId);
	if (theTag) 
	{
		if (theTag.style.display == 'none') 
		{
			if(type=='div')
			{
				theTag.style.display = 'block';
			}
			else
			{
				theTag.style.display = '';
			}
		}
	}
}		
function tagHide(tagId) 
{
	var theTag = document.getElementById(tagId);
	if (theTag) 
	{
		if (theTag.style.display != 'none') 
		{
			theTag.style.display = 'none';
		}
	}
}

/* -------------------------------------------------------------------------------------------------------------------------*/	
function windowOpen(theURL,winName,width,height,left,top)
{
	var win;
	var features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	win=window.open(theURL,winName,features);
	win.focus();
}

function windowLocation(file)
{
	window.location=file;
}	
  
/* -------------------------------------------------------------------------------------------------------------------------*/	
function isValidURL(url)
{
	var url_str1=url.search(/^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/);
	var url_str2=url.search(/^[http(s)://]+[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$/);	
	
	if(url_str1==-1 && url_str2==-1)
	{
		return false;	
	}
	else
	{
		return true;	
	}
}

function checkEmail(email) 
{
	if (window.RegExp)
	{
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,6}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(email) && reg2.test(email)) 
		{
			return true;
		}
		return false;
	} 
	else 
	{
		if(email.indexOf("@") >= 0)
			return true;
		return false;
	}
}

function echeck(obj) 
{
	var str=obj.value;
	var strid=obj.id;
	
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1)
	{
	   alert("Invalid E-mail ID");
	   obj.value="";
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   alert("Invalid E-mail ID");
	   obj.value="";
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail ID");
		obj.value="";
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid E-mail ID");
		obj.value="";
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		alert("Invalid E-mail ID");
		obj.value="";
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid E-mail ID");
		obj.value="";
		return false;
	}
	
	if (str.indexOf(" ")!=-1)
	{
		alert("Invalid E-mail ID");
		obj.value="";
		return false;
	}

	return true;				
}

/* -------------------------------------------------------------------------------------------------------------------------*/
	
function checkMe(radio,obj)
{
	if(radio.checked==1)
	{
		obj.disabled = false;
	}
	else if(radio.checked==0)
	{
		obj.disabled = true;
		obj.focus();
	}
} 

function CheckAllCheckbox(obj,formname)
{					
	var len = document.forms[formname].elements.length;
	var obj_len = obj.name.length;
	
	for(i=0;i<len;i++) 
	{
		obj12 = document.forms[formname].elements[i].id;
		
		if((obj12.substring(0,obj_len) == obj.name) && (document.forms[formname].elements[i].type = "checkbox")) 
		{
			document.forms[formname].elements[i].checked = obj.checked;
		}
	}
}
function clearValue(input_id)
{
	document.getElementById(input_id).value='';
}
/* -------------------------------------------------------------------------------------------------------------------------*/
	
function displayDateTime(timeId)
{
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year < 2000) 
	year = year + 1900; 
	
	//--- Get Time
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	var timeValue = "" + ((hours >12) ? hours -12 :hours)
	if (timeValue == "0") timeValue = 12;
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	//timeValue +=((seconds < 10) ? "0" : ":") + seconds
	timeValue += (hours >= 12) ? " PM" : " AM"
	
	//--- Get Day
	var days=new Array(7);
	days[0]="Sunday";
	days[1]="Monday";
	days[2]="Tuesday";
	days[3]="Wednesday";
	days[4]="Thursday";
	days[5]="Friday";
	days[6]="Saturday";
	var lday=days[time.getDay()];	
	
	var clocktime = lday + ", "  +lmonth + " " + date + ", " + year + " " + timeValue;
	
	if(document.getElementById(timeId)!=null)
	{
		document.getElementById(timeId).innerHTML = clocktime;
		setTimeout("displayDateTime()",1000);
	}
}	
	
function displayTime(timeId)
{
	var time = new Date();
	var hours = time.getHours();
	var timeOfDay = ( hours < 12 ) ? "AM" : "PM";
	var minutes = time.getMinutes();
	minutes=((minutes < 10) ? "0" : "") + minutes;
	var seconds = time.getSeconds();
	seconds=((seconds < 10) ? "0" : "") + seconds;
	var clocktime = hours + ":" + minutes + ":" + seconds + " " + timeOfDay;
	
	document.getElementById(timeId).innerHTML = clocktime;
	setTimeout("displayTime()",1000);
}	

/* -------------------------------------------------------------------------------------------------------------------------*/
	
function delConfirm()
{
	ret=confirm('Tem certeza que deseja deletar?');

	if(ret==false)
	{
		return false;
	}
	else 
	{
		return true;
	}
}	
	
function cancelConfirm()
{
	ret=confirm('Tem certeza que deseja cancelar?');

	if(ret==false)
	{
		return false;
	}
	else 
	{
		return true;
	}
}	

function getBlurText(id,defaultValue)
{
	if (document.getElementById(id).value == '')
	{
		document.getElementById(id).value = defaultValue;
	}
}
function getFocusText(id,defaultValue)
{
	if(document.getElementById(id).value == defaultValue) 
	{
		document.getElementById(id).value = '';
	}
}
function is_email(email)
	{
		if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/))
			return false;
		return true;
	}
//Sanjay
function textCounter(field,cntfield,maxlimit) 
{
	if (field.value.length > maxlimit)
	{
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{
		cntfield.value = maxlimit - field.value.length;
	}
}

