//---------------------------------+
//  CARPE  S l i d e r        1.5  |
//  2006 - 01 - 03                 |
//  By Tom Hermansson Snickars     |
//  Copyright CARPE Design         |
//  http://carpe.ambiprospect.com/ |
//  Contact for custom scripts     |
//  or implementation help.        |
//---------------------------------+

// Global vars. You don't need to make changes here to change your sliders.
// Changing the attributes in your (X)HTML file is enough.
var carpeDefaultSliderLength      = 100;
var carpeSliderDefaultOrientation = 'horizontal';
var carpeSliderClassName          = 'carpe_slider';
var carpeSliderDisplayClassName   = 'carpe_slider_display';

var ctrlPrefix = "ctl00_ContentPlaceHolder1_";
// these are the x,y coordinates of the panelDrag (hard-coded for now) 
// Now generated from EditImages and passed in through AddJavascriptToDragImages()
var panelY = 0; 
var panelX = 0; 
// Rich - The size of the image has changed to 400 by 300. These values are aslo
//        used to set the dragable area when calling Drag.init()
// The Height and Width of the dragable area are now set through setupSlider(nWidth,nHeight)
var panelW = 0;
var panelH = 0;


var bShowedAlertForImage = false;


var DSImages = new Array;
//Initialise, say... 10 of them
for(count = 0; count<10 ; count++)
{
   if (DSImages[count] == null) 
   {
//       var strIndex = count +1;
//       DSImages[count] = new DragNScaleImage(null, "Image" + strIndex, 100, 200,250); // ref,ID, magnification, w,h
   }
}
//DSImages[1] = new DragNScaleImage(null, "Image2", 100, 200,250); 
// New Jan 25, 2006
function InitDSIitem(index, ref, id, mag, w, h, preScaleLeft, preScaleTop)
{
    dsi = DSImages[index];
    if(dsi != null)
    {
        dsi.ref = ref;
        dsi.objectId = id;
        dsi.magnification = mag;
        dsi.originalwidth = w;
        dsi.originalheight = h;
        dsi.preScaleLeft = preScaleLeft;
        dsi.preScaleTop = preScaleTop;
    }
}


// this is a constructor for our Image class which allows us to scale and drag 'n drop.
function DragNScaleImage(ref, objectId, magnification, originalwidth, originalheight, 
                            preScaleLeft, preScaleTop)
{
    this.ref = ref; // reference to the actual html object
    this.objectId = objectId;
    this.magnification = magnification;
    this.originalwidth = originalwidth;
    this.originalheight = originalheight;
    this.preScaleLeft = preScaleLeft;
    this.preScaleTop = preScaleTop;
}

// Note that there are 2 different signatures here for each function
// One which supplies an external percentage, and one which uses this.magnification
DragNScaleImage.prototype.getActualWidth = function()
{
    return this.originalwidth * this.magnification/100;
}

DragNScaleImage.prototype.getActualHeight = function()
{
    return this.originalheight * this.magnification/100;
}

DragNScaleImage.prototype.getActualWidth = function(percent)
{
    //return this.originalwidth * this.magnification/100;
    return this.originalwidth * percent/100;
}

DragNScaleImage.prototype.getActualHeight = function(percent)
{
    //return this.originalheight * this.magnification/100;
    return this.originalheight * percent/100;
}

// The prescaleLocation is used to remember the original x,y (top,left) location before
// we do a slider scale... so that we know where it started from and we can then return 
// to that exact point if we choose not to scale to the full size we initially dragged.
// We reset the preScaleLocation on the DragEnd for any image we've done.
DragNScaleImage.prototype.setPreScaleLocation = function()
{
    //return this.originalheight * this.magnification/100;
    img = this.ref;
    if(img != null)
    {
        this.preScaleLeft = img.style.left;
        this.preScaleTop = img.style.top;
    }
    return;
}




