//==========================================================================
/*
function getRequestBody(form, ajaxParam)
{
    alert("In the request Body");
	var aParams = new Array();
	
	for (var i = 0; i < form.elements.length; i++)
	{		    
		if(form.elements[i].disabled==false)
		{
			if(form.elements[i].type=='radio')
			{		    
				if(form.elements[i].checked)
				{
					sParam = encodeURIComponent(form.elements[i].name);
			        sParam += "=";			    
					sParam += encodeURIComponent(form.elements[i].value);
					aParams.push(sParam);

				}
			}
			else if(form.elements[i].type=='checkbox')
			{
				if(form.elements[i].checked)
				{
					sParam = encodeURIComponent(form.elements[i].name);
			        sParam += "=";
			        sParam += encodeURIComponent(form.elements[i].value)
			        aParams.push(sParam);

			     }
			}
			else
			{
				sParam = encodeURIComponent(form.elements[i].name);
		        sParam += "=";
				sParam += encodeURIComponent(form.elements[i].value);
				aParams.push(sParam);
		    }
		}
	}
	alert("Request Body complete");
	sParam = "ACTION=";
	sParam += ajaxParam;	
	aParams.push(sParam);
		
	return aParams.join("&");
	
	//return "null";
}
*/
//==========================================================================

function resetForm(form)
{
	for (var i = 0; i < form.elements.length; i++)
	{
		if(Left(form.elements[i].name,3) == 'lst')
			form.elements[i].value = 0;
		if(Left(form.elements[i].name,3) == 'txt')
			form.elements[i].value = '';
		if(form.elements[i].name == 'cmdadd')
			form.elements[i].value = 'Add';
		if(form.elements[i].name == 'cmdupd')
			form.elements[i].value = 'Update';
		if(form.elements[i].name == 'hiddenActionControl')
			form.elements[i].value = 'Add';
		if(form.elements[i].name == 'showReport')
			form.elements[i].value = 1;
	}
}

//==========================================================================

function UpdateData(httpRequest,tbl)
{

var dateformat=1;
//alert(httpRequest.readyState);
	if (httpRequest.readyState == 4)
	 {
	    //alert(httpRequest.status)
		if (httpRequest.status == 200)
		{
			var doc;
			doc = httpRequest.responseXML;
			
			if(doc)
			{
			    var string = httpRequest.responseTEXT;
			    //var doc = string[0];
			    //alert(string);
				var node;
				//node = doc.getElementsByTagName('strQry').item(0);
				//alert(node.firstChild.data);
				
				// alert for uniqueness, errors while executing query
				node = doc.getElementsByTagName('sInfo').item(0);
				if(node)
				{
				//alert("sInfo found");
					data=node.firstChild.data;
					data_arr = data.split("=")
					if(data_arr[1].length>0)
						alert(data_arr[1]);
				}
								             
				// redirection
				node = doc.getElementsByTagName('Redir').item(0);
				if(node)
				{
				//alert("redir found");
					data=node.firstChild.data;
					data_arr = data.split("$")
					if(data_arr[1].length>0)
						window.navigate(data_arr[1]);
				}
				
				// report updation
				node = doc.getElementsByTagName('ReportType').item(0);
                //alert("report");							
				if(node)
				{
				//alert(node);
					data=node.firstChild.data;
					if(data)
					{
					//alert(data);
						if(data=='ListPlain')
							ReportTable_ListPlain(doc,tbl,dateformat);
						else if(data=='Grid')
							ReportTable_Grid(doc,tbl);
						else if(data=='Notepad')
							ReportTable_Notepad(doc,tbl,dateformat);
						else if(data=='ListPlain-Editable')
							ReportTable_ListPlainEditable(doc,tbl,dateformat);
					}
				}
			}
		}
	}
}

//==========================================================================

