/*===============================================================================
		Function Name:	SetFocus
		Purpose		 :	Set Focus
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
================================================================================*/

//function ValidatePhoneNumber(Number)
//{
//    var strValidChars="0123456789-.() ";

//	var strChar;
//	var blnResult = true;

//	for (k = 0; k < Number.length; k++)
//	{
//		strChar = Number.charAt(k);
//		if (strValidChars.indexOf(strChar) == -1)
//		{
//			blnResult = false;
//			return blnResult;
//		}
//	}
//	if(blnResult)
//	{
//	     strValidChars="0123456789";
//	     var Counter=0;
//         for (k = 0; k < Number.length; k++)
//	        {
//		        strChar = Number.charAt(k);
//		        if (strValidChars.indexOf(strChar) != -1)
//		        {
//			        Counter=Counter+1;
//		        }
//	        }   
//	        if (Counter!=10)
//	        {
//	            blnResult = false;
//			    return blnResult;
//	        }
//	}
//	//alert(blnResult);
//	return blnResult;
//}

function ValidatePhoneNumber(Number)
{
    return (isInteger(Number) && Number.length == 12);
}

function isInteger(s)
{   
    var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
        {
            if(!((c == "-") && ((i == 3) || (i == 7))))
            {

                return false;                    
            }
        }
        if (((c > "0") || (c < "9")))
        {
            if((c != "-") && ((i == 3) || (i == 7)))
            {
                return false;
            }
        }
        
    }
    // Phone number is valid.
    return true;
}



/*===============================================================================
		Function Name:	SetFocus
		Purpose		 :	Set Focus
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
================================================================================*/
function ValidateCulture()
{
	
	var objCultureID=document.all['lblCultureID'];
	var objDefLang=document.all['lblDefaultCultureID'];
	var display_Label=document.all['lblError'];
		display_Label.innerText='';
	
	var s1=objCultureID.innerText;
	var s2=objDefLang.innerText;
	if(s1!=s2)
	{
		GetMessage('Default_Language','lblError');
		return false;
	}
	return true;	
}

/*===============================================================================
		Function Name:	SetFocus
		Purpose		 :	Set Focus
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
================================================================================*/

function SingleSelect(RadioButtonClientID, CheckBoxClientID, DataGridName)
{

	if(document.all[CheckBoxClientID].checked == false)
	{
		document.all[CheckBoxClientID].checked=true;
	}
	var arrElem=document.getElementsByTagName('input');
	for(i=0;i<arrElem.length;i++)
		{
			if(arrElem[i].type=='radio' && arrElem[i].id.indexOf(DataGridName)!=-1)
			{
				arrElem[i].checked = false;
			}
		}
		document.all[RadioButtonClientID].checked = 'checked';
}
			
			
			
			
			


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 Name:	SetFocus
		Purpose		 :	Set Focus
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/
function SetFocus(Ctrl)
{
	var objCtrl=document.all[Ctrl];
	objCtrl.focus();
}



