// JavaScript Document

//GLOBALS
/*
*
* LEAVE THESES ALONE
*
*/
//FOR CONFIRM FUNCTION
var confirmed = false;
var elementClass = '';
var titleText = '';


// confirmAction()
/*
* Builds arrays where confirmation can take place
*
* @return bool
*/
function confirmAction() {

        //IS DOM SUPPORTED
        if(!document.getElementsByTagName('a')) return false;

        //GET ELEMENTS ON PAGE TO WORK WITH
        var confirmLinks   = document.getElementsByTagName('a');
        var buttons = document.getElementsByTagName('input');
	
        //PROCESS ELEMENTS
        loopElements(confirmLinks);
        loopElements(buttons);
	
        return false;

}

// loopElements()
/*
* Processes passed elements, gets text for confirm box and sends for confirmation
* @return bool @param array of elements
*/
function loopElements(elements) {
	
        for(var i=0; i<elements.length; i++) { //LOOP THROUGH ELEMENTS
	
                elementClass = elements[i].className; //ASSIGN CLASSNAME
		
                if(elementClass != '' && elementClass.indexOf('confirm') > -1) { //DOES CONFIRM CLASSNAME EXIST ON ELEMENT
		
                        elements[i].onclick = function() { //ELEMENT CLICKED
			
                                titleText = '';
			
                                if(this.getAttribute('alt')) {
					
                                        titleText = this.getAttribute('alt'); //GET TEXT FROM ALT ATTRIBUTE ON BUTTONS
					
                                }else if(this.getAttribute('title')) {
					
                                        titleText = this.getAttribute('title');	//GET TEXT FROM TITLE ON LINKS
					
                                }
				
                                if(titleText.length > 0) alertText = titleText; //APPLY TEXT TO VARIABLE
				
                                confirmed = getConfirmation(alertText); //PASS TEXT TO FUNCTION
				
                                return confirmed; //RETURN RESULT
			
                        }
		
                }
	
        }
	
}

// getConfirmation()
/*
* Displays confirmation box returns result
* @return bool @param String of text to display
*/
function getConfirmation(text) {

        var result = confirm(text); //SHOW CONFIRMATION BOX

        return result; //RETURN RESULT

}

// externalLinks()
/*
* Allows external links to be opened in a new window without the use of target attribute
* @return bool
*/
function externalLinks() {
	
        //SETS DOMAIN OF SITE
        var domainName=document.domain;
	
        var externalLinks=document.getElementsByTagName("a"); //FIND ALL LINKS ON THE CURRENT PAGE
	
        for(var i=0; i<externalLinks.length; i++) { //LOOP THROUGH LINKS ARRAY
	              
                var attribute=externalLinks[i].getAttribute("href"); //GETS CONTENT OF 'HREF' ATTRIBUTE ON CLICKED LINK
                if(attribute !== null ){
                        var elementClass = externalLinks[i].className; //STORES CLASS NAME OF ELEMENT
		
                        var contains_http=attribute.indexOf("http"); //GET VALUE http IN 'HREF' **FOR MOZILLA&&
		
                        var contains_domain=attribute.indexOf(domainName); //GET VALUE domainName **FOR IE**
		
                        if(newWindowLink == true) {
		
                                if(contains_http>-1 && contains_domain==-1) { //DOES CONTAIN AN 'http' OR DOES NOT CONTAIN domainName
			
                                        setElementAttribute(externalLinks[i], 'target', '_blank');	
				
                                }
		
                        }
		
                        if(elementClass.indexOf('new_window') > -1 ) { //FORCE LINK TO OPEN IN NEW WINDOW
			
                                setElementAttribute(externalLinks[i], 'target', '_blank');
			
                        }     
                }

		
        }
	
}

// setElementAttribute()
/*
* Sets elements attribute
* @return bool; @param element: Element to attach attr to, attr: The attribute to be added, val: value of attribute
*/
function setElementAttribute(element, attr, val) {

        element.setAttribute(attr, val); //SET ATTRIBUTE ON ELEMENT

        return true;

}

// popUpWindows()
/*
* Creates a popup window
* @return bool;
*/
function popUpWindows() {
	
        var links = document.getElementsByTagName('a'); //MAKE ARRAY OF LINKS
        var url = '';
	
        for(var i=0; i<links.length; i++) { //LOOP LINKS
		
                var classes = links[i].className;
		
                if(classes != '') {
			
                        var splitClasses = classes.split(' '); //EXPLODE CLASSES ON SPACE ' '
					
                        for(var x=0; x<splitClasses.length; x++) { //LOOP THROUGH MULTIPLE CLASSNAMES
					
                                if(splitClasses[x].indexOf('popup_window') > -1) { //IS LINK A POPUP WINDOW
				
                                        links[i].onclick = function() { //LINK CLICKED
			
                                                var classes = this.className; //GET CLASS NAMES
					
					
						
                                                url = this.getAttribute('href'); //FINDS WHAT PAGE WINDOW IS TO SHOW
								
                                                var dimentions = getDimentions(splitClasses[x]); //GET DIMENTIONS
								
                                                var newWindow = window.open(url, '', 'width='+dimentions['width']+', height='+dimentions['height']+', scrollbars=yes, resize=yes'); //SET NEW WINDOW
								
                                                newWindow; //LAUNCH
								
                                                return false; //STOP LINK
							
                                        }
						
                                }
				
                        }
		
                }
	
        }
	
}

