function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function confirmDelete(name,id){
   var name=confirm("Are you sure you would like to delete \""+ name+"\"?")
   if (name==true)
   {
      MM_goToURL('parent','?deleteid='+id);
	  return document.MM_returnValue;
   }
}

function confirmDeletion(name,urlargs){
   var name=confirm("Are you sure you would like to delete \""+ name+"\"?")
   if (name==true)
   {
      MM_goToURL('parent','?'+urlargs);
	  return document.MM_returnValue;
   }
}

function confirmDuplication(name,urlargs){
   var name=confirm("Are you sure you would like to duplicate \""+ name+"\"?")
   if (name==true)
   {
      MM_goToURL('parent','?'+urlargs);
	  return document.MM_returnValue;
   }
}

function confirmChangeLoss(action,urlargs){
   var name=confirm("You will lose any unsaved changes by "+action+". Do you wish to proceed?")
   if (name==true)
   {
      MM_goToURL('parent','?'+urlargs);
	  return document.MM_returnValue;
   }
}

function confirmDeletePageSection(pageName,pageid,sectionid){
   var name=confirm("Are you sure you would like to delete the page section from\""+pageName+"\"?")
   if (name==true)
   {
      MM_goToURL('parent','?pageid='+pageid+'&deletesection='+sectionid);
	  return document.MM_returnValue;
   }
}

function confirmDeleteGroup(name,id){
   var name=confirm("Are you sure you would like to delete \""+ name+"\"?")
   if (name==true)
   {
      MM_goToURL('parent','?deletegroupid='+id);
	  return document.MM_returnValue;
   }
}

function confirmDeleteAssetFile(fileid,assetgroupid){
   var name=confirm("Are you sure you would like to delete this image?")
   if (name==true)
   {
	   MM_goToURL('parent','?deleteid='+fileid+'&assetgroup='+assetgroupid);
	   return document.MM_returnValue;
   }
   
}

function showadmintab(section) 
{ 
	var sections = new Array("tabone","tabtwo","tabthree","tabfour","tabfive","tabsix","tabseven");

	for( i=0; i<sections.length; i++)
	{
		if ( document.getElementById(sections[i]) != null )
		{
			if( section==sections[i] )
			{
				document.getElementById(sections[i]).className = "tabnavigationbody";
		
				switch ( document.getElementById(sections[i]+"link").className )
				{
					case "tabnavigation":
						document.getElementById(sections[i]+"link").className = "tabnavigation-on";				
						break;
					case "tabnavigation-wide":
						document.getElementById(sections[i]+"link").className = "tabnavigation-wide-on";				
						break;
               case "tabnavigation-narrow":
						document.getElementById(sections[i]+"link").className = "tabnavigation-narrow-on";				
						break;						
				}
			}
			else
			{
				document.getElementById(sections[i]).className = "hidden";
		
				switch ( document.getElementById(sections[i]+"link").className )
				{
					case "tabnavigation-on":
						document.getElementById(sections[i]+"link").className = "tabnavigation";				
						break;
					case "tabnavigation-wide-on":
				        document.getElementById(sections[i]+"link").className = "tabnavigation-wide";				
						break;
				   case "tabnavigation-narrow-on":
				      document.getElementById(sections[i]+"link").className = "tabnavigation-narrow";				
						break;
				}
			}
		}
	}
}

function preview()
{
   /* get the information from the images array */
   var imageSrc = imageAlt = "";
   var list = document.getElementById("list");
   for( var i=0; i<images.length; i++ )
   {
      for( var j=0; j<images[i]["items"].length; j++ )
      {
         if( images[i]["items"][j]['id']==list.options[list.selectedIndex].value )
         {
            switch (images[i]["items"][j]['filetype'])
            {
               case "image":
                  imageSrc = "/admin/assetmanager/resize_image.php?image="+images[i]["items"][j]['filename'];
                  imageAlt = images[i]["items"][j]['description'];
                  break;
               case "flash":
                  imageSrc = "/images/icon_pdf_large.png";
                  imageAlt = "flash icon";
                  break;			   
            }
            break;
         }
      }
   }

   /* add an image to the preview box */
   if( imageSrc!="" )
   {
      document.getElementById("previewimage").src = imageSrc;
      document.getElementById("previewimage").alt = imageAlt;
   }
   else
   {
      document.getElementById("previewimage").src = "/images/noimage.png";
      document.getElementById("previewimage").alt = "no image selected";
   }
}


function display_preview_image( imagesize )
{
   /* get the information from the images array */
   var imageSrc = imageAlt = "";
   var list = document.getElementById("list");
   for( var i=0; i<images.length; i++ )
   {
      for( var j=0; j<images[i]["items"].length; j++ )
      {
         if( images[i]["items"][j]['id']==list.options[list.selectedIndex].value )
         {
            switch (images[i]["items"][j]['filetype'])
            {
               case "image":
                  imageSrc = "/admin/assetmanager/resize_image.php?image="+images[i]["items"][j]['filename'];
                  if ( imagesize != "" ) imageSrc += "&size="+imagesize;
                  imageAlt = images[i]["items"][j]['description'];
                  break;
               case "flash":
                  imageSrc = "/images/icon_pdf_large.png";
                  imageAlt = "flash icon";
                  break;			   
            }
            break;
         }
      }
   }

   /* add an image to the preview box */
   if( imageSrc!="" )
   {
      document.getElementById("previewimage").src = imageSrc;
      document.getElementById("previewimage").alt = imageAlt;
   }
   else
   {
      document.getElementById("previewimage").src = "/images/noimage.png";
      document.getElementById("previewimage").alt = "no image selected";
   }
}

function confirmLogOut()
{
	var name=confirm("Are you sure you want to logout of the CMS?")
	if (name==true)
	{
		MM_goToURL('parent','/admin/logout.php');
		return document.MM_returnValue;
	}
}