function UpdateData(httpRequest,tbl, formName)
{

var dateformat=1;
//alert(httpRequest.readyState);
	if (httpRequest.readyState == 4)
	 {
	 //  alert(httpRequest.status)
		if (httpRequest.status == 200)
		{
			var doc;
			doc = httpRequest.responseXML;
			if(doc)
			{
			    var string = httpRequest.responseTEXT;
			    //var doc = string[0];
			    //alert(string);
				var node;
				//node = doc.getElementsByTagName('strQry').item(0);
				//alert(node.firstChild.data);
				
				// alert for uniqueness, errors while executing query
				node = doc.getElementsByTagName('sInfo').item(0);
				if(node)
				{
				//alert("sInfo found");
					data=node.firstChild.data;
					data_arr = data.split("=")
					if(data_arr[1].length>0)
						alert(data_arr[1]);
				}
				
				var selectedIndex;
	            selectedIndex = doc.getElementsByTagName('SelectedIndex').item(0);
	            var Control = doc.getElementsByTagName('Control').item(0);
	            var datas;
                var controlDatas;
                  
	            if(selectedIndex)
	            {	                
	                 datas = selectedIndex.firstChild.data;
	                 datas = datas.split(",");
	            }
	            if(Control)
	            {
	                 controlDatas = Control.firstChild.data;
	                 controlDatas = controlDatas.split(",");	                    
	            }
	            if(selectedIndex)
	            {	
	                 for(j = 0; j < datas.length; j++)
	                 {  
	                      var data =  datas[j];
	                      var controlData = controlDatas[j]; 
	                      for (i=0; i<formName.elements.length; i++)
				          {
					        control = formName.elements[i];
					       // alert(control.type);
					        if(control.name==controlData)
					        {
					            //if(control.type == "select-one")
					                control.value = data;
					            /*else if(control.type == "text")
					            {
					                alert("ok");
					                //control.value = data;
					            }*/
					        }         
                          }
                     }
	               }
	               
	              
	               var fieldStatus = doc.getElementsByTagName('FieldStatus').item(0);
		           var status = doc.getElementsByTagName('Status').item(0);
                   var datas;
                   var statusDatas;
                  
	               if(fieldStatus)
	               {
	                              
	                 datas = fieldStatus.firstChild.data;
	                 datas = datas.split(",");
	                }
	                 	
	               if(status)
	                {
	                 
	                    statusDatas = status.firstChild.data;
	                    statusDatas = statusDatas.split(",");	                    
	                }
	                //alert(statusDatas);
	                if(datas && statusDatas)
	                {
	                    for(j = 0; j < datas.length; j++)
	                     {
	                     
	                        var data = datas[j];
	                        
	                        var statusData = statusDatas[j];
	                       
	                        for (i=0; i<formName.elements.length; i++)
				            {
					            control = formName.elements[i];
        					    
					            if(control.name==data)
					            {
					                if(statusData == "disable")
				                    {
				                        control.disabled = true;
				                    }	
				                    else
				                        control.disabled = false;				           
				                }
				              }                     
                           }
                       }
	               
	                              
	                fieldControls = doc.getElementsByTagName('FillControls').item(0);
	                fieldValues = doc.getElementsByTagName('Values').item(0);
	                
	                if(fieldControls)
	                {
	                    Controls = fieldControls.firstChild.data;
	                   // alert(Controls);
	                    var controlNames = Controls.split(",");
	                    
	                   fieldValues = fieldValues.firstChild.data;
	                   fieldValues = fieldValues.split(",");
	                                        
	                    for(i = 0; i < controlNames.length; i++)
	                    {
	                        var fieldControl = controlNames[i];
	                        var fieldValue = fieldValues[i];
	                        for(j = 0; j < formName.elements.length; j++)
	                        {
	                            control = formName.elements[j];
	                             //alert(fieldControl);
	                            if(control.name == fieldControl)
	                            {   	                           
	                               if(control.type=='radio')
	                                {
	                                    if(control.value == fieldValue)
	                                    {
	                                       control.checked = true; 
	                                     }
	                                }
	                               else if(control.type == 'checkbox')
	                                {
	                                    control.checked = fieldValue;
	                                }
	                                 else if(control.type =='select-one')
	                                {
	                                    control.selectedindex = fieldValue;
	                                }
	                                else
	                                {
	                                    control.value = fieldValue;
	                                }
	                            }
	                        }
	                    }
	                }
	               
	          /* node = doc.getElementsByTagName('LinkOnFormParameters').item(0);
	           if(node)
				{
				    //alert("redir found");
			        var parameters = node.firstChild.data;
			        parameters = parameters.split(",");
			       //var string;
			       //alert("ok");
			        for(i = 0; i < parameters.length; i++)
			        {
			            parameter = parameters[i];
			            //string = parameter;
			        }
			        
			        var url = doc.getElementsByTagName('URL').item(0);
			        var link = url.firstChild.data;
					
			             alert(control.name);
			               td = document.createElement('td');
			               tr = document.createElement('tr');
			                td.className = "pagetext2insidenoalign";
			                td.setAttribute('align','center')
			                td.setAttribute('width','15%')
			
			            
			    
				strHtml = "<a href='Default_Update' class='link7'>Add new<a> ";
				//strHtml = strHtml + "<a href='javascript:"+fieldupddellinks[1]+"' class='link7'>Remove<a>";
			    
			//else
			//{
				//strHtml = "<a href='javascript:"+fieldupddellinks[0]+"' class='link7'>"+UpdDelHeader+"<a>";
			//}
			td.innerHTML = strHtml;
			tr.appendChild(td);
		                    					           
		           
		             }*/
	           // redirection
				node = doc.getElementsByTagName('Redir').item(0);
				if(node)
				{
				//alert("redir found");
					data=node.firstChild.data;
					data_arr = data.split("$")
					if(data_arr[1].length>0)
						window.navigate(data_arr[1]);
				}
				
				// report updation
				node = doc.getElementsByTagName('ReportType').item(0);
                //alert("report");							
				if(node)
				{
				//alert(node);
					data=node.firstChild.data;
					if(data)
					{
					//alert(data);
						if(data=='ListPlain')
							ReportTable_ListPlain(doc,tbl,dateformat);
						else if(data=='Grid')
							ReportTable_Grid(doc,tbl);
						else if(data=='Notepad')
							ReportTable_Notepad(doc,tbl,dateformat);
						else if(data=='ListPlain-Editable')
							ReportTable_ListPlainEditable(doc,tbl,dateformat);
					}
				}
			}
		}
	}
}