// getDimentions()
/*
* Gets dimentions of popup window
* @return array; @param thisClass: Classname of link clicked
*/
function getDimentions(thisClass) {

        var parts = thisClass.split('_'); //EXPLODE CLASSNAME ON UNDERSCORE _
        var winWidth = parts[parts.length-2]; //WIDTH IS SECOND LAST ELEMENT
        var winHeight = parts[parts.length-1]; //HEIGHT IS LAST ELEMENT
	
        var dimentions = new Array();
	
        dimentions['width']  = winWidth;
        dimentions['height'] = winHeight;
	
        return dimentions; //RETURN

}


// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = false; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD

//ONLOAD MANAGER
function womOn(){
        window.onload = womGo;
}

function womGo(){
        for(var i = 0;i < woms.length;i++)
                eval(woms[i]);
				
		
		basketqty();
		scrollthumbs();
		$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
		homepagepanel();
		
		productenlarge();
}

function productenlarge ()
{
	if( $('#ahreftwo').length == 0 ) return false;
	
	
	$('ul#thumb_list > li').each(function(index) 
	{
		$(this).click(function()
		{
			$('ul#thumb_list > li.selected').removeClass('selected');
			$(this).addClass("selected");
		});
	});
	
	
	$("#ahreftwo").click(function()
    {
		jQuery.facebox({ image: $("#ahreftwo").attr("href") });
		
		if($('#scrollimgleft').length == 0) 
		{
			$(".popup").append('<div id="scrollimgleft" ></div><div id="scrollimgright" ></div>'); 
		}
		
		$('#scrollimgright').bind('click', function() 
		{
			var item = $('ul#thumb_list > li.selected').next();
			
			if($('ul#thumb_list > li.selected').next().length == 0) 
			{
				var item = $('ul#thumb_list > li:first-child');
			}
			
			$('ul#thumb_list > li.selected').removeClass('selected');
			item.addClass('selected');
			
			var nextimg = item.children("img").attr("src");
			var nextimg = nextimg.replace("/tinythumbs/", "/huge/");
			$('.image > img').attr("src",nextimg);
			//$('#ahreftwo').attr("href",nextimg);
			
			var nextimg = nextimg.replace("/huge/", "/large/");
			//$('#main').attr("src",nextimg);
			
		});
		
		$('#scrollimgleft').bind('click', function() 
		{
			var item = $('ul#thumb_list > li.selected').prev();

			if($('ul#thumb_list > li.selected').prev().length == 0) 
			{
				var item = $('ul#thumb_list > li:last-child');
			}
			
			$('ul#thumb_list > li.selected').removeClass('selected');
			item.addClass('selected');
			
			var nextimg = item.children("img").attr("src");
			var nextimg = nextimg.replace("/tinythumbs/", "/huge/");
			$('.image > img').attr("src",nextimg);
			//$('#ahreftwo').attr("href",nextimg);
			
			var nextimg = nextimg.replace("/huge/", "/large/");
			//$('#main').attr("src",nextimg);
		});
		
		return false;
	});
	
	
	
}


function homepagepanel ()
{
	if( $('#productinfowrap_inner').length == 0 ) return false;
	
	$('#productinfowrap_inner').hide();
	
	$("#js_homeprodtab").click(function()
    {
		if( $('#productinfowrap_inner').is(':visible') ) 
		{
			$('#productinfowrap_inner').hide();
			$('#js_homeprodtab > span').removeClass('downarrow');
			
		}
		else
		{
			$('#productinfowrap_inner').show();
			$('#js_homeprodtab > span').addClass('downarrow');
		}
	});
}

function fabricsamples ()
{
	
	if (document.getElementById('fabric_id').value == '')
	{
		jQuery.facebox({ div: '#fabric_options' });

		$('div').remove('#scrollimgleft');
		$('div').remove('#scrollimgright');
		
		return false;
	} 
	else 
	{
		return true;	
	}
	
}

function scrollthumbs()
{
	$("#js_scrollingimg").easySlider();
}

