/*
Author          : Saqib Gill
Date Created    : 30-Sep-2008
Date Modified   : 
*/
function PopulateMenuItems(formName)
{
if (document.getElementById("selMenuItems").value > 0) 
    {
        document.getElementById("Type").value= "1";
        var MenuText = document.getElementById("selMenuItems").options[document.getElementById("selMenuItems").selectedIndex].text;
        document.getElementById("TextType").value = MenuText;
        checkAction(27,91,1,formName,false,null,false);
    }   
}
function showHideMenuItem(SectionCounter,ShowHide,formName)
{

        var ChangeComplete = function(oxml)
		{
			var errormessage = oxml.responseText;
			//alert(errormessage);
			if (errormessage == 'success')
			{
			    //alert("success");
			    document.getElementById("Type").value= "1";
			    checkAction(27,91,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}		
		
		var data = "SectionToChange=" + document.getElementById("secCounter_" + SectionCounter).value + "&ShowHide=" + ShowHide
		hiddenSubmit('cms/security_menu_items_show_hide_process.asp',data,ChangeComplete,0,null,true);
}
function moveMenuItem(SectionCounter,Direction,formName)
{
	//var CompID = parseInt(document.getElementById("compID").value);
	//var lastLoadedID = parseInt(document.getElementById("lastLoadedID").value);
	//var lastLevel = parseInt(document.getElementById("lastLevel").value);
	
	//alert(CompID);
	if ((Direction == 1 && SectionCounter != 1) || (Direction == 2 && SectionCounter != parseInt(document.getElementById("totalCount").value)))
	{	
		if (Direction == 1)				
		{
			data = "ItemToMoveUp=" + document.getElementById("secCounter_" + SectionCounter).value + "&ItemToMoveDown=" + document.getElementById("secCounter_" + (SectionCounter-1)).value;					
		}
		else
		{
			data = "ItemToMoveDown=" + document.getElementById("secCounter_" + SectionCounter).value + "&ItemToMoveUp=" + document.getElementById("secCounter_" + (SectionCounter+1)).value;			
		}
		
        var MoveComplete = function(oxml)
		{
			var errormessage = oxml.responseText;
			//alert(errormessage);
			if (errormessage == 'success')
			{
				document.getElementById("Type").value= "1";
			    checkAction(27,91,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}		
		hiddenSubmit('cms/security_menu_item_move_process.asp',data,MoveComplete,0,null,true);
	}
	else
	{
		alert("This item cannot move in the chosen direction.");
		return;
	}
}

function SaveMenuItems(formName)
{

        var iDebug = function(oxml)
		{
			var errormessage = oxml.responseText;
		    //document.getElementById("topcontent").innerHTML =  errormessage;
		    //return;
			if (errormessage == 'success')
			{
			    alert(errormessage);
			    document.getElementById("Type").value= "1";
			    checkAction(27,91,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}		
	if (validatemenu()== true)
	    {
		    var data = "SectionName=" + encodeURIComponent(document.getElementById("txtMenuItem").value) + "&SectionID=" + document.getElementById("selMenuItems").value + "&PSectionName=" + encodeURIComponent(document.getElementById("txtSubMenuItem").value)+ "&SubSectionID=" + document.getElementById("selSubMenuItems").value
	        hiddenSubmit('cms/security_menu_item_update_process.asp',data,iDebug,0,null,true);
	    }
}

function refresh() 
{ 
    window.location.reload(); 
} 

function validatemenu()
{
if (document.getElementById("txtMenuItem").value == "")
    {
        alert('Please enter a valid Menu');
        document.getElementById("txtMenuItem").focus();
        return false;
    }
else
    {
    return true;
    }
}


function showpage(formName)
{   
   document.getElementById("txtBody").focus();
   checkAction(33,146,1,formName,false,null,false);
}

function SavePageItems(formName)
{

        var iDebug = function(oxml)
		{
			var errormessage = oxml.responseText;
		    //document.getElementById("topcontent").innerHTML =  errormessage;
		    //return;
		    //alert(errormessage);
			if (errormessage == 'success')
			{
			    alert(errormessage);
			    checkAction(33,146,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}		
             
   		    var data = "PageID=" + document.getElementById("selMenuItems").value + "&Body=" + encodeURIComponent(document.getElementById("txtBody").value)
	        hiddenSubmit('cms/security_page_item_update_process.asp',data,null,4,null,true);
	        checkAction(33,146,1,formName,false,null,false);
    }

function SavePageRoles(formName)
{

        var iDebug = function(oxml)
		{
			var errormessage = oxml.responseText;
		    //document.getElementById("topcontent").innerHTML =  errormessage;
		    //return;
		    //alert(errormessage);
			if (errormessage == 'success')
			{
			    alert(errormessage);
			    checkAction(33,146,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}
		     var id = '';
                for (i=0;i<document.frmPageAdmin.selRightList.options.length;i++)
	               {	
	                  id = id + document.frmPageAdmin.selRightList.options[i].value + ","; 
	               }
	               var str = String(id);
	               var RoleID = str.substring(0,str.length-1);
	               
   		    var data = "PageID=" + document.getElementById("selMenuItems").value + "&RoleID=" + RoleID
   		    //alert(data);
	        hiddenSubmit('cms/security_role_item_update_process.asp',data,null,4,null,true);
	        checkAction(33,146,1,formName,false,null,false);
    }

function showRole(formName)
{   
   checkAction(35,149,1,formName,false,null,false);
}

function PopulateGirdPageItems(formName)
{
if (document.getElementById("selGPagesItems").value > 0) 
    {
        var MenuText = document.getElementById("selGPagesItems").options[document.getElementById("selGPagesItems").selectedIndex].text;
        document.getElementById("txtGPage").value = MenuText;
        checkAction(35,149,1,formName,false,null,false);
    } 
else
    {
        document.getElementById("txtGPage").value = "";
        document.getElementById("selGPagesItems").focus();
    }  
}

function SaveGridProc(formName)
{
        var iDebug = function(oxml)
		{
			var errormessage = oxml.responseText;
		    document.getElementById("topcontent").innerHTML =  errormessage;
		    return;
		    //alert(errormessage);
			if (errormessage == 'success')
			{
			    alert(errormessage);
			    checkAction(35,149,1,formName,false,null,false);
			}
			else
			{
				alert("An error has occurred. Please retry...");
			}
			regularCursor();
			oxml = null;
		}

	  if (document.getElementById("txtGPage").value =="")
	      {
	      alert('Please Check Value');
	      document.getElementById("txtGPage").focus();
	      }           
	 	  else
	      {
	        var data = "PageTitle=" + encodeURIComponent(document.getElementById("txtGPage").value) + "&Proc=" + document.getElementById("txtProc").value + "&CompID=" + document.getElementById("selGPagesItems").value
            hiddenSubmit('cms/security_grids_items_update_process.asp',data,iDebug,0,null,true);
            //checkAction(35,149,1,formName,false,null,false);
	      }
        
}

function SaveGridFields(formName)
{
     document.getElementById("Mode").value= true;
     checkAction(35,149,1,formName,false,null,false);
}


function GetFieldsRelationship(formName)
{
    checkAction(38,181,1,formName,false,null,false);
}