function CheckAll(oElement)
{
  	bChecked = document.getElementById("MainCheckAll").checked;
	bindeterminate = document.getElementById("MainCheckAll").indeterminate;
//	var allInput=document.getElementsByTagName("input");
	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		//alert("outside IF:" + strID);
		if (strID.indexOf("Main")>=0 || strID.indexOf("Sub")>=0 || strID.indexOf("Menu")>=0 || strID.indexOf("Home")>=0 || strID.indexOf("TermsCondition")>=0 || strID.indexOf("IDLv4_")>=0){
			document.getElementById(strID).indeterminate = bindeterminate;
			document.getElementById(strID).checked=bChecked;
		}
	}
} 
//-----------------------------------------------------------------------------------    
function ChkLv1(oElement)
{
    oForm = oElement.form;
    oElement = oForm.elements[oElement.name];
	//alert(oElement.length);
	if (oElement.length != undefined){
		if(oElement.length > 0){
		   bChecked = oElement[0].checked;
		   for(var i=0; i<oElement.length; i++){
			   oElement[i].checked = bChecked;
			   //if ( oElement[i].id.indexOf("Sub")>=0 || oElement[i].id.indexOf("Main")>=0 || oElement[i].id.indexOf("IDLv4_")>=0){	
				ChkLv2(document.getElementById(oElement[i].id));
				//ChkLv3(document.getElementById(oElement[i].id));
			  // }
		   }
	    }
	}
}
//-----------------------------------------------------------------------------------    
function ChkLv2(oElement)
{
    var bChecked = document.getElementById(oElement.id).checked;
//	var allInput=document.getElementsByTagName("input");
	if (oElement != undefined){
		var subCategoryId = oElement.id;     //Sub180
		//--- For Lv1 ~ Lv3 --------------------------
		for(j=0; j<allInput.length; j++){
			strName = allInput[j].name;
			strID = allInput[j].id;
			if (strName == subCategoryId){
	            //alert(strID);             //Menu3014, Menu3192
				document.getElementById(strID).checked=bChecked;
			}
		}
		//--- For Lv4 --------------------------------
		for(j=0; j<allInput.length; j++){
			strName = allInput[j].name;
			strID = allInput[j].id;
			//alert ("subCategoryId" + subCategoryId +"---strName-"+ strName )
			if (strName == subCategoryId){
			    //strID=Menu3198,Menu3199,Menu3200
			    Elem = document.getElementsByName(strID)
				for(k=0; k<Elem.length; k++){
			        //Lv4_Nm = Elem[k].name;
			        Lv4_Id = Elem[k].id;	
					if ( Lv4_Id.indexOf('IDLv4_')>=0 ) {
					    document.getElementById(Lv4_Id).checked=bChecked
					}
				}					
				//ChkLv3(document.getElementById(strID)) //Sub179--Menu3014
			}
		}
		//--------------------------------------------
	}
}
//-----------------------------------------------------------------------------------   
function ChkLv3(oElement) //Fired from Lv3, Check/uncheck all Lv4, Self's ID = Lv4's name = Menu3014
{
    var bChecked = document.getElementById(oElement.id).checked;
//	var allInput=document.getElementsByTagName("input");
	if (oElement != undefined){
		var subCategoryId = oElement.id;
		//alert(subCategoryId);
		//alert(allInput.length);
		for(j=0; j<allInput.length; j++){
			strName = allInput[j].name;
			strID = allInput[j].id;
			if (strName == subCategoryId){
				//alert ("3"+ strName);
				//alert ("4"+ subCategoryId);
				//alert (strName);
				document.getElementById(strID).checked=bChecked;
			}
		}
	}
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
function TogLv1(oElement) 
{ 
  	bIndeterminate = false; 
  	bChecked = true; 
  	nChecked = 0;
	nTotal = 0;
//	var allInput=document.getElementsByTagName("input");
	//document.getElementById(oElement.id).checked=false;
  	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		if (strID.indexOf("Main")>=0 || strID.indexOf("Home")==0 || strID.indexOf("TermsCondition")==0){
			if (document.getElementById(strID).checked){
				nChecked++; 
			}
			nTotal++;
		}
	}
	//alert("nChecked = " + nChecked + ":nTotal = " + nTotal );
	if(nChecked < nTotal) { 
		if(nChecked > 1 || document.getElementById(oElement.id).checked) 
		  bIndeterminate = true; 		  
		else { 
		  bIndeterminate = false; 
		  bChecked = false; 
		} 
 	} 
  	else { 
		bIndeterminate = false; 
  	} 
	document.getElementById("MainCheckAll").indeterminate = bIndeterminate; 
	document.getElementById("MainCheckAll").checked = bChecked;
}
//-----------------------------------------------------------------------------------    
function TogLv2(oElement)
{
    bIndeterminate = false; 
  	bChecked = true; 
  	nChecked = 0;
	nTotal = 0;
//	var allInput=document.getElementsByTagName("input");
	document.getElementById("MainCheckAll").indeterminate = bIndeterminate; 
	document.getElementById("MainCheckAll").checked = document.getElementById(oElement.id).checked;
	subcategoryname = document.getElementById(oElement.id).name;
	//alert(oElement.id);
	//alert(subcategoryname);
	var categoryid;
  	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		strName  = allInput[j].name;
		if (strName == subcategoryname ){
			//alert ("strName = " + strName );
			if (strID.indexOf("Main") >= 0){
				categoryid = strID;
				//alert("main id=" + categoryid );
			}
			if (document.getElementById(strID).checked){
				nChecked++; 
			}
			nTotal++;
		}
	}
	//alert("nChecked = " + nChecked + ":nTotal = " + nTotal );
	if(nChecked < nTotal) { 
		if(nChecked > 1 || document.getElementById(oElement.id).checked) {
		  bIndeterminate = true; 
		}
		else { 
		  bChecked = false; 
		} 
 	} 
	//document.getElementById("MainCheckAll").indeterminate = bIndeterminate; 
	//document.getElementById("MainCheckAll").checked = bChecked;
	//
	document.getElementById(categoryid).indeterminate = bIndeterminate; 
    document.getElementById(categoryid).checked = bChecked; 
	//alert("TogLv1");
	TogLv1(document.getElementById(categoryid));
}
//-----------------------------------------------------------------------------------  
function TogLv3(oElement) 
{ 
  	// oElement is menu
    // subcategory's id = menu's name
	// category's name = subcategory's name
	subID = document.getElementById(oElement.id).name;
    oForm = oElement.form; 
    oElement = oForm.elements[oElement.name]; 
//	var allInput=document.getElementsByTagName("input");
	var subName;
	var catID;
    if(oElement.length) { 
      bIndeterminate = false; 
      bChecked = true; 
      nChecked = 0; 
      for(i = 1; i < oElement.length; i++) 
        if(oElement[i].checked) 
          nChecked++; 
      if(nChecked < oElement.length - 1) { 
        if(nChecked) {
          bIndeterminate = true; 
		}  
        else { 
          bIndeterminate = false; 
          bChecked = false; 
        } 
      } 
      else { 
        bIndeterminate = false; 
      } 
	  
	  //find the category it belongs to
	//alert(subID);
	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		strName  = allInput[j].name;
		if (strID == subID ){
			subName = strName;
		}
	}
	//alert(subName);
	
	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		//alert(strID);
		strName  = allInput[j].name;
		if (subName == strName && strID.indexOf("Main") >= 0){
			catID = strID;
		}
	}
	  //alert(catID);
      oElement[0].indeterminate = bIndeterminate; 
      oElement[0].checked = bChecked; 
	  document.getElementById(catID).indeterminate = bIndeterminate; 
	  document.getElementById(catID).checked = bChecked;
	  TogLv2(document.getElementById(catID));
	  //document.getElementById("MainCheckAll").indeterminate = bIndeterminate; 
	  //document.getElementById("MainCheckAll").checked = bChecked;
    } 
}
//-----------------------------------------------------------------------------------  
function TogLv4(oElement) 
{
  	// oElement is menu
    // subcategory's id = menu's name
	// category's name = subcategory's name
	subID = document.getElementById(oElement.id).name;				// Menu3014=Lv4.name=Lv3.id
    oForm = oElement.form; 
    oElement = oForm.elements[oElement.name]; 
//	var allInput=document.getElementsByTagName("input");
	var subName;
	var catID;
    if(oElement.length) { 
        bIndeterminate = false; 
        bChecked = true; 
        nChecked = 0; 
        for(i = 1; i < oElement.length; i++) 
            if(oElement[i].checked) 
                nChecked++; 
                if(nChecked < oElement.length - 1) { 
                    if(nChecked) {
                        bIndeterminate = true; 
                    }  
                    else { 
                          bIndeterminate = false; 
                          bChecked = false; 
                    } 
                } 
                else { 
                    bIndeterminate = false; 
            } 
	  
	  //find the category it belongs to
	//alert(subID);
	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		strName  = allInput[j].name;
		if (strID == subID ){
			subName = strName;
		}
	}
	//alert(subName);
	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		//alert(strID);
		strName  = allInput[j].name;
		if (subName == strName && strID.indexOf("Main") >= 0){
			catID = strID;
		}
	}
	  //alert(catID);
      oElement[0].indeterminate = bIndeterminate;		//indeterminate/indeterminate Lv3
	  oElement[0].checked = bChecked;				//check/unckeck Lv3
     	  
	 // document.getElementById(catID).indeterminate = bIndeterminate; 
	 // document.getElementById(catID).checked = bChecked;
	  //TogLv2(document.getElementById(catID));

    } 
	//------------------------------------------------------------
	//alert(subID)
	Lv3_Elem = document.getElementById(subID)			// Menu3014=Lv4.name=Lv3.id
	TogLv3(Lv3_Elem);
	//------------------------------------------------------------
}
//------------------------------------------------------------
function Terms(oElement)
{   
  	bIndeterminate = false; 
  	bChecked = true; 
  	nChecked = 0;
	nTotal = 0;
//	var allInput=document.getElementsByTagName("input");
	//document.getElementById(oElement.id).checked=false;
  	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		if (strID.indexOf("TermsCondition")==0){
			if (document.getElementById(strID).checked){
				nChecked++; 
			}
			nTotal++;
		}
	}
	//alert("nChecked = " + nChecked + ":nTotal = " + nTotal );
	if(nChecked < nTotal) { 
		if(nChecked > 1 || document.getElementById(oElement.id).checked) 
		  bIndeterminate = true; 
		else { 
		  bIndeterminate = false; 
		  bChecked = false; 
		} 
 	} 
  	else { 
		bIndeterminate = false; 
  	} 
	document.getElementById("MainCheckAll").indeterminate = bIndeterminate; 
	document.getElementById("MainCheckAll").checked = bChecked;
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
function SH_Block(thisID) //show/hide block bellow
{   //alert(thisID)
    //return(false)
	var head = document.getElementById(thisID).style;
   // alert(head)
    //return(false)	
	if (head.display=="none"){
			head.display="";
	}
	else{
		head.display="none";
	}
}
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
function IsNumeric(strString)
   //  check for valid numeric strings 
{
	   var strValidChars = "0123456789.-";
	   var strChar;
	   var blnResult = true;
	
	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 blnResult = false;
			 }
		  }
	   return blnResult;
}
//----------------------------------------------------------------	
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
function AssignMenuList()
{

	var thisValue;
	var thisParent;
	var MenuList='';
	var SubCatList='';
	var allInput=document.getElementsByTagName("input");

	for(j=0; j<allInput.length; j++){
		strID = allInput[j].id;
		if (strID.indexOf("IDLv4_") >= 0 && document.getElementById(strID).checked){
			thisValue = document.getElementById(strID).value;
			MenuList = MenuList + "," + thisValue;
			//Added 04/01/2009
			thisParent = document.getElementById(strID).parentNode.id;
			if (thisParent.indexOf("Main") >=0) {thisParent = thisParent.replace("Main","");}
			else if (thisParent.indexOf("Sub") >=0) {thisParent = thisParent.replace("Sub","");}
			else if (thisParent.indexOf("Menu") >=0) {thisParent = thisParent.replace("Menu","");}
			else thisParent = thisParent;
			if (thisParent.indexOf("_3") >=0) {thisParent = thisParent.replace("_3","");}
			else if (thisParent.indexOf("_6") >=0) {thisParent = thisParent.replace("_6","");}
			else if (thisParent.indexOf("_9") >=0) {thisParent = thisParent.replace("_9","");}
			else thisParent = thisParent;
			if (thisParent == null || thisParent == ""){thisParent = "99999999"}//This is for elements with no parent			
			SubCatList = SubCatList + "," + thisParent;
			//this was added to create the list of Parents or SubCategories. -CP 04/01/2009 
		}
	}
	
	MenuList = MenuList.substring(1, MenuList.length)
	SubCatList = SubCatList.substring(1, SubCatList.length)
	document.getElementById("SelectedMenu").value = MenuList;	
	document.getElementById("SelectedSubCat").value = SubCatList;

	if (document.getElementById("Home").checked)
	{
		document.getElementById("SelectedHome").value = "Y";
	}
	else
	{
		document.getElementById("SelectedHome").value = "N";
	}
}

//----------------------------------------------------------------	
function ShowLoading()
{
		document.getElementById("InProgress").style.display="";
		document.getElementById("PrintList").style.display="none";
}
//----------------------------------------------------------------	
function submit_form_hide()
{  
		document.getElementById("ctrlblock").innerHTML="<img src=\"/_images/_design/animated.gif\">";
		document.PrintForm.submit();
}

/**/