function basketqty()
{
	if( $('.js_addone').length == 0 ) return false;
	
	$(".js_addone").click(function()
    {
		var currentVal = parseInt($(this).siblings("input").val());
        if (currentVal != NaN)
        {
            $(this).siblings("input").val(currentVal + 1);
        } 
    });

    $(".js_minusone").click(function()
    {
        var currentVal = parseInt($(this).siblings("input").val());
        if (currentVal != NaN)
        {
			if((currentVal - 1) > 0)
			{
            	$(this).siblings("input").val(currentVal - 1);
			}
        }
    });

}



function womAdd(func){
        woms[woms.length] = func;
}



function CreateBookmarkLink() {

        title = document.title;
        url = window.location.href;
	
        if (window.sidebar) { 
                window.sidebar.addPanel(title, url,"");
        } else if(window.external) {
                window.external.AddFavorite( url, title); 
        } else if(window.opera && window.print) {
                return true;
        }
	
}

function objToggle(obj) { 

        var obj = document.getElementById(obj);

        if(obj.style.display == "block") { 
                obj.style.display = "none";
        } else { 
                obj.style.display = "block";
        }

}

function objToggleMenu(obj, cat_id) { 

        var obj = document.getElementById(obj);
        var arrow = 'arrow_' + cat_id;
	
        if(obj.style.display == "block") { 
                obj.style.display = "none";
                document.getElementById(arrow).src = 'images/arrow_down.gif';
        } else { 
                obj.style.display = "block";
                document.getElementById(arrow).src = 'images/arrow_up.gif';
        }

}


function showFabricBoxes(location){
	
        var div = document.getElementById(location);
        var ulList = div.getElementsByTagName('ul');
	
        for(var i=0; i<ulList.length; i++) {
		
                var liList = ulList[i].getElementsByTagName('li');
		
                for (var x=0; x<liList.length; x++){
			
                        if (x > 15){
				
                                if (liList[x].style.display == 'block') liList[x].style.display = 'none';
                                if (liList[x].style.display == 'none') liList[x].style.display = 'block';
				
                        }
			
                }
		
        }
	
        document.getElementById('fabric_expander').innerHTML = '';
	
        return true;
	
}



function imageSwap() {

        if(!document.getElementById('thumb_list')) return false;

        var placeHolder  = document.getElementById('main'); //LARGE IMAGE
        var imageList    = document.getElementById('thumb_list'); //UL OF IMAGE LIST
        var listElements = imageList.getElementsByTagName('li'); //LIS IN IMAGELIST
        var ahref		 = document.getElementById('ahref');
	
        for(var i=0; i<listElements.length; i++) { //LOOP THROUGH LIS
	
                var image = listElements[i].getElementsByTagName('img'); //GET IMAGES WITHIN LIS
		
                for(var x=0; x<image.length; x++) { //LOOP IMAGES
		
                        image[x].onclick = function() { //CLICKED ON AN IMAGE
			
                                //THUMB FILENAME
                                var file_location = this.getAttribute('src'); //GET FILE LOCATION
                                var location_explode = file_location.split('/');
                                var filename = location_explode[(location_explode.length-1)]; //FIND LAST VALUE
				
                                //CURRENT LARGE FILENAME
                                var file_location = placeHolder.getAttribute('src');
                                var location_explode = file_location.split('/');
                                var large_filename = location_explode[(location_explode.length-1)]; //FIND LAST VALUE
				
                                var thumb = 'uploads/images/products/tinythumbs/'+large_filename; //SET NEW SRC FOR THUMBNAME
                                var large = 'uploads/images/products/large/'+filename; //SET NEW SRC FOR PLACEHOLDER
                                var enlargement = 'uploads/images/products/huge/'+filename;
								
								$("#ahreftwo").attr("href",enlargement);
								
                                placeHolder.setAttribute('src', large); //SET ATTS
                                ahref.setAttribute('href', enlargement);
                                //this.setAttribute('src', thumb);
				//remove element as its recreated below
				$('.mousetrap').remove();
				$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
                        }
		
                }
		
	
        }
	
}

