/******************************************************************************************************************/
//	File Name		: JScript.cs		
//	Description		: Used for the Client side functionality in SearchPicker control 
//	Project			: SearchPicker control
//	Created Date	: 11-MAY-2007
//	Author			: Sreenivasa Reddy.sadu
//*****************************************************************************************************************
//	Revision History
//*****************************************************************************************************************
//	Date		|	Modified By		|	 Description
//*****************************************************************************************************************/
//				|					| 
//*****************************************************************************************************************/


/////////////////////////////////Validation for the page number text box//////////////////////////////////////////

//creating a function to validate the Pagenumber textbox
function IsNumeric()
{
//creating a variable and assigning the value of the Page number text box to the variable
 var strInput=document.getElementById('txtPageNo').value;
	//strInput is input string
	//iLength is the length of the string
	var iLength=strInput.length;
	
	//iLoop is for looping purpose
	//flag and flag1 are two integer variables one for numeric count another for non numeric count. 	
	var iLoop,flag=0,flag1;
	
	//iNumeric is for numeric values
	var iNumeric;
	
	// input string each character is checking for all numeric values 0 to 9
	if(strInput!="")
	{
		for(iNumeric=0;iNumeric<=9;iNumeric++)
		{
			for(iLoop=0;iLoop<strInput.length;iLoop++)
			{
				// if not matched with 0 to 9 then returns that not a numeric with an indication as false 
				if(strInput.charAt(iLoop)==iNumeric)
					//setting the flag value to 1
					flag+=1;
				else
				//setting the flag value to 0
					flag1=0;
					
			}
			
		}
		//checking the flag value
		if(flag!=strInput.length)
		{ 
			//displaying aletr message 
			alert("Please enter the valid page number");
			//clearing the pagenumber textbox
			document.getElementById('txtPageNo').value="";
			return false;
		}
		else
		{//alert("it is a numeric");
			return true;
			//return true;	
		}
	}
	else
	{
		//displaying aletr message 
			alert("Please enter the page number");
			//clearing the pagenumber textbox
			document.getElementById('txtPageNo').value="";
			
			return false;
	}
	
	
	
}





//////////////////////////////////WindowOpen(strpickerid)/////////////////////////////////////////////////////////

//function to open a new window or popup containing the DataGrid filled with Data from database. 
//this function will take twoo input parameters Page url and the picker id of the data.xml file.

function showSearchPicker(strpage,strpickerid)
{
	//function to open a new window with the specified values based on the picker Id and the page url
	window.open(""+strpage+"?id="+strpickerid+"","SearchPicker","left=400,height=290,width=600,scrollbars=no,resizable=no");
}

//function to open a window or popup caontaing the DataGrid filled with the data from the Xml file.this function 
//will take three input parameters page url,picker id from data.xml file and another picker id from the source xml 
//file.
function showXmlSearchPicker(strpage,strpickerid,strxmlpickerid)
{
	//function to open a new window with the specified values based on the picker Ids and the page url
	window.open(""+strpage+"?id="+strpickerid+"?"+strxmlpickerid+"","SearchPicker","left=400,height=290,width=600,scrollbars=no,resizable=no");
}

function showXmlSmallSearchPicker(strpage,strpickerid,strxmlpickerid)
{
	//function to open a new window with the specified values based on the picker Ids and the page url
	window.open(""+strpage+"?id="+strpickerid+"?"+strxmlpickerid+"","SearchPicker","left=700,height=190,width=220,top=470,scrollbars=no,resizable=no");
}
///////////////////////////////Transfer(strcontrolid) function////////////////////////////////////////////////////

//this function will take the string of id's of the Controls as input Arguments and the values to the 
//controls will be assigned by using an array with the help of hidden field value.
	function transferData(strcontrolid)
	{
		//Creation of new Array object for control ids
		var arrconid = new Array();
		//Creation of new Array object for assigning the spilited values of the controls
		var arrval = new Array();
		//Creation of new Array object for assigning the values for the controls
		var arrcontrolval = new Array();
		//Creation of new Array object for assigning the value of the hiden field value
		var arrhdnval=new Array();
		//Creation of new Array object for assigning the value of the control ids
		var arrcolid=new Array();
		//Assigning the string of control ids to the Array arrcollid
		arrcolid[0]=strcontrolid;
		//using for loop to split the string of id of the control
		for(var k=0;k<1;k++)
		{
			//assigning the splited array value to another array for storing the array values
			arrconid[0]=arrcolid[k].split('/');
			//using for loop to store or assign the controlId's in an array
			for(var l=0;l<arrconid[0].length-1;l++)
			{
				//Assigning the control id's to the Array
				arrcontrolval[l]=window.opener.document.getElementById(arrconid[0][l]);
			}
		}
			//Assigning the hidden fied values as a string to an array
			arrhdnval[0] =document.getElementById("hdnId").value;
			//using for loop to split the string
			for(var i=0;i<1;i++)
			{
				//assigning the splitted string of values to another array
				arrval[0]=arrhdnval[0].split('~');
				//using for loop to store the values of the Hidden field in an array
				for(var j=0;j<arrval[0].length-1;j++)
				{
					//Assigning the Hidden field value to the Array of control values
					arrcontrolval[j].value=arrval[0][j];
				}
			}
				//to close the window or popup  
				window.close();
		}


