//Show/hide  one page element
function toggle(e) {
    var eVisible = xGetElementById(e)

    if (eVisible.style.visibility=='visible') {
		xHide(e);
	}else{
	   xShow(e);
	}

}

//Show/hide more than one page element
function ShowHide(id) {
	if( document.getElementsByName ){
		var divs = document.getElementsByName(id);
		if( divs && divs.length > 0 ){	
			for( i=0;i<divs.length;i++ ){
				if ( divs[i].style.display == "none" ){
					divs[i].style.display = "block";
				}else{
					divs[i].style.display = "none";	
				}
			}
		}		
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function imageDialogBox(){
	window.open ("../WebEditor/addEditImage.aspx?ImagePath=img","NewWindow","scrollbars=no,resizable=yes, status=yes, width=480,height=550,left=100,top=100")
}

function xShow(e) {

  if(!(e=xGetElementById(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='visible';
  else if(xDef(e.visibility)) e.visibility='show';
}

function xHide(e) {
  if(!(e=xGetElementById(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='hidden';
  else if(xDef(e.visibility)) e.visibility='hide';
}

function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;

  return e;
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function confirmSubmit(objForm){
    var agree=confirm("You are deleting the selected page and all related items. Are you sure you want to continue?");
    if (agree){
       objForm.submit();
    }else{
	   return false;
    }
}

function deleteConfirmation(objForm){
    var agree=confirm("You are deleting this module and all related data. Are you sure you want to continue?");
    if (agree){
       objForm.submit();
    }else{
	   return false;
    }
}

function submithisForm(PageID, PageModuleID, ModuleID, moduleDetailID){
        doPostBack('selectModule', cmForm,PageID,PageModuleID, ModuleID, moduleDetailID);
    }
                       
function doPostBack(sEvent, objForm, PageID, PageModuleID, ModuleID, ModuleDetailID, appPath, GroupID, CategoryID){

    objForm.hidFormEvent.value =sEvent;

    if (sEvent=="delete"){
		if (PageID>0) {objForm.PageID.value = PageID;}
        confirmSubmit(objForm, PageID);

    }else if (sEvent=="deleteModule"){

        if (PageID>0) {objForm.PageID.value = PageID;}
        if ((PageModuleID == 0) || (PageModuleID>0)) {objForm.PageModuleID.value = PageModuleID;}
        if ((ModuleID == 0) || (ModuleID>0)) {objForm.ModuleID.value = ModuleID;}
		 confirmSubmit(objForm);
		
    }else if (sEvent=="editModule"){
       openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddEditModules", 830, 620)
        
	}else if (sEvent=="editCatalogModule"){
        openWindow(appPath+"management/contents/ModuleCatalogInfo.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddEditModules", 830, 620)
			
		
    }else if (sEvent=="editModuleText"){
        openWindow(appPath+"management/webEditor/webEditor.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "WebEditor", 830, 620)

    }else if (sEvent=="addNewModule"){
        openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&PageModuleID=0&ModuleID=0", "AddNewModule", 830, 620)

    }else if (sEvent=="editPage"){
        document.location="PageDetails.aspx?PageID="+PageID
        
    }else if (sEvent=="editCategory"){
        document.location="categoriesXAttributes.aspx?CategoryID="+CategoryID+"&GroupID="+GroupID


    }else if (sEvent=="newPage" ){
        document.location="PageDetails.aspx?PageID=0&parentID="+PageID
        
   }else if (sEvent=="newCategory" ){
        document.location="categoryInfo.aspx?CategoryID=0&parentID="+CategoryID+"&GroupID="+GroupID
        
    }else if (sEvent=="addModuleDetail"){
        openWindow(appPath+"management/contents/moduleDetails.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddModuleDetails", 830, 620)

    }else if (sEvent=="editModuleDetail"){
        openWindow(appPath+"management/contents/moduleDetails.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID+"&moduleDetailID="+ModuleDetailID, "EditModuleDetails", 830, 620)

   }else if (sEvent=="moveModuleDetail"){
         document.ModuleID = ModuleID;
         document.ModuleDetailID = ModuleDetailID
		 objForm.submit();


    }else if (sEvent=="deleteModuleDetail"){

        var agree=confirm("You are deleting the selected module detail. \n Are you sure you want to continue?");
            if (agree){
				objForm.ModuleID.value = ModuleID;
				objForm.ModuleDetailID.value = ModuleDetailID
				objForm.hidFormEvent.value = "deleteDetail"
				
				objForm.submit();
            }else{
	           return;
            }


    }else{

        
        if (PageID>0) {
			objForm.PageID.value = PageID;
			setCookie('GroupID',GroupID,365)
			}
        if (CategoryID>0){
			objForm.CategoryID.value = CategoryID;
			document.cookie.GroupID = GroupID;
        }
        if ((PageModuleID == 0) || (PageModuleID>0)) {
			objForm.PageModuleID.value = PageModuleID;
		}
        if ((ModuleID == 0) || (ModuleID>0)) {
			objForm.ModuleID.value = ModuleID;
		}
		if ((GroupID == 0) || (GroupID>0)) {
			document.cookie.GroupID = GroupID;
		}
	
    objForm.submit();
 }
}


function checkSelectedModule(objForm, ModuleID, PageColumnClientID){

// alert("selectedIndex=" +document.cmForm.[PageColumnClientID].selectedIndex +": "+objForm.ModuleID.value);
    if (ModuleID>0) {
        if (document.cmForm[PageColumnClientID].selectedIndex==0) {
            alert("Please, select the module position")
             return false;

        }else if ((document.cmForm[PageColumnClientID].selectedIndex==5) && (objForm.ModuleID.value>0)) {

            var agree=confirm("The module that you are mporting, will be entered after the selected module on the page. \n Do you want to continue?");
            if (agree){
                objForm.hidFormEvent.value ="importModule";
                if (ModuleID>0){objForm.ModuleID.value = ModuleID;}
                objForm.submit();
              }else{
	           return false;
            }
        }else if ((document.cmForm[PageColumnClientID].selectedIndex==5) && (objForm.ModuleID.value==0)) {
            alert("There is not any selected module on the page.");
            return;

        }else{

         var agree=confirm("The module that you are mporting, will be entered on the top of the selected page column. \n  Do you want to continue?");
            if (agree){
                objForm.hidFormEvent.value ="importModule";
                if (ModuleID>0)
					{objForm.ModuleID.value = ModuleID;}
                objForm.submit();
            }else{
	           return false;
            }
        }
    }else{
        alert("Please, select the module position")
        return false;
    }
}


function openWindow(url, windowName, width, height)
	{
		var newWin = new Object();
        newWin.win=window.open(url, windowName,'width=' + width + ',height=' + height + ',resizable=1, scrollbars=yes, menubar=no, status=yes, top=100, left=100' );
		newWin.win.opener=self;
		newWin.win.focus();
	}

function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return null
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate)
}


function valueCol(){
	var dateTime ="";
}	

function setSelectedDate(SelectedDate, controlName,objWindow){
objWindow.close();
document.forms[0][controlName].value=SelectedDate

}
function displayTimePicker(controlName, controlValue ){
	PageURL="controls/datePicker.aspx?controlName=" + controlName 
	window.open(PageURL, "Calendar", "left=400, top=300, height=300, width=400");

}




