﻿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;
   
   }


/* 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 administrator?";
		   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;
	   }
	   case 14:
	   {
		   myurl="delete_usergroup.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this user group?";
		   if (y==4)
		   {
			   myurl="index_usergroups.aspx";
		       myconfirm="YOU CANNOT DELETE THE ADMIN USERGROUP - IT IS FORBIDDEN";   
		   }
		   break;
	   }
	   case 15:
	   {
		   myurl="delete_page2.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this resource centre page?";
		   break;
	   }
	   case 16:
	   {
		   myurl="delete_user_application.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this applicant?";
		   break;
	   }
	   case 17:
	   {
		   myurl="delete_user_active.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this user?";
		   break;
	   }
	   case 18:
	   {
		   myurl="delete_user_deactivated.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this user?";
		   break;
	   }
	   case 19:
	   {
		   myurl="delete_image.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this image?";
		   break;
	   }
	   case 20:
	   {
		   myurl="delete_file.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this file?";
		   break;
	   }
	   case 21:
	   {
		   myurl="delete_newscat.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to delete this news category?";
		   if (y==1)
		   {
			   myurl="index_newscats.aspx";
		       myconfirm="YOU CANNOT DELETE THIS CATEGORY - IT IS USED FOR UNCATEGORIZED NEWS ARTICLES";
		   }
		   break;
	   }
	   case 22:
	   {
		   myurl="delete_news.aspx?id=" + y + "&confirm=1";
		   myconfirm="Are you sure you would like to permanently delete this news item?";
		   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 ;
}
function preview_page1()
{
   newscatid=document.getElementById('ctl00_rightpane_content_f_newscatid').value;
   window.open (("/File/preview1.aspx?newscatid=" + newscatid),"Preview"); 
}
function preview_page2()
{
   nav2id=document.getElementById('ctl00_rightpane_content_f_nav2id').value;
   newscatid=document.getElementById('ctl00_rightpane_content_f_newscatid').value;
   window.open (("/File/preview2.aspx?nav2id=" + nav2id + "&newscatid=" + newscatid),"Preview"); 
}
function show_preview_page1()
{
   pagecontent=window.opener.document.getElementById('ctl00_rightpane_content_f_pagetext').value;
   document.getElementById('mytext').innerHTML=pagecontent;
}
function show_preview_page2()
{
   pagecontent=window.opener.document.getElementById('ctl00_rightpane_content_f_pagetext').value;
   document.getElementById('mytext').innerHTML=pagecontent;
}
function process_search()
{
	myerror = 0;
    myerrormsg = "";
	if (trim(document.frmsearch.criteria.value)== '') 
	{
		myerrormsg = myerrormsg + ' -Enter a search term\n';
        myerror = 1;
	}
	 if (myerror == 1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }
}

function process_request_info()
{
   myerror = 0;
   myerrormsg = "The following information is required:\n";
   if (trim(document.frminfo.fi_name.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your name\n';
        myerror = 1;
   }
   if (trim(document.frminfo.fi_email.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your email\n';
        myerror = 1;
   }
   else
   {
      if (isValidEmail(document.frminfo.fi_email.value)==false)
	  {
	     myerrormsg = myerrormsg + ' -Enter your email (a valid address)\n';
         myerror = 1;  
	   }
	}
	if (myerror==1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }	
}

function process_callback()
{
   myerror = 0;
   myerrormsg = "The following information is required:\n";
   if (trim(document.frmcallback.fc_name.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your name\n';
        myerror = 1;
   }
   if (trim(document.frmcallback.fc_telephone.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your telephone\n';
        myerror = 1;
   }
	if (myerror==1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }	
}

function process_request_price_info()
{
   myerror = 0;
   myerrormsg = "The following information is required:\n";
   if (trim(document.frmpriceinfo.fp_name.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your name\n';
        myerror = 1;
   }
   if (trim(document.frmpriceinfo.fp_email.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your email\n';
        myerror = 1;
   }
   else
   {
      if (isValidEmail(document.frmpriceinfo.fp_email.value)==false)
	  {
	     myerrormsg = myerrormsg + ' -Enter your email (a valid address)\n';
         myerror = 1;  
	   }
	}
	if (myerror==1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }	
}
function process_login()
{
   myerror = 0;
   myerrormsg = "The following information is required:\n";
   if (trim(document.loginfrm.l_username.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your username\n';
        myerror = 1;
   }
   if (trim(document.loginfrm.l_password.value)== '') 
   {
		myerrormsg = myerrormsg + ' -Enter your password\n';
        myerror = 1;
   }	
   if (myerror==1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }	
}
function chkpassword()
{
	myerror = 0;
    myerrormsg = "";
    myerrormsg = 'Please provide the following\n';
	if (trim(document.frmpwd.f_email2.value)== '') 
	{
		myerrormsg = myerrormsg + ' -E-Mail Address\n';
        myerror = 1;
	}
	else
	{
       if (isValidEmail(document.frmpwd.f_email2.value) == false) 
       {
          myerrormsg = myerrormsg + ' -E-Mail (A valid address)\n';
          myerror = 1;
       } 
	}
	 if (myerror == 1) 
    {
        alert(myerrormsg);
        return false;
    }
    else 
    {
        return true;
    }
}