function prodAdminToggle(obj) { 
	
        if (obj == 'general'){
                document.getElementById('general').style.display = "block";			
                document.getElementById('location').style.display = "none";	
                document.getElementById('associated').style.display = "none";
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'general';
        }
	
        if (obj == 'location'){
                document.getElementById('general').style.display = "none";	
                document.getElementById('location').style.display = "block";
                document.getElementById('associated').style.display = "none";	
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'location';
        }
	
        if (obj == 'associated'){
                document.getElementById('general').style.display = "none";			
                document.getElementById('location').style.display = "none";	
                document.getElementById('associated').style.display = "block";
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'associated';
        }
	
        if (obj == 'amazon'){
                document.getElementById('general').style.display = "none";			
                document.getElementById('location').style.display = "none";	
                document.getElementById('associated').style.display = "none";
                document.getElementById('amazon').style.display = "block";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'amazon';
        }

        if (obj == 'promo'){
                document.getElementById('general').style.display = "none";			
                document.getElementById('location').style.display = "none";	
                document.getElementById('associated').style.display = "none";
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "block";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'promo';
        }
	
        if (obj == 'fabrics'){
                document.getElementById('general').style.display = "none";			
                document.getElementById('location').style.display = "none";	
                document.getElementById('associated').style.display = "none";
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "block";
                document.getElementById('image').style.display = "none";
                document.getElementById('tab').value = 'fabrics';
        }
	
        if (obj == 'image'){
                document.getElementById('general').style.display = "none";			
                document.getElementById('location').style.display = "none";
                document.getElementById('associated').style.display = "none";	
                document.getElementById('amazon').style.display = "none";
                document.getElementById('promo').style.display = "none";
                document.getElementById('fabrics').style.display = "none";
                document.getElementById('image').style.display = "block";
                document.getElementById('tab').value = 'image';
        }
	
}


function validate(formobj, formtype){
		
        switch(formtype) { 
                case "contact":
                        var fieldRequired = Array("enq_name", "enq_email", "enq_telephone", "enq_referral", "enq_comments");
                        break;
                case "register":
                        var fieldRequired = Array("account_username", "account_password", "account_confirm_password", "account_fullname", "account_email", "account_company", "account_outlet");
                        break;
                case "checkout":
                        var fieldRequired = Array("order_del_name", "order_del_addr1", "order_del_postcode", "order_del_tel", "order_bil_name", "order_bil_addr1", "order_bil_postcode", "order_bil_tel", "order_bil_email");
                        break;
        }
	
        var error = false;
	
        var normalClass = "textfield";
        var invalidClass = "textfield_invalid";
	
        for (var i = 0; i < fieldRequired.length; i++){
                var obj = formobj.elements[fieldRequired[i]];
                if(obj) {
                        obj.className = normalClass;
                }
        }
	
        for (var i = 0; i < fieldRequired.length; i++){
                var obj = formobj.elements[fieldRequired[i]];
                if (obj){
                        switch(obj.type){
                                case "select-one":
                                        if (obj.selectedIndex == 0 || obj.options[obj.selectedIndex].text == ""){
                                                obj.className = invalidClass;
                                                error = true;
                                        }
                                        break;
                                case "select-multiple":
                                        if (obj.selectedIndex == -1){
                                                obj.className = invalidClass;
                                                error = true;
                                        }
                                        break;
                                case "text":
                                case "textarea":
                                        if (obj.value == "" || obj.value == null){
                                                obj.className = invalidClass;
                                                error = true;
                                        }
                                        break;
                                default:
                        }
                }
        }
	
        if (!error){
		
                return true;
		
        } else {
		
                alert("Some fields were not filled in. Please complete the highlighted fields.");
                return false;
		
        }
}



/*function getSelection(ta)
  { var bits = [ta.value,'','','']; 
    if(document.selection)
      { var vs = '#$%^%$#';
        var tr=document.selection.createRange()
        if(tr.parentElement()!=ta) return null;
        bits[2] = tr.text;
        tr.text = vs;
        fb = ta.value.split(vs);
        tr.moveStart('character',-vs.length);
        tr.text = bits[2];
        bits[1] = fb[0];
        bits[3] = fb[1];
      }
    else
      { if(ta.selectionStart == ta.selectionEnd) return null;
        bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
      }
     return bits;
  }*/

function matchPTags(str)
{
        str = ' ' + str + ' ';
        ot = str.split(/\[[B|U|I].*?\]/i);
        ct = str.split(/\[\/[B|U|I].*?\]/i);
        return ot.length==ct.length;
}

function addPTag(ta,pTag)
{
        bits = getSelection(ta);
        if(bits)
        {
                if(!matchPTags(bits[2]))

                {
                        alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
                        return;
                }
                ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
        }
}
  

		
function select_fabric(fabric_id, title, price, img){
		
        document.getElementById('fabric_id').value = fabric_id;
        document.getElementById('fabric_title').innerHTML = title;
        document.getElementById('request_sample_price').innerHTML = price;
        document.getElementById('fabric_options').style.display = 'none';
        document.getElementById('request_sample_chosen').style.display = 'block';
        document.getElementById('selectedimg').src = 'uploads/images/swatches/' + img;
		
		if( $('#facebox').is(':visible') ) 
		{
			$(document).trigger('close.facebox')
		}
		
		
}
		
function deselect_fabric(){
		
        document.getElementById('fabric_id').value = '';
        document.getElementById('fabric_title').innerHTML = '';
        document.getElementById('request_sample_price').innerHTML = '';
        document.getElementById('fabric_options').style.display = 'block';
        document.getElementById('request_sample_chosen').style.display = 'none';
        document.getElementById('selectedimg').src = '';
}


