﻿// Header Slideshow

var slideCache = new Array();
function RunSlideShow(pictureName, imageFiles, displaySecs) {
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0, imageSeparator);
    if (document.all) {
        document.getElementById(pictureName).style.filter = "blendTrans(duration=2)";
        document.getElementById(pictureName).filters.blendTrans.Apply();
    }
    document.getElementById(pictureName).src = "/Image/headers/" + nextImage;
    if (document.all) {
        document.getElementById(pictureName).filters.blendTrans.Play();
    }
    var futureImages = imageFiles.substring(imageSeparator + 1, imageFiles.length)
    + ';' + nextImage;
    setTimeout("RunSlideShow('" + pictureName + "','" + futureImages + "'," + displaySecs + ")",
    displaySecs * 1000);
    // Cache the next image to improve performance.
    imageSeparator = futureImages.indexOf(";");
    nextImage = futureImages.substring(0, imageSeparator);
    if (slideCache[nextImage] == null) {
        slideCache[nextImage] = new Image;
        slideCache[nextImage].src = nextImage;
    }
}

//Highslide Config
hs.captionEval = 'this.a.title';
hs.graphicsDir = '/includes/scripts/highslide_graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.5;
//hs.dimmingOpacity = 0.75;

// Add the controlbar
hs.addSlideshow({
	slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: '0.75',
		position: 'bottom center',
		offsetX: '0',
		offsetY: '-10',
		hideOnMouseOut: true
	},
	thumbstrip: {
		mode: 'horizontal',
		position: 'bottom center',
		relativeTo: 'viewport'
	}

});
// gallery config object
var config1 = {
	slideshowGroup: 'group1',
	transitions: ['expand', 'crossfade']
};

// Turn Settings (JQuery)
$("#pageflip").hover(function() { //On hover...
	$("#pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
			width: '307px',
			height: '319px'
		}, 500);
	} , function() {
	$("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
			width: '50px',
			height: '52px'
		}, 220);
	$(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
			width: '50px',
			height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
});
	