//==========================================================================

function GetData(httpRequest,formName)
{
	if (httpRequest.readyState == 4)
	 {//alert(httpRequest.status)
		if (httpRequest.status == 200)
		{
			var doc;
			doc = httpRequest.responseXML;
			
			if(doc)
			{//alert(httpRequest.responseTEXT)
				var node;
				
				for (i=0; i<formName.elements.length; i++)
				{
					ctrl = formName.elements[i].name;
					
					node = doc.getElementsByTagName(ctrl).item(0);
					if(node)
					{
						data=node.firstChild.data;
						data_arr = data.split("=");
						if(data)
						{
							if(Left(ctrl,3) == 'rad')
							{
								if(formName.elements[i].value == data_arr[1])
									formName.elements[i].checked=true;
							}
							else
								formName.elements[i].value = data_arr[1];
						}
					}
				}	
			}
		}
	}
}

//==========================================================================

function FillCombo(doc,nodename,ctrl)
{
	var node;
	var subnode_list_front, subnode_list_back;
	
	var selectedIndex;
    selectedIndex = doc.getElementsByTagName('SelectedIndex').item(0);
    
    var selection = -1;
    if(selectedIndex != null)
    {
        selection = selectedIndex.firstChild.data;        
    }  
    
    node = doc.getElementsByTagName(nodename).item(0);
   	if (node == null) 
	{
		return;
	}
	ctrl.length = 0;
	var no = new Option();
	no.value = 0;
	no.text = 'None';
	ctrl[0] = no;
				
	subnode_list_front = node.getElementsByTagName('Front');
	subnode_list_back = node.getElementsByTagName('Back');
	
	node = subnode_list_front.item(0);
	//alert(subnode_list_front.length);
	for(i=0;i<subnode_list_front.length;i++)
	{		
		if(subnode_list_front(i).firstChild)
		{
		    var no = new Option();
		    no.value = subnode_list_back(i).firstChild.data;
		    no.text = subnode_list_front(i).firstChild.data;
		    ctrl[i+1] = no;
		    if(no.value == selection)
		    {
		        ctrl.value = no.value;    
		    }
		 }
	}
	
}