/*============================================================================================================
		Function Name:	Check_All
		Purpose		 :	Select All the Check Boxes in the Grid
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/

	function SelectAll(DataGridName,SelectAllCheckBoxName,GridCheckBoxName)
	{
	
	
	var Name=DataGridName+'__ctl1_'+SelectAllCheckBoxName;
	var chkSelectAll=document.all[DataGridName+'__ctl2_'+SelectAllCheckBoxName]; 
	
	
	var Loop=true;
	
	
	
	var SelectAll=false;
	
	
	if (chkSelectAll.checked==true)
		{	SelectAll=true;	}
	else
		{	SelectAll=false;}
	
	//alert(	SelectAll);
	var Counter=1;
	var Exit=0;
	
	while(Loop)
	{
		Name=DataGridName+'__ctl'+Counter+'_'+GridCheckBoxName;
		var checkBox=document.all[Name]; 
		
		if (checkBox!=null)
			checkBox.checked=SelectAll;
		else
		{
			Exit=Exit+1;
			if (Exit>5) 
				Loop=false;
		}
		Counter=Counter+1;
	}
	
	return true;
	
}




/*============================================================================================================
		Function Name:	Check_All
		Purpose		 :	Select All the Check Boxes in the Grid
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/

	function CheckSelectAll(DataGridName,SelectAllCheckBoxName,GridCheckBoxName)
	{
	var Name=DataGridName+'__ctl1_'+SelectAllCheckBoxName;
	var chkSelectAll=document.all[DataGridName+'__ctl2_'+SelectAllCheckBoxName]; 
	var AllChecked=0;
	var CheckBoxCount=0
	var Loop=true;
	var Counter=1;
	var Exit=0;
	while(Loop)
	{
		Name=DataGridName+'__ctl'+Counter+'_'+GridCheckBoxName;
		var checkBox=document.all[Name]; 
		//alert(Name);		
		if (checkBox!=null)
		{
			CheckBoxCount=CheckBoxCount+1;
			if (checkBox.checked==false)
			{
				chkSelectAll.checked=false;
			}
			else
			{
				AllChecked=AllChecked+1;
			}
		}
		else
		{
			Exit=Exit+1;
			if (Exit>5) 
				Loop=false;
		}
		Counter=Counter+1;
	}
	//alert(CheckBoxCount);
	//alert(AllChecked);
	
	if (AllChecked==CheckBoxCount)
		chkSelectAll.checked=true;
	
	return true;
	
}


/*============================================================================================================
		Function Name:	ShowPreview
		Purpose		 :	Display the Image Full View
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/


function ShowPreview(Path)
			{
				window.open('Preview.aspx?Image='+Path,'Preview','width=500,height=500,resizable=1,scrollbars=1');
				
				return false;
			}
			
			
			
			
			
			
			
			
			
	/*============================================================================================================
		Function Name:	Check_All
		Purpose		 :	Select All the Check Boxes in the Grid
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/

	function SelectAllWithoutPaging(DataGridName,SelectAllCheckBoxName,GridCheckBoxName)
	{
	
	
	var Name=DataGridName+'__ctl1_'+SelectAllCheckBoxName;
	var chkSelectAll=document.all[DataGridName+'__ctl1_'+SelectAllCheckBoxName]; 
	
	
	var Loop=true;
	
	
	
	var SelectAll=false;
	
	
	if (chkSelectAll.checked==true)
		{	SelectAll=true;	}
	else
		{	SelectAll=false;}
	
	//alert(	SelectAll);
	var Counter=1;
	var Exit=0;
	
	while(Loop)
	{
		Name=DataGridName+'__ctl'+Counter+'_'+GridCheckBoxName;
		var checkBox=document.all[Name]; 
		
		if (checkBox!=null)
			checkBox.checked=SelectAll;
		else
		{
			Exit=Exit+1;
			if (Exit>5) 
				Loop=false;
		}
		Counter=Counter+1;
	}
	
	return true;
	
}

function SelectAllWithoutPaging(DataGridName,SelectAllCheckBoxName,GridCheckBoxName,radioButtonID)
	{
	
	
	var Name=DataGridName+'__ctl1_'+SelectAllCheckBoxName;
	var chkSelectAll=document.all[DataGridName+'__ctl1_'+SelectAllCheckBoxName]; 
	var radioButtonName;
	
	var Loop=true;
	
	
	
	var SelectAll=false;
	
	
	if (chkSelectAll.checked==true)
		{	SelectAll=true;	}
	else
		{	SelectAll=false;}
	
	//alert(	SelectAll);
	var Counter=1;
	var Exit=0;
	
	while(Loop)
	{
		Name=DataGridName+'__ctl'+Counter+'_'+GridCheckBoxName;
		radioButtonName=DataGridName+'__ctl'+Counter+'_'+radioButtonID;
		var rdButton =document.all[radioButtonName]; 
		if(SelectAll==false && rdButton!=null)
		{
			rdButton.checked=false;
		}
		var checkBox=document.all[Name]; 
		
		if (checkBox!=null)
			checkBox.checked=SelectAll;
		else
		{
			Exit=Exit+1;
			if (Exit>5) 
				Loop=false;
		}
		Counter=Counter+1;
	}
	
	return true;
	
}


/*============================================================================================================
		Function Name:	Check_All
		Purpose		 :	Select All the Check Boxes in the Grid
		Parameters	 :	
		Date		 :	
		Author		 :	Ishwar Goyal
	============================================================================================================*/

	function CheckSelectAllWithoutPaging(DataGridName,SelectAllCheckBoxName,GridCheckBoxName)
	{
	var Name=DataGridName+'__ctl1_'+SelectAllCheckBoxName;
	var chkSelectAll=document.all[DataGridName+'__ctl1_'+SelectAllCheckBoxName]; 
	var AllChecked=0;
	var CheckBoxCount=0
	var Loop=true;
	var Counter=1;
	var Exit=0;
	while(Loop)
	{
		Name=DataGridName+'__ctl'+Counter+'_'+GridCheckBoxName;
		var checkBox=document.all[Name]; 
		//alert(Name);		
		if (checkBox!=null)
		{
			CheckBoxCount=CheckBoxCount+1;
			if (checkBox.checked==false)
			{
				chkSelectAll.checked=false;
			}
			else
			{
				AllChecked=AllChecked+1;
			}
		}
		else
		{
			Exit=Exit+1;
			if (Exit>5) 
				Loop=false;
		}
		Counter=Counter+1;
	}
	//alert(CheckBoxCount);
	//alert(AllChecked);
	
	
	
	if (AllChecked==CheckBoxCount)
		chkSelectAll.checked=true;
	
	
	return true;
	
}









function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

//Function for controlling maxlength in a text area
function textCounter(textBoxID, maxlimit) {
	
	if (document.getElementById(textBoxID).value.length > maxlimit) // if too long...trim it!
	{
		document.getElementById(textBoxID).value = document.getElementById(textBoxID).value.substring(0, maxlimit);
	}
}
function formatNumberNew(obj) 
{ 	
	var Initialvalue = obj.value; 
	var valueLen = obj.value.length; 
	var formattedValue='';
	var firstexist = false;
	
	if(valueLen<=12 && valueLen >0 && (Initialvalue.charAt(3)!= "-" || Initialvalue.charAt(6)!= "-")) 
	{ 
		if(Initialvalue.charAt(3)!= "-")
		{
			formattedValue = Initialvalue.substring(0,3) + "-" + Initialvalue.substring(3,6);
			firstexist = false;
		}
		else
		{
			formattedValue = Initialvalue.substring(0,7);
			firstexist = true;
		}
		
		if(firstexist == true)
		{	
			if(Initialvalue.charAt(7)!= "-")
			{
				formattedValue = formattedValue + "-" + Initialvalue.substring(7);
			}
			else
			{
				formattedValue = formattedValue + "-" + Initialvalue.substring(8);
			}
		}
		else
		{
			
			if(Initialvalue.charAt(6)!= "-")
				formattedValue = formattedValue + "-" + Initialvalue.substring(6);
			else
				formattedValue = formattedValue + "-" + Initialvalue.substring(7);
			
		}
		if((formattedValue.charAt(formattedValue.length-2) == "-")&& (formattedValue.charAt(formattedValue.length-1) == "-"))
			formattedValue = formattedValue.substring(0,formattedValue.length-2);	
		obj.value = formattedValue;
	} 
	
} 

//Fogbugz issue 654.Clear Masks on Phone # fields on Site. Function to validate phone.
function ValidatePhoneNo(Number)
{
  // var ValidChars = "0123456789-[]()";
  //var Valid = "-[]()";
  // var InvalidlastChar = "-[(";
  // var i;
  // var Count=0;
   
	  // for (i = 0; i < Number.length; i++)
	   //{
	   //  var strchar = Number.charAt(i);
	   //  if (ValidChars.indexOf(strchar) == -1)return false ;
	   //  if (InvalidlastChar.indexOf(Number.charAt(Number.length-1)) != -1) return false;
	    // if (Valid.indexOf(strchar) != -1)
	    // {
	       // Count = Count+1;
	    //}
	    // if(Count>3)return false;
	   //}
	  return true;
}

function PhoneValidation(Number)
{
    var ValidChars = "-[]()";
    var i;
    for (i = 0; i < Number.length; i++)
    { 
        var strchar = Number.charAt(i);
        if (((strchar < "0") || (strchar > "9")))
        {
          if (ValidChars.indexOf(strchar) == -1)
          return false ;
        }
    }
    return true;
}
