//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(windowsName, imageName){
	window.open ("../WebEditor/addEditImage.aspx?ImagePath=img&imageName="+imageName,"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 its 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, ModuleTypeID, indexID, GroupPageID, PaneName){

//document.getElementById("hidFormEvent").value=sEvent
   objForm.hidFormEvent.value =sEvent;

    if (sEvent=="delete"){
		if (PageID>0) {objForm.PageID.value = PageID;}
        confirmSubmit(objForm, PageID);
		return;
    }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;}
		 deleteConfirmation(objForm);
		return;
    }else if (sEvent=="editModule"){
         openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID +"&PaneName=" +PaneName , "AddEditModules", 830, 620)
		return;
		
     }else if (sEvent=="editModuleItem"){
         openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&TemplateModuleID="+PageModuleID+"&ModuleID="+ModuleID +"&PaneName="+PaneName, "AddEditModules", 830, 620)
		return;   
             
	}else if (sEvent=="editStaticModule"){
         openWindow(appPath+"management/contents/ModuleProperties.aspx?PageID="+PageID + "&ModuleID="+ModuleID +"&PaneName="+PaneName, "AddEditModules", 830, 620)
		return;
		
    }else if (sEvent=="editModuleCollection"){
      // openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&TemplateModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddEditModules", 830, 620)
         openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&TemplateModuleID="+PageModuleID+"&ModuleID="+ModuleID +"&PaneName="+PaneName, "AddEditModules", 830, 620)
		return;
		       
	}else if (sEvent=="editCatalogModule"){
        openWindow(appPath+"management/contents/ModuleCatalogInfo.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddEditModules", 830, 620)
		return;	
		
    }else if (sEvent=="editModuleText"){
        openWindow(appPath+"management/webEditor/webEditor.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "WebEditor", 830, 620)
		return;
    }else if (sEvent=="addNewModule"){
       openWindow(appPath+"management/contents/ModuleInfo.aspx?PageID="+PageID + "&PageModuleID=0&ModuleID=0&ModuleTypeID=" + ModuleTypeID+"&PaneName=Layout", "AddNewModule", 830, 620)
		return;
		
    }else if (sEvent=="editPage"){
          openWindow("PageDetails.aspx?PageID="+PageID, "EditPage",  800,600)
          return;
    }else if (sEvent=="editCategory"){
        document.location="categoriesXAttributes.aspx?CategoryID="+CategoryID+"&GroupID="+GroupID
        return; 
	}else if (sEvent=="editForm"){

        openWindow(appPath+ "?ModuleID="+ModuleID, "EditForm", 830, 620)
		return;

    }else if (sEvent=="newPage" ){
       openWindow("PageDetails.aspx?PageID=0&parentID="+PageID, "NewPage",  800,600)
        return;
   }else if (sEvent=="newCategory" ){
        document.location="categoryInfo.aspx?CategoryID=0&parentID="+CategoryID+"&GroupID="+GroupID
        return;
    }else if (sEvent=="addModuleDetail"){
        openWindow(appPath+"management/contents/moduleDetails.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID, "AddModuleDetails", 830, 620)
		return;
    }else if (sEvent=="editModuleDetail"){
        openWindow(appPath+"management/contents/moduleDetails.aspx?PageID="+PageID + "&PageModuleID="+PageModuleID+"&ModuleID="+ModuleID+"&moduleDetailID="+ModuleDetailID, "EditModuleDetails", 830, 620)
		return;
   }else if (sEvent=="orderModuleDetail"){
         objForm.ModuleID.value = ModuleID;
         objForm.ModuleDetailID.value = ModuleDetailID
		 objForm.submit();
		return;

    }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 = "	Detail"
				
				objForm.submit();
            }else{
	           return;
            }
	}else if (sEvent=="orderModule"){
			objForm.PageModuleID.value = PageModuleID;
			objForm.ModuleID.value = ModuleID;
			objForm.hidFormEvent.value = "orderModule"
			objForm.submit();
	}else if (sEvent=="selectItem"){
		
		 if (PageID>0) {
			objForm.PageID.value = PageID;
		}
		
        if (CategoryID>0){
			objForm.CategoryID.value = CategoryID;
        }
        
        if ((PageModuleID == 0) || (PageModuleID>0)) {
			objForm.PageModuleID.value = PageModuleID;
		}
		
        if ((ModuleID == 0) || (ModuleID>0)) {
			objForm.ModuleID.value = ModuleID;
		}
	
		document.location="webContents.aspx?PageID="+PageID+"&GroupPageID="+GroupPageID+"#"+indexID;

    }else{

        if (PageID>0) {
			objForm.PageID.value = PageID;
			if (GroupID>0) {setCookie('Group_ID',GroupID,365)}
			}
        if (CategoryID>0){
			objForm.CategoryID.value = CategoryID;
			if (GroupID>0) setCookie('Group_ID',GroupID,365)
			
        }
        if ((PageModuleID == 0) || (PageModuleID>0)) {
			objForm.PageModuleID.value = PageModuleID;
		}
		
        if ((ModuleID == 0) || (ModuleID>0)) {
			objForm.ModuleID.value = ModuleID;
		}
		if ((ModuleDetailID == 0) || (ModuleDetailID>0)) {
			objForm.ModuleDetailID.value = ModuleDetailID;
		}
		if ((GroupID == 0) || (GroupID>0)) {
			if (GroupID>0) {setCookie('Group_ID',GroupID,365)}

		}

    objForm.submit();
 }
}