///////////////////////////////loadStyleSheet() function/////////////////////////////////////////////////////////

			
			//funtion to Change the stylesheet 
			function loadStyleSheet()
			{
			//debugger
				//Creating an array object for storing the cookie value
				var arr = new Array();
				//assiging the cookie to the array
				arr[0]=document.cookie;
				//Creating an array object for storing the splited cookie value
				var arrlen = new Array();
				//using for loop to split the cookie value
				for(var l=0;l<1;l++)
				//assigning the splited value to the array variable
				arrlen[0]=arr[l].split(';');
				//declaring a variable and assigning the CreateElememt to the variable
				var lnk = document.createElement("Link");
				//assiging the rel value for the link element
				lnk.rel="stylesheet";
				//assiging the href value to the link variable
				lnk.href=arrlen[0][0];
				//adding the link element to the body
				document.body.appendChild(lnk);
			}

///////////////////////////////windowClose() function/////////////////////////////////////////////////////////////
			
			//function to close the window or popup
			function windowClose()
			{
				//to close the window
				window.close();
			}
			
////////////////////////////////////applyColor(color) function///////////////////////////////////////////////////

			
			//function to select the style sheet
			function applyColor(color)
			{
				//using switch case 
				switch(color)
				{
				//for case blue color
				case "Blue":
				//setting the cookie value with the name of the style sheet
					document.cookie="../../Styles/SearchPicker/StyleBlue.css";
					//declaring a variable and assigning create elemtnt to create a Link tag
					var lnk = document.createElement("Link");
					//assigning rel value for the LInk element
					lnk.rel="stylesheet";
					//assigning the href to the Link element.
					lnk.href="../../Styles/SearchPicker/StyleBlue.css";
					//adding the link element to the body
					document.body.appendChild(lnk);
					break;
				case "Black":
					//setting the cookie value with the name of the style sheet
					document.cookie="../../Styles/SearchPicker/StyleBlack.css";
					//declaring a variable and assigning create elemtnt to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleBlack.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				case "Red":
				//setting the cookie value with the name of the stylesheet
					document.cookie="../../Styles/SearchPicker/StyleRed.css";
					//declaring a variable and assigning create element to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleRed.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				case "Green":
				//setting the cookie value with the name of the stylesheet
					document.cookie="../../Styles/SearchPicker/StyleGreen.css";
					//declaring a variable and assigning  create element to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleGreen.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				case "Olive":
					//setting the cookie value with the name of the stylesheet
					document.cookie="../../Styles/SearchPicker/StyleOlive.css";
					//declaring a variable and assigning  create element to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleOlive.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				case "Cyan":
					//setting the cookie value with the name of the stylesheet
					document.cookie="../../Styles/SearchPicker/StyleCyan.css";
					//declaring a variable and assigning  create element to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the Link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleCyan.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				case "Orange":
					//setting the cookie value with the name of the sytle sheet
					document.cookie="../../Styles/SearchPicker/StyleOrange.css";
					//declaring a variable and assigning  create element to create a link tag
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleOrange.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
					//default case
				default:
				//setting the cookie style sheet url value as default value.
					document.cookie="../../Styles/SearchPicker/StyleBlue.css";
					//declaring a variable and assigning  create element to create a link tags
					var lnk = document.createElement("Link");
					//assigning rel value to the link tag	
					lnk.rel="stylesheet";
					//assigning the href to the link tag
					lnk.href="../../Styles/SearchPicker/StyleBlue.css";
					//adding the element to the body
					document.body.appendChild(lnk);
					break;
				}
			}
/////////////////////////////////setValue(strvalue,commonName,limit) function/////////////////////////////////////

			//this function will take the values of a Row as a string ,name of rdoid to form the id of the radio button, Rowcount
			//and this function is to assign the value to the hidden field and for the functionality of the radio button 
			//singel selection.
			function setValue(strvalue,commonname,limit)
			{
				 //variable for the part of the radio button control id which is common for all the id's
				 var partid="_ctl0__ctl";
				 //variable for storing the generated radio button id
				 var rdoid;
				 //varaible to assign the New value of the Hidden field value
				 var hdnnewval;
				 //variable to assing the new id of the checked radio buotton
				 var rdonewid;
				 //using for loop to generate Radio button id's			
				 for(var j=2;j<=limit;j++)
				 {
					//assigning generated radio button id to a variable
					rdoid=partid + j +'_'+commonname;
					//checking radio button is selected or not
					if(document.getElementById(rdoid).checked==true)
					{
						//checking hidden field value is null or not, this condition will be satisfied if the 
						//hdnprevious value is null						
						if(document.getElementById("hdnPrevious").value=="")
						{
							//if the hidden field value is null the making the radio button checked true.
							document.getElementById(rdoid).checked=true;
							//storing the radio button id in the hidden field
							document.getElementById("hdnPrevious").value=rdoid;
							break;
						}
						//using for loop to generate the next id for the radio button
						for(var k=j;k<=limit;k++)
						{	
							//checking the Hidden field value is null or not this condition will be satisfied if
							//hdnprevious value is not null
							if(document.getElementById("hdnPrevious").value!="")
							{
								//generating new id for the radio button
								hdnnewval=partid + k +'_'+commonname;
								//assigning the hidden field value to a variable
								rdonewid=document.getElementById("hdnPrevious").value; 
								//making the radio button checked false.
								document.getElementById(rdonewid).checked=false;
								break;
							}
						}
						//assigning the New radio button id to the Hidden field
						document.getElementById("hdnPrevious").value=hdnnewval;
					}
				}
				//assigning the field values string to the hidden field value  
				document.getElementById("hdnId").value = strvalue; 
			}