//global variable for message
var v1="Select a valid option";

//function right(e) {
//if (navigator.appName == 'Netscape' && 
//(e.which == 3 || e.which == 2))
//return false;
//else if (navigator.appName == 'Microsoft Internet Explorer' && 
//(event.button == 2 || event.button == 3)) {
//alert("Sorry, you do not have permission to right click.");
//return false;
//}
//return true;
//}

//document.onmousedown=right;
//document.onmouseup=right;
//if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//if (document.layers) window.captureEvents(Event.MOUSEUP);
//window.onmousedown=right;
//window.onmouseup=right;

//window.history.go(1); 

//function ensureInFrameset()
//{
//	var p= parent.location.href
//	var pSub = p.slice(p.lastIndexOf("/")+1).toUpperCase()
//	//alert(pSub);
//	if (pSub != "CATIPAGE.ASP" && pSub!="AUTHENTICATE.ASP" && pSub != "MAIN.ASP")
//	{
//		var actPage=1
//		alert("You are not allowed to use addres bar or manually change page.\nMail regarding same sent to PM / Software Team");
//		window.open(p.slice(0,p.lastIndexOf("/")+1) + "CatiPage.asp?p=" + actPage,"_parent");
//	}
//}
//ensureInFrameset();

//This function validates the textfield for numeric value
function isNumeric(textField,type)
{
	var theChar,message,text,temp;
	var length,dotCount=0,perCount=0;
	var numeric;
		
	message = "Enter only numeric value.";
	numeric = true;	
	text = textField.value;
	length = text.length;
	
	//alert("text===" + text);
		 
	for(var i=0 ; i<length ; i++)	   //Iterate through entire text value.
	{
		theChar = text.substring(i,i+1);  //Extract a Character and check it.
		if(type == "real" && ((theChar<"0" || theChar>"9") && theChar != "."))
			
			numeric = false;
		else if(theChar == ".")           //check for multiple appearence of "."
			dotCount++;
		else if(type == "per" && ((theChar<"0" || theChar>"9") && theChar != "." && theChar!="%"))
		{				
			numeric = false;

		}
		else if(type=="per" && theChar == "%")
		{	
		
			perCount++;
		}	
			
		if(type == "integer" && (theChar<"0" || theChar>"9"))
		{
			message="Enter only numeric integer value."
			textField.value = "";
			textField.focus();
			numeric = false;
		}
	}
	

	if(!numeric || dotCount > 1 || perCount>1) 
	{
		alert(message);
		textField.value = "";
		textField.focus();
		return false;
	}
	else if(text.charAt(length-1) == "." )
	{
		if(text.length==1)
			textField.value="0";
//		else
//			textField.value = textField.value + "0";
	}
	
	/********************	
	if ((type == "per" && text.parseInt(textField.value,10) > 100) || (type == "per" && 
	text.parseInt(text.substring(0,length-1),10) > 100 && (text.charAt(text.length-1) == 	"%")))
	{
		
		alert("Less than 100%");
		textField.value = "";
		textField.focus();
		return false;
		
	}****************/
	if(type=="per")
	{
			var b,a="";
			b=text;
			
			if (b.charAt(b.length-1)=='%')
			{
				//alert('hj');

				
				for(var i=0;i<b.length-1;i++)
					a=a+b.charAt(i);
					
			b=a;
			}
		if(b>100)
		{
			alert("Enter percentage less than or equal to 100.");
			textField.value = '';
			textField.focus();
			return false;
		}
	}
	return true;
}



function isBlankNumeric(theField)  
{
	var theText = theField.value;
	var flag;
	flag=false;
	if (theText=="")
		{			
			message = "Please enter the Number.";
		}
	else
	if (theText=="0")
		{
			message = "Cannot Be Blank Or Zero  ";
		}		
	else
		{
			for (i=0;i<theText.length;i++)
				{
					if (theText.charAt(i)!=" ")
						{
							flag=true;
						}
				}
		message = "Please enter the Number.";
		}
//	message = "Please enter the Number.";
	if (flag==false)
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
}


//This function checks for validates the textfields for  character data.
function isCharacter(theField)
{
	var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-, .0123456789 !@#$%^&*()_+|\`~`";
	var theText = theField.value;
	var mess = " ";
	var valid = true;
	var count=0;
	
	for(var i=0;i<theText.length;i++)
	{
		var aChar = theText.substring(i,i+1);
		if (aChar==" ")
		{
			count = count+1;
		}
		if(str.indexOf(aChar)< 0 && valid==true)
		{
			mess += "Enter only valid characters.\n";
			valid = false;
		}
	}
	if(count==theText.length)
	{
		mess +="Input valid Characters.\n";
		valid = false;
	}
	if(!valid)
	{
		alert(mess);
		theField.value="";
		theField.focus();
		return false;
	}
	return true;
}

function isBlank(theField)  
{
	var theText = theField.value;
	var flag;
	flag=false;
	if (theText=="")
		{
		}
	else
		{
			for (i=0;i<theText.length;i++)
				{
					if (theText.charAt(i)!=" ")
						{
							flag=true;
						}
				}
		}
	message = "Please enter the text.";
	if (flag==false)
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
	
	
//	if (theText=="")
//	{	
//		alert(message);
//		theField.focus();
//		return false;	
//	}
//	return true;
}

function isBlankText(theField)  
{
	var theText = theField.value;
	var flag;
	flag=false;
	if (theText=="")
		{
		}
	else
		{
			for (i=0;i<theText.length;i++)
				{
					if (theText.charAt(i)!=" ")
						{
							return true;
						}
				}
		}
		return false;	
	
	return true;
}



function isNumericBlank(theField)  
{
	var theText = theField.value;
	message = "Please enter the value.";
	if (theText=="")
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
}

function isText(theField, QNo)  
{
//	var theText = theField.value;
	message = "Please enter the value in " + QNo;
//	if (theText=="")
//	{	
//		alert(message);
//		theField.focus();
//		return false;	
//	}
//	return true;
	var theText = theField.value;
	var flag;
	flag=false;
	if (theText=="")
		{
		}
	else
		{
			for (i=0;i<theText.length;i++)
				{
					if (theText.charAt(i)!=" ")
						{
							flag=true;
						}
				}
		}
	if (flag==false)
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
}

function AllBlank()
{
 var el = document.forms[0].elements;
    for(var i = 0 ; i < el.length ; ++i) 
    {	
        if(el[i].type == "text") 
            {
                if(!isBlank(el[i]))
                return false;
            }
    }
    return true;
}

