// Javascript document

// Functions
function alignBox(){	    
	var count=0
    var arrayDiv = document.getElementById('Middle').getElementsByTagName('div');
    for (var i=0; i<arrayDiv.length; i++) {
            if(arrayDiv[i].className=='Box'){
              count++;
                if(count==2){
					arrayDiv[i].style.marginLeft = '22px';
			        count=0;
			     }
			}
		}   
}

function FindMax(arrHeights)
{
	var maxHeight = 0;
	for (var i = 0; i<arrHeights.length; i++)
	{
		if (arrHeights[i] > maxHeight)
		{
			maxHeight = arrHeights[i] ;
		}
	}
	return maxHeight;
}

var key =0;
heights = new Array();

function saveHeight(sender)
{
	var senderHeight = sender.offsetHeight;
	heights.push(senderHeight);
	sender.setAttribute('id','box' + key);
	key++;
}

function setHeightTwoBlocks()
{
	if(document.getElementById("SpanBox")) 
	{
		var maxHeight = FindMax(heights);	
		for (var i = 0; i<heights.length; i++)
		{
			if(document.getElementById("box" + i))
			{
				document.getElementById("box" + i).style.height = (maxHeight - 15) + "px";
			}
		}
	}
}

function showEditControls(sender)
{
	sender.getElementsByTagName("span")[0].style.display = "block";
}

function hideEditControls(sender)
{
	sender.getElementsByTagName("span")[0].style.display = "none";
}

function setPrintButton(button)
{
    var Color = document.getElementsByTagName("body")[0].className
    if(Color!=""){
        num = Color.indexOf(" ");
        sColor = (Color.substr(0,num));
        if(document.getElementById(button))
        {
            document.getElementById(button).src = "/Images/btn_Print_"+sColor+".gif"
        }
     }

 }

function setTestimonialImages()
{ 
    if(document.getElementById("TestimonialImages")) {

        var ImgSrc = escape(document.getElementById("TestimonialImages").src)
       // alert(ImgSrc);
        var splitted = ImgSrc.split("/");
        var fileName = splitted[splitted.length-1]
        var fileNameWithoutExtension = fileName.split(".")[0]
        var extension = fileName.split(".")[1]
        
        if(ImgSrc!=""){
        if(fileName.indexOf('aspx') > 0) {
        
        
            document.getElementById("TestimonialImages").src = ImgSrc + "Home";
            document.getElementById("TestimonialImages").style.display = "none";
            document.getElementById("TestimonialFlashImage").style.display = "block";
            document.getElementById("TestimonialFlashImage").innerHTML = '<embed type="application/x-shockwave-flash" src="coca_cola_image_border.swf" flashvars="imgURL=' + ImgSrc + 'Home" style="" id="f10411" name="f10411" quality="high" menu="false" width="100%" height="100%" />';
        }else{
            document.getElementById("TestimonialImages").src = "/Images/Testimonial/" + fileNameWithoutExtension +"_Home." + extension;
            document.getElementById("TestimonialImages").width="231";
        }
    }

    }
}

function setTestimonialImageSubPages()
{ 
    if(document.getElementById("TestimonialImages"))
    {

        var ImgSrc = escape(document.getElementById("TestimonialImages").src)
       // alert(ImgSrc);
        var splitted = ImgSrc.split("/");
        var fileName = splitted[splitted.length-1]
        var fileNameWithoutExtension = fileName.split(".")[0]
        
        if(ImgSrc!=""){
        if(fileName.indexOf('aspx') > 0) 
        {
        
        
            document.getElementById("TestimonialImages").src = ImgSrc;
            document.getElementById("TestimonialImages").style.display = "none";
            document.getElementById("TestimonialFlashImage").style.display = "block";
            document.getElementById("TestimonialFlashImage").innerHTML = '<embed type="application/x-shockwave-flash" src="coca_cola_image_border.swf" flashvars="imgURL=' + ImgSrc + '" style="" id="f10411" name="f10411" quality="high" menu="false" width="100%" height="100%" />';
        }
    }
    }
}

function insertCode()
{
	var subject=document.forms.myForm.myTextarea;
	if (document.selection) {
		var range=document.selection.createRange();
		if (range.parentElement()==subject) {
			range.text=arguments[0]+(arguments[1]?range.text+arguments[1]:"");
			return;
		}
	}
	else if (subject.selectionStart || subject.selectionStart=='0') {	
		var str=subject.value;
		var a=subject.selectionStart, b=subject.selectionEnd;
		subject.value=str.substring(0,a)+arguments[0]+(arguments[1]?str.substring(a,b)+arguments[1]:"")+str.substring(b, str.length);
		return;
	}
	subject.value+=arguments[0]+(arguments[1] || "");
}
