
function CreateForm(DivId,ActionName,HiddenFieldName,HiddenFieldValue)
{
	
	var frmString='<body><form name="FrmCreate" action="'+ActionName+'" method="post"><input type="hidden" name="'+HiddenFieldName+'" value="'+HiddenFieldValue+'"></form></body>';
	document.getElementById(DivId).innerHTML=frmString;
	document.FrmCreate.submit();
}

//********** Add _ajx suffix in url 

function CreateAjaxURL(link){		
  var arrPath = link.split('?');
	if(typeof(arrPath[1])!="undefined")
	{
		
		
		//if(!regex.exec(arrPath[1]))
		if(arrPath[1].indexOf('_ajx')==-1)
			link += "&_ajx=1" ;
	}
	else
		link += "?_ajx=1" ;

	
	return link;

}

function ShowUploadingProgrees()
{	
	document.getElementById("Media_Uploading").style.display="";	
}
/* validate date form user input*/

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); 
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
		if(i>=1 && i<=9)
		{
			i="0"+i;
		}
        this[i] = 31
        if (i=="04" || i=="06" || i == "09" || i=="11") 
			{this[i] = 30}
        if (i=="02") 
			{this[i] = 29}
   } 
   return this ;
}

/* this function use to validate user date 
   to use this validation call 	ValidateDate($Year(YYYY format),$Month(mm format),$Day(dd format))
  */
function ValidateDate(strYear,strMonth,strDay)
{
     var daysInMonth= DaysArray(12);
    if((strMonth=="02" && strDay > daysInFebruary(strYear)) || strDay > daysInMonth[strMonth])
	{ 
		return true;
	}
	return false;
}



// Removes leading whitespaces
	function Ltrim( value ) {
	
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	
	}
	
		// Removes ending whitespaces
	function Rtrim( value ) {
	
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	
	}
	
	// Removes leading and ending whitespaces
	function trim( value ) {
	
		return Ltrim(Rtrim(value));
	
	}


	function getbrowser(){
					if(navigator.appName.indexOf("Netscape")>-1){
						return("Netscape");
					}
					else if((navigator.appName.indexOf("Microsoft")>-1) || (navigator.appName.indexOf("MSIE")>-1)){
						return("IE");
					}
					else if(navigator.appName.indexOf("Opera")>-1){
						return("Opera");
					}
					else{
						return(navigator.appName);
					}
					<!--+"-"+version;// -->
					return 1;
				}
    

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}


function setActiveNavMenu(containerId,aRef)
{
	var NV3 = document.getElementById(containerId);
	var NVAs = NV3.getElementsByTagName('a');
	var nAs = NVAs.length;
	for(var i=0;i<nAs;i++)
	{
			if(NVAs[i]!=aRef)
			{
				if(!NVAs[i].setAttribute('class',''))
					NVAs[i].className = '';
			}
			else
			{
				if(!NVAs[i].setAttribute('class','active'))
					NVAs[i].className = 'active';
			}
	}
}


// added by : Anurag
function matchString(strMatch, strString)
{		
	var objRegExp = eval("/"+strMatch+"/i");		
	return objRegExp.test(strString); 
	
}


function GetFocusOnField( strFormName ,strFieldName)//form Name,and field Name
	{

		//alert('comonnnnnnnnnnn')
		setTimeout("AShortDelayInFocus('"+strFormName+"','"+strFieldName+"')", 1000);
	}

function ShowSearchDiv(divid)
{	
		objQuick=document.getElementById('QuickSearch');
		objAdv=document.getElementById('AdvSearch');
		if(divid==1)
		{	objQuick.style.display='';
			objAdv.style.display='none';
		}
		else if(divid==2)
		{   objQuick.style.display='none';
			objAdv.style.display='';
		}
	


}


function StartAction(varname)
 {
	  
    if(varname==true)
            CheckAllData();
    else
         RevertCheckAllData();
 }


