﻿var imgArray = [];

function fixedIE(tl, n, el) {
    var sc = 'scroll' + tl, d = document, c = 'compatMode',
b = d[c] && d[c] == 'CSS1Compat' ? d.documentElement : d.body;
    n = n - 0; if (typeof n != 'number') return 0;
    if (/^(Top|Left)$/.test(tl))
        return b[sc] + n + 'px';
    if (/^(Bottom|Right)$/.test(tl) && typeof el == 'object') {
        tl = tl == 'Right' ? 'Left' : 'Top', sc = 'scroll' + tl;
        var dim = 'client' + (tl == 'Top' ? 'Height' : 'Width');
        return b[sc] + b[dim] - el[dim] - n + 'px';
    }
    return 0;
}

function changeImage(strImage){
    document.getElementById('ctl00_ctMainContent_imgMainImg').src="/AdImages/" + strImage;    
}

function MM_preloadImages() {
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function ShowActive(prefix, id, color){
    //document.getElementById('img'+id+color).style.display="";
    //document.getElementById('img'+id).style.display="none";
    document.getElementById('img' + id).src = prefix + '/images/' + id + color + '.jpg';
}

function ShowOriginal(prefix, id, color){
    //document.getElementById('img'+id+color).style.display="none";
    //document.getElementById('img'+id).style.display="";
    document.getElementById('img' + id).src = prefix + '/images/' + id + '.jpg';
}

function redirect(url) {
    window.location = url;
}

function ShowDiv(whichLayer)
{
    if (document.getElementById)
    {
        document.getElementById(whichLayer).style.display="";
    }
    else if (document.all)
    {
        document.all[whichLayer].style.display = "";
    }
    else if (document.layers)
    {
        document.layers[whichLayer].style.display ="";
    }
}

function HideDiv(whichLayer)
{
    if (document.getElementById)
    {
        document.getElementById(whichLayer).style.display="none";
    }
    else if (document.all)
    {
        document.all[whichLayer].style.display = "none";
    }
    else if (document.layers)
    {
        document.layers[whichLayer].style.display ="none";
    }
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


var msgbox;

function center(object)
{
    object.style.marginLeft = "-" + parseInt(object.offsetWidth / 2) + "px";
    object.style.marginTop = "-" + parseInt(object.offsetHeight / 2) + "px";
}
 
function msgBox(divID)
{
    //fix height/width
    document.getElementById('main_Overlay').style.height=getPageSize('height');
    document.getElementById('main_Overlay').style.width=getPageSize('width');
    
    //show preferences
    msgbox = document.getElementById(divID);   
    msgbox.style.display = "block";
    document.getElementById("main_Overlay").style.display="block";
}

function getPageSize(returnVal) {
        
     var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	if(returnVal == "width"){
	    return pageWidth;
	}
	else{
	    return pageHeight;
	}	
}

function closeModal(divID){
    document.getElementById(divID).style.display='none';
    document.getElementById('main_Overlay').style.display='none';
}


function WordCount(id, countid)
{
    var splitstring = document.getElementById(id).value.trim().split(" ");
    var splitlength = splitstring.length;
    if(splitlength > 45){
        var myString = "";
        for(i = 0; i < 45; i++){
            myString = myString + " " + splitstring[i];
        }
        document.getElementById(id).value = myString;
    }
    document.getElementById(countid).value = splitlength;
}

function Chizeck(deleteid, renewid, soldid) 
{
    document.getElementById(deleteid).checked = false;
    document.getElementById(renewid).checked = false;
    document.getElementById(soldid).checked = false;
}

function optionalcontract() 
{
    if (document.getElementById('divOptional').style.display == "none") {
        document.getElementById('divOptional').style.display = "";
        document.getElementById('spanOptional').innerHTML = "-";
    }
    else {
        document.getElementById('divOptional').style.display = "none";
        document.getElementById('spanOptional').innerHTML = "+";
    }
}

var num = 0;
var IsAuto;

function slideshow(slide_num) {
    var exploded = imgArray[slide_num].split("|");
    document.getElementById('mypic').src = exploded[0];
    document.getElementById('hmypic').href = exploded[1];
    if (IsAuto == true) {
        setTimeout("slideshowUp()", 5000);
    }
}

function slideshowUp() {
    num++;
    num = num % imgArray.length;
    slideshow(num);
}

function slideshowBack() {
    num--;
    if (num < 0) { num = imgArray.length - 1; }
    num = num % imgArray.length;
    slideshow(num);
}

