// JavaScript Document
popUpWin = 0;
function popUpWindow(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindowMenubar(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollBars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function popUpWindow_scroll(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollBars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowAll(URLStr, title, left, top, width, height,id)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, title, 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollBars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


	
	
function cNum(e) {
	var strCheck = '0123456789\b\t	 ';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}

function cNumPhone(e) {
	var strCheck = '0123456789\b\t	 +()[]-';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 0 || whichCode == 13)
	{
		return true ;		
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
}


///other js functions used in nyjax
	var fldname;
	var arr;
	fldname=document.getElementsByTagName("div");
	nyjax_cols=new Array(); // Please do not modify this variable ---ny
	function nybdy_load()
	{			
				var fld;

					for(var i=0; i < fldname.length; i++)
					{
						fld=fldname.item(i).id;
					//alert(fld);
						if(fld.substr(0,4) == "fld_")
						{
							var k;
							k=document.getElementById(fld);
							k.style.display='none';
						} 
					}
	}

function nyshowtxt(id)
{

		var fld;
		//alert(fldname.length);
		for(var i=0; i < fldname.length; i++)
		{
			fld=fldname.item(i).id;
			var pos=fld.indexOf("_"+id)
			if (pos > 0)
			{
					
					for(var l=0; l < nyjax_cols.length; l++)
						{
							var k,j;
							//alert("id---"+ l +"\n length ---"+ nyjax_cols.length);
							k=document.getElementById('fld_'+nyjax_cols[l]+'_'+id);
							j=document.getElementById('div_'+nyjax_cols[l]+'_'+id);
							nycreateallelements(nyjax_cols[l],id,j);// this function will create all fields for this row.--ny
							k.style.display='block';
							j.style.display='none';
						}
						break;
			}
//alert('fld_options_'+id);
			
		}
			
}

	function nyclick_cancel(id)
	{
					var k,j,strval;
		 strval = document.getElementById("listofids").value;
		// alert(id+"---"+strval);
		 var t = ","+id;
	//	 alert(t);
		strval = var_replace(strval,t,"");
		 document.getElementById("listofids").value = strval;
					for(var i=0; i < nyjax_cols.length; i++)
					{

						k=document.getElementById('div_'+nyjax_cols[i]+'_'+id);
						k.style.display='block';
						
						j=document.getElementById('fld_'+nyjax_cols[i]+'_'+id);
						j.innerHTML='';
						j.style.display='none';
					}	
			
	}

	/* function to create form fields dynamically  */
	function nycreateallelements(colname,id,div)
	{
	//alert(colname+"_0");
	     document.getElementById("listofids").value += ","+id;
			var fname;
		 fname = colname.toLowerCase();
		 fname = fname.replace(" ","_");
		var a = document.getElementById(fname+"_0").parentNode.id;
//	a.lastIndexOf("_");
		var firstelement = a.substr(a.lastIndexOf("_")+1,a.length);
		if(firstelement != id)
		{
				 var tempvalarr = Array();
				 var tempkeyarr = Array();	
		
				
				
				 var  newfld = document.getElementById(fname+"_0").cloneNode(true);
				 newfld.id = "";
				 newfld.name = fname+"_"+id;
				 
				 newfld.value = div.innerText;
				

if(newfld.type == "select-one")
				 {
					  newfld.value = null;
					var len = newfld.options.length;
					var val = Trim(div.innerText);
					for(var h=0;h<len;h++)
					{
					//	alert("--"+newfld.options[h].text+"----"+newfld.options[h].value+"--");
						var str = Trim(newfld.options[h].text);
						tempvalarr[h] = str;
						tempkeyarr[h] = newfld.options[h].value;
					}
					newfld.options.length = 0;
					for(var k=0;k<len;k++)
					{
						var opt = document.createElement('OPTION');
						opt.value = tempkeyarr[k];
						opt.text = tempvalarr[k];
						newfld.options.add(opt);
						if(val == tempvalarr[k])
						{
				//			alert("key ---"+opt.text +"\n value---"+opt.value);
							newfld.options[k].selected = true;	
						}
					}
		
					
					
					
				 }
				
				
		
			  newfld.removeAttribute("name");
			//newfld.removeAttribute("onblur");
				var  nameval= fname+"_"+id;
			  newfld.setAttribute("NAME", nameval);
			//newfld.setAttribute("ONBLUR",  obtxt);
			
			var insertHere = document.getElementById("fld_"+colname+"_"+id);
				insertHere.appendChild(newfld);
				
				 if(newfld.type == "hidden")
				 {
					insertHere.innerHTML = newfld.value+' '+insertHere.innerHTML;					 
				 }

			
		}

/*alert(newfld.getAttribute("name"));
		newfld.setAttribute("name",fldname+"_"+id);
		alert(newfld.name+"-----"+fldname+"_"+id);

	if(newfld.removeAttribute("name"))
	{
		alert("removed")
	}else
	{
		alert("not removed")
	}
			
	
	var  nameval= fldname+"_"+id;
	//alert(newfld.setAttributeNode("name"));
	if(newfld.setAttribute("name", nameval))
	{
		alert("set")
	}else
	{
		alert("not set")
	}
	//var newfld =document.createElement("<INPUT TYPE='text' class='formfld' NAME='"+fldname+"' VALUE='"+div.innerText+"'>")
/*	var fld_div = document.getElementById("fld_"+colname+"_"+id);
		fld_div.appendChild(newfld);
	*/	
	
		
		//fld_div.insertBefore(newfld);
	
	//	alert(insertHere.innerHTML);
		
	}
	
	
	/* just testing  */
	
	
	
	// ==========================================================================
// Fuctions to mimic LTrim, RTrim, and Trim...

// Author          Aurélien Tisné	(CS)
// Date            03 avr. 2003 23:11:39
// Last Update     $Date$
// Version         $Revision$
// ==========================================================================

// --------------------------------------------------------------------------
// Remove leading blanks from our string.

// I               str - the string we want to LTrim
// Return          the input string without any leading whitespace

// Date            03 avr. 2003 23:12:13
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}

// --------------------------------------------------------------------------
// Remove trailing blanks from our string.

// I               str - the string we want to RTrim
// Return          the input string without any trailing whitespace

// Date            03 avr. 2003 23:13:50
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
function RTrim(str)
{
  // We don't want to trip JUST spaces, but also tabs,
  // line feeds, etc.  Add anything else you want to
  // "trim" here in Whitespace
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...

    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;


    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}


// --------------------------------------------------------------------------
// Remove trailing and leading blanks from our string.

// I               str - the string we want to Trim
// Return          the trimmed input string

// Date            03 avr. 2003 23:15:09
// Author          Aurélien Tisné	(CS)
// --------------------------------------------------------------------------
function Trim(str)
{
  return RTrim(LTrim(str));
}


 function var_replace(s, t, u) 
 {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += var_replace(s.substring(i + t.length, s.length), t, u);
  return r;
  }
  
  
  function yconnect(url,frm,cnt,loading)
{


//show the result in this content
    var responseSuccess = function(o){ 
        document.getElementById(cnt).innerHTML=o.responseText;
    }

//if any failure show msg 
    var responseFailure = function(o){ 
        alert("XMLHTTPRequest Failure");
    }

//used to handle call back events     
    var callback =
    {
        success:responseSuccess,
        failure:responseFailure
    }



// Create object and intiate connection. 

if(frm != ''){
// set the from where you need to get the data 
YAHOO.util.Connect.setForm(frm);
var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callback,null);
}else{
var cObj = YAHOO.util.Connect.asyncRequest('GET', url, callback,null);
}
//This is to check the connection status 
var callStatus = YAHOO.util.Connect.isCallInProgress(cObj);
//alert(loading);
// check for the status and show loading information 
if(callStatus){
//document.getElementById(cnt).innerHTML="<img src='images/pleasewait.gif'>";
document.getElementById(cnt).innerHTML="Loading...";
}

}