// JavaScript Document

function abc(frmname,fieldname)
	{
		this.formobj=document.forms[frmname];	
		alert(this.formobj.name);
		//str.focus();
	}
	
	function selectRadio(radioName,radioValue) 
	{
		//this function is used to select one radio button from a group depending on the value from database.
		var j=0;
		
		for(var i=0;i< radioName.length; i++)
		{
			
			if(radioName[i].value==radioValue)
			{
				
				j=i;
				break;	
			}
			
		}
		radioName[j].checked=true;
	
	}
	
	function dropDown(fieldName,fieldValue)				         
	{
	//This function is used to select value from drop down box depending on the value in  database
		var j;
		//alert(fieldName+ "\t"+fieldValue);
		
		for(var i=0;i<fieldName.length;i++)
		{
			if(fieldName.options[i].value==fieldValue)
			{
				
				j=i;
				//alert(j);
				break;
			}
							
		}
		fieldName.selectedIndex=j;
	}
	
	function validateName(fieldName,msg)
	{
		//This function is used to validate Fname,Mname,Lname
		//It cannot validate multi-line TextBox
		var valid=true;
		var str=removeExtraSpace(fieldName.value);
		fieldName.value=str;
		if(str=="") // || fieldName.length()>250
		{
			alert(msg);
			fieldName.value="";
			fieldName.focus();
			valid=false;
		
		}
		
		return valid;
	}
	
	function isInteger(s)
	{
	   var i;
    	for (i = 0; i < s.length; i++)
    	{   
        	// Check that current character is number.
        	var c = s.charAt(i);
        	if (((c < "0") || (c > "9"))) return false;
    	}
    	// All characters are numbers.
    	return true;
	}
	
	function validatePhone(fieldName,length,msg)
	{
			var valid=true;
			var str=fieldName.value;
			if(isInteger(str)==false || str=="")
			{
					alert(msg);
					fieldName.focus();
					fieldName.value="";
					return false;
			}
			
	}
	
	function CheckEmail(fieldName,msg)
	 {
	 	
		var email = fieldName.value;
		var AtPos = email.indexOf("@");
		var blank=email.indexOf(" ");
		var StopPos = email.lastIndexOf(".");
		var valid=true;
		if (email == "") 
		{
			valid=false;
			alert(msg);
			fieldName.focus();
			fieldName.value="";
			return valid;
		}
		if (AtPos == -1 || StopPos == -1 || AtPos==0 || blank!=-1)
		 {
			valid=false;
			alert(msg);
			fieldName.focus();
			fieldName.value="";
			return valid;
		}
		if (StopPos < AtPos || StopPos == email.length -1  )
		 {
			valid=false;
			alert(msg);
			fieldName.focus();
			fieldName.value="";
			return valid;
		}
		if (StopPos - AtPos == 1) 
		{
			valid=false;
			alert(msg);
			fieldName.focus();
			fieldName.value="";
			return valid;
		} 
		return valid;
	}
	
	
	function removeExtraSpace(input)
	{
		
		var output = "";
		for (var l = 0; l < input.length; l++)
	 	{
			if ((input.charCodeAt(l) != 32) && (input.charCodeAt(l+1) != 32) ) //&& (input.charCodeAt(i + 1) == 10)) 
			{
				output=output+ input.charAt(l);
			}
			if ((input.charCodeAt(l) != 32) && (input.charCodeAt(l+1) == 32) ) //&& (input.charCodeAt(i + 1) == 10)) 
			{
				
				output=output+ input.charAt(l)+ " ";
			}
		
		}
		if(output.charAt(output.length - 1) == " ")
		{
			output=output.substring(0,output.length - 1);
		}
		//alert(output);
		return output;
	}

	
	function selectAtleast1Checkbox(fieldName,msg) //It is used to check whether one checkbox is selected from a checkbox group	
	{
		var valid=false;
		var i;
		
		if(isNaN(fieldName.length))
		{
			if(fieldName.checked==true)
			{
				valid=true;
			}
			else
			{
				fieldName.focus();
			}
		}
		else
		{
			for (i=0;i<fieldName.length;i++) 
			{
				if (fieldName[i].checked) 
				{
					valid=true;
					break;
				}
			}
			if(valid==false)
			{
				fieldName[0].focus();
			}
			
		}
		if(valid==false)
		{
			alert(msg);
		}
		return valid;
			
	}//function ends here
	
	function selectAtleast1RB(fieldName,msg) //It is used to check whether one radio button is selected from a radio group	
	{
		var valid=false;
		var i;
		
		if(isNaN(fieldName.length))
		{
			if(fieldName.checked==true)
			{
				valid=true;
			}
		}
		else
		{
			for (i=0;i<fieldName.length;i++) 
			{
				if (fieldName[i].checked) 
				{
					valid=true;
					break;
				}
			}
			if(valid==false)
			{
				alert(msg);
				fieldName[0].focus();
			}
			
		}
		return valid;
			
	}//function ends here
	
	function selectAtleastRB(fieldName) //It is used to check whether one radio button is selected from a radio group	
	{
		var valid=false;
		var i;
		
		if(isNaN(fieldName.length))
		{
			if(fieldName.checked==true)
			{
				valid=true;
			}
		}
		else
		{
			for (i=0;i<fieldName.length;i++) 
			{
				if (fieldName[i].checked) 
				{
					valid=true;
					break;
				}
			}
			if(valid==false)
			{
				//alert(msg);
				fieldName[0].focus();
			}
			
		}
		return valid;
			
	}//function ends here
	
	function checkImage(fname)//check certification image
   {
   		var valid=true;
   		var ext = fname;
  		ext = ext.substring(ext.length-3,ext.length);
  		ext = ext.toLowerCase();
		
 		if(ext == 'jpg' || ext =='gif' || ext =='pdf') 
  		{
				//document.form1.image.value=document.form1.file1.value; // Image is hidden field
				//alert(document.form1.image.value);
				valid=true;
  		}
  		else
		{
    			alert('You selected a .'+ext + ' file; please select a .jpg or .gif or .pdf file instead!');
    			valid= false; 
 		}
		
		return valid;
   }// checkImage function ends
   
   function getExtension(fname)
	{
		var valid=true;
		var firstpos=fname.lastIndexOf('.')+1;
		//alert(firstpos);
		var lastpos=fname.length;
		var ext=fname.substring(firstpos,lastpos);
		
		if(ext == 'doc' || ext =='pdf' || ext =='txt' || ext =='rtf') 
  		{
				//document.form1.image.value=document.form1.file1.value; // Image is hidden field
				//alert(document.form1.image.value);
				valid=true;
  		}
  		else
		{
    			alert('You selected a .'+ext + ' file; please select a .doc or .txt or .pdf  or .rtf file instead!');
    			valid= false; 
 		}
		
		return valid;
		//alert('My name is "'+Namer+'"');
		//alert(Namer);
		//return Namer;
	}//getExtension() ends here
	

