// global variables
var n4,ie,n6;
var win_width,win_height;
var maximum=255;
var maximum_sms=100;
var generic_gallery=false;
// go to page - redirect user to a specific url
function gotopage(url){
    window.location.href=url;
}

//alert("here in scripts.js")
//Event.observe(window, 'load', function(){alert("load event attached");});
Event.observe(window, 'load', page_trigger, false);
//alert("here in scripts.js")
//Event.observe(window, 'resize', page_resize, false);

//generic function to start galleries, scrollers and other dhtml elements
function page_trigger(){
//alert("page triggers");
    var el=get_el('js_triggers'); // checks for site specific triggers
    if (el) {
       // alert("JS: " + el.value);
        eval(el.value); // executes the triggers that are found;
    }
    var el=get_el("your_details");
    if (el){
        //alert("fixing your details");
        $('your_details').value='';
    }

    var el=get_el('gallery_data');
    if (el){
        var gallery_buffer=el.value
        var g_display=get_el('gallery_display_element');
        var g_info=get_el('gallery_information_element'); //optional element that allows us to display the title of images as they cycle in gallery
        var g_contact_sheet=get_el('gallery_contact_sheet')
        
        var g_cycle= true; // auto cycling gallery
        var t=5000; // default timing
        var w=280; // default width of gallery image
        var h=215; // default height of gallery image
		var g_num_preview = 5;
        var el=get_el("gallery_data_width");//check if there's an override of default values
        if (el) {
            w=el.value;
        }
        var el=get_el("gallery_data_height");//check if there's an override of default values
        if (el) {
            h=el.value;
        }
        var el=get_el("gallery_data_timing");//check if there's an override of default values
        if (el) {
            t=el.value;
        }
        var el=get_el("gallery_cycle");//check if there's an override of default values
        if (el) {
            if (el.value = "false"){
                g_cycle=false;
            }            
        }    
        var el=get_el("gallery_preview_elements");//check if there's an override of default values
        if (el) {
            g_num_preview = el.value
        }             

		
        if (g_contact_sheet){
            //alert("dont forget comments")
            generic_gallery=new make_gallery(gallery_buffer, g_display.value,g_cycle,t,w,h,g_info.value,g_contact_sheet,g_num_preview);
        }
        else if (g_info){
            generic_gallery=new make_gallery(gallery_buffer, g_display.value,g_cycle,t,w,h,g_info.value);
        }
        else{
            generic_gallery=new make_gallery(gallery_buffer, g_display.value,g_cycle,t,w,h);
        }
        generic_gallery.start('generic_gallery');
        var el=get_el('gallerywrap');
        if (el) {
            Rico.Corner.round('gallerywrap',{corners:"all"});
        }
        var el=get_el('prev_button');
        if (el) {
            Rico.Corner.round('prev_button',{corners:"all"});
        }
        var el=get_el('next_button');
        if (el) {
            Rico.Corner.round('next_button',{corners:"all"});
        }
            
    }
    var el=get_el('chat_data');
    if (el){
        enable_chat_client(el.value);
    }
	
	var el = get_el('visitor_tracking');
	//alert(el);
	if(el)
	{
		enable_visitor_tracking(el);
	}
}
function page_resize(){
 	var el=get_el('scroller_placeholder');
	if (el){
		myScroller1.moveTo(el.offsetLeft + 20,el.offsetTop);		
	}
    var el=get_el('scroll_placeholder');
	if (el){
		scrollerReload();		
	}
}


//Browser type determination
function get_browser_type() {
    if (document.layers){  
		n4 = true;
	}
    else if (document.all) {
    	    ie = true;
    } 
    else if (document.getElementById) {
    	    n6 = true;
    }
    return true;
}


//determining screen dimensions
function get_dimensions(){
    var x=get_browser_type();
 
    if ((screen.width>=1024) && (screen.height>=768))
    {
        return  "1024";
    }
    else
    {
        return "800";
    }
}


//generic "get an item by reference" which can handle either a getElementbyID or via the IE All collection
// note that "parent" argument is optional
// this is supplanted by the $ function built into prototype-1.4.0.js
function get_el(elem,parent) {
	if (document.layers) {
	    if (parent) {
	     return eval("document."+parent+".document."+elem);
	      }
	    else {
		return eval("document."+elem);
		     }
		
	  } 
	    else if (document.all) {
		return eval("document.all."+elem);
	} 
	    else if (document.getElementById) {
		return eval("document.getElementById('"+elem+"')");
	}
	//alert("here");
}


//generic handler which will return the "style" properties of a HTML object
//parent argument is optional
function get_style(elem,parent) {
	if (document.layers) {
	    if (parent) {
	     return eval("document."+parent+".document."+elem);
	      }
	    else {
		return eval("document."+elem + ".style");
		     }
		
	  } 
	    else if (document.all) {
		return eval("document.all."+elem + ".style");
	  } 
	    else if (document.getElementById) {
		return eval("document.getElementById('"+elem+"').style");
		
	}
}