//==========================================================================

function FillControls(doc,nodenames,ctrls)
{
	var node;	
	var length = nodenames.length;
	
	for(i=0;i<nodenames.length;i++)
	{
		node = doc.getElementsByTagName(nodenames[i]).item(0);
		node_val = node.firstChild.data;
		ctrls[i].value = node_val;
	}
}


function FillControlFromFunction(doc,nodename,ctrl)
{
    ctrl.value = "";
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	
	if(node != null)
	{
	    var node_val = node.firstChild.data;
	    ctrl.value = node_val;	
	}
}

function FillCheckBoxFromFunction(doc,nodename,ctrl)
{
    var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	
	if(node != null)
	{
	    var node_val = node.firstChild.data;	    
	    if(node_val == "on")
	    {
	        ctrl.checked = true;
	    }
	    else
	        ctrl.checked = false;    
	}
}
function getMessageString(doc,nodename, messageDiv)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	
	var error = 1;
	if(node != null)
	{
	    var node_val = node.firstChild.data;
	    
	    var messageDivControl = document.getElementById(messageDiv);
	    messageDivControl.innerHTML = node_val;	
	    if(node_val.search(/Success/) != -1 || node_val.search(/Empty/) != -1 )
	    {
	        error = 0;	        	    	    
	    }
	}
	return error;
}

function getValidate(doc,nodename, isValidate)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);    
	var error = 1;
	if(node != null)
	{
	    var node_val = node.firstChild.data;
	    var messageDivControl = document.getElementById(isValidate);
	    if(node_val.search(/SUCCESS/) != -1  )
	    {
	        error = 0;	  	         
	    }
	}	 
	return error;
}

function getString(doc,nodename, messageDiv)
{
	var node , messageDivControl,node_val;	
	node = doc.getElementsByTagName(nodename).item(0);
	if(node != null)
	{
	    node_val  = node.firstChild.data; 	     
	}	
	return node_val;
}


function getValidate1(doc,nodename, isValidate1)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	var error = 1;
	if(node != null)
	{
	    var node_val = node.firstChild.data; 
	    var messageDivControl = document.getElementById(isValidate1);
	    if(node_val.search(/SUCCESS/) != -1  )
	    {
	        error = 0;	  	         
	    }
	}	
	return error;
}

function getValidate2(doc,nodename, isValidate2)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	var error = 1;
	if(node != null)
	{
	    var node_val = node.firstChild.data; 
	    var messageDivControl = document.getElementById(isValidate2);
	    if(node_val.search(/SUCCESS/) != -1  )
	    {
	        error = 0;	  	         
	    }
	}	
	return error;
}


function getUpgradeValidate(doc,nodename, UpgradeValidate)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	var error = 1;
	if(node != null)
	{
	    var node_val = node.firstChild.data; 
	    var messageDivControl = document.getElementById(UpgradeValidate);
	    if(node_val.search(/FAIL/) != -1  )
	    {
	        alert("Your Shopping Cart is Reset to Number of Upgrades");
	        error = 0;	  	         
	    }
	}	
	return error;
}