function checkRadios() {
 var el = document.forms[0].elements;
 var radiogroup, radiocount=0;
// added following line by muquit on 1 aug 08 to allow checking when one radio button exists
 for(var i = 0 ; i < el.length ; ++i) {	   if(el[i].type == "radio")   radiocount++;  }
  
 
 
 for(var i = 0 ; i < el.length ; ++i) {
	
  if(el[i].type == "radio") {
   radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   //alert(el[i].name);
   
   var itemchecked = false;
// added following line by muquit on 1 aug 08 to allow checking when one radio button exists
	if (radiocount==1 && el[i].checked==true)	 {return true;}
	
	
	for(var j = 0 ; j < radiogroup.length ; ++j) {
    	//---- Added by avani----
    	if(radiogroup[j].disabled)
    	{
    		//alert ("Called" + radiogroup[j].name);
    		itemchecked = true;
			break;   		
    	}
    	//---------
    	//alert(itemchecked);
    	if(radiogroup[j].checked) {
	itemchecked = true;
	
	 break;
	}
   }
   if(!itemchecked) { 
	
    alert("Please select an option ");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 



function checkRadiosblank() {
 var el = document.forms[0].elements;
 var radiogroup;
	 
 for(var i = 0 ; i < el.length ; ++i) {
	
  if(el[i].type == "radio") {
   radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   //alert(el[i].name);
   var itemchecked = false;

	for(var j = 0 ; j < radiogroup.length ; ++j) {
    	//---- Added by avani----
    	if(radiogroup[j].disabled)
    	{
    		//alert ("Called" + radiogroup[j].name);
    		itemchecked = true;
			break;   		
    	}
    	//---------
    	if(radiogroup[j].checked) {
	itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
	
   // alert("Please select an option ");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 


function checkRadio() {
 var el = document.forms[0].elements;
 var radiogroup;
	 
 for(var i = 0 ; i < el.length ; ++i) {
	
  if(el[i].type == "radio") {
   radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   //alert(el[i].name);
   var itemchecked = false;

	for(var j = 0 ; j < radiogroup.length ; ++j) {
    	if(radiogroup[j].checked) {
	itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
	
    alert("Please select an option ");
  
	return false;
   }
  }
 }
 return true;
}

function checkRadiosMatrix() {
 var el = document.forms[0].elements;
 var radiogroup;
	 
 for(var i = 0 ; i < el.length ; ++i) {
	//alert(i);
if(el[i].disabled==false)	
{

  if(el[i].type == "radio") {
   radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   //alert(el[i].name);
   var itemchecked = false;

	for(var j = 0 ; j < radiogroup.length ; ++j) {
    	if(radiogroup[j].checked) {
	itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
	//alert(el[i].id.substr(2,1));
    //alert(el[i].id.charAt(2));
   //alert(el[i].id);
    alert("Please select an option for row ("+el[i].id.substr(0,1)+").");
    //alert("Please select an option ");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 }
 return true;
} 



function isalpha(theField)
{
	var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var theText = theField.value;
	var mess = " ";
	var valid = true;
	var count=0;
	
	for(var i=0;i<theText.length;i++)
	{
		var aChar = theText.substring(i,i+1);
		if (aChar==" ")
		{
			count = count+1;
		}
		if(str.indexOf(aChar)< 0 && valid==true)
		{
			mess += "Enter only Alphabet.\n";
			valid = false;
		}
	}
	if(count==theText.length)
	{
		mess +="Input only alphabet.\n";
		valid = false;
	}
	if(!valid)
	{
		alert(mess);
		theField.value="";
		theField.focus();
		return false;
	}
	return true;
}

function isAlphanumeric(theField)
	{
	var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var theText = theField.value;
	flag=false;
	if (theText=="")
		{
		}
	else
		{
			for (i=0;i<theText.length;i++)
				{
				for (j=0;j<str.length;j++)
					{
					if (theText.charAt(i)==str.charAt(j))
						{
							flag=true;
						}
					}	
				}
		}
	message = "Cannot Enter Blank Or Numeric Value.";
	if (flag==false)
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
	
}



function isBlankInd(theField,txt)  
{
	var theText = theField.value;
	var flag;
	flag=false;
	if (theText=="")
		{
		}
	else
		{
			for (i=0;i<theText.length;i++)
				{
					if (theText.charAt(i)!=" ")
						{
							flag=true;
						}
				}
		}
	message = "Please enter the "+txt +".";
	if (flag==false)
	{	
		alert(message);
		theField.focus();
		return false;	
	}
	return true;
	
	
//	if (theText=="")
//	{	
//		alert(message);
//		theField.focus();
//		return false;	
//	}
//	return true;
}


function checkBoxes()
{
	var el = document.forms[0].elements;
	var checkgroup;
	var checkname;
	var itemchecked = false;	 
	var flg = false;	 
	var i;
	checkname="";
	for(i= 0 ; i < el.length ; ++i) 
	{
		if(el[i].type == "checkbox")
		{
			if (flg == false)
			{
				checkname = el[el[i].name];
				flg=true;
			}
			checkgroup = el[el[i].name]; 
			if (checkgroup.checked)
			{
				itemchecked = true;
				break;
			}
		}	
	}
			if(!itemchecked) 
			{ 
				alert("Please select an option");
				checkname.focus();
				return false;
			}
	return true;
} 

function checkmultiRadios()
{
 var el = document.forms[0].elements;
 var radiogroup;
	 
 for(var i = 0 ; i < el.length ; ++i) {
	//alert(el.length);
	//alert(i); 
  if(el[i].type == "radio") {
   var itemchecked = false;


    	if(el[i].checked) {
	itemchecked = true;
	 break;
	}
   }
}
   if(!itemchecked) { 
    alert("Please select an option ");
    //if(el[i].focus)
     el[0].focus();
	return false;
   }
  //}
 //}
 return true;
}


function CheckBoxesCount()
{
	var el = document.forms[0].elements;
	var checkgroup;
	var cnt=0;
	var checkname;
	var itemchecked = false;	 
	var flg = false;	 
	var i;
	checkname="";
	for(i= 0 ; i < el.length ; ++i) 
	{
		if(el[i].type == "checkbox")
		{
			if (flg == false)
			{
				checkname = el[el[i].name];
				flg=true;
			}
			checkgroup = el[el[i].name]; // get the whole set of radio buttons.
			if (checkgroup.checked)
			{
				cnt=cnt+1;
			
			}
		}	
	}
	return cnt;
} 

function CheckEmail(str) {
		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")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}


function CheckMatrix(textfield,i1,chk)
{
			var cnt;
			cnt=0;
			
			
			var el=document.forms[0].elements;
				for(i=0;i<el.length;i++)
				{
				
					if(el[i].type=='checkbox' && el[i].name.substr(textfield.name.length-1,1)==i1)
					{
						if(el[i].checked==true)
						{
						cnt++
						
							if(cnt>chk)
							{
							alert('select only two option')
							el[i].checked=false;
							
							}
						}
						
					}
				}

 }   

function Check(textfield,i1)
{
			var cnt;
			cnt=0;
			
			
			var el=document.forms[0].elements;
				for(i=0;i<el.length;i++)
				{
				
					if(el[i].type=='checkbox' && el[i].name.substr(textfield.name.length-1,1)==i1)
					{
						if(el[i].checked==true)
						{
						cnt++
						
							if(cnt>chk)
							{
							alert('select only two option')
							el[i].checked=false;
							
							}
						}
						
					}
				}

 }
 
 function RankMatrix(textfield,i1)
			{
			var text=textfield.selectedIndex;
           
		       var el = document.forms[0].elements;
               j=0;
              for(i= 0 ; i < el.length ; i++) 
	          {    
	            //alert(el[i].name.substr(textfield.name.length-1,1));
		          if (el[i].name!=textfield.name && el[i].name.substr(textfield.name.length-1,1)==i1)
		            {
		              if(el[i].selectedIndex==text)
		               {
		                alert("This rank is already selected");
		                
		                textfield.value="";
		                }
		        }
	         }	
         }   

 function Rank(textfield)
			{
			var text=textfield.selectedIndex;
           
		       var el = document.forms[0].elements;
               j=0;
              for(i= 0 ; i < el.length ; i++) 
	          {    
		          if (el[i].name!=textfield.name)
		            {
		              if(el[i].selectedIndex==text)
		               {
		                alert("This rank is already selected");
		                
		                textfield.value="";
		                }
		        }
	         }	
         }  
 
    function RankMatrix14(textfield,i1)
			{
			var text=textfield.selectedIndex;
           
		       var el = document.forms[0].elements;
               j=0;
              for(i= 0 ; i < el.length ; i++) 
	          {    
	            //alert(el[i].name.substr(textfield.name.length-1,1));
		          if (el[i].name!=textfield.name && el[i].name.substr(textfield.name.length-1,1)==i1)
		            {
		              if(el[i].selectedIndex==text)
		               {
		                alert("This is already selected");
		                
		                textfield.value="";
		                }
		        }
	         }	
         }   
             
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}     


function isOtherText(rad,theField)  
{
	
	
	var theText = theField.value;
	var flag;
	flag=false;
	message = "Please enter the value.";
	if (rad==true && theText=="")
		{
		alert(message);
		theField.focus();
		return false;	
		}
	else
		{
	
		if (rad==false)
			{
				theField.value="";
			}
		}	
	return true;
}

function checkRadiosMatrixOther() {
 var el = document.forms[0].elements;
 var radiogroup;
	 
	 for(var i = 0 ; i < el.length ; ++i)  
	 {
		//alert(i);
		if(el[i].type == "radio") 
		{
			radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			//alert(el[i].name);
			var itemchecked = false;
			var count=0;
			for(var j = 0 ; j < radiogroup.length ; ++j) 
			{
				//---- Modifed by avani----------------------------------------------------------------
    			if(radiogroup[j].disabled)
    			{
    				count=count+1;	
					//alert ("Called" + radiogroup[j].name+ " "+ count);
					continue;
    			}
    			if(radiogroup[j].checked) 
    			{
					itemchecked = true;					
					break;	
				}
				
			}
			if(count==j)
			{
				itemchecked=true;
				//alert("called:2313");
			}
   			//-------------------------------------------------------------------------------------------
			if (el[i].id!='oth')
			{
				if(!itemchecked) 
				{ 
					//alert(el[i].id.substr(2,1));
					//alert(el[i].id.charAt(2));
					//alert(el[i].id);
					alert("Please select an option for row ("+el[i].id.substr(0,1)+").");
					//alert("Please select an option ");
					if(el[i].focus)
						el[i].focus();
					return false;
				}
			}	
		 }
	 }
	return true;
} 

function CheckEmail(str) {
		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")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function checkBoxescount()
{
	var el = document.forms[0].elements;
	var checkgroup;
	var tot=0;
	var checkname;
	var itemchecked = false;	 
	var flg = false;	 
	var i;
	checkname="";
	for(i= 0 ; i < el.length ; ++i) 
	{
		if(el[i].type == "checkbox")
		{
			if (flg == false)
			{
				checkname = el[el[i].name];
				flg=true;
			}
			checkgroup = el[el[i].name]; 
			if (checkgroup.checked)
			{
				tot=tot+1;
			}
		}
	}
return tot;
}
