﻿
var MoveForward = 1;

function IsValidImgOrVideoFile(sender,e)
{
    filePath = e.Value;
    
    filePath = trim(filePath);
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
    
    if(!IsValidImageExtension(fileExt) && !IsValidVideoExtension(fileExt))
        e.IsValid = false;
    else
        e.IsValid = true;
}

function isNumeric(e)
{
    var keynum;
    var keychar;
    var numcheck;
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    return numcheck.test(keychar);
}
function IsChar() 
{
   x = event.keyCode; 
   alert(x);
 }

function upperCase(id)
{
    var x=document.getElementById(id).value;
    var keynum;
    document.getElementById(id).value=x.toUpperCase();
}


function ToLower(ctl)
{
    if(ctl.value != null && ctl.value != "")
        ctl.value=ctl.value.toLowerCase();    
}

function showProgress(ctl)
{
    if(MoveForward==1)
    {
        var filePath=trim(document.getElementById(ctl).value);
        var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
        if(IsValidVideoExtension(fileExt))
        {
            divProgress = document.getElementById("divProgressBar");
            divCont = document.getElementById("divContinue");
            
            divProgress.style.visibility = "visible";
            divProgress.style.display = "block";
            divCont.style.visibility = "hidden";
            divCont.style.display = "none";
        }
    }
}

function ShowDropDown(DropDownId, LocationId, ButtonId)
{       
    DropDownList=document.getElementById(DropDownId);
    Location=document.getElementById(LocationId);
    Button=document.getElementById(ButtonId);
    
    DropDownList.style.display="block";
    DropDownList.style.visibility="visible";    
    
    Location.style.display="none";
    Location.style.visibility="hidden";    
    
    Button.style.display="none";
    Button.style.visibility="hidden";
    
    return false;
}

function trim(s) 
{
        while (s.substring(0,1) == ' ') {
	        s = s.substring(1,s.length);
        }
        while (s.substring(s.length-1,s.length) == ' ') 
        {
	        s = s.substring(0,s.length-1);
        }
        return s;
}
 
function IsEmptyImageFile(sender,e)
{       
    filePath = e.Value;
    
    filePath = trim(filePath);
        
    if(filePath == "")
    {    
        e.IsValid=false;
    }
    else
    {     
        e.IsValid=true;
    }
}
  
function IsEmptyVideoFile(sender,e)
{   
    filePath = e.Value;
    
    filePath = trim(filePath);
        
    if(filePath == "")
    {    
        e.IsValid=false;
    }
    else
    {     
        e.IsValid=true;
    }
}

var bValidUserFiles=true;
var bEmptyUserFiles=true;
function ValidateUserFilesUpload(sender,e)
{
    if(trim(e.Value).length>0)
    {
        
    }
}

function IsValidVideoFile(sender,e)
{
    filePath = e.Value;
    
    filePath = trim(filePath);
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
    
    if(!IsValidVideoExtension(fileExt))    
        e.IsValid = false;
    else
        e.IsValid = true;
}

function IsValidImageFile(sender,e)
{
    filePath = e.Value;
    
    filePath = trim(filePath);
    
    var fileExt = filePath.substring(filePath.lastIndexOf('.') + 1);
    
    if(!IsValidImageExtension(fileExt))    
        e.IsValid = false;
    else
        e.IsValid = true;
}

function IsValidImageExtension(ext)
{
    if(trim(ext) != '')
    {
        if(ext.toLowerCase() == 'gif' || ext.toLowerCase() == 'jpg' || ext.toLowerCase() == 'jpeg' || ext.toLowerCase() == 'bmp' || ext.toLowerCase() == 'png')
            return true;
        else
            return false;
    }
}

function ValidateMaxLength(sender, e)
    {   
        var txtAboutMe =e.Value;
        
        if(txtAboutMe.length > 500)
            e.IsValid=false;
        else
            e.IsValid=true;
    }
    
function ValidateMaxLength250(sender, e)
{   
        var txt =e.Value;
        
        if(txt.length > 250)
            e.IsValid=false;
        else
            e.IsValid=true;
}

function ValidateMaxLength1000(sender, e)
    {   
        var txtAboutMe =e.Value;
        
        if(txtAboutMe.length > 1000)
            e.IsValid=false;
        else
            e.IsValid=true;
    }
    
function ValidateMaxLength4000(sender, e)
    {   
        if(e.Value.length > 4000)
            e.IsValid=false;
        else
            e.IsValid=true;
    }   
    
function ValidateMaxLength2000(sender, e)
    {   
        if(e.Value.length > 2000)
            e.IsValid=false;
        else
            e.IsValid=true;
    }       
    
 function ValidateMaxLength500(sender, e)
    {   
        if(e.Value.length > 500)
            e.IsValid=false;
        else
            e.IsValid=true;
    }       
    
 function ValidateMailTestLength(sender, e)
    {   
        var txtAboutMe =e.Value;
        
        if(txtAboutMe.length > 200)
            e.IsValid=false;
        else
            e.IsValid=true;
    }