function getCustomerId(doc,nodename, customer_id)
{
	var node;	
	node = doc.getElementsByTagName(nodename).item(0);
	var customerId  ;
	if(node != null)
	{
	    var node_val = node.firstChild.data; 
	    alert("Node Val"+node_val);	    
	    var messageDivControl = document.getElementById(customer_id);
	    customerId = node_val;
	}	
	return customerId;
}





//////////******************* Code for Change For PETS - Department Number and Name 

function getSelctedTextFromEditableCombo(backID,ctrlname)
{
    var i=0;
    var newName;
	while (ctrlname.options[i]!= null)
	{
	    var controlValue = ctrlname.options[i].value;
	    if(controlValue==backID)
	    {
	    newName= ctrlname.options[i].text;			                     		                             
        break;			                    
	    }
	    i++;
    }    
    return newName;
}

//////////******************* Code for Timer on the page start 

var timerID = 0;
var tStart  = null;
var timerObj = null;

function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   } 
if(timerObj)
    timerObj.innerHTML = getCurrentTimeInFormat();
       //timerObj.innerHTML = "" + new Date();
   //                                + tDate.getMinutes() + ":" 
     //                              + tDate.getSeconds();
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

function GetXmlHttpObject()
{
var xmlHttp=null;

try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}




function Start() {
   tStart   = new Date();
if(timerObj)
   timerObj.innerHTML = "10:00";
else
   timerObj = document.getElementById('timer');

   timerID  = setTimeout("UpdateTimer()", 1000);
}


function getCurrentTimeInFormat()
{
	var currentDate=new Date()
	var TimeStamp,month,period,day,year;
	hour=currentDate.getHours()
	min=currentDate.getMinutes()
	sec=currentDate.getSeconds()
	year=currentDate.getFullYear()
	date=currentDate.getDate()

switch(currentDate.getDay())
{
    case 0:day="Sunday";break;
    case 1:day="Monday";break;
    case 2:day="Tuesday";break;
    case 3:day="Wednesday";break;
    case 4:day="Thursday";break;
    case 5:day="Friday";break;
    case 6:day="Saturday";break;
}

switch(currentDate.getMonth())
{
    case 0:month="Jan";break;
    case 1:month="Feb";break;
    case 2:month="Mar";break;
    case 3:month="Apr";break;
    case 4:month="May";break;
    case 5:month="June";break;
    case 6:month="July";break;
    case 7:month="Aug";break;
    case 8:month="Sept";break;
    case 9:month="Oct";break;
    case 10:month="Nov";break;
    case 11:month="Dec";break;
}


if(sec<10)
{
	sec="0"+sec;
}
if(min<10)
{
	min="0"+min;
}
if(hour<10)
{
    hour = "0"+hour;
}

    var TimeStamp = day+", "+month+" "+date+" "+year+", "+hour+":"+min+":"+sec+" "
    return TimeStamp;
}


//////////******************* Code for Timer on the page end

//==========================================================================

// the stylesheet object, loaded only once..
//var stylesheetDoc;
/*function initialize()
{
	loadStylesheet("../../includes/css/spine.xsl");
	//alert(stylesheetDoc);
}

function loadStylesheet(stylesheet)
{
	var xmlHttp=getXMLHTTPRequest();
	xmlHttp.open("GET", stylesheet, false);        
	xmlHttp.send(null);
	if(this.DOMParser) // browsers with native functionality
	{
		var dp = new DOMParser();
		stylesheetDoc = dp.parseFromString(xmlHttp.responseText, "text/xml");
	}
	else if(window.ActiveXObject) // Internet Explorer? 
	{
		stylesheetDoc = createMsxml2DOMDocumentObject();         
		stylesheetDoc.async = false;
		stylesheetDoc.load(xmlHttp.responseXML);
	}
}*/

//==========================================================================

