// JavaScript Document

	function displayMedium(imageSrc){
		var subImages = document.getElementById('imageholder').getElementsByTagName('IMG');
		if(subImages.length==0){
			var img = document.createElement('IMG');
			document.getElementById('imageholder').appendChild(img);
		}else img = subImages[0];
		img.src = imageSrc;
		
	}



var ImageScroller = function(_imageScrollerParentDivID, _imageScrollerChildDivID) {
   _imageScrollerParentDivID = getElem(_imageScrollerParentDivID); 
   _imageScrollerChildDivID = getElem(_imageScrollerChildDivID); 
   var prImagePaths = new Array(); 
   var prImageAltText = new Array(); 
   var prImageClicks = new Array(); 
   var prImageDescription = new Array(); 
   var iNumOfThumbsShown = 1; 
   var iNumOfImages; 
   
   var bAutoScroll = 0; 
   //0=false, 1=true
   var iAutoScrollDelay = 1000; 
   var bAutoScrollDirection = 1; 
   //0=back, 1=forward
   var bAutoReverse = 1; 
   //0=false, 1=true
   var iScrollType = 1; 
   //0=horizontal, 1=vertical
   var bEnableThumbBorder = 0; 
   //0=no, 1=yes
   var bEnableCurrentCount = 0; 
   //0=no, 1=yes
   var bEnableThumbDescription = 0; 
   //0=no, 1=yes
   var bClickOpenType = 0; 
   //0=same window, 1=new window
   var iImageScrollAmount = 1;
   //number of images to scroll
   
   var objCounterDiv = ""; 
   var objDescriptionDiv = ""; 
   var iSmoothSlideInterval = 3; 
   var iSmoothSlideAmount = 7; 
   var moveTimer; 
   
   this.THUMB_HEIGHT = 80; 
   this.THUMB_WIDTH = 80; 
   this.THUMB_PADDING = 4; 
   
   var CURRENT_THUMB_INDEX = 1; 
   var NEW_REVERSE_OFFSET = 0; 
   var MAX_REVERSE_OFFSET = 0; 
   var NEW_FORWARD_OFFSET = 0; 
   var IS_SCROLLING = false; 
   //* BEGIN FUNCTIONS *//
   this.setNumOfImageToScroll = function(_NumOfImagesToScroll) {
        iImageScrollAmount = parseInt(_NumOfImagesToScroll);
   };
   this.enableThumbnailDescription = function(_descriptionDivID) {
      bEnableThumbDescription = 1; 
      objDescriptionDiv = _descriptionDivID; 
      }; 
   this.setScrollType = function(_iType) {
      if (_iType == 0) {
         iScrollType = 0; 
         }
      else {
         iScrollType = 1; 
         }
      }; 
   this.setScrollSpeed = function(_iSpeed) {
      if (_iSpeed > 0 || _iSpeed < 1000) {
         iSmoothSlideInterval = _iSpeed; 
         }
      else {
         iSmoothSlideInterval = 7; 
         }
      }; 
   this.setScrollAmount = function(_iAmount) {
      if (_iAmount > 0 || _iAmount < 1000) {
         iSmoothSlideAmount = _iAmount; 
         }
      else {
         iSmoothSlideAmount = 7; 
         }
      }; 
   this.setClickOpenType = function(_openType) {
      if (_openType == 0 || _openType == 1) {
         bClickOpenType = _openType; 
         }
      }; 
   this.enableCurrentCount = function(_counterDivID) {
      bEnableCurrentCount = 1; 
      objCounterDiv = _counterDivID; 
      }; 
   this.enableThumbBorder = function(_boolean) {
      bEnableThumbBorder = _boolean; 
      }; 
   this.setThumbsShown = function(_newNumOfThumbsShown) {
      iNumOfThumbsShown = parseInt(_newNumOfThumbsShown); 
      }; 
   this.addThumbnail = function(_thumbnailURL, _fullClickURL, _thumbnailAlt, _thumbnailDescription) {
      prImagePaths[prImagePaths.length] = _thumbnailURL; 
      prImageClicks[prImageClicks.length] = _fullClickURL; 
      prImageAltText[prImageAltText.length] = _thumbnailAlt; 
      prImageDescription[prImageDescription.length] = _thumbnailDescription; 
      }; 
   this.setThumbnailHeight = function(_newThumbHeight) {
      this.THUMB_HEIGHT = _newThumbHeight; 
      }; 
   this.getThumbnailHeight = function() {
      return this.THUMB_HEIGHT; 
      }; 
   this.setThumbnailWidth = function(_newThumbWidth) {
      this.THUMB_WIDTH = _newThumbWidth; 
      }; 
   this.getThumbnailWidth = function() {
      return this.THUMB_WIDTH; 
      }; 
   this.setThumbnailPadding = function(_newThumbPadding) {
      this.THUMB_PADDING = _newThumbPadding; 
      }; 
   this.getThumbnailPadding = function() {
      return THUMB_PADDING; 
      }; 
   this.getCurrentThumbIndex = function() {
      return CURRENT_THUMB_INDEX; 
      }; 
   this.getThumbnailCount = function() {
      return iNumOfImages; 
      }; 
   this.renderScroller = function() {
      iNumOfImages = prImagePaths.length; 
      if (iNumOfThumbsShown > iNumOfImages) {
         iNumOfThumbsShown = iNumOfImages; 
         }
      MAX_REVERSE_OFFSET = 0 - (iNumOfImages - iNumOfThumbsShown) * this.THUMB_WIDTH; 
      if (this.THUMB_PADDING > 0) {
         MAX_REVERSE_OFFSET = MAX_REVERSE_OFFSET - (iNumOfImages * this.THUMB_PADDING); 
         }
      if (bEnableThumbBorder == 1) {
         MAX_REVERSE_OFFSET = MAX_REVERSE_OFFSET - (iNumOfImages * 4); 
         }
      if (iScrollType == 0) {
         _imageScrollerParentDivID.style.width = (this.THUMB_WIDTH * iNumOfThumbsShown) + (iNumOfThumbsShown * (this.THUMB_PADDING * 2)) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.width = (parseInt(_imageScrollerParentDivID.style.width) + (iNumOfThumbsShown * 4)) + "px"; 
            }
         _imageScrollerParentDivID.style.height = this.THUMB_HEIGHT + (this.THUMB_PADDING * 2) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.height = (parseInt(_imageScrollerParentDivID.style.height) + 4) + "px"; 
            }
         _imageScrollerChildDivID.style.width = (this.THUMB_WIDTH * iNumOfImages) + (iNumOfImages * (this.THUMB_PADDING * 2)) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerChildDivID.style.width = (parseInt(_imageScrollerChildDivID.style.width) + (iNumOfImages * 4)) + "px"; 
            }
         }
      else if (iScrollType == 1) {
         _imageScrollerParentDivID.style.width = (this.THUMB_WIDTH) + ((this.THUMB_PADDING * 2)) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.width = (parseInt(_imageScrollerParentDivID.style.width) + (4)) + "px"; 
            }
         _imageScrollerParentDivID.style.height = (this.THUMB_HEIGHT * iNumOfThumbsShown) + (iNumOfThumbsShown * (this.THUMB_PADDING * 2)) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerParentDivID.style.height = (parseInt(_imageScrollerParentDivID.style.height) + (iNumOfThumbsShown * 4)) + "px"; 
            }
         _imageScrollerChildDivID.style.width = (this.THUMB_WIDTH) + (this.THUMB_PADDING * 2) + "px"; 
         if (bEnableThumbBorder == 1) {
            _imageScrollerChildDivID.style.width = (parseInt(_imageScrollerChildDivID.style.width) + 4) + "px"; 
            }
         }
      //*** [Begin] Image Cacheing code ***//
      var oHref;
      var oImage;
        oHref = document.createElement("a");
        oImage = document.createElement("img");
        
      for (i = 0; i < iNumOfImages; i++) {
        oHref = document.createElement("a");
        oHref.href = "javascript:displayMedium('"+ prImageClicks[i] +"')";
        oHref.title = prImageAltText[i];
        
        oImage = document.createElement("img");
            oImage.src = prImagePaths[i];
            oImage.alt = prImageAltText[i];
            oImage.border = 0;
            oImage.width = this.THUMB_WIDTH;
            oImage.height = this.THUMB_HEIGHT;
            oImage.style.padding = this.THUMB_PADDING;
            
          oHref.appendChild(oImage);
          _imageScrollerChildDivID.appendChild(oHref);
            
      }
      //*** [End]   Image Cacheing code ***//
      
      if (bEnableCurrentCount == 1) {
         addAnEvent(window, "load", this.updateCurrentCount); 
         }
      if (bEnableThumbDescription == 1) {
         addAnEvent(window, "load", this.updateCurrentDescription); 
         }
      }; 
   this.scrollUp = function() {
      _origOffset = parseInt(_imageScrollerChildDivID.style.top); 
      _currentOffset = parseInt(_imageScrollerChildDivID.style.top); 
      _newOffset = _currentOffset - (this.THUMB_HEIGHT * iImageScrollAmount); 
      if (this.THUMB_PADDING > 0) {
         _newOffset = _newOffset - (2 * this.THUMB_PADDING); 
         }
      if (bEnableThumbBorder == 1) {
         _newOffset = _newOffset - 4; 
         }
      if (IS_SCROLLING == false && _newOffset >= MAX_REVERSE_OFFSET) {
         NEW_FORWARD_OFFSET = _newOffset; 
         moveScrollerUp(); 
         }
      }; 
   this.scrollDown = function() {
      _origOffset = parseInt(_imageScrollerChildDivID.style.top); 
      _currentOffset = parseInt(_imageScrollerChildDivID.style.top); 
      _newOffset = _currentOffset + (this.THUMB_HEIGHT * iImageScrollAmount); 
      if (this.THUMB_PADDING > 0) {
         _newOffset = _newOffset + (2 * this.THUMB_PADDING); 
         }
      if (bEnableThumbBorder == 1) {
         _newOffset = _newOffset + 4; 
         }
      if (_newOffset <= 0) {
         if(_currentOffset > (_origOffset - this.THUMB_HEIGHT)) {
            if (IS_SCROLLING == false && _newOffset >= MAX_REVERSE_OFFSET) {
               NEW_REVERSE_OFFSET = _newOffset; 
               moveScrollerDown(); 
               }
            }
         }
      }; 
   this.scrollTop = function() {
      if (IS_SCROLLING == false) {
         NEW_FORWARD_OFFSET = ( - 1 * (iNumOfImages - iNumOfThumbsShown) * this.THUMB_HEIGHT); 
         CURRENT_THUMB_INDEX = iNumOfImages - iNumOfThumbsShown; 
         moveScrollerUp(); 
         }
      }; 
   this.scrollBottom = function() {
      if (IS_SCROLLING == false) {
         NEW_REVERSE_OFFSET = 0; 
         CURRENT_THUMB_INDEX = iNumOfImages - iNumOfThumbsShown; 
         moveScrollerDown(); 
         }
      }; 
   this.scrollReverse = function() {
      _origOffset = parseInt(_imageScrollerChildDivID.style.left); 
      _currentOffset = parseInt(_imageScrollerChildDivID.style.left); 
      _newOffset = _currentOffset + (this.THUMB_WIDTH * iImageScrollAmount); 
      if (this.THUMB_PADDING > 0) {
         _newOffset = _newOffset + (this.THUMB_PADDING * (2 * iImageScrollAmount)); 
         }
      if (bEnableThumbBorder == 1) {
         _newOffset = _newOffset + 4; 
         }
      if (_newOffset <= 0) {
         if(_currentOffset > (_origOffset - (this.THUMB_WIDTH * iImageScrollAmount))) {
            if (IS_SCROLLING == false) {
               NEW_REVERSE_OFFSET = _newOffset; 
               moveScrollerRight(); 
               }
            }
         }
      }; 
   this.scrollForward = function() {
      _origOffset = parseInt(_imageScrollerChildDivID.style.left); 
      _currentOffset = parseInt(_imageScrollerChildDivID.style.left); 
      _newOffset = _currentOffset - (this.THUMB_WIDTH * iImageScrollAmount); 
      if (this.THUMB_PADDING > 0) {
         _newOffset = _newOffset - ((2 * iImageScrollAmount) * this.THUMB_PADDING); 
         }
      if (bEnableThumbBorder == 1) {
         _newOffset = _newOffset - 4; 
         }
      if (IS_SCROLLING == false && _newOffset >= MAX_REVERSE_OFFSET) {
         NEW_FORWARD_OFFSET = _newOffset; 
         moveScrollerLeft(); 
         }
      }; 
   this.scrollEnd = function() {
      if (IS_SCROLLING == false) {
         NEW_FORWARD_OFFSET = MAX_REVERSE_OFFSET; 
         CURRENT_THUMB_INDEX = iNumOfImages - iNumOfThumbsShown; 
         moveScrollerLeft(); 
         }
      }; 
   this.scrollBegin = function() {
      if (IS_SCROLLING == false) {
         NEW_REVERSE_OFFSET = 0; 
         CURRENT_THUMB_INDEX = 2; 
         moveScrollerRight(); 
         }
      }; 
   this.updateCurrentDescription = function() {
      getElem(objDescriptionDiv).innerHTML = prImageDescription[CURRENT_THUMB_INDEX - 1]; 
      }; 
   this.updateCurrentCount = function() {
      getElem(objCounterDiv).innerHTML = CURRENT_THUMB_INDEX + "/" + iNumOfImages; 
      }; 
   function moveScrollerUp() {
      _ElementObj = _imageScrollerChildDivID; 
      _currentOffset = parseInt(_ElementObj.style.top); 
      if (_currentOffset > NEW_FORWARD_OFFSET && (_currentOffset - iSmoothSlideAmount) >= NEW_FORWARD_OFFSET) {
         _ElementObj.style.top = _currentOffset - iSmoothSlideAmount + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerUp, iSmoothSlideInterval); 
         }
      else if (_currentOffset > NEW_FORWARD_OFFSET) {
         _ElementObj.style.top = _currentOffset - 1 + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerUp, iSmoothSlideInterval); 
         }
      else {
         IS_SCROLLING = false; 
         CURRENT_THUMB_INDEX++; 
         window.clearTimeout(moveTimer); 
         if (bEnableThumbDescription == 1) {
            getElem(objDescriptionDiv).innerHTML = prImageDescription[CURRENT_THUMB_INDEX - 1]; 
            }
         if (bEnableCurrentCount == 1) {
            getElem(objCounterDiv).innerHTML = CURRENT_THUMB_INDEX + "/" + iNumOfImages; 
            }
         }
      }; 
   function moveScrollerDown() {
      _ElementObj = _imageScrollerChildDivID; 
      _currentOffset = parseInt(_ElementObj.style.top); 
      if (_currentOffset < NEW_REVERSE_OFFSET && (_currentOffset + iSmoothSlideAmount) <= NEW_REVERSE_OFFSET) {
         _ElementObj.style.top = _currentOffset + iSmoothSlideAmount + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerDown, iSmoothSlideInterval); 
         }
      else if (_currentOffset < NEW_REVERSE_OFFSET) {
         _ElementObj.style.top = _currentOffset + 1 + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerDown, iSmoothSlideInterval); 
         }
      else {
         IS_SCROLLING = false; 
         CURRENT_THUMB_INDEX--; 
         window.clearTimeout(moveTimer); 
         if (bEnableThumbDescription == 1) {
            getElem(objDescriptionDiv).innerHTML = prImageDescription[CURRENT_THUMB_INDEX - 1]; 
            }
         if (bEnableCurrentCount == 1) {
            getElem(objCounterDiv).innerHTML = CURRENT_THUMB_INDEX + "/" + iNumOfImages; 
            }
         }
      }; 
   function moveScrollerRight() {
      _ElementObj = _imageScrollerChildDivID; 
      _currentOffset = parseInt(_ElementObj.style.left); 
      if (_currentOffset < NEW_REVERSE_OFFSET && (_currentOffset + iSmoothSlideAmount) <= NEW_REVERSE_OFFSET) {
         _ElementObj.style.left = _currentOffset + iSmoothSlideAmount + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerRight, iSmoothSlideInterval); 
         }
      else if (_currentOffset < NEW_REVERSE_OFFSET) {
         _ElementObj.style.left = _currentOffset + 1 + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerRight, iSmoothSlideInterval); 
         }
      else {
         IS_SCROLLING = false; 
         CURRENT_THUMB_INDEX--; 
         window.clearTimeout(moveTimer); 
         if (bEnableThumbDescription == 1) {
            getElem(objDescriptionDiv).innerHTML = prImageDescription[CURRENT_THUMB_INDEX - 1]; 
            }
         if (bEnableCurrentCount == 1) {
            getElem(objCounterDiv).innerHTML = CURRENT_THUMB_INDEX + "/" + iNumOfImages; 
            }
         }
      }; 
   function moveScrollerLeft() {
      _ElementObj = _imageScrollerChildDivID; 
      _currentOffset = parseInt(_ElementObj.style.left); 
      if (_currentOffset > NEW_FORWARD_OFFSET && (_currentOffset - iSmoothSlideAmount) >= NEW_FORWARD_OFFSET) {
         _ElementObj.style.left = _currentOffset - iSmoothSlideAmount + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerLeft, iSmoothSlideInterval); 
         }
      else if (_currentOffset > NEW_FORWARD_OFFSET) {
         _ElementObj.style.left = _currentOffset - 1 + "px"; 
         IS_SCROLLING = true; 
         moveTimer = window.setTimeout(moveScrollerLeft, iSmoothSlideInterval); 
         }
      else {
         IS_SCROLLING = false; 
         CURRENT_THUMB_INDEX++; 
         window.clearTimeout(moveTimer); 
         if (bEnableThumbDescription == 1) {
            getElem(objDescriptionDiv).innerHTML = prImageDescription[CURRENT_THUMB_INDEX - 1]; 
            }
         if (bEnableCurrentCount == 1) {
            getElem(objCounterDiv).innerHTML = CURRENT_THUMB_INDEX + "/" + iNumOfImages; 
            }
         }
      }; 
   function addAnEvent(_obj, _eventName, _functionName) {
      if (window.addEventListener) {
         _obj.addEventListener(_eventName, _functionName, false); 
         }
      else {
         _obj.attachEvent("on" + _eventName, _functionName); 
         }
      }; 
   function getElem(_elemID) {
      return document.getElementById(_elemID); 
      }; 
   };



	var arrayOfRolloverClasses = new Array();
	var arrayOfClickClasses = new Array();
	var activeRow = false;
	var activeRowClickArray = new Array();
	
	function highlightTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(this!=activeRow){
			this.setAttribute('origCl',this.className);
			this.origCl = this.className;
		}
		this.className = arrayOfRolloverClasses[tableObj.id];
		
		activeRow = this;
		
	}
	
	function clickOnTableRow()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;		
		
		if(activeRowClickArray[tableObj.id] && this!=activeRowClickArray[tableObj.id]){
			activeRowClickArray[tableObj.id].className='';
		}
		this.className = arrayOfClickClasses[tableObj.id];
		
		activeRowClickArray[tableObj.id] = this;
				
	}
	
	function resetRowStyle()
	{
		var tableObj = this.parentNode;
		if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;

		if(activeRowClickArray[tableObj.id] && this==activeRowClickArray[tableObj.id]){
			this.className = arrayOfClickClasses[tableObj.id];
			return;	
		}
		
		var origCl = this.getAttribute('origCl');
		if(!origCl)origCl = this.origCl;
		this.className=origCl;
		
	}
		
	function addTableRolloverEffect(tableId,whichClass,whichClassOnClick)
	{
		arrayOfRolloverClasses[tableId] = whichClass;
		arrayOfClickClasses[tableId] = whichClassOnClick;
		
		var tableObj = document.getElementById(tableId);
		var tBody = tableObj.getElementsByTagName('TBODY');
		if(tBody){
			var rows = tBody[0].getElementsByTagName('TR');
		}else{
			var rows = tableObj.getElementsByTagName('TR');
		}
		for(var no=0;no<rows.length;no++){
			rows[no].onmouseover = highlightTableRow;
			rows[no].onmouseout = resetRowStyle;
			
			if(whichClassOnClick){
				rows[no].onclick = clickOnTableRow;	
			}
		}
		
	}
	
    function setCheckboxColumn(theCheckbox){
    if (document.getElementById(theCheckbox)) {
        document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
        }
    } else {
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
            if (document.getElementById(theCheckbox)) {
                document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
            }
         }
      }
   }

    function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }  

   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType(\'text/xml\');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('ajaxprocess').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
     var poststr = "p309_fullname=" + escape(encodeURI(document.getElementById("p309_fullname").value )) +"&p309_useremail=" + escape(encodeURI(document.getElementById("p309_useremail").value )) +"&p309_empresa=" + escape(encodeURI(document.getElementById("p309_empresa").value )) +"&p309_telefono=" + escape(encodeURI(document.getElementById("p309_telefono").value )) +"&p309_num=" + escape(encodeURI(document.getElementById("p309_num").value ));
    makePOSTRequest('plugins/p309_mailing/ajaxfunct.php?actiond=submituser', poststr);
   }

	var fromBoxArray = new Array();
	var toBoxArray = new Array();
	var selectBoxIndex = 0;
	var arrayOfItemsToSelect = new Array();
	
	
	function moveSingleElement()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;
		if(this.tagName.toLowerCase()=='select'){			
			tmpFromBox = this;
			if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox = toBoxArray[selectBoxIndex]; else tmpToBox = fromBoxArray[selectBoxIndex];
		}else{
		
			if(this.value.indexOf('>')>=0){
				tmpFromBox = fromBoxArray[selectBoxIndex];
				tmpToBox = toBoxArray[selectBoxIndex];			
			}else{
				tmpFromBox = toBoxArray[selectBoxIndex];
				tmpToBox = fromBoxArray[selectBoxIndex];	
			}
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			if(tmpFromBox.options[no].selected){
				tmpFromBox.options[no].selected = false;
				tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);
				
				for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){
					tmpFromBox.options[no2].value = tmpFromBox.options[no2+1].value;
					tmpFromBox.options[no2].text = tmpFromBox.options[no2+1].text;
					tmpFromBox.options[no2].selected = tmpFromBox.options[no2+1].selected;
				}
				no = no -1;
				tmpFromBox.options.length = tmpFromBox.options.length-1;
											
			}			
		}
		
		
		var tmpTextArray = new Array();
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpTextArray.push(tmpFromBox.options[no].text + '___' + tmpFromBox.options[no].value);			
		}
		tmpTextArray.sort();
		var tmpTextArray2 = new Array();
		for(var no=0;no<tmpToBox.options.length;no++){
			tmpTextArray2.push(tmpToBox.options[no].text + '___' + tmpToBox.options[no].value);			
		}		
		tmpTextArray2.sort();
		
		for(var no=0;no<tmpTextArray.length;no++){
			var items = tmpTextArray[no].split('___');
			tmpFromBox.options[no] = new Option(items[0],items[1]);
			
		}		
		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			tmpToBox.options[no] = new Option(items[0],items[1]);			
		}
	}
	
	function sortAllElement(boxRef)
	{
		var tmpTextArray2 = new Array();
		for(var no=0;no<boxRef.options.length;no++){
			tmpTextArray2.push(boxRef.options[no].text + '___' + boxRef.options[no].value);			
		}		
		tmpTextArray2.sort();		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			boxRef.options[no] = new Option(items[0],items[1]);			
		}		
		
	}
	function moveAllElements()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;		
		if(this.value.indexOf('>')>=0){
			tmpFromBox = fromBoxArray[selectBoxIndex];
			tmpToBox = toBoxArray[selectBoxIndex];			
		}else{
			tmpFromBox = toBoxArray[selectBoxIndex];
			tmpToBox = fromBoxArray[selectBoxIndex];	
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);			
		}	
		
		tmpFromBox.options.length=0;
		sortAllElement(tmpToBox);
		
	}
	
	
	/* This function highlights options in the "to-boxes". It is needed if the values should be remembered after submit. Call this function onsubmit for your form */
	function multipleSelectOnSubmit()
	{
		for(var no=0;no<arrayOfItemsToSelect.length;no++){
			var obj = arrayOfItemsToSelect[no];
			for(var no2=0;no2<obj.options.length;no2++){
				obj.options[no2].selected = true;
			}
		}
		
	}
	
	function createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight)
	{		
		fromObj = document.getElementById(fromBox);
		toObj = document.getElementById(toBox);
		
		arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;

		
		fromObj.ondblclick = moveSingleElement;
		toObj.ondblclick = moveSingleElement;

		
		fromBoxArray.push(fromObj);
		toBoxArray.push(toObj);
		
		var parentEl = fromObj.parentNode;
		
		var parentDiv = document.createElement('DIV');
		parentDiv.className='multipleSelectBoxControl';
		parentDiv.id = 'selectBoxGroup' + selectBoxIndex;
		parentDiv.style.width = totalWidth + 'px';
		parentDiv.style.height = totalHeight + 'px';
		parentEl.insertBefore(parentDiv,fromObj);
		
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		subDiv.style.styleFloat = 'left';
		fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelLeft;
		subDiv.appendChild(label);
		
		subDiv.appendChild(fromObj);
		subDiv.className = 'multipleSelectBoxDiv';
		parentDiv.appendChild(subDiv);
		
		
		var buttonDiv = document.createElement('DIV');
		buttonDiv.style.verticalAlign = 'middle';
		buttonDiv.style.styleFloat = 'left';
		buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px';
		buttonDiv.style.width = '30px';
		buttonDiv.style.textAlign = 'center';
		parentDiv.appendChild(buttonDiv);
		
		var buttonRight = document.createElement('INPUT');
		buttonRight.type='button';
		buttonRight.value = '->';
		buttonDiv.appendChild(buttonRight);	
		buttonRight.onclick = moveSingleElement;	
		
		var buttonAllRight = document.createElement('INPUT');
		buttonAllRight.type='button';
		buttonAllRight.value = '>>';
		buttonAllRight.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllRight);		
		
		var buttonLeft = document.createElement('INPUT');
		buttonLeft.style.marginTop='10px';
		buttonLeft.type='button';
		buttonLeft.value = '<-';
		buttonLeft.onclick = moveSingleElement;
		buttonDiv.appendChild(buttonLeft);		
		
		var buttonAllLeft = document.createElement('INPUT');
		buttonAllLeft.type='button';
		buttonAllLeft.value = '<<';
		buttonAllLeft.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllLeft);
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		subDiv.style.styleFloat = 'left';
		toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelRight;
		subDiv.appendChild(label);
				
		subDiv.appendChild(toObj);
		parentDiv.appendChild(subDiv);		
		
		toObj.style.height = (totalHeight - label.offsetHeight) + 'px';
		fromObj.style.height = (totalHeight - label.offsetHeight) + 'px';

			
		selectBoxIndex++;
		
	}
	
		
     function getAdmin(countryId,action,divid,additionalvars) {		
		var strURL="../plugins/p308_clothing_cart/ajaxfunct.php?actiond="+action+"&sectionid="+countryId+"&additionalvars="+additionalvars;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById(divid).innerHTML=req.responseText;
						if(action == "multipleselect")
						{
						 createMovableOptions("parents","options",500,300, 'Disponibles', 'Seleccionados');	
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
	 
}
function ShowTB(obj,divid){
 if (obj == "NEW"){
document.getElementById(divid).innerHTML= "Nuevo Grupo: <input type=\"text\" name=\"newgroup\" value=\"\" size=\"20\"/>";
 }
 else
 {
	alert(txt); 
 }
}