function IsValidVideoExtension(ext)
{
    if(trim(ext) != '')
    {
        if(ext.toLowerCase() == 'dat' || ext.toLowerCase() == 'flv' || ext.toLowerCase() == 'mpg' || ext.toLowerCase() == 'mpeg' || ext.toLowerCase() == 'avi' || ext.toLowerCase() == 'wmv' || ext.toLowerCase() == 'mp4' || ext.toLowerCase() == 'mov')
            return true;
        else
            return false;
    }
}



function IsCheckBoxSelected(ComboClientId)
{   
    var type = document.getElementById(ComboClientId).value; 
    var flagg = CheckIsComboSelected(ComboClientId);
    if(flagg==-1)
        return false;    
     frm=document.forms[0];
     bIsSelected = false;
       
    for(i=0;i<frm.elements.length;i++)  
		{
			if(frm.elements[i].type=="checkbox" && frm.elements[i].name!="chkSelectAll" && frm.elements[i].checked)  
		    {  
                bIsSelected = true;
            }
         } 
    
   if(!bIsSelected)
   {
        alert("Atleast one checkbox should be selected before continuing.");
        return false;
   }
   
   else
     { 
         if(type == "2")
             return confirm("Do you want to deactivate selected record(s)?");
        else if(type == "1")
            return confirm("Do you want to activate selected record(s)?"); 
         else if(type == "3")
            return confirm("Do you really want to Delete selected record(s)?");
        else
           alert("Please choose action from the dropdown list.");
        
        return false;
     }
   
   return true;
}


function IsCheckBoxSelectedInGrid()
{   
    
     frm=document.forms[0];
     bIsSelected = false;
       
    for(i=0;i<frm.elements.length;i++)  
		{
			if(frm.elements[i].type=="checkbox" && frm.elements[i].name!="chkSelectAll" && frm.elements[i].checked)  
		    {  
                bIsSelected = true;
            }
         } 
    
   if(!bIsSelected)
   {
        alert("Atleast one checkbox should be selected before continuing.");
        return false;
   }
   
   else
     { 
        
             return confirm("Do you want to remove selected record(s) from the Top Sellers?");
        
     }
   
   return true;
}

function IsRadioButtonSelected()
{   
   // var type = document.getElementById().value; 
    frm=document.forms[0];
    bIsSelected = false;
       
    for(i=0;i<frm.elements.length;i++)  
		{
			if(frm.elements[i].type=="radio" && frm.elements[i].checked)  
		    {  
		  
                bIsSelected = true;
               // exit for;
            }
         } 
    
   if(!bIsSelected)
   {
        alert("Atleast one radio button should be selected before continuing.");
        return false;
   }
   
}

function CheckIsComboSelected(combo)
{
    if(document.getElementById(combo).value == "-1")
    {
         alert("Please choose action from the dropdown list.");
         document.getElementById(combo).focus();
         return -1;
    }
    return 1;
}


function checkall(ctl)
{ 
    frm=document.forms[0];
	if(ctl.checked)
	{ 
		for(i=0;i<frm.elements.length;i++)  
		{
			if(frm.elements[i].type=="checkbox")  
			{  
			    if(!frm.elements[i].disabled)
			    {
				    frm.elements[i].checked=true; 
				}
			}  
		}  
	}
	else
	{  
		for(i=0;i<frm.elements.length;i++)  
		{  
			for(i=0;i<frm.elements.length;i++)  
			{  
				if(frm.elements[i].type=="checkbox")  
				{  
					frm.elements[i].checked=false;  
				}  
			}  
		}  
	}  
}

//for check is all Checkbox selected from list then select All Checkbox else Deselect	
function resetcheckall(id)
{
    for(i=0;i<document.forms[0].elements.length;i++)  
		{
			if(document.forms[0].elements[i].type=="checkbox")  
			{ 
    			if(document.forms[0].elements[i].id.indexOf(id) >0)
    					{
				            if(document.forms[0].elements[i].checked == false)
				             {
				                document.forms[0].chkSelectAll.checked =false;
				               return;
				             }
				        } 
			}  
		}  
    document.forms[0].chkSelectAll.checked =true;
     return ;
		
}	

function showProg(ProgId, btId)
{ 
    if(document.getElementById(ProgId) && document.getElementById(btId))
    { 
        divProgress = document.getElementById(ProgId);
        divCont = document.getElementById(btId);
                
        divProgress.style.visibility = "visible";
        divProgress.style.display = "block";
        divCont.style.visibility = "hidden";
        //divCont.style.display = "none";
    }    
}