/* generic string handler - indicates if dodgy characters exist in a posted string*/
function fixstring(svalue, bmail){
var str=svalue;
var sinvalid="!,£,\$,%,',\&";

if (bmail==true){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(')|(%)|(")/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
}
else{
	var reg1 = /(\.\.)|(^\.)|(')|(%)|(")/; // not valid
	var reg2 = /([a-zA-Z0-9])|([a-zA-Z])|([0-9])/; // valid

}
if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
	return true;
	}
return false;
}

// generic passowrd reminder trigger
function no_password(){
	var sURL = "../asp/password_request.asp";
	open_small(sURL);
}

//password reminder service
function get_window_name(){
	return window.name;
}


//check entry then perform login
function perform_login(localisedsite, validation_version){
    var log_actions=false;
    var localisation_source = ''
    var login_version=0;
    var min_password=6; // default minimum size for a password
    var max_password=12; // default maximum password length
    var iArg=6;
    var el=get_el("log_actions"); // form element to indicate if logging required for this login dialogue
    if (el){
        log_actions=true;
    }
	// localisedsite is a parameter passed in by sites that utilise an xml document to control prompts (TODO)
    // version is an integer (optional) indicating what verion of login we wish to perform (e.g. null - defaults to zero is standard email and password, 1 == username NOT an email adress)
    //check_inputs(0);
    if (arguments.length!=0){
        localisation_source=localisedsite;
        login_version=validation_version;
    }
    if (login_version==0){
            
           var el=get_el("txt_email");
           var sval=el.value              
        // check that a value has been entered for the user name field
        	if (sval.length==0){
                if (log_actions){
                    log_action("login_no_username");
                }
        		alert("Please enter your username!");
        		el.focus();
        		return false;
        	}
        // check that the format matches email address format	
        	if (!fixstring(sval,true)){
                if (log_actions){
                    log_action("login_invalid_username_format");
                }
        		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
        		el.focus();
        		return false;
        	}
        }
    else{
        	var el=get_el("txt_email");
        	var sval=el.value
        // check that a value has been entered for the user name field
        	if (sval.length==0){
        		alert("Please enter your username!");
        		el.focus();
        		return false;
        	}
        
    }
	
	var el=get_el("txt_password");
	var sval=el.value
	if (sval.length==0){
        if (log_actions){
            log_action("login_no_password");
        }
		alert("Please enter your password!");
		el.focus();
		return false;
	}
	else{
		if (!fixstring(sval,false)){
            if (log_actions){
                log_action("login_invalid_password_format");
            }
			alert("Your password contains characters that are not supported on our system!");
			el.focus();
			return false;
		}
	}
// check that the password conforms to min/max requirements
		if (sval.length<min_password){
            if (log_actions){
                log_action("short_password_length");
            }
			alert("This system requires a password length of " + min_password + " characters!");
            el.value="";
			el.focus();
			return false;
			
		}
		if (sval.length > max_password){
            if (log_actions){
                log_action("long_password_length");
            }
            alert("This system only supports password length of " + max_password + " characters!");
            el.value=""
			el.focus();
			return false;
			
		}
	el.value=sval;
	return true;
}
//log_action: performs and asynchronous get via ajax to log a JavaScript result
function log_action(action_name){
    var url="common/agility_ajax.asp"
    var p="action=30&log=" + action_name
     ajax_get_url(url,p,'', '');
     return true;
}


// check password reminder form values entred and if value ok then post password reminder form
function send_password(){
    var log_actions=false;
    var el=get_el("log_actions"); // form element to indicate if logging required for this login dialogue
    if (el){
        log_actions=true;
    }
	var el=get_el("txt_email");
	var sval=el.value
// check that a value has been entered for the user name field
	if (sval.length==0){
        if (log_actions){
            log_action("password_no_username");
        }
		alert("Please enter your email address!");
		el.focus();
		return false;
	}
// check that the format matches email address format	
	if (!fixstring(sval,true)){
        if (log_actions){
            log_action("password_invalid_username_format");
        }
    
    
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		el.focus();
		return false;
	}
	
    return true;
}
// check_password_change form values entred and if value ok then post password reminder form
function check_password_change(){
	var el=get_el("txt_password");
	var m_password=el.value
	
	var el2=get_el("txt_re_password");
	var pass2=el2.value
	
// check that a value has been entered for the user name field
	if (m_password!=pass2){
		alert("The passwords you entered don't match");
		el.focus();
		return false;
	}
	if (m_password.length<6){
        alert("Passwords must be at least 6 characters long and contain at least one character or one numeric value!");
        el.focus();
        return false;
    }
	// remove any invalid characters
       var numeric_values="0123456789";
       var alpha_values="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
       var special_characters="$_-#~!";
       var check_characters=numeric_values + alpha_values + special_characters;
       // check that has at least one numeric and/or one character
       var has_numeric=false;
       var has_alpha=false;
       for (var c=0;c<m_password.length;c++){
	   	   if (check_characters.indexOf(m_password.substr(c,1))<0){
               //alert(m_password.substr(c,1));
               alert("Sorry, but the password that you have entered '" + m_password + "' contains this unsupported character '" + m_password.substr(c,1) + "'!");
               el.focus();
               return false;
           }
           
           if (numeric_values.indexOf(m_password.substr(c,1))!=-1){
               has_numeric=true;
           }
           
           if (alpha_values.indexOf(m_password.substr(c,1))!=-1){
               has_alpha=true;
           }
           
       }
       if (has_alpha==false){
           alert("Our password policy requires at least one alphabetical character !");
           el.focus();
           return false;
       }
       
       if (has_numeric==false){
           alert("Our password policy requires at least one numeric character !");
           el.focus();
           return false;
       }
       if (confirm("you have entered a new password for this user account. Do you wish to continue! ")==false){
           return false;
       }
  

    return true;
}

// used to present a "characters remaining" facility on a contact us form
function characters(){
var t=get_el("txt_comment");
var h=get_el("chars");
    if (parseInt(t.value.length)>maximum){	
    	
    	t.value=t.value.substr(0,t.value.length-1)
    	return void[0];
    }
	remaining=maximum-parseInt(t.value.length)
	h.innerText=remaining;
}

function characters_sms(){
var t=get_el("txt_comment");
var h=get_el("chars");
    if (parseInt(t.value.length)>maximum_sms){	
    	
    	t.value=t.value.substr(0,t.value.length-1)
    	return void[0];
    }
	remaining=maximum_sms-parseInt(t.value.length)
	h.innerText=remaining;
}

// used to validate the "contact us" form
function validate_form(){
// first ensure that required fields have been completed
    // is this form using presubmission validation ?
    


    //check the name
    var el=get_el("txt_name")
    if (el.value.length==0){
        alert("please enter your name !")
        el.focus();
        return false;    
    }
    
    //check the email address
    var el=get_el("txt_email")
    if (el.value.length==0){
        alert("please enter your email address !")
        el.focus();
        return false;    
    }
    var sval=el.value
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		el.focus();
		return false;
	}
	
    //check the comment
    var el=get_el("txt_comment")
    if (el.value.length==0){
        alert("please let us know how we can assist !")
        el.focus();
        return false;    
    }
	else if (el.value.length>1024){
		alert("Your comment is limited to 1024 characters, please shorten your query.")
        el.focus();
        return false;    
	}
}

// used to validate the "contact us" form
function validate_form_with_telephone(){
// first ensure that required fields have been completed
    //check the name
    var el=get_el("txt_name")
    if (el.value.length==0){
        alert("please enter your name !")
        el.focus();
        return false;    
    }
    
    //check the email address
    var el=get_el("txt_email")
    if (el.value.length==0){
        alert("please enter your email address !")
        el.focus();
        return false;    
    }
    var sval=el.value
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		el.focus();
		return false;
	}
	
    var el=get_el("txt_telephone")
    if (el.value.length==0){
        alert("please enter your telephone number !")
        el.focus();
        return false;    
    }
    
    //check the comment
    var el=get_el("txt_comment")
    if (el.value.length==0){
        alert("please let us know how we can assist !")
        el.focus();
        return false;    
    }
}


function validate_comment(){
    var el=get_el("txt_comment")
    if (el.value.length==0){
        alert("please let us know how we can assist !")
        el.focus();
        return false;    
    }
}