function show_fabric_selection(product_id){
	
        var id_fabric_options = 'fabric_options_' + product_id;
        document.getElementById(id_fabric_options).style.display = 'block';
	
}

function select_fabric_assoc(product_id, title, fabric_id, price, img){
	
        var id_fabric_id = 'fabric_id_' + product_id;
        var id_fabric_title = 'fabric_title_' + product_id;
        var id_request_sample_price = 'request_sample_price_' + product_id;
        var id_fabric_options = 'fabric_options_' + product_id;
        var id_request_sample_chosen = 'request_sample_chosen_' + product_id;
        var id_selectedimg = 'selectedimg_' + product_id;
	
        document.getElementById(id_fabric_id).value = fabric_id;
        document.getElementById(id_fabric_title).innerHTML = title;
        document.getElementById(id_request_sample_price).innerHTML = price;
        document.getElementById(id_fabric_options).style.display = 'none';
        document.getElementById(id_request_sample_chosen).style.display = 'block';
        document.getElementById(id_selectedimg).src = 'uploads/images/swatches/' + img;
	
}

function deselect_fabric_assoc(product_id){
	
        var id_fabric_id = 'fabric_id_' + product_id;
        var id_fabric_title = 'fabric_title_' + product_id;
        var id_fabric_price = 'fabric_price_' + product_id;
        var id_request_sample_price = 'request_sample_price_' + product_id;
        var id_fabric_options = 'fabric_options_' + product_id;
        var id_request_sample_chosen = 'request_sample_chosen_' + product_id;
        var id_selectedimg = 'selectedimg_' + product_id;
	
        document.getElementById(id_fabric_id).value = 0;
        document.getElementById(id_fabric_title).innerHTML = '';
        document.getElementById(id_request_sample_price).innerHTML = '';
        document.getElementById(id_fabric_options).style.display = 'block';
        document.getElementById(id_request_sample_chosen).style.display = 'none';
        document.getElementById(id_selectedimg).src = 'uploads/images/swatches/' + img;
	
}

function ismaxlength(obj){
        var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
        if (obj.getAttribute && obj.value.length>mlength)
                obj.value=obj.value.substring(0,mlength)
}

function delivery_populate(){
	
        document.getElementById('delivery_firstname').value = document.getElementById('firstname').value;
        document.getElementById('delivery_surname').value = document.getElementById('surname').value;
        document.getElementById('delivery_address1').value = document.getElementById('address1').value;
        document.getElementById('delivery_address2').value = document.getElementById('address2').value;
        document.getElementById('delivery_address3').value = document.getElementById('address3').value;
        document.getElementById('delivery_town').value = document.getElementById('town').value;
        document.getElementById('delivery_county').value = document.getElementById('county').value;
        document.getElementById('delivery_postcode').value = document.getElementById('postcode').value;
	
}

function checkfabric(){
	
        if (document.getElementById('fabric_id').value == ''){
		
                alert('Please choose a fabric option');
                return false;
	
        } else {
		
                return true;	
		
        }
	
}

function checkfabric_assoc(product_id){
	
        var id_fabric_id = 'fabric_id_' + product_id;
        var id_fabric_options = 'fabric_options_' + product_id;
        var id_request_sample_chosen = 'request_sample_chosen_' + product_id;
	
        if (document.getElementById(id_fabric_options).style.display = 'none'){
                document.getElementById(id_fabric_options).style.display = 'block';
        }
	
        if (document.getElementById(id_fabric_id).value == ''){
		
                alert('Please choose a fabric option');
                return false;
	
        } else {
                document.getElementById(id_fabric_options).style.display = 'none';
                return true;	
		
        }
	
}


function sampleTallyCheck(){

        var tally = 0;
	
        var fields = document.getElementsByTagName('input');
	
        for(var i=0; i<fields.length; i++)
        {
			
                if ((fields[i].getAttribute('type')=='checkbox') && (fields[i].checked == true)){
			
                        tally++;
				
                        if (tally > 5) fields[i].checked = false;
				
                }
			
        }
		
        if (tally > 5){
		
                alert ('You have selected five samples.');
		
                return false;
		
        }

}


function confirmSubmit(){

        var agree=confirm("Are you sure you wish to delete this item?");

        if (agree)

                return true ;

        else

                return false ;

}

function bookmark(url,title){
        if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
                window.external.AddFavorite(url,title);
        } else if (navigator.appName == "Netscape") {
                window.sidebar.addPanel(title,url,"");
        } else {
                alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
        }
}