function ValidateGrpName_Num(sender,e)
{
    var txt=e.Value; 
    var alphaa = txt.charAt(0);
	var hh = alphaa.charCodeAt(0);
	
	for(var j=0; j<txt.length; j++)
	{
		  var alphaa = txt.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  
		  if(j==0)
		  {
		        if((hh > 64 && hh<91) || (hh > 96 && hh<123))
	            {
		            e.IsValid=true;
	            }
	            else	
	            {
		            e.IsValid=false;
		            return;
	            }
		  }
		  else
		  {
		      if((hh > 31 && hh < 35) || (hh > 37 && hh < 42) || (hh > 43 && hh < 59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		      {		    
		      }
		    else	
		    {
		        e.IsValid=false;
		        return;
		    }
		}
	}
	
    e.IsValid=true;
}

function ValidateSName_Num_SC(sender,e)
{
    var txt=e.Value; 
    var alphaa = txt.charAt(0);
	var hh = alphaa.charCodeAt(0);
	
	for(var j=0; j<txt.length; j++)
	{
		  var alphaa = txt.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  
		  if(j==0)
		  {		   
		        if((hh > 64 && hh < 91) || (hh > 96 && hh<123))
	            {
		            e.IsValid=true;
	            }
	            else	
	            {
		            e.IsValid=false;
		            return;
	            }
		  }
		  else
		  {
		        if((hh > 47 && hh < 58) || (hh > 64 && hh<91) || (hh > 96 && hh < 123))
		        {		    
		        }
		        else	
		        {
		            e.IsValid=false;
		            return;
		        }
		  }
	}	
    e.IsValid=true;
}


//var isDivMenuClicked = 0;
/*function hideAllMenus()
{   
    if(isDivMenuClicked==0)
    {    
        var divCntMenu=document.getElementById("divCntMenu");
        var divLocMenu=document.getElementById("divLocMenu");
        var divRegMenu=document.getElementById("divRegMenu");
    
        divCntMenu.style.visibility="hidden";
        divCntMenu.style.display="none";        
        
        divLocMenu.style.visibility="hidden";
        divLocMenu.style.display="none";        
        
        divRegMenu.style.visibility="hidden";
        divRegMenu.style.display="none";     
    }
    
    isDivMenuClicked = 0;
    return false;
}

function hideMenus(Menu1, Menu2)
{    
    var divMenu1=document.getElementById(Menu1);
    var divMenu2=document.getElementById(Menu2);
    
    divMenu1.style.visibility="hidden";
    divMenu1.style.display="none";
    
    divMenu2.style.visibility="hidden";
    divMenu2.style.display="none";
}

function showLocMenu(evnt)
{    
    isDivMenuClicked = 1;
    
    var divLocMenu=document.getElementById("divLocMenu");
    //divLocMenu.style.left=evnt.clientX;
    if(divLocMenu.style.visibility=="hidden")
    {
        divLocMenu.style.visibility="visible";
        divLocMenu.style.display="block";
    }
    else
    {
        divLocMenu.style.visibility="hidden";
        divLocMenu.style.display="none";
    }    
    
    hideMenus("divCntMenu", "divRegMenu");
    
    return false;
}

function showCntMenu(evnt)
{    
    isDivMenuClicked = 1;
    
    var divCntMenu=document.getElementById("divCntMenu");
    //divCntMenu.style.left=evnt.clientX;
    if(divCntMenu.style.visibility=="hidden")
    {
        divCntMenu.style.visibility="visible";
        divCntMenu.style.display="block";
    }
    else
    {
        divCntMenu.style.visibility="hidden";
        divCntMenu.style.display="none";
    }
    
    hideMenus("divLocMenu","divRegMenu");
    
    return false;
}

function showRegMenu(evnt)
{    
    isDivMenuClicked = 1;
    
    var divRegMenu=document.getElementById("divRegMenu");
    //divRegMenu.style.left=evnt.clientX;
    if(divRegMenu.style.visibility=="hidden")
    {
        divRegMenu.style.visibility="visible";
        divRegMenu.style.display="block";
    }
    else
    {
        divRegMenu.style.visibility="hidden";
        divRegMenu.style.display="none";
    }
    
    hideMenus("divLocMenu","divCntMenu");
    
    return false;
}*/
// Replace special characters from string
function  ReplaceSplChars(InputString,TxtClientID)
{
//alert(InputString);
//  while(InputString.indexOf('_')>0)
//  {
//     InputString=InputString.replace('_','__');   
//  }
 while(InputString.indexOf(' ')>0)
  {
     InputString=InputString.replace(' ','-');   
  }
  while(InputString.indexOf('.')>0)
  {
     InputString=InputString.replace('.','-');   
  }
   while(InputString.indexOf('_&_')>0)
  {
     InputString=InputString.replace('_&_','-and-');   
  }
  while(InputString.indexOf('&')>0)
  {
     InputString=InputString.replace('&','and');   
  }
   while(InputString.indexOf('_')>0)
  {
     InputString=InputString.replace('_','-');   
  }
  //alert(InputString);
  var TxtBox= document.getElementById(TxtClientID);
   TxtBox.value=InputString; 
}

// To Check length up to 500 
function ValidateMaxLength500(sender, e)
{   
        var txtbox =e.Value;
        if(txtbox.length > 500)
            e.IsValid=false;
        else
            e.IsValid=true;
}
// To Check length up to 1000 
function ValidateMaxLength1000(sender, e)
{   
        var txtbox =e.Value;
        if(txtbox.length > 1000)
            e.IsValid=false;
        else
            e.IsValid=true;
}
// Give alert when value of textbox is blank
function ChkValue(txtClientID)
{
    var txtbox=document.getElementById(txtClientID);
    if(txtbox.value=='')
     {
        alert('Enter some text for search.');
        return false;
     }
}