// checks that the search dialogue has been completed correct before posting 
function check_search(){
 var el=get_el("fkeywords")
 if (el){
    if (el.value.length==0){
        alert("please enter one or more keywords to search for!");
        el.focus();
        return false;
    }
 }
 return true;
}

// build a heirarchial menu
function make_menu(svalue){
	if (svalue.charAt(svalue.length - 1) == "|") svalue = svalue.substr(0,svalue.length - 1);
	var sdata=svalue.split("|");
    this.contents=new Array();
    this.add=add_to_menu;
    this.id=0;
    for (var i=0;i<sdata.length;i++){
        scurrent=sdata[i];
        var mnu=new make_menu_item(scurrent);
        if (mnu.parentid==0){
            this.contents[this.contents.length]=mnu;
        }
        else{
           this.add(mnu)
        }
    }
    //alert(this.contents.length);
    return this;
}

function make_menu_item(svalue){
	if (svalue.charAt(svalue.length - 1) == "^") svalue = svalue.substr(0,svalue.length - 1);
	var sdata=svalue.split("^");
    this.contents=new Array();
    this.id=sdata[0] // unique id of record
    this.parentid=sdata[1];
    this.title=sdata[2];
    this.url=sdata[3];
    this.add=add_to_menu;
    return this;
}

function add_to_menu(obj){
    for (var i=0;i<this.contents.length;i++){
        if (this.contents[i].id==obj.parentid){
            this.contents[i].contents[this.contents[i].contents.length]=obj;
        }    
    }
}

// write our menu
function write_menu(obj, level){
var shtml='';
var n=level + 1;
var h=0;
    //alert(obj.contents.length)
    for (var i=0;i<obj.contents.length;i++){
        var mnu=obj.contents[i];
        h=h + 20;
        if (level==0){
            shtml+='<div class="menu" id="' + mnu.id + '" style="width: 175px;">';
            //alert(shtml);
        }
        else{
            shtml+='<div class="submenu" id="' + mnu.id + '" style="width: 175px; height: 20px; visibility: visible;">';
        }
        //alert(shtml)
        shtml+= '<a href="' + mnu.url + '">' + mnu.title + '</a>';
        shtml+=write_menu(mnu,n);
        shtml+='</div>';
        
    }
    
        if ((level!=0)&&(obj.contents.length > 0)){
        shtml='<div id="mnublock' + obj.id + '" style="width: 175px;"><div class="nomenu" id="menu' + obj.id + '" style="display: none; height: ' + h + 'px; position: relative; width: 175px">' + shtml + '</div></div>';
        }
    return shtml;
}


/* 
--------------                make javascript gallery object         -------------------- 
    function name: make_gallery
    description:   returns a gallery object that will then cycle through series of images - loading a control (div) with appropriate image
    parameters: 
            gBuffer == the chevron and pipe delimited string needed to build gallery images
            gControl == name of the control (div) that is to be loaded with gallery images 
            gAuto == true/false flag indicating if gallery is to be cycled automatically
            gInterval == number of milliseconds between image change events
            gWidth==width of images
            gHeight=height of images
            gDisplay==optional: name of area to display the alt text for an image
            gPreview = optional name of area to display image previews
    		gNumPreview = optional number of image previews to display (required if previous param "gPreview" is present)
*/
var gallery_timer=0; // page level variable for the gallery object
function make_gallery(gBuffer,gControl,gAuto,gInterval, gWidth,gHeight,gDisplay,gPreview,gNumPreview){
    //alert(gBuffer);   
    var svalue=gBuffer
    if (svalue.length==0){
        this.ok=false;
        this.start=start_gallery;
        return this;
    }
    if (svalue.charAt(svalue.length - 1) == "|") svalue = svalue.substr(0,svalue.length - 1);
	var sdata=svalue.split("|"); // array of chevron delimited strings
    this.controlname=gControl;
    this.auto=gAuto;
    this.interval=gInterval;
    this.imagewidth=gWidth;
    this.imageheight=gHeight ;
    this.start=start_gallery;
    this.next=get_next_image;
    this.previous=get_last_image;
    this.stop=stop_gallery;
    this.index=0;
    this.contents=new Array();
    this.get_current=get_current_gallery_item; 
    this.set_current=set_current_gallery_item;
    
    this.ok=true;
   	if(arguments.length==9)
    {
        this.my_preview=gPreview;
		this.number_preview=gNumPreview;
        this.render_preview = build_gallery_preview;
		this.display=gDisplay;
		this.showpreview=true;
        this.showtitle=true;
    }	
    else if (arguments.length==7){
        this.display=gDisplay;
        this.showtitle=true;
    }
    else{
        this.display='';
        this.showtitle=false; 
		this.showpreview=false;   
    }
    for (var i=0;i<sdata.length;i++){
        var g = new make_gallery_item(sdata[i],gControl);
        this.contents[this.contents.length]=g;
    }
    //alert(this.contents.length);
   //alert(gControl);   
if($(gControl)){
    if (this.contents[0].source.indexOf('ttp:')!=0){   
         if (this.imagewidth == 0){
           var shtml='<img id="galleryimage" src="' + this.contents[0].source + '" alt="' + this.contents[0].title + '" height="' + this.imageheight + 'px;" style="border:0px;">'
         }
         else if(this.imageheight == 0){
//           alert("height=0");
           var shtml='<img id="galleryimage" src="' + this.contents[0].source + '" alt="' + this.contents[0].title + '" width="' + this.imagewidth + 'px;height=auto;" style="border:0px;">'
         }
         else{
           var shtml='<img id="galleryimage" src="' + this.contents[0].source + '" alt="' + this.contents[0].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">'
         }
    }
    else{
       // alert(this.contents[0].source);
        if (this.imagewidth == 0){
            var shtml='<img id="galleryimage" src="../images/' + this.contents[0].source + '" alt="' + this.contents[0].title + '" height="' + this.imageheight + 'px;" style="border:0px;">'
        }
         else if(this.imageheight == 0){
//           alert("height=0");
           var shtml='<img id="galleryimage" src="../images/' + this.contents[0].source + '" alt="' + this.contents[0].title + '" width="' + this.imagewidth + 'px;height=auto;" style="border:0px;">'
         }
         else{
          var shtml='<img id="galleryimage" src="../images/' + this.contents[0].source + '" alt="' + this.contents[0].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">'
        }
    }    
    $(gControl).innerHTML=shtml;
    if (this.showtitle){
        $(this.display).innerHTML=this.contents[0].title;
    }
    if(this.showpreview){
        this.render_preview();
    }
}    
    return this;
}

function get_current_gallery_item(){
    return this.contents[this.index].id;
}

//sets the current gallery item using the index