function comboBox(fieldName,fieldValue)// this is used to select multiple value depending on the value in database	
{
	var arr=fieldValue.split(",");
	//alert(arr.length);
	var sel=new Array();
	var k=0
	for(var i=0;i<arr.length;i++)
	{
		//alert(arr[i]);
		for(var j=0;j<fieldName.length;j++)
		{
			//alert(arr[i]);
			if(fieldName.options[j].value==arr[i])
			{
				//alert(fieldName.options[j].value+ "   " + arr[i]);
				fieldName.options[j].selected=true;
				//alert(arr[i]);
			}//if ends
			
		}//for ends
		
	}//for ends
	
	//fieldName.options[1].selected=true;
	//fieldName.options[3].selected=true;
	//fieldName.options[5].selected=true;
}//function ends


function chbox(fieldvalue,dbvalue)
{
	if(fieldvalue==dbvalue)
	{
		return "checked";
	}
	else
	{
		return "unchecked";
	}

}

function comboBox1(fieldName,fieldValue)// this is used to select multiple value depending on the value in database	
{
	var arr=fieldValue.split(",");
	//alert(arr.length);
	//var sel=new Array(3);
	var k=0
	for(var i=0;i<arr.length;i++)
	{
		alert("Data base value" + arr[i]);
		for(var j=0;j<fieldName.length;j++)
		{
			alert("Combo box value"+fieldName.options[j].value);
			if(fieldName.options[j].value==arr[i])
			{
				//alert(fieldName.options[j].value+ "   " + arr[i]);
				fieldName.options[j].selected=true;
				//alert(arr[i]);
			}//if ends
			
		}//for ends
		
	}//for ends
	
	//fieldName.options[1].selected=true;
	//fieldName.options[3].selected=true;
	//fieldName.options[5].selected=true;
}//function ends

	
function dropDown1(fieldName,fieldValue)				         
	{
	//This function is used to select value from drop down box depending on the value in  database
		var j;
		//alert(fieldName+ "\t"+fieldValue);
		
		for(var i=0;i<fieldName.length;i++)
		{
			alert(fieldName.options[i].value);
			if(fieldName.options[i].value==fieldValue)
			{
				j=i;
				//alert(j);
				break;
			}
							
		}
		fieldName.selectedIndex=j;
	}	
		