﻿// Header Slideshow
function Isfloat(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

//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']
};




/* 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 process_paypal() 
{
    myerror = 0;
    myerrormsg = "";
    myerrormsg = 'Please provide the following\n';


    if (trim(document._xclick.cust_name.value) == '') 
    {
        myerrormsg = myerrormsg + ' -Your Name\n';
        myerror = 1;
    }
    if (trim(document._xclick.cust_email.value) == '') 
    {
       myerrormsg = myerrormsg + ' -E-Mail Address\n';
       myerror = 1;
    }
    if (trim(document._xclick.cust_email.value)!= '') 
    {
       if (isValidEmail(document._xclick.cust_email.value) == false) 
       {
          myerrormsg = myerrormsg + ' -E-Mail (A valid address)\n';
          myerror = 1;
       }   
    }
	if (trim(document._xclick.item_name.value) == '') 
    {
       myerrormsg = myerrormsg + ' -Description\n';
       myerror = 1;
    }
	if (trim(document._xclick.amount.value) == '') 
    {
       myerrormsg = myerrormsg + ' -Amount to Pay\n';
       myerror = 1;
    }
	else
	{
	   if (Isfloat(document._xclick.amount.value) == false) 
       {
          myerrormsg = myerrormsg + ' -Amount to Pay (Must be a numeric value)\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?";
		   if ((y==1) || (y==2))
		   {
			   myurl="index_nav.aspx";
		       myconfirm="YOU CANNOT DELETE THE STANDARD NAVIGATION GROUPS.\nCLICK ANY BUTTON TO RETURN TO THE INDEX";   
		   }
		   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_ratecard.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this ratecard?";
		   break;
	   }
	   case 13:
	   {
		   myurl="delete_calendar.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this availability calendar?";
		   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;
	   }
	   case 14:
	   {
		   myurl="delete_booking.aspx?id=" + y + "&confirm=1&calendar=" + z;
		   myconfirm="Are you sure you would like to delete this booking?";
		   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 ;
}