function set_current_gallery_item(varname,a){
    this.index = a
    if (this.index == this.contents.length){
            this.index=0;
        }      
        if (this.contents[this.index].source.indexOf('ttp:')!=0){            
            if (this.imagewidth == 0){
              var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
         else if(this.imageheight == 0){
           //alert("height=0");
           var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;height=auto;" style="border:0px;">'
         }
            else{
               var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
        }
        else
        {
            if (this.imagewidth == 0){
              var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
            else{
              var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
            
        }
        $(this.controlname).innerHTML=shtml;
        if (this.showtitle){
            $(this.display).innerHTML=this.contents[this.index].title;
        }
        if (this.auto){

        gallery_timer=setTimeout(varname + ".next('" + varname + "');",this.interval);
        }
        if(this.my_preview)
        {
            this.render_preview();
        }
}

/* 
--------------             build_gallery_preview (for use in gallery object) ---------------- 
    function name: build_gallery_preview
    description: creates a clickable preview of n the images in the gallery.
    parameters:
            svalue - image id ^ image title ^ image source ^ sequence ^ |
 */
function build_gallery_preview(){
    this.my_preview.innerHTML = "";
    var a, shtml;
	var iStart, iEnd;

	iStart = this.number_preview * Math.floor(this.index/this.number_preview);
	iEnd = (iStart + this.number_preview/1);
	if(iEnd>this.contents.length)
	{
		iEnd = this.contents.length;
	}
	//alert(iStart +'<- '+this.index+'/'+this.contents.length+' -> '+ iEnd);
//	alert(iStart + " -> " + iEnd);
    shtml = '<table class="preview_table">'
    shtml += '<tr>'
	
    //for(a=0; a<this.contents.length; a=a+1)
	for(a=iStart; a<iEnd; a=a+1)
    {
        if (a%5==0 && a!=0)
        {
            shtml+='</tr><tr>'
        }
        shtml += "<td>"
        shtml += '<div ><a href="javascript: generic_gallery.set_current(\'generic_gallery\', '+a+')"><img src="' + this.contents[a].source + '" height="70" width="70"';
        if(this.index == a)
        {
            shtml += 'class="selected"';
        }
        else
        {
            shtml += 'class="not_selected"';
        }
        
        shtml += '/></a> '        
        shtml += '</div>'
        shtml += '</td>'        
    }
    shtml += '</tr>'
	shtml +='</table>';
	var x = iEnd;
	var y = iStart -1;
	//alert(x +' -> '+ y);
	
	if(y<0){y=0;}
	if(x>=this.contents.length){x=0;}
	//alert(y +'<- '+this.index+'/'+this.contents.length+' -> '+ x);
	
	shtml +='<table width="450px">';
	shtml += '<tr>';
	shtml += '<td align="left"><div id="prev_preview_button" class="preview_button"><a class="button_link" href="javascript: generic_gallery.set_current(\'generic_gallery\', '+y+')">Back</a></div></td>';
	shtml += '<td align="right"><div id="next_preview_button" class="preview_button"><a class="button_link" href="javascript: generic_gallery.set_current(\'generic_gallery\', '+x+')">Next</a></div></td>';
	shtml += '</tr>';
	shtml +='</table>';
    this.my_preview.innerHTML =shtml;
	Rico.Corner.round('next_preview_button',{corners:"all"});
	Rico.Corner.round('prev_preview_button',{corners:"all"});
}

/* 
--------------             make gallery item (for use in gallery object) ---------------- 
    function name: make_gallery_item
    description: creates a single gallery item that gets loaded into the gallery display area
    parameters:
            svalue - image id ^ image title ^ image source ^ sequence ^ |
 */
function make_gallery_item(strSource,gControl){
    //alert(strSource)
    if (strSource.charAt(strSource.length - 1) == "^") strSource = strSource.substr(0,strSource.length - 1);
	var sdata=strSource.split("^"); // array 
    this.id=sdata[0];
    this.title=sdata[1];
    this.source=sdata[2];
    this.sequence=sdata[3];
    this.current=false;
    //alert(this.source.indexOf('http'))
    if (this.source.indexOf('http')!=0){
        this.code='<img id="galleryimage" src="../images/' + this.source + '" alt="' + this.title + '">'
        
        var pimage=new Image(); //get the image down into the local cache
        pimage.src='../images/' + this.source  
    }
    else{
        this.code='<img id="galleryimage" src="' + this.source + '" alt="' + this.title + '">'
        var pimage=new Image(); //get the image down into the local cache
        pimage.src=this.source       
    }
    this.image_object=pimage;
    return this;
}

/* 
-------------------       start gallery (for use with gallery object) ---------------------
   function name: start_gallery
   description:    starts (if auto) a gallery object cycling through images
   parameters: none
*/
function start_gallery(varname){	
	if (this.ok){
        if (this.auto){
            if (this.contents.length > 1){
                gallery_timer=setTimeout(varname + ".next('" + varname + "');",this.interval);
            }
        }
    }
    return void[0];
}

/* 
-------------------      Get Next Image (for use with Gallery Object) --------------------- 

*/
function get_next_image(varname){        
        this.index++
        //alert("next image " + this.index + ' of ' + this.contents.length)
        if (this.index == this.contents.length){
            this.index=0;
        }      
        if (this.contents[this.index].source.indexOf('ttp:')!=0){            
            if (this.imagewidth == 0){
              var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
         else if(this.imageheight == 0){
           //alert("height=0");
           var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;height=auto;" style="border:0px;">'
         }
            else{
               var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
        }
        else
        {
            if (this.imagewidth == 0){
              var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
            else{
              var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">';
            }
            
        }
        $(this.controlname).innerHTML=shtml;
        if (this.showtitle){
            $(this.display).innerHTML=this.contents[this.index].title;
        }
        if (this.auto){

        gallery_timer=setTimeout(varname + ".next('" + varname + "');",this.interval);
        }
        if(this.my_preview)
        {
            this.render_preview();
        }
}
/* 
-------------------      Get Previous Image (for use with Gallery Object) --------------------- 

*/
function get_last_image(){
        this.index--
        if (this.index==-1){
            this.index=0;
        }
        if (this.contents[this.index].source.indexOf('ttp:')!=0){
            if (this.imagewidth == 0){
              var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">'
            }
         else if(this.imageheight == 0){
           //alert("height=0");
           var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[0].title + '" width="' + this.imagewidth + 'px;height=auto;" style="border:0px;">'
         }
            else{
               var shtml='<img id="galleryimage" src="' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">'
            }
        }
        else{
            if (this.imagewidth == 0){
               var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" height="' + this.imageheight + 'px;" style="border:0px;">'
            }
            else{
               var shtml='<img id="galleryimage" src="../images/' + this.contents[this.index].source + '" alt="' + this.contents[this.index].title + '" width="' + this.imagewidth + 'px;" height="' + this.imageheight + 'px;" style="border:0px;">'
            }
        }
        $(this.controlname).innerHTML=shtml;
        if (this.showtitle){
            $(this.display).innerHTML=this.contents[this.index].title;
        }
        if(this.my_preview)
        {
            this.render_preview();
        }

}
/* 
-------------------      Stop Gallery (for use with Gallery Object) --------------------- 

*/
function stop_gallery(){
    clearTimeout(gallery_timer);
}
/*
-------------------      Generic Window Handling        ----------------------------------
                                                                                          
            set of functions to manipulate windows
                -1- open_new_window(url, n, f, w, h, t, l)
                    this function opens a window called 'n' at location 'url'
                    and uses "defaults" if "f" is true
                    otherwise it expects w and h
                    
                    optional: with a width of "screen width / w"
                    optional: with a height of "screen height / h"
                    optional: with a top position of "(screen height - window_height) / t"
                    optional: with a left position of "(screen width - window_width) / l"
                                                                                          
------------------
*/


/* parameters for open new window
        url: url to be opened
        n: name to assign to new window
        f: use default settings? f=0 implies use custom settings
        w: factor to use when calculating window width e.g. w=2 ==> 50% of screen width
        h: factor to use when calculating window height e.g. h=2 ==> 50% of screen height
        t: top in pixels
        l: left position in pixels
        
*/
function open_new_window(url, n, f, w,h,t,l){
// default values for settings variables
var url_to_open="";
var name_of_window="";
var window_width=0;
var window_height=0;
var screen_width=screen.width;
var screen_height=screen.height;
var window_left=0;
var window_top=0;
var def_settings=false;

//          check that a valid url has been passed
            url_to_open=url;
            if (url_to_open.length==0){
                return void 0;
            }
//    alert(url_to_open);

//          check that a valid window name has been passed
            name_of_window=n;
            if (name_of_window.length==0){
                    name_of_window="NON"
                }    
//    alert(f);
            if (f!=0){
                def_settings=true;
            }   
             
            if (def_settings){
//              default settings are half screen size window                
                window_width=(screen_width/2);
                window_height=(screen_height/2);
                window_left=(screen_width-window_width)/2; // centered
                window_top=(screen_height-window_height)/2; //vertically centered
            }
            else{
//              use the users parameters
                if (parseInt(w) > 5){
                    window_width=w;
                    window_height=h;
                }
                else{
                    window_width=(screen_width/w);
                    window_height=(screen_height/h);
                
                }
                window_left=l
                window_top=t
                               
            }
    var settings='Height=' + window_height + ',Width=' + window_width + ',Top=' + window_top + ',left=' + window_left + ',scrollbars=yes,resizable=1, location=1,status=1'
	var w=window.open(url_to_open,name_of_window,settings);
    if (!w){
        alert("please check your pop-up blocker as we were unable to open a new window to service your request!");
        return false;
    }
	if (w.opener==null)w.opener=window;
    w.focus()
}

/** ----- Open popup windows **/
function smallwin(URL) {
	var w=window.open(URL,"","Height=480,Width=500,Top=20,left=40,scrollbars=yes,resizable=1");
	if (w.opener==null)w.opener=window;
}

function mediumwin(URL) {
	var w=window.open(URL,"","Height=480,Width=700,Top=20,left=40,scrollbars=yes,resizable=1");
	if (w.opener==null)w.opener=window;
}

/** ----- confirm an action - if confirmed then redirect to the url passed -- **/

function confirm_action(text,url,winflag,ajax_url,ajax_params,ajax_target,ajax_function, debug_target){
/* winflag indicates one of three options
    0 implies that we redirect to the URL
    1 implies that we open a new window
    2 implies that we use ajax to open the url requested
   */
   
    if (confirm(text)){
        if (winflag==1){
            // if winflag = 1 ==> open new window
            	var k=window.open(url,"","Height=480,Width=500,Top=20,left=40,scrollbars=yes,resizable=1");
        }
        
        else{
            if (winflag==2){
                // to use option 2 the url is passed as an array in this format
                // url|params|target|function(s) to run when complete
                //var ajax_data=url.split("|");
                //alert(ajax_data[0]);
                //alert(ajax_data[1]);
                //alert(ajax_data[2]);
                //alert(ajax_data[3]);
                
                //alert(ajax_url);
                //alert(ajax_params);
                //alert(ajax_target);
                //alert(ajax_function);
               //ajax_get_url(ajax_data[0].toString(),ajax_data[1].toString(),ajax_data[2].toString(), ajax_data[3].toString());
               //alert(arguments.length)
                if (arguments.length==8){
                    // debug the ajax result
                    //alert(ajax_function);
                    ajax_get_url(ajax_url,ajax_params,debug_target, ajax_function);
                }
                else{
                    ajax_get_url(ajax_url,ajax_params,ajax_target, ajax_function);
                }
            }
            else{
                window.location.href=url;
            }
        }
        return true;
    }
    return false;
}

function agility_confirm_action(text,url,winflag,ajax_url,ajax_params,ajax_target,ajax_function, debug_target){
/* winflag indicates one of three options
    0 implies that we redirect to the URL
    1 implies that we open a new window
    2 implies that we use ajax to open the url requested
   */
   
    if (confirm(text)){
        if (winflag==1){
            // if winflag = 1 ==> open new window
            	var k=window.open(url,"","Height=480,Width=500,Top=20,left=40,scrollbars=yes,resizable=1");
        }
        
        else{
            if (winflag==2){
                // to use option 2 the url is passed as an array in this format
                // url|params|target|function(s) to run when complete
                //var ajax_data=url.split("|");
                //alert(ajax_data[0]);
                //alert(ajax_data[1]);
                //alert(ajax_data[2]);
                //alert(ajax_data[3]);
                
                //alert(ajax_url);
                //alert(ajax_params);
                //alert(ajax_target);
                //alert(ajax_function);
               //ajax_get_url(ajax_data[0].toString(),ajax_data[1].toString(),ajax_data[2].toString(), ajax_data[3].toString());
               //alert(arguments.length)
                if (arguments.length==8){
                    // debug the ajax result
                    //alert(ajax_function);
                    ajax_get_url(ajax_url,ajax_params,debug_target, ajax_function);
                }
                else{
                    ajax_get_url(ajax_url,ajax_params,ajax_target, ajax_function);
                }
            }
            else{
                window.location.href=url;
            }
        }
        return void[0];
    }
    return false;
}


function close_refresh(){
        self.opener.location.reload();
        self.close();
    

}
function preview_advert(id){
var myConn = new XHConn();
if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
var fnWhenDone = function (oXML) {
//    alert(oXML.responseText);
    var el=get_el("previewadverts");
    var buffer=oXML.responseText
    
    el.innerHTML='<strong>preview</strong><br>' + buffer;
 };
myConn.connect("../common/preview_advert.asp", "GET", "ID=" + id, fnWhenDone);
}


/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


// function used in shopping systems to check that numeric values have been entered into an array of textboxes
// the text boxes are displayed on "include_basket.asp" and use the uid field id as their "name"
// check quantities is passed the comma delimited version of these uid's so that it can resolve the names of the textboxes
function check_quantities(keys){
    if (keys.charAt(keys.length - 1) == ",") keys = keys.substr(0,keys.length - 1);
	var sdata=keys.split(",");
    for (var i=0;i<sdata.length;i++){
        var c = $(sdata[i]).value;
        if (c.length==0){
                alert("please enter a number for the quantity !");
                $(sdata[i]).focus();
                return false;
        }
        if (isNaN(c)){
                alert("please enter only numbers for the quantity !");
                $(sdata[i]).focus();
                return false;
        
        }
    }
 return true;
}


function open_small(url){
var x=screen.width;
var y=screen.height;
var win_width=500;
var win_height=400;
var win_left=(x-win_width)/2;
var win_top=(y-win_height)/2;
var win_options="Height="  + win_height + ",Width=" + win_width + ",Top=" + win_top + ",left=" + win_left + ",scrollbars=yes,resizable=1,toolbar=yes";
   var win=window.open(url,"",win_options);
   if (win.opener==null) win.opener=window;

}


// check_dialogue: validates users input on a form
function check_dialogue(form_inputs){
    
}

//function to check a billing dialogue - tests that required fields are complete
function check_billing(){
 // check that firstname has been entered
    if ($F('txt_firstname').length==0){
        alert("please enter your first name !");
        $('txt_firstname').focus();
        return false;
    }
 // check that surname has been entered
    if ($F('txt_lastname').length==0){
        alert("please enter your last name !");
        $('txt_lastname').focus();
        return false;
    }
 // check that email address has been entered and is of the correct format
    if ($F('txt_email').length==0){
        alert("please enter your email address !");
        $('txt_email').focus();
        return false;
    }
    var sval=$F('txt_email')
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		$('txt_email').focus();
		return false;
	}
 // check that address 1,2 & 3 have been completed
    if ($F('txt_address1').length==0){
        alert("please enter your complete address !");
        $('txt_address1').focus();
        return false;
    }
    if ($F('txt_address2').length==0){
        alert("please enter your complete address !");
        $('txt_address2').focus();
        return false;
    }
   // if ($F('txt_address3').length==0){
    //    alert("please enter your complete address !");
   //     $('txt_address3').focus();
    //    return false;
   // }
 // check that country has been selected
    var el=get_el("list_countries")
    if (el.options[el.selectedIndex].value==0){
        alert("please select your country !");
        el.focus();
        return false;
    
    }
 // check that either a telephone number or mobile number have been entered
    if (($F('txt_telephone').length==0)&&($F('txt_mobile').length==0)){
        alert("please enter a telephone or mobile number !");
        $('txt_telephone').focus();
        return false;
    }
    return true;

}

//function to check a member details - tests that required fields are complete
function check_member(){

	//var el=get_el("member_type")
	//alert(el.value)
	//if (el.value==0){
    //    alert("Please select a membership type !");
    //    $('member_type').focus();
   //     return false;
   // }
    
	var el=get_el("member_type");
	var radioChecked = 0;
	if(!el)
		return false;	
	var elLength = el.length;
	if(elLength == undefined)
		if(!el.checked)
			return false;		
	for(var i = 0; i < elLength; i++) {		
		if(el[i].checked) {
			radioChecked = 1;
		}
	}
	if (radioChecked == 0){
        alert("please select a membership type !");
        //el.focus();
        return false;
    }
	
	

 // check that firstname has been entered
    if ($F('txt_firstname').length==0){
        alert("please enter your first name !");
        $('txt_firstname').focus();
        return false;
    }
 // check that surname has been entered
    if ($F('txt_lastname').length==0){
        alert("please enter your last name !");
        $('txt_lastname').focus();
        return false;
    }
 // check that email address has been entered and is of the correct format
    if ($F('txt_email').length==0){
        alert("please enter your email address !");
        $('txt_email').focus();
        return false;
    }
    var sval=$F('txt_email')
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		$('txt_email').focus();
		return false;
	}
 // check that address 1,2 & 3 have been completed
    if ($F('txt_address1').length==0){
        alert("please enter your complete address !");
        $('txt_address1').focus();
        return false;
    }
    if ($F('txt_address2').length==0){
        alert("please enter your complete address !");
        $('txt_address2').focus();
        return false;
    }
   // if ($F('txt_address3').length==0){
    //    alert("please enter your complete address !");
   //     $('txt_address3').focus();
    //    return false;
   // }
 // check that country has been selected
    
 // check that either a telephone number or mobile number have been entered
    if (($F('txt_telephone').length==0)&&($F('txt_mobile').length==0)){
        alert("please enter a telephone or mobile number !");
        $('txt_telephone').focus();
        return false;
    }
		
	
    return true;

}
//function to check associate member details - tests that required fields are complete
function check_associate_member(){	

 // check that firstname has been entered
    if ($F('txt_firstname').length==0){
        alert("please enter your first name !");
        $('txt_firstname').focus();
        return false;
    }
 // check that surname has been entered
    if ($F('txt_lastname').length==0){
        alert("please enter your last name !");
        $('txt_lastname').focus();
        return false;
    }
 // check that email address has been entered and is of the correct format
    if ($F('txt_email').length==0){
        alert("please enter your email address !");
        $('txt_email').focus();
        return false;
    }
    var sval=$F('txt_email')
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		$('txt_email').focus();
		return false;
	}
 // check that address 1,2 & 3 have been completed
    if ($F('txt_address1').length==0){
        alert("please enter your complete address !");
        $('txt_address1').focus();
        return false;
    }
    if ($F('txt_address2').length==0){
        alert("please enter your complete address !");
        $('txt_address2').focus();
        return false;
    }
   // if ($F('txt_address3').length==0){
    //    alert("please enter your complete address !");
   //     $('txt_address3').focus();
    //    return false;
   // }
 // check that country has been selected
    
 // check that either a telephone number or mobile number have been entered
    if (($F('txt_telephone').length==0)&&($F('txt_mobile').length==0)){
        alert("please enter a telephone or mobile number !");
        $('txt_telephone').focus();
        return false;
    }
		
	
    return true;

}

//function to check associate member details - tests that required fields are complete
function check_attendee(){	

 // check that firstname has been entered
    if ($F('txt_firstname').length==0){
        alert("please enter your first name !");
        $('txt_firstname').focus();
        return false;
    }
 // check that surname has been entered
    if ($F('txt_lastname').length==0){
        alert("please enter your last name !");
        $('txt_lastname').focus();
        return false;
    }
 // check that email address has been entered and is of the correct format
    if ($F('txt_email').length==0){
        alert("please enter your email address !");
        $('txt_email').focus();
        return false;
    }
    var sval=$F('txt_email')
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("Your email address is invalid this system only supports the format 'yourname@address.com' !");
		$('txt_email').focus();
		return false;
	} 	
    return true;
}



//function to check a delivery address - tests that required fields are complete
function check_delivery(){
//    return check_inputs("txt_fistname",,,,,,)
 // check that firstname has been entered
    if ($F('txt_firstname').length==0){
        alert("please enter the first name !");
        $('txt_firstname').focus();
        return false;
    }
 // check that surname has been entered
    if ($F('txt_lastname').length==0){
        alert("please enter the last name !");
        $('txt_lastname').focus();
        return false;
    }
 // check that email address has been entered and is of the correct format
    if ($F('txt_email').length==0){
        alert("please enter the email address !");
        $('txt_email').focus();
        return false;
    }
    var sval=$F('txt_email')
    // check email is correct format
	if (!fixstring(sval,true)){
		alert("The email address is invalid this system only supports the format 'yourname@address.com' !");
		$('txt_email').focus();
		return false;
	}
 // check that address 1,2 & 3 have been completed
    if ($F('txt_address1').length==0){
        alert("please enter the complete delivery address !");
        $('txt_address1').focus();
        return false;
    }
    if ($F('txt_address2').length==0){
        alert("please enter the complete delivery  address !");
        $('txt_address2').focus();
        return false;
    }
    
    //if ($F('txt_address3').length==0){
    //    alert("please enter the complete delivery  address !");
    //    $('txt_address3').focus();
    //    return false;
   // }
   
 // check that country has been selected
    var el=get_el("list_countries")
    if (el.options[el.selectedIndex].value==0){
        alert("please select the delivery country !");
        el.focus();
        return false;
    
    }
 // check that either a telephone number or mobile number have been entered
    if (($F('txt_telephone').length==0)&&($F('txt_mobile').length==0)){
        alert("please enter a contact telephone or mobile number for this address!");
        $('txt_telephone').focus();
        return false;
    }
    return true;

}

function confirm_adc_sync()
{
	var el = get_el("adcnumber");
	var adc = el.value;

	if (adc.length==0)
	{
		alert("Please enter an AdC Number")
		el.focus();
		return false;	
	}
	
	el = get_el("orderreference");
	var ref = el.value;
	
	return confirm("Are you sure the AdC Number '"+ adc +"' is the correct unit for order reference '"+ ref +"'");
}

/* --------- set_date_value -----------------------
        there are three parts to a date  control
        these are list_days, list_month & list_year
        this function accepts the i date part being updated
        and the name of a parent conrtol to update
        using these the function builds a date string and sets 
        the parent element to the value of date string
*/

function set_date_value(date_part, name_of_parent){
    var day_of_month
    var month_of_year
    var year_of_birth
    var el=get_el("list_days");
    day_of_month=el.value;
    var el=get_el("list_months");
    month_of_year=el.value;
    var el=get_el("list_years");
    year_of_birth=el.value;
    $(name_of_parent).value=day_of_month.toString() + ' ' + month_of_year.toString()  + ' ' +  year_of_birth.toString()    
}

// opens a url using ajax
function ajax_get_url(url,p, ctarget, chandler){
  var d=new Date();
  var handler=chandler;
  if (chandler.length!=0){
    if (chandler.indexOf('(')==-1){
    handler+='();'
    }
  }
  
  //alert(url);
  //alert(p);
  //alert(ctarget)
  //alert(chandler)
  //alert("here")
  if (handler.length!=0){
    var myAjax = new Ajax.Updater(ctarget, 
        url, 
        {
            method: 'get', 
            parameters: p + '&d=' + d.toString(),
            onComplete: eval(handler)
        });        
  }
  else{
    var myAjax = new Ajax.Updater(ctarget, 
        url, 
        {
            method: 'get', 
            parameters: p + '&d=' + d.toString()
        });        
  }
}

/*  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    POST URL
    function name: ajax_post_url
    purpose; generic form posting utlity that uses the prototype ajax object
    parameters: url to post to, parameters to be passed (as querystring)
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
function ajax_post_url(url, p, ctarget,chandler){
//alert(url)
  var d=new Date();
    var myAjax = new Ajax.Updater(ctarget, 
        url, 
        {
            method: 'post', 
            parameters: p + '&d=' + d.toString(),
            onComplete: chandler
        });  
}

function debug_ajax(obj){
    alert("debugging ajax");
	if (obj){
		alert(obj.responseText);
	}
    else{
        alert("no object returned!")
    }
}

// validate a registration form that uses qualifiers and a role model / rule book

function validate_registration_form(){
//var buffer=$("element_map").value;
    var element_map=$("element_map").value.split("^");
    var element_types=$("element_types").value.split("^");
    for (var i=0; i<element_map.length;i++){
        //alert(element_types[i])
        //alert(element_map[i])
        switch(element_types[i]){
            case 'GROUP':
                break;
            case 'CHECKBOXLINK': // make sure the check box has been ticked
                if ($(element_map[i]).checked!=true){
                    alert($(element_map[i]).validationmsg);
                    $(element_map[i]).focus();
                    return false;
                }
                break;
            case 'DATEOFBIRTH': // ensure that date of birth is valid
                // basic validation based on there being a validation msg
                if (($(element_map[i]).value.length==0)&&($(element_map[i]).validationmsg.length!=0)){
                    alert($(element_map[i]).validationmsg);
                    //$(element_map[i]).focus();
                    return false;
                }
                // if basic validation is ok then something has been entered
                var v=$(element_map[i]).value // will be in format d m y
                var date_elements=v.split(' ');
                var check_date=new Date(date_elements[2],parseInt(date_elements[1])-1,date_elements[0])
                var today=new Date();
                //alert(today);
                //alert(check_date);
                elname='validate_' + element_map[i]
                var age=$(elname).value
                if ((check_date.getFullYear() + parseInt(age)) > today.getFullYear()){
                    alert($(element_map[i]).validationmsg);
                    return false;
                }
                break;
            case 'TEXTBOX': // make sure that user has entered valid data
                if (($(element_map[i]).value.length==0)&&($(element_map[i]).validationmsg.length!=0)){
                    alert($(element_map[i]).validationmsg);
                    $(element_map[i]).focus();
                    return false;
                }
                break;
            case 'EMAIL': // ensure a valid email address
                if (($(element_map[i]).value.length==0)&&($(element_map[i]).validationmsg.length!=0)){
                    alert($(element_map[i]).validationmsg);
                    $(element_map[i]).focus();
                    return false;
                }
                break;
            case 'TELEPHONE': // validate telephone number (?)
                if (($(element_map[i]).value.length==0)&&($(element_map[i]).validationmsg.length!=0)){
                    alert($(element_map[i]).validationmsg);
                    $(element_map[i]).focus();
                    return false;
                }
                break;
        }
    
    
    }
}

function write_details(){
	el= get_el("basket_details");
	if (el){
		if (el.innerHTML == ""){
		 	el.innerHTML = 'Please select the "Recalculate" button in order to save the details, before you proceed'
		}
	}	
}
function open_tandc(){
    window.open('include_terms_and_conditions.asp', 'tandc', 'toolbar,scrollbars=yes,width=500,height=600');
    el=get_el("tandc_select");
    el.checked = true;
}

function check_tandc(){            
    el=get_el("tandc_select");
    if (!el.checked){
        alert("You must read the Terms & Conditions to proceed!");
        return false
    }    
    return true 
}
/* briefly display a div indicating to user that they have submitted a form (used in generic_form in agility/common)*/    
function show_save_progress(){
    
   var el=get_el("but_save");
   if (el){
       Element.hide('but_save'); 
   }
   var el=get_el("but_close");
   if (el){
       Element.hide('but_close'); 
   }
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
    
    	// Get the editor contents in XHTML.
        //var debug_size=oEditor.GetXHTML( true )
    	//alert(debug_size.length) ;		// "true" means you want it formatted.
        //var debug_eile=oEditor.GetHTML()
        //alert(debug_eile)
        var datasource_name = 'fd_' + el.value;
        $(datasource_name).value= oEditor.GetXHTML( true );  
        //$(datasource_name).value= oEditor.GetHTML();  
    }       
    return true;
}

/* for user with mutli-part forms (enhanced_form.inc) - performs much the same function as the show_save_progress function but optimised for multipart data*/
function display_progress(){
var progress_bar_url=$F('progress_bar_url');
   
   var el=get_el("but_save");
   if (el){
       Element.hide('but_save'); 
   }
   var el=get_el("but_close");
   if (el){
       Element.hide('but_close'); 
   }
    var el=get_el('FCKDATASOURCE');
    if (el){    
        var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
    
    	// Get the editor contents in XHTML.
        //var debug_size=oEditor.GetXHTML( true )
    	//alert(debug_size.length) ;		// "true" means you want it formatted.
        //var debug_eile=oEditor.GetHTML()
        //alert(debug_eile)
        var datasource_name = 'fd_' + el.value;
        //$(datasource_name).value= oEditor.GetXHTML( true );  
        //$(datasource_name).value= oEditor.GetHTML();  
       $(datasource_name).value= oEditor.GetXHTML(true);  
    }       



// display a window indicating save progress 
            var w=380;
            var h=50;
            var winLeft=Math.round((screen.width - w)/2);
            var winTop=Math.round((screen.height - h)/2);
            var sVersion = navigator.appVersion;
             
           if (sVersion.indexOf('MSIE') != -1 && sVersion.substr(sVersion.indexOf('MSIE')+5,1) > 4)
          {
        		var settings="dialogWidth:380px; dialogHeight:50px; center:yes";
        		var x=window.showModelessDialog(progress_bar_url+ '&b=IE',null,settings);
            }
            else
            {
        		//var x=window.open(progress_bar_url+ '&b=NN','','width=370,height=115', true);
                var x=window.open(progress_bar_url+ '&b=NN','','width=380px,height=50', true);
        
           }
           
            x.focus()
   
   

            

    Event.observe(window, 'unload', function(event){
      window.opener.location.reload();
      }, false);
    return true;


}




/* Loads the new FCK Editor  */
var oFCKeditor=false
function load_editor(){
//alert("load_editor");
    var datasource_name = 'fd_' + $('FCKDATASOURCE').value;
    var prefix=$('fck_base_url').value;
    
    //var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('common')) ;
    var sBasePath = prefix + '/fck/fckeditor/';
    //alert(sBasePath);
    oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
    //alert(oFCKeditor);
    oFCKeditor.BasePath	= sBasePath ;
    oFCKeditor.Height	= 300 ;
    //oFCKeditor.Value	= 'This is some <strong>sample text<\/strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor<\/a>.' ;
    oFCKeditor.Value = $(datasource_name).value
    var toolbar_set=$('html_editor_to_use').value
    var el=get_el("fck_css"); // this parameter set in enhanced_form.inc and can contain a comma delimited list of css files
    if (el){
        buffer=el.value;
            //alert(buffer.indexOf(','));
            if (buffer.indexOf(',') > 0){
                var css=buffer.split(",");
                oFCKeditor.Config['EditorAreaCSS'] = css;
            }
            else{
                oFCKeditor.Config['EditorAreaCSS'] =buffer;
            
            }
    }
    var el=get_el("fck_css_body"); // this parameter set in enhanced_form.inc and sets the element against which all styles are applied when presented in the editor
    if (el){
        buffer=el.value;
        oFCKeditor.Config['BodyId'] = buffer;
    }
    
        
    
    oFCKeditor.ToolbarSet = toolbar_set;
    oFCKeditor.Config['LinkUpload'] = false;
    oFCKeditor.Config['LinkBrowser'] = false;
    oFCKeditor.Create() ;
    
}
function savecontent(){
}


/*validate_basket: uses array of uid values to check the inputs on a basket manager page */
function validate_basket(){
    var el=get_el("uid_map");
    if (el){
        var control_map=el.value; //comma delimited string
        var control_array=control_map.split(",");
        for (var i=0;i<control_array.length; i++){
            var q_name = "quantity_" + control_array[i];
            //alert(q_name)
            //check that there is an entry
            var el=get_el(q_name);
            if (el.value.strip().length==0){
                alert("please enter a  quantity in numeric format only!");
                el.focus();
                return false;
            }
            //check that entry is numeric
            if(isNaN(el.value)){
                alert("please enter a  quantity in numeric format only!");
                el.focus();
                return false;
            
            }
            
            //check that a valid stock option has been select (<>null)
            
            //return true if all ok
        }
    }

}


function open_pop_window(url){
 var settings='Height=' + screen.height + ',Width=' + screen.width + ',Top=0,left=0,scrollbars=yes,resizable=1, location=1,status=1'
 
 var w=window.open(url,'quicklink',settings);    
}