// carpeGetElementsByClass: Cross-browser function that returns
// an array with all elements that have a class attribute that
// contains className
function carpeGetElementsByClass(className)
{
	var classElements = new Array();
	var els = document.getElementsByTagName("*");
	var elsLen = els.length;
	var pattern = new RegExp("\\b" + className + "\\b");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
// carpeLeft: Cross-browser version of "element.style.left"
// Returns or sets the horizontal position of an element.
function carpeLeft(elmnt, pos)
{
	if (!(elmnt = document.getElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.left) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.left = pos + 'px';
		else {
			pos = parseInt(elmnt.style.left);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelLeft) {
		if (typeof(pos) == 'number') elmnt.style.pixelLeft = pos;
		else pos = elmnt.style.pixelLeft;
	}
	return pos;
}
// carpeTop: Cross-browser version of "element.style.top"
// Returns or sets the vertical position of an element.
function carpeTop(elmnt, pos)
{
	if (!(elmnt = document.getElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.top) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.top = pos + 'px';
		else {
			pos = parseInt(elmnt.style.top);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelTop) {
		if (typeof(pos) == 'number') elmnt.style.pixelTop = pos;
		else pos = elmnt.style.pixelTop;
	}
	return pos;
}
// moveSlider: Handles slider and display while dragging
function moveSlider(evnt)
{
	var evnt = (!evnt) ? window.event : evnt; // The mousemove event
	if (mouseover) { // Only if slider is dragged
		x = slider.startOffsetX + evnt.screenX; // Horizontal mouse position relative to allowed slider positions
		y = slider.startOffsetY + evnt.screenY; // Horizontal mouse position relative to allowed slider positions
		if (x > slider.xMax) x = slider.xMax; // Limit horizontal movement
		if (x < 0) x = 0 // Limit horizontal movement
		if (y > slider.yMax) y = slider.yMax; // Limit vertical movement
		if (y < 0) y = 0; // Limit vertical movement
		carpeLeft(slider.id, x);  // move slider to new horizontal position
		carpeTop(slider.id, y); // move slider to new vertical position
		sliderVal = x + y; // pixel value of slider regardless of orientation
		sliderPos = (slider.distance / display.valuecount) * 
			Math.round(display.valuecount * sliderVal / slider.distance);
		v = Math.round((sliderPos * slider.scale + slider.from) * // calculate display value
			Math.pow(10, display.decimals)) / Math.pow(10, display.decimals);
		display.value = v; // put the new value in the slider display element
		
		
		scalePreview(slider.index, v);
		
		return false;
	}
	return;
}


// slide: Handles the start of a slider move.
function slide(evnt)
{
	if (!evnt) evnt = window.event; // Get the mouse event causing the slider activation.
	slider = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
	dist = parseInt(slider.getAttribute('distance')); // The allowed slider movement in pixels.
	slider.distance = dist ? dist : carpeDefaultSliderLength ;// Deafault distance from global var.
	ori = slider.getAttribute('orientation'); // Slider orientation: 'horizontal' or 'vertical'.
	orientation = ((ori == 'horizontal') || (ori == 'vertical')) ? ori : carpeSliderDefaultOrientation;
		// Default orientation from global variable.
	displayId = slider.getAttribute('display'); // ID of associated display element.
	display = document.getElementById(displayId); // Get the associated display element.
	display.sliderId = slider.id; // Associate the display with the correct slider.
	dec = parseInt(display.getAttribute('decimals')); // Number of decimals to be displayed.
	display.decimals = dec ? dec : 0 // Default number of decimals: 0.
	val = parseInt(display.getAttribute('valuecount'));  // Allowed number of values in the interval.
	display.valuecount = val ? val : slider.distance + 1; // Default number of values: the sliding distance.
	from = parseFloat(display.getAttribute('from')); // Min/start value for the display.
	from = from ? from : 0; // Default min/start value: 0.
	to = parseFloat(display.getAttribute('to')); // Max value for the display.
	to = to ? to : slider.distance; // Default number of values: the sliding distance.
	slider.scale = (to - from) / slider.distance; // Slider-display scale [value-change per pixel of movement].
	if (orientation == 'vertical') { // Set limits and scale for vertical sliders.
		slider.from = to; // Invert for vertical sliders. "Higher is more."
		slider.xMax = 0;
		slider.yMax = slider.distance;
		slider.scale = -slider.scale; // Invert scale for vertical sliders. "Higher is more."
	}
	else { // Set limits for horizontal sliders.
		slider.from = from;
		slider.xMax = slider.distance;
		slider.yMax = 0;
	}
	slider.startOffsetX = carpeLeft(slider.id) - evnt.screenX; // Slider-mouse horizontal offset at start of slide.
	slider.startOffsetY = carpeTop(slider.id) - evnt.screenY; // Slider-mouse vertical offset at start of slide.
	mouseover = true;
	document.onmousemove = moveSlider; // Start the action if the mouse is dragged.
	document.onmouseup = sliderMouseUp; // Stop sliding.
	return false;
}
// sliderMouseUp: Handles the mouseup event after moving a slider.
// Snaps the slider position to allowed/displayed value. 
function sliderMouseUp()
{
	if (mouseover) {
		v = (display.value) ? display.value : 0; // Find last display value.
		pos = (v - slider.from)/(slider.scale); // Calculate slider position (regardless of orientation).
		if (slider.yMax == 0) {
			pos = (pos > slider.xMax) ? slider.xMax : pos;
			pos = (pos < 0) ? 0 : pos;
			carpeLeft(slider.id, pos); // Snap horizontal slider to corresponding display position.
		}
		if (slider.xMax == 0) {
			pos = (pos > slider.yMax) ? slider.yMax : pos;
			pos = (pos < 0) ? 0 : pos;
			carpeTop(slider.id, pos); // Snap vertical slider to corresponding display position.
		}
		if (document.removeEventListener) { // Remove event listeners from 'document' (W3C).
			document.removeEventListener('mousemove', moveSlider, false);
			document.removeEventListener('mouseup', sliderMouseUp, false);
		}
		else if (document.detachEvent) { // Remove event listeners from 'document' (IE).
			document.detachEvent('onmousemove', moveSlider);
			document.detachEvent('onmouseup', sliderMouseUp);
		}
	}
	//alert("mouseup slider v:" + v);
	scalePreview(slider.index, v);
	
	// then reset the drag.init stuff, with this new magnification level ***
	
	mouseover = false; // Stop the sliding.
}
function focusDisplay(evnt)
{
	if (!evnt) evnt = window.event; // Get the mouse event causing the display activation.
	display = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated display element.
	lock = display.getAttribute('typelock'); // Is the user allowed to type into the display?
	if (lock == 'on') {
		display.blur();
	}
	return;
}

function moveArrow(mode) 
{
    if(parseInt(mode) ==1) 
    { 
        //alert('mode=' + mode);
        var ctrl = getRefToControl('imgArrow', 0, '_');
        if(ctrl != null) 
        {
            //alert('found ctrl ');
            ctrl.style.width='1px'; 
            ctrl.style.height='1px';
            
            ctrl = getRefToControl('imgArrow', 1, '_');
            if(ctrl!=null)
            {
                ctrl.style.width='40px'; 
                ctrl.style.height='20px';
            }
            else
            {
                //alert('couldnae find the second one');
            }
        
        }
        else
        {
            //alert('didnae find the ctrl');
        }        
    }
}
                

function reportDrag(index, x, y) 
{
    var ctrl = getRefToControl("xy", index, "$");
    if(ctrl == null) 
    {
        var plus1 = 1 + parseInt(index);
        alert("xy" + plus1 + " could not be found on the page");
    }
    else
        ctrl.value = x + "," + y;
    //alert("reported drag x=" + x+", y="+y);
}

// This is the new version, which is generalized to work with xy or xyt (though
// we haven't changed the old references to take advantage of this one.
function reportDrag(ctrlname, index, x, y) 
{   //ctrlname = "xy" or "xyt" for text
    var ctrl = getRefToControl(ctrlname, index, "$");
    if(ctrl == null) 
    { 
        var plus1 = 1 + parseInt(index);
        //alert(ctrlname + plus1 + " could not be found on the page, I'll try $ -> _");
        ctrl = getRefToControl(ctrlname, index, "_");
        if(ctrl == null) 
        { 
            alert(ctrlname + plus1 + " could not be found on the page");
        }
        else
        {
            ctrl.value = x + "," + y;
        }
    }
    else
        ctrl.value = x + "," + y;
    
    //alert("reported drag to "+ ctrl.id +" x=" + x+", y="+y);
}

function reportScale(index, magn) 
{
    var ctrl = getRefToControl("mag", index, "$");   
    if(ctrl == null)
    {
        ctrl = getRefToControl("mag", index, "_"); 
    }
    
    if(ctrl != null)
    {
        ctrl.value = magn;
    }
    else
    {   var plus1 = 1 + parseInt(index);
        alert("could not find object mag" + plus1 + " on the page");
    }
    
    //alert("reported scale mag=" + magn);
}
                
// This automatically does the conversion from zero-based index to 1-based
function getRefToImage(index)
{
    var parentName = "ctl00_ContentPlaceHolder1_Image";
    var realIndex = 1 + index
    var ctrl = parentName + realIndex;
    var oDrag = document.all ? document.all[ctrl] : document.getElementById(ctrl);

    return oDrag;
}

// In this case, prefix will be either 'mag' or 'xy' and infix= _ or $
//
function getRefToControl(prefix, index, infix)
{
    var realIndex = 1 + index;
    // or? ctl00$ContentPlaceHolder1$mag 
    var ctrlName = "ctl00" + infix +"ContentPlaceHolder1"+infix + prefix + realIndex;
    
    var ctrl = document.all ? document.all[ctrlName] : document.getElementById(ctrlName);
    return ctrl;
}

function getRefToGenericControl(name, infix)
{
    var ctrlName = "ctl00" + infix +"ContentPlaceHolder1"+infix + name;
    var ctrl = document.all ? document.all[ctrlName] : document.getElementById(ctrlName);
    return ctrl;
}

function getRefToControlForSure(name)
{
    var ctrl = document.all ? document.all[name] : document.getElementById(name);
    
    if(ctrl == null)
    {
        var ctrlName = "ctl00_ContentPlaceHolder1_" + name;
        ctrl = document.all ? document.all[ctrlName] : document.getElementById(ctrlName);
        
        if(ctrl == null)
        {
            ctrlName = "ctl00$ContentPlaceHolder1$" + name;
            ctrl = document.all ? document.all[ctrlName] : document.getElementById(ctrlName);
        }
    }
    
    return ctrl;
}

// This function will take a given img and look at its ID which we assume to be of the 
// format ctl00_ContentPlaceHolder1_Image1 (1-based), and return the zero-based index
// of this image.  Just basic string manipulation.
function getImageIndex(img)
{
    var myId = img.id.replace("ctl00_ContentPlaceHolder1_Image","");
    
    var nId = parseInt(myId);
    if(nId > 0) 
        nId -=1;
    
    return nId;
}

function getImageIndex(img, whole_prefix)
{
    if(whole_prefix == null)
        whole_prefix = "ctl00_ContentPlaceHolder1_Image";
        
    var myId = img.id.replace(whole_prefix,"");
    
    var nId = parseInt(myId);
    if(nId > 0) 
        nId -=1;
    
    return nId;
}

function scalePreview(index, percent)
{
    // get a reference to the image from the DSI array
    
    var oThisDSI = DSImages[index];
    var oDrag = DSImages[index].ref;
    
    if(oDrag != null)
    {
        var width  = oThisDSI.getActualWidth(percent);
        var height = oThisDSI.getActualHeight(percent);
        
        var nWidth = width|0;
        var nHeight = height |0;
        
        // We could use a new preScaleX and preScaleY to calculate these, so that
        // the user can re-shrink without losing their original placement x and y
        //  (we would probably set these when we're finished with a previous move
        //   on the MouseUp part of a scale... remember too to reportDrag after we
        //   finish this one, so that we get the real x,y reported.)
        
    //    var myX = oDrag.style.left.replace("px","");
    //    var myY = oDrag.style.top.replace("px","");

        var myX = oThisDSI.preScaleLeft.replace("px",""); // instead of oDrag.style.left
        var myY = oThisDSI.preScaleTop.replace("px","");  // instead of oDrag.style.top
        
        myX = parseInt(myX);
        myY = parseInt(myY);
        
         
        // If we've gone over the border horizontally...    
        var offsetX = 0;
        
        var myFullX = nWidth + myX;
        var myFullY = nHeight + myY
        
        if(myFullX > (panelX + panelW))
        {
            offsetX = (panelX + panelW) - myFullX ; // gives a negative
        }
        
        // or vertically...
        var offsetY = 0;
        if(myFullY > (panelY + panelH))
        {
            offsetY = (panelY + panelH) - myFullY ; // gives a negative
        }
        
        oDrag.style.left = (myX + offsetX) + "px";
        oDrag.style.top = (myY + offsetY) + "px";
        
        oDrag.style.width = width + 'px';
        oDrag.style.height = height + 'px';
        
        // now report the new settings, so we can update at the next postback
        var left = oDrag.style.left.replace("px","");
        var top = oDrag.style.top.replace("px","");
        
        
        reportDrag("xy",index, left, top); // shall we comment this out? Nah, prob need it for grow @ borders
        //alert("index="+index+" x="+x + " y=" +y);
        reportScale(index, percent);
        
        // Recall that the following command sets the boundaries within which the
        // image may be dragged (we need to do this again, because its size has
        // recently changed within this function)
        Drag.init(oDrag, null, panelX, panelX + ((panelW)-width), panelY,panelY + ((panelH)-height));                       

        // And then we need to reset the onDragEnd for the dragged object
        oDrag.onDragEnd = function(x,y) { reportDrag("xy",index,x,y); DSImages[getImageIndex(this)].setPreScaleLocation(); } 
	}
	else
	{
	    //alert("in scalePreview, oDrag is null, and DSImages index = " + index);
	}    
    
    return;
}


function setupSlider(nWidth,nHeight)
{
    panelW = nWidth;
    panelH = nHeight;

    //alert("inside setupSlider()");
    sliders = carpeGetElementsByClass(carpeSliderClassName); // Find the horizontal sliders.
    if(sliders != null)
    {
	    var len = sliders.length;
	    
	    for (i = 0; i < sliders.length; i++) 
	    {
		    sliders[i].onmousedown = slide; // Attach event listener.
		    sliders[i].index = i;
		    // then save the original dimensions for the image associated with each slider
		    
		    oDrag = getRefToImage(i);
		    var nMag = 75;
		    var magref = getRefToControl('mag', i, "_");
		    if(magref != null)
		    {
		        nMag = magref.value;
		        if(nMag == "")
		            nMag = 75;
		    }
		        
		    if(oDrag != null)
		    {
		        var curW = oDrag.style.width.replace("px","");
		        var curH = oDrag.style.height.replace("px","");
    		    
		        var strIndex = i +1;
    		    
		        if(DSImages[i] == null)
		        {
//		            var origW = (4/3) * curW;
//		            var origH = (4/3) * curH;
		            
		            var origW = (100/nMag) * curW;
		            var origH = (100/nMag) * curH;
		            
		            DSImages[i] = new DragNScaleImage(oDrag, oDrag.id, nMag, origW, origH, oDrag.style.left, oDrag.style.top); // ref,ID, magnification, w,h, preScaleLeft, psTop
		        }
		        else if(DSImages[i] != null)
		        {
		            DSImages[i].ref = oDrag;
		            DSImages[i].objectId = oDrag.id;
		            
		            // re-set the magnification... get it from the mag control
		            DSImages[i].magnification = nMag;
		        }
    		    
		        // let's s set the drag.init stuff here too
		        Drag.init(oDrag, null, panelX, (panelX + panelW - curW),panelY, (panelY + panelH - curH));		       
		        oDrag.onDragEnd = function(x,y) 
		        {
		            var index = getImageIndex(this);
		            reportDrag("xy",index,x,y); 
		            //alert("index_setup="+index+" x="+x + " y=" +y);
		            DSImages[getImageIndex(this)].setPreScaleLocation(); 
		        } 
		        
		    }
		}
		
	}
	
	displays = carpeGetElementsByClass(carpeSliderDisplayClassName); // Find the displays.
	if(displays != null)
	{
	    for (i = 0; i < displays.length; i++) 
	    {
		    displays[i].onfocus = focusDisplay; // Attach event listener.
    		
		    // set the default magnification
		    var oDrag = getRefToImage(i);
		    if(oDrag != null)
		    {
		        displays[i].value = DSImages[i].magnification;
		    }
	    }
	}
	
}

// All we really need to do for this is to setup a Drag.init for each of the
// TextImages that we have
function setupDragText(nWidth,nHeight)
{
    panelW = nWidth;
    panelH = nHeight;

    var panelDrag = getRefToGenericControl("panelDragBoard", "_");
    if(panelDrag == null)
    {
        panelDrag = getRefToGenericControl("panelDragBoard", "$");
    }
    
    if(panelDrag != null)
    {
        var yTop = panelDrag.style.top;
        var xLeft = panelDrag.style.left;
    }
    
    for(x=0 ; x<11 ; x++)
    {
        oDrag = getRefToControl("TextImage",x,"_");
        if(oDrag != null)
        {
            //var temp = oDrag.style.width;
            var curW = oDrag.style.width.replace("px","");
		    var curH = oDrag.style.height.replace("px","");
		        
            Drag.init(oDrag, null, panelX, panelX + panelW - curW, panelY, panelY + panelH - curH);
            
            oDrag.onDragEnd = function(x,y) 
		        {
		            var index = getImageIndex(this, "ctl00_ContentPlaceHolder1_TextImage");
		            reportDrag("xyt",index,x,y); 
		            //alert("index_setup="+index+" x="+x + " y=" +y);
		        } 
        }
    }
    
    // And since we now want to Drag the AdImages even on the EditTExt page...
    // we need to init drag all of them too :)
    for(x=0 ; x<11 ; x++)
    {
        oDrag = getRefToControl("Image",x,"_");
        if(oDrag != null)
        {
            var temp = oDrag.style.width;
            var curW = oDrag.style.width.replace("px","");  // this could be a problem
		    var curH = oDrag.style.height.replace("px","");
		        
            Drag.init(oDrag, null, panelX, panelX + panelW - curW, panelY, panelY + panelH - curH);
            
            oDrag.onDragEnd = function(x,y) 
		        {
		            var index = getImageIndex(this, "ctl00_ContentPlaceHolder1_Image");
		            reportDrag("xy",index,x,y); 
		            //alert("index_setup="+index+" x="+x + " y=" +y);
		        } 
        }
    }
}

//		    if(oDrag != null)
//		    {
//		        var curW = oDrag.style.width.replace("px","");
//		        var curH = oDrag.style.height.replace("px","");
//    		    
//		        var strIndex = i +1;
//    		    
//		        if(DSImages[i] == null)
//		        {
//		            var origW = (100/nMag) * curW;
//		            var origH = (100/nMag) * curH;
//		            
//		            DSImages[i] = new DragNScaleImage(oDrag, oDrag.id, nMag, origW, origH, oDrag.style.left, oDrag.style.top); // ref,ID, magnification, w,h, preScaleLeft, psTop
//		        }
//		        else if(DSImages[i] != null)
//		        {
//		            DSImages[i].ref = oDrag;
//		            DSImages[i].objectId = oDrag.id;
//		            
//		            // re-set the magnification... get it from the mag control
//		            DSImages[i].magnification = nMag;
//		        }
//    		    
//		        // let's s set the drag.init stuff here too
//		        Drag.init(oDrag, null, panelX, (panelX + 200 - curW),panelY, (panelY + 300 - curH));
//		        oDrag.onDragEnd = function(x,y) 
//		        {
//		            var index = getImageIndex(this);
//		            reportDrag(index,x,y); 
//		            //alert("index_setup="+index+" x="+x + " y=" +y);
//		            DSImages[getImageIndex(this)].setPreScaleLocation(); 
//		        } 
//		        
//		    }
//		}
//		
//	}	


//window.onload = function() // Set up the sliders and the displays.
//{
 //   setupSlider();
//}

function alertForFirstImage()
{
    return ;
    if(bAllowFirstAlert)
    {
        var img1 = getRefToImage(0);
        var img2 = getRefToImage(1);
        
        if((img1 != null) && (img2 == null))
        {
            var strMesg = "Please note that images on the preview appear at\n" +
                          "a relatively low resolution, while the final ad\n" +
                          "will be at the high quality necessary for television broadcast." ;
            
            bAllowFirstAlert = false;
            bNoMoreAlerts = true;
            alert(strMesg);
        }
    }
}

function showProcessing()
{    
    var ctrlName = "imgProcessing";
    var img = document.all ? document.all[ctrlName] : document.getElementById(ctrlName);
    if( img == null)
    {
        img = getRefToGenericControl("imgProcessing", "_");
        
        if(img == null)
        {
            img = getRefToGenericControl("imgProcessing", "$");
        }
    }
    
    if(img != null)
    {
        img.style.width = "144px";
        img.style.height = "16px";
    }
    
    // and then hide the btSubmit, if there is one ;-)
    var btn = getRefToControlForSure("btnSubmit");
    if(btn != null)
    {
        btn.style.width = "0px";
    }
}
 
//
// The following two functions are for the Banner ad rotation
// We really should change the code here so that it allows Firefox etc
//
function loadpage() 
{
    browver= parseInt(navigator.appVersion);
    browtype = navigator.appName;
    browsertype = "old";
    if (browtype == "Netscape" && !(browver < 3)) 
    {
      browsertype = "new"; 
    }
    if (browtype == "Microsoft Internet Explorer" && !(browver < 4)) 
    {
        browsertype = "new";
    }
    if (browsertype == "new") 
    {
        thetimer = setTimeout("changeimage()", 3000);
        banneradcode = 0;
//        listofimages = new Array(6);
//        listofimages[0] = new Image(446,77)
//        listofimages[0].src = "images/banners/smw-anim-1.gif"
//        listofimages[1] = new Image(446,77)
//        listofimages[1].src = "images/banners/smw-anim-2.gif"
//        listofimages[2] = new Image(446,77)
//        listofimages[2].src = "images/banners/smw-anim-3.gif"
//        listofimages[3] = new Image(446,77)
//        listofimages[3].src = "images/banners/smw-anim-4.gif"
//        listofimages[4] = new Image(446,77)
//        listofimages[4].src = "images/banners/TVLRural_BannerAd05.gif"
//        listofimages[5] = new Image(446,77)
//        listofimages[5].src = "images/banners/TVLRural_BannerAd06.gif"
    }
}

function changeimage()
{
    if (browsertype == "new") 
    {
        banneradcode = banneradcode + 1;
        if (banneradcode == "8") 
        {
            banneradcode = 1;
        }
        imagesource = "images/banners/smw-anim-" + banneradcode + ".gif";
        window.document.bannerad.src = imagesource;
        thetimer = setTimeout("changeimage()", 5000);
    }
    else if (browsertype == "old") 
    {}
}