function CheckAllData()
{
	      for(var i=0;i<document.frmGridData.elements.length;i++)
          {
			 //alert(document.frmGridData.elements[i].name.indexOf("chk"));
              if(document.frmGridData.elements[i].name.indexOf("chk")!="-1")
              {
				  
				 if(document.frmGridData.elements[i].disabled==false)
				 {
					document.frmGridData.elements[i].checked=true;
				 }
			 }
          }
}
function RevertCheckAllData()
	{
	 
	  for(var i=0;i<document.frmGridData.elements.length;i++)
       {
			if(document.frmGridData.elements[i].name.indexOf("chk")!="-1" && document.frmGridData.elements[i].checked==true)
			{
				  if(document.frmGridData.elements[i].disabled==false)
				  {
					 document.frmGridData.elements[i].checked=false;
				  }
			}
			else if(document.frmGridData.elements[i].name.indexOf("chk")!="-1" && document.frmGridData.elements[i].checked==false)
			{
				if(document.frmGridData.elements[i].disabled==false)
				{
				   document.frmGridData.elements[i].checked=true;
				}
			}    
       }
  }




function UncheckMain()
{
   var boolCheck = true;
   if(document.frmGridData.MainCheck.checked==false)
    {
		 for(var i=0;i<document.frmGridData.elements.length;i++)
		 {
			   if(document.frmGridData.elements[i].name.indexOf("chk")!="-1" && document.frmGridData.elements[i].checked==false)
			   {
						 boolCheck = false;
							 break;
			   }
		  }
		  if(boolCheck==true)
						document.frmGridData.MainCheck.checked=true;           
	}
    else
    {
       document.frmGridData.MainCheck.checked=false;         
    }
}

 
function CheckIsSelected(formName,checkBoxName,hiddenName,msg)
{
	 
	
        var obj=eval("document."+formName);
                var chkobj=eval("document."+formName+"."+checkBoxName);
				var hidobj=eval("document."+formName+"."+hiddenName);
                var blSelected = false;
        
                if(!chkobj.length)
                {
                        if(chkobj.checked)
                                blSelected = true;
                }
                else
                {
                        for(i=0;i<chkobj.length;i++)
                        {
                                if(chkobj[i].checked)
                                { 
                                    blSelected = true;
                                    break;
                                }
                                
                        }
                }
		
        if(!blSelected)
        {
			
            if(msg)
                   alert(msg);
                  else
                  alert('Please select at least one record.');

            return false
        }
                else
                {
					
                        var values="";
                        if(!chkobj.length)
                        {
                                hidobj.value=chkobj.value;
                        }
                        else
                        {
                                for(i=0;i<chkobj.length;i++)
                                {
                                        if(chkobj[i].checked)
                                                values = values+chkobj[i].value+",";
                                }
                                hidobj.value=values.substring(0,values.length -1);
                       }
                        //alert(hidobj);

						//alert(document.frmGridData.delids.value);
                       
                        return true;
                }
				
}

 
function MultiDelete(link,msg)
{
	if(CheckIsSelected('frmGridData','chk','dataids'))
	{ 

		link=link+"&id="+document.frmGridData.dataids.value;
		if(confirm(msg))
		{
			link =CreateAjaxURL(link);
			return AjaxRequestGet(link,'GridData');
		   
		}
			 
		else
			return false;	
	} 
}
 


function DeleteData(link)
{
	if(confirm('Are you sure to delete record?'))
	{ 
		link =CreateAjaxURL(link);
		AjaxRequestGet(link,'GridData');
		
	}	

}


//Word Filter Function

function WordFilter(value)
{
	var FILTER_TEXT = new Array("Fuck","Fuk","Dick","Pussy","Ass","Cock","Sperm","XXX","penis","vegina","Porn");
	var _CFG_FILTER = FILTER_TEXT.join("|") ;
	var _CFG_FILTER_TEXT=eval("/"+_CFG_FILTER+"/i");
	if(eval(_CFG_FILTER_TEXT.test(trim(value))))
			return true;	
	else
			return false;
}



/*----------------------------------------------*/
function RemoveActiveNavMenu(containerId,heading,arrHeading)
{
	var blnHeading = false;
	for(i=0;i<arrHeading.length;i++)
	{
		if(arrHeading[i]==heading)
		{
			blnHeading = true;
			break;
		}
	}
	if(blnHeading)
		return true;

	var NV3 = document.getElementById(containerId);
	var NVAs = NV3.getElementsByTagName('a');
	var nAs = NVAs.length;
	for(var i=0;i<nAs;i++)
	{
		if(!NVAs[i].setAttribute('class',''))
			NVAs[i].className = '';
	}
}