function checkAll(id, checked){
	
        var length = id.length;
	
        var fields = document.getElementsByTagName('input');
	
        for(var i=0; i<fields.length; i++)
        {
			
                if (fields[i].getAttribute('type') == 'checkbox'){
				
                        var theid = fields[i].getAttribute('name');
                        if (theid.substring(0, length) == id) fields[i].checked = checked;
				
                }
			
        }
		
}

//////////////////////////////////////////////////////////////////////////////////
// Cloud Zoom V1.0.2
// (c) 2010 by R Cecco. <http://www.professorcloud.com>
// MIT License
//
// Please retain this copyright header in all versions of the software
//////////////////////////////////////////////////////////////////////////////////
function format(str) {
        for (var i = 1; i < arguments.length; i++) {
            str = str.replace('%' + (i - 1), arguments[i]);
        }
        return str;
    }

    function CloudZoom(jWin, opts) {
        var sImg = $('img', jWin);
		var	img1;
		var	img2;
        var zoomDiv = null;
		var	$mouseTrap = null;
		var	lens = null;
		var	$tint = null;
		var	softFocus = null;
		var	$ie6Fix = null;
		var	zoomImage;
        var controlTimer = 0;      
        var cw, ch;
        var destU = 0;
		var	destV = 0;
        var currV = 0;
        var currU = 0;      
        var filesLoaded = 0;
        var mx,
            my; 
        var ctx = this, zw;
        // Display an image loading message. This message gets deleted when the images have loaded and the zoom init function is called.
        // We add a small delay before the message is displayed to avoid the message flicking on then off again virtually immediately if the
        // images load really fast, e.g. from the cache. 
        //var	ctx = this;
        setTimeout(function () {
            //						 <img src="/images/loading.gif"/>
            if ($mouseTrap === null) {
                var w = jWin.width();
                jWin.parent().append(format('<div style="width:%0px;position:absolute;top:75%;left:%1px;text-align:center" class="cloud-zoom-loading" >Loading...</div>', w / 3, (w / 2) - (w / 6))).find(':last').css('opacity', 0.5);
            }
        }, 200);


        var ie6FixRemove = function () {

            if ($ie6Fix !== null) {
                $ie6Fix.remove();
                $ie6Fix = null;
            }
        };

        // Removes cursor, tint layer, blur layer etc.
        this.removeBits = function () {
            //$mouseTrap.unbind();
            if (lens) {
                lens.remove();
                lens = null;             
            }
            if ($tint) {
                $tint.remove();
                $tint = null;
            }
            if (softFocus) {
                softFocus.remove();
                softFocus = null;
            }
            ie6FixRemove();

            $('.cloud-zoom-loading', jWin.parent()).remove();
        };


        this.destroy = function () {
            jWin.data('zoom', null);

            if ($mouseTrap) {
                $mouseTrap.unbind();
                $mouseTrap.remove();
                $mouseTrap = null;
            }
            if (zoomDiv) {
                zoomDiv.remove();
                zoomDiv = null;
            }
            //ie6FixRemove();
            this.removeBits();
            // DON'T FORGET TO REMOVE JQUERY 'DATA' VALUES
        };


        // This is called when the zoom window has faded out so it can be removed.
        this.fadedOut = function () {
            
			if (zoomDiv) {
                zoomDiv.remove();
                zoomDiv = null;
            }
			 this.removeBits();
            //ie6FixRemove();
        };

        this.controlLoop = function () {
            if (lens) {
                var x = (mx - sImg.offset().left - (cw * 0.5)) >> 0;
                var y = (my - sImg.offset().top - (ch * 0.5)) >> 0;
               
                if (x < 0) {
                    x = 0;
                }
                else if (x > (sImg.outerWidth() - cw)) {
                    x = (sImg.outerWidth() - cw);
                }
                if (y < 0) {
                    y = 0;
                }
                else if (y > (sImg.outerHeight() - ch)) {
                    y = (sImg.outerHeight() - ch);
                }

                lens.css({
                    left: x,
                    top: y
                });
                lens.css('background-position', (-x) + 'px ' + (-y) + 'px');

                destU = (((x) / sImg.outerWidth()) * zoomImage.width) >> 0;
                destV = (((y) / sImg.outerHeight()) * zoomImage.height) >> 0;
                currU += (destU - currU) / opts.smoothMove;
                currV += (destV - currV) / opts.smoothMove;

                zoomDiv.css('background-position', (-(currU >> 0) + 'px ') + (-(currV >> 0) + 'px'));              
            }
            controlTimer = setTimeout(function () {
                ctx.controlLoop();
            }, 30);
        };

        this.init2 = function (img, id) {

            filesLoaded++;
            //console.log(img.src + ' ' + id + ' ' + img.width);	
            if (id === 1) {
                zoomImage = img;
            }
            //this.images[id] = img;
            if (filesLoaded === 2) {
                this.init();
            }
        };

        /* Init function start.  */
        this.init = function () {
            // Remove loading message (if present);
            $('.cloud-zoom-loading', jWin.parent()).remove();


/* Add a box (mouseTrap) over the small image to trap mouse events.
		It has priority over zoom window to avoid issues with inner zoom.
		We need the dummy background image as IE does not trap mouse events on
		transparent parts of a div.
		*/
            $mouseTrap = jWin.parent().append(format("<div class='mousetrap' style='background-image:url(\".\");z-index:100;position:absolute;width:%0px;height:%1px;left:%2px;top:%3px;\'></div>", sImg.outerWidth(), sImg.outerHeight(), 0, 0)).find(':last');

            //////////////////////////////////////////////////////////////////////			
            /* Do as little as possible in mousemove event to prevent slowdown. */
            $mouseTrap.bind('mousemove', this, function (event) {
                // Just update the mouse position
                mx = event.pageX;
                my = event.pageY;
            });
            //////////////////////////////////////////////////////////////////////					
            $mouseTrap.bind('mouseleave', this, function (event) {
                clearTimeout(controlTimer);
                //event.data.removeBits();                
				if(lens) { lens.fadeOut(299); }
				if($tint) { $tint.fadeOut(299); }
				if(softFocus) { softFocus.fadeOut(299); }
				zoomDiv.fadeOut(300, function () {
                    ctx.fadedOut();
                });																
                return false;
            });
            //////////////////////////////////////////////////////////////////////			
            $mouseTrap.bind('mouseenter', this, function (event) {
				mx = event.pageX;
                my = event.pageY;
                zw = event.data;
                if (zoomDiv) {
                    zoomDiv.stop(true, false);
                    zoomDiv.remove();
                }

                var xPos = opts.adjustX,
                    yPos = opts.adjustY;
                             
                var siw = sImg.outerWidth();
                var sih = sImg.outerHeight();

                var w = opts.zoomWidth;
                var h = opts.zoomHeight;
                if (opts.zoomWidth == 'auto') {
                    w = siw;
                }
                if (opts.zoomHeight == 'auto') {
                    h = sih;
                }
                //$('#info').text( xPos + ' ' + yPos + ' ' + siw + ' ' + sih );
                var appendTo = jWin.parent(); // attach to the wrapper			
                switch (opts.position) {
                case 'top':
                    yPos -= h; // + opts.adjustY;
                    break;
                case 'right':
                    xPos += siw; // + opts.adjustX;					
                    break;
                case 'bottom':
                    yPos += sih; // + opts.adjustY;
                    break;
                case 'left':
                    xPos -= w; // + opts.adjustX;					
                    break;
                case 'inside':
                    w = siw;
                    h = sih;
                    break;
                    // All other values, try and find an id in the dom to attach to.
                default:
                    appendTo = $('#' + opts.position);
                    // If dom element doesn't exit, just use 'right' position as default.
                    if (!appendTo.length) {
                        appendTo = jWin;
                        xPos += siw; //+ opts.adjustX;
                        yPos += sih; // + opts.adjustY;	
                    } else {
                        w = appendTo.innerWidth();
                        h = appendTo.innerHeight();
                    }
                }

                zoomDiv = appendTo.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:%2px;height:%3px;background-image:url(\'%4\');z-index:99;background-repeat:no-repeat;"></div>', xPos, yPos, w, h, zoomImage.src)).find(':last');

                // Add the title from title tag.
                if (sImg.attr('title') && opts.showTitle) {
                    zoomDiv.append(format('<div class="cloud-zoom-title">%0</div>', sImg.attr('title'))).find(':last').css('opacity', opts.titleOpacity);
                }

                // Fix ie6 select elements wrong z-index bug. Placing an iFrame over the select element solves the issue...		
                if ($.browser.msie && $.browser.version < 7) {
                    $ie6Fix = $('<iframe frameborder="0" src="#"></iframe>').css({
                        position: "absolute",
                        left: xPos,
                        top: yPos,
                        zIndex: 99,
                        width: w,
                        height: h
                    }).insertBefore(zoomDiv);
                }

                zoomDiv.fadeIn(500);

                if (lens) {
                    lens.remove();
                    lens = null;
                } /* Work out size of cursor */
                cw = (sImg.outerWidth() / zoomImage.width) * zoomDiv.width();
                ch = (sImg.outerHeight() / zoomImage.height) * zoomDiv.height();

                // Attach mouse, initially invisible to prevent first frame glitch
                lens = jWin.append(format("<div class = 'cloud-zoom-lens' style='display:none;z-index:98;position:absolute;width:%0px;height:%1px;'></div>", cw, ch)).find(':last');

                $mouseTrap.css('cursor', lens.css('cursor'));

                var noTrans = false;

                // Init tint layer if needed. (Not relevant if using inside mode)			
                if (opts.tint) {
                    lens.css('background', 'url("' + sImg.attr('src') + '")');
                    $tint = jWin.append(format('<div style="display:none;position:absolute; left:0px; top:0px; width:%0px; height:%1px; background-color:%2;" />', sImg.outerWidth(), sImg.outerHeight(), opts.tint)).find(':last');
                    $tint.css('opacity', opts.tintOpacity);                    
					noTrans = true;
					$tint.fadeIn(500);

                }
                if (opts.softFocus) {
                    lens.css('background', 'url("' + sImg.attr('src') + '")');
                    softFocus = jWin.append(format('<div style="position:absolute;display:none;top:2px; left:2px; width:%0px; height:%1px;" />', sImg.outerWidth() - 2, sImg.outerHeight() - 2, opts.tint)).find(':last');
                    softFocus.css('background', 'url("' + sImg.attr('src') + '")');
                    softFocus.css('opacity', 0.5);
                    noTrans = true;
                    softFocus.fadeIn(500);
                }

                if (!noTrans) {
                    lens.css('opacity', opts.lensOpacity);										
                }
				if ( opts.position !== 'inside' ) { lens.fadeIn(500); }

                // Start processing. 
                zw.controlLoop();

                return; // Don't return false here otherwise opera will not detect change of the mouse pointer type.
            });
        };

        img1 = new Image();
        $(img1).load(function () {
            ctx.init2(this, 0);
        });
        img1.src = sImg.attr('src');

        img2 = new Image();
        $(img2).load(function () {
            ctx.init2(this, 1);
        });
        img2.src = jWin.attr('href');
    }

    $.fn.CloudZoom = function (options) {
        // IE6 background image flicker fix
        try {
            document.execCommand("BackgroundImageCache", false, true);
        } catch (e) {}
        this.each(function () {
			var	relOpts, opts;
			// Hmm...eval...slap on wrist.
			eval('var	a = {' + $(this).attr('rel') + '}');
			relOpts = a;
            if ($(this).is('.cloud-zoom')) {
                $(this).css({
                    'position': 'relative',
                    'display': 'block'
                });
                $('img', $(this)).css({
                    'display': 'block'
                });
                // Wrap an outer div around the link so we can attach things without them becoming part of the link.
                // But not if wrap already exists.
                if ($(this).parent().attr('id') != 'wrap') {
                    $(this).wrap('<div id="wrap" style="top:0px;z-index:100;position:relative;"></div>');
                }
                opts = $.extend({}, $.fn.CloudZoom.defaults, options);
                opts = $.extend({}, opts, relOpts);
                $(this).data('zoom', new CloudZoom($(this), opts));

            } else if ($(this).is('.cloud-zoom-gallery')) {
                opts = $.extend({}, relOpts, options);
                $(this).data('relOpts', opts);
                $(this).bind('click', $(this), function (event) {
                    var data = event.data.data('relOpts');
                    // Destroy the previous zoom
                    $('#' + data.useZoom).data('zoom').destroy();
                    // Change the biglink to point to the new big image.
                    $('#' + data.useZoom).attr('href', event.data.attr('href'));
                    // Change the small image to point to the new small image.
                    $('#' + data.useZoom + ' img').attr('src', event.data.data('relOpts').smallImage);
                    // Init a new zoom with the new images.				
                    $('#' + event.data.data('relOpts').useZoom).CloudZoom();
                    return false;
                });
            }
        });
        return this;
    };

    $.fn.CloudZoom.defaults = {
        zoomWidth: 'auto',
        zoomHeight: 'auto',
        position: 'right',
        tint: false,
        tintOpacity: 0.5,
        lensOpacity: 0.5,
        softFocus: false,
        smoothMove: 3,
        showTitle: true,
        titleOpacity: 0.5,
        adjustX: 0,
        adjustY: 0
    };

/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			//obj.width(w); 
			//obj.height(h); 
			//obj.css("overflow","hidden");
			//-3 = number of items showing
			var ts = s-3;
			var t = 0;
			$("ul", obj).css('width',s*(w + 10));			
			
			/*if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};*/				
			
			//if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				if(options.numeric){
					html += '<ol id="'+ options.numericId +'"></ol>';
				} else {
					if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				};
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			if(options.numeric){									
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			} else {
				$("a","#"+options.nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+options.prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
			};
			
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							//alert(t+' '+ts);
							$("a","#"+options.nextId).hide();
							$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+options.nextId).show();
							$("a","#"+options.lastId).show();					
						};
						if(t==0){
							$("a","#"+options.prevId).hide();
							$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+options.prevId).show();
							$("a","#"+options.firstId).show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){				
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);