// Creates the XMLHTTP Request object
/*function getXMLHTTPRequest()
{
	var xRequest=null;
	if (window.XMLHttpRequest)
	{
		xRequest = new XMLHttpRequest();
	}
	else if (typeof ActiveXObject != "undefined")
	{
		xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xRequest;
}*/

//==========================================================================

/*function createMsxml2DOMDocumentObject()
{
  // will store the reference to the MSXML object
  var msxml2DOM;
  // MSXML versions that can be used for our grid
  var msxml2DOMDocumentVersions = new Array("Msxml2.DOMDocument.6.0",
                                            "Msxml2.DOMDocument.5.0",
                                            "Msxml2.DOMDocument.4.0");
  // try to find a good MSXML object
  for (var i=0; i < msxml2DOMDocumentVersions.length && !msxml2DOM; i++) 
  {
    try 
    { 
      // try to create an object
      msxml2DOM = new ActiveXObject(msxml2DOMDocumentVersions[i]);
    } 
    catch (e) {}
  }
  // return the created object or display an error message
  if (!msxml2DOM)
    alert("Please upgrade your MSXML version from \n" + 
          "http://msdn.microsoft.com/XML/XMLDownloads/default.aspx");
  else 
    return msxml2DOM;
}*/

//==========================================================================

// Performs a GET to our processSQL.aspx web page with the query
/*function sendRequest(type, query, changefunc)
{
	obj=getXMLHTTPRequest();
	if (obj!=null)
	{
		obj.onreadystatechange = changefunc;
		obj.open(type, query, true);
		obj.send(null);
	}
	return false;
}*/

//==========================================================================

/*function convertMS(responseTxt)
{
	try
	{
	//Create a xml tag in run time
		var testandoAppend = document.createElement('xml');
	//Put the requester.responseText in the innerHTML of the xml tag
		testandoAppend.setAttribute('innerHTML',responseTxt);
	//Set the xml tag's id to _formjAjaxRetornoXML
		testandoAppend.setAttribute('id','_formjAjaxRetornoXML');
	//Add the created tag to the page context
		document.body.appendChild(testandoAppend);

	//Now we can get the xml tag and put it on a var
		xmlDoc = document.getElementById('_formjAjaxRetornoXML');
	//So we have a valid xml we can remove the xml tag
		document.body.removeChild(document.getElementById('_formjAjaxRetornoXML'));
		return xmlDoc;
	}
	catch(e)
	{
		alert(e.message);
	}
}*/

//==========================================================================

/*function updateReport(httpRequest)
{
	var reportDivId = "testDiv";
// when readyState is 4, we read the server response
	//alert("ok");
	response = httpRequest.responseTEXT;
	if (response.indexOf("ERRNO") >= 0 
		|| response.indexOf("error") >= 0
		|| response.length == 0)
	{
		// display error message
		alert(response.length == 0 ? "Server serror." : response);
		return;
	}

	xmlResponse = httpRequest.responseXML;
	
	// browser with native functionality?    
	if(window.XMLHttpRequest && window.XSLTProcessor && 
	  window.DOMParser)
	{			
		// load the XSLT document
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(stylesheetDoc);
		// generate the HTML code for the new page of products
		page = xsltProcessor.transformToFragment(xmlResponse, document);
		// display the page of products
		var gridDiv = document.getElementById(reportDivId);
		gridDiv.innerHTML = "";
		gridDiv.appendChild(page);
	} 
	// Internet Explorer code
	else if (window.ActiveXObject) 
	{			
		xmlResponse = convertMS(httpRequest.responseText)
		// load the XSLT document
		var theDocument = createMsxml2DOMDocumentObject();
		theDocument.async = false;
		theDocument.load(xmlResponse);
		// display the page of products
		//alert(httpRequest.responseText);
		var gridDiv = document.getElementById(reportDivId);
		gridDiv.innerHTML = theDocument.transformNode(stylesheetDoc);
		//alert(httpRequest.responseText);
	}
}*/

//==========================================================================