/* Check of an E-Mail address appears valid */
function isValidEmail(str) 
{
    return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

/* Trim Left and Right Whitespace */
function trim(s) 
{
    if (s.value > 0) {
        while (s.substring(0, 1) == ' ') {
            s = s.substring(1, s.length);
        }
        while (s.substring(s.length - 1, s.length) == ' ') {
            s = s.substring(0, s.length - 1);
        }
    }
    return s;
}

/* Display an Alert */
function showalert(stralert)
{
	alert(stralert);
}

// Form Processing Functions

function process_frmMailList() 
{
    myerror = 0;
    myerrormsg = "";
    myerrormsg = 'Please provide the following\n';


    if (trim(document.frmMailList.ml_firstname.value) == '') 
    {
        myerrormsg = myerrormsg + ' -First Name\n';
        myerror = 1;
    }
    if (trim(document.frmMailList.ml_lastname.value) == '') 
    {
        myerrormsg = myerrormsg + ' -Last Name\n';
        myerror = 1;
    }
    if (trim(document.frmMailList.ml_email.value) == '') 
    {
       myerrormsg = myerrormsg + ' -E-Mail Address\n';
       myerror = 1;
    }
    if (trim(document.frmMailList.ml_email.value)!= '') 
    {
       if (isValidEmail(document.frmMailList.ml_email.value) == false) 
       {
          myerrormsg = myerrormsg + ' -E-Mail (A valid address)\n';
          myerror = 1;
       }   
    }
    if (myerror == 1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }
}

function cms_chkpassword()
{
	myerror = 0;
    myerrormsg = "";
    myerrormsg = 'Please provide the following\n';
	if (trim(document.frmcmspwd.f_email2.value)== '') 
	{
		myerrormsg = myerrormsg + ' -E-Mail Address\n';
        myerror = 1;
	}
	else
	{
       if (isValidEmail(document.frmcmspwd.f_email2.value) == false) 
       {
          myerrormsg = myerrormsg + ' -E-Mail (A valid address)\n';
          myerror = 1;
       } 
	}
	 if (myerror == 1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }
}
function cms_delete_me(x,y)
{
	var myurl="";
	var myconfirm="";
	
	switch(x)
    {
       case 1:
	   {
		   myurl="delete_user.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this user?";
		   break;
	   }
	   case 2:
	   {
		   myurl="delete_page.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this web page?";
		   if (y==1)
		   {
			   myurl="index_pages.aspx";
		       myconfirm="YOU CANNOT DELETE THE HOME PAGE OF THE WEBSITE.\nCLICK ANY BUTTON TO RETURN TO THE INDEX OF WEB PAGES";   
		   }
		   break;
	   }
	   case 3:
	   {
		   myurl="delete_navgroup.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this navigation group?";
		   break;
	   }
	   case 4:
	   {
		   myurl="delete_navoption.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this navigation option?";
		   break;
	   }
	   case 5:
	   {
		   myurl="delete_headergroup.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this header group?";
		   break;
	   }
	   case 7:
	   {
		   myurl="delete_gallery.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this gallery?";
		   break;
	   }
	   case 9:
	   {
		   myurl="delete_mailtemplate.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this mail template?";
		   break;
	   }
	   case 10:
	   {
		   myurl="delete_mailgroup.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this mail group?";
		   if (y==1)
		   {
			   myurl="index_mailgroups.aspx";
		       myconfirm="YOU CANNOT DELETE THE GENERAL MAILING LIST - IT IS FORBIDDEN";   
		   }
		   break;
	   }
	    case 11:
	   {
		   myurl="delete_subscriber.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this subscriber?";
		   break;
	   }
	   case 12:
	   {
		   myurl="delete_topbox.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this top box?";
		   break;
	   }
	   case 13:
	   {
		   myurl="delete_sidebar.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this sidebar?";
		   break;
	   }
	}
	
	var agree=confirm(myconfirm);
    if (agree)
    {
	     window.location=myurl;
    }
}

function cms_delete_me2(x,y,z)
{
	var myurl="";
	var myconfirm="";
	switch(x)
    {
	   case 4:
	   {
		   myurl="delete_navoption.aspx?id=" + y + "&confirm=1&navgroup=" + z;
		   myconfirm="Are you sure you would like to delete this navigation option?";
		   break;
	   }
	   case 6:
	   {
		   myurl="delete_headerfile.aspx?id=" + y + "&confirm=1&headergroup=" + z;
		   myconfirm="Are you sure you would like to delete this header file?";
		   break;
	   }
	    case 8:
	   {
		   myurl="delete_galleryimage.aspx?id=" + y + "&confirm=1&gallerygroup=" + z;
		   myconfirm="Are you sure you would like to delete this picture?";
		   break;
	   }
	}
	
	var agree=confirm(myconfirm);
    if (agree)
    {
	     window.location=myurl;
    }
}

function BrowseServer()
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.BasePath = '/ckfinder/' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	finder.SelectFunction = SetFileField ;
	finder.Popup() ;

	// It can also be done in a single line, calling the "static"
	// Popup( basePath, width, height, selectFunction ) function:
	// CKFinder.Popup( '../../', null, null, SetFileField ) ;
	//
	// The "Popup" function can also accept an object as the only argument.
	// CKFinder.Popup( { BasePath : '../../', SelectFunction : SetFileField } ) ;
}

// This is a sample function which is called when a file is selected in CKFinder.
function SetFileField( fileUrl )
{
	document.getElementById( 'ctl00_rightpane_content_f_navurl' ).value = fileUrl ;
}

function process_search() 
{
    myerror = 0;
    myerrormsg = "";
    myerrormsg = 'Please provide the following\n';


    if (trim(document.frmsearch.searchterm.value) == '') 
    {
        myerrormsg = myerrormsg + ' -A Search Term\n';
        myerror = 1;
    }
    
    if (myerror == 1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }
}