function checkSelectedModule(objForm, ModuleID, PageAreaClientID){

// alert("selectedIndex=" +document.cmForm.[PageAreaClientID].selectedIndex +": "+objForm.ModuleID.value);
    if (ModuleID>0) {
        if (document.cmForm[PageAreaClientID].selectedIndex==0) {
            alert("Please, select the module position")
             return false;

        }else if ((document.cmForm[PageAreaClientID].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[PageAreaClientID].selectedIndex==6) && (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 ="";
}	
//called from Date Picker popup window
function setSelectedDate(SelectedDate, controlName,objWindow){
objWindow.close();
document.forms[0][controlName].value=SelectedDate

}
function displayTimePicker(controlName, FormName, ParameterName){

	PageURL="../contents/controls/datePicker.aspx?controlName=" + controlName + "&SelectedDate=" + FormName[controlName].value
	window.open(PageURL, "Calendar", "left=400, top=300, height=300, width=400");

}

function RefreshPage(windowAction, selfAction){

	try{
		//if there is  any  ErrMsg tag, no error found
		if (document.getElementById('ErrMsg').getAttribute('id')!=""){
			return false;
		}     
	}catch(e){


		if (windowAction=="submit"){
			window.opener.cmForm.submit();
			
		}else if (windowAction=="refresh"){
			window.opener.location.reload(true);
		}
	
		if (selfAction=="close"){
			self.close();
			
		}else if (selfAction=="refresh"){
			document.location=document.location;
		}
	}

}

function delCookie (cookieName) 
{
if (getCookie(cookieName)) 
	{
	document.cookie = cookieName + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

			
function ConfirmTemplateDeletion(TemplateID)
{
    var agree=confirm("You are deleting the selected template. Are you sure you want to continue?");
    if (agree){
		document.forms[0].hidFormEvent.value="delete"
		document.forms[0].TemplateID.value=TemplateID
		
       document.forms[0].submit();
    }else{
	   return false;
    }
}


function CheckPopup(evt) { 
	window.opener.location=window.opener.location;
} 



function createHyperLink(hyperLink, hypertarget, selection, DetailLink)
	{

	hyperLink = hyperLink.replace("<%=AppPath%>","/")
	document.forms[0][selection].value=hyperLink;
	}

function CheckUniqueID(me, ModuleID)
{

	url = "GetFormElementName.aspx?ElementName=" + me.value + "&ModuleID=" + ModuleID;

	xmlhttp=null;
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		
	}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=state_Change
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
		
	}else{
		alert("Your browser does not support XMLHTTP.")
	}		
				
}
	

function state_Change()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
  		if (xmlhttp.status==200)
  		{
			if (xmlhttp.responseText=="true")
			{
				document.all["ElementNameReqVal"].innerHTML ="The element name is not unique";
  				document.all["ElementNameReqVal"].style.visibility='visible';	
  				document.getElementById("btnSave").disabled=true;
  			
  			}else{
  				document.getElementById("btnSave").disabled=false;	
			}

 		}else{
			alert("Problem retrieving XML data:" + xmlhttp.statusText)
  		}
	}
}

	function OpenHypWin(objParent, RedirectUrl){

			if (RedirectUrl==true)
			{
				window.open("../webEditor/addEditLinks.aspx?URLHyperlink=" +document.forms[0][objParent].value+"&OpenerURLField=" +objParent+"&DetailLink=RedirectUrl", "Hyperlink", "top=100, left=100, width=600, height=600, resizable=1, scrollbars=yes, menubar=no, status=yes");
			}else{
				//window.open("../webEditor/addEditLinks.aspx?URLHyperlink=" +document.forms[0][objParent].value+"&HyperlinkTarget="+document.forms[0].[objParent + 'Target'].value+"&OpenerURLField=" +objParent+"&DetailLink=true", "Hyperlink", "top=100, left=100, width=600, height=600, resizable=1, scrollbars=auto, menubar=no, status=yes");
			}
}
		



