//global variables that can be used by ALL the functions on this page.
var inputs;
var imgFalse = '../imgs/no.gif';
var imgTrue = '../imgs/yes.gif';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
	replaceChecks();
}

function replaceChecks() {
	
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');

	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {

		//check if the input is a checkbox
		if(inputs[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputs[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image 
			img.onclick = new Function('checkChange('+i+')');
			//place image in front of the checkbox
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			
			//hide the checkbox
			inputs[i].style.display='none';
		}
	}
}

//change the checkbox status and the replacement image
function checkChange(i) {

	if(inputs[i].checked) {
		inputs[i].checked = '';
		document.getElementById('checkImage'+i).src=imgFalse;
	} else {
		inputs[i].checked = 'checked';
		document.getElementById('checkImage'+i).src=imgTrue;
	}
}

//
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//

var dhtmlgoodies_slideSpeed = 15;	// Higher value = faster
var dhtmlgoodies_timer = 5;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
function showHideContent(e,inputId)
{
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){

		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}
		}else{
			dhtmlgoodies_activeId = inputId;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_icon'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}



function productListImagePop(ProductID)
{

    var url = "product-list-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function productMainImagePop(ProductID)
{

    var url = "product-main-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function addproductListImagePop(ProductID)
{

    var url = "add-product-list-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function addproductMainImagePop(ProductID)
{

    var url = "add-product-main-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function productStarsListImagePop(ProductID)
{

    var url = "product-stars-list-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function productStarsMainImagePop(ProductID)
{

    var url = "product-stars-main-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function addproductStarsListImagePop(ProductID)
{

    var url = "add-product-stars-list-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function addproductStarsMainImagePop(ProductID)
{

    var url = "add-product-stars-main-image.asp?ProductID=" + ProductID + ""
    openWin(url,"LrgeImg",550,250);
}
function StoreCounty(StoreID)
{

    var url = "Apend-Store-County.asp?StoreID=" + StoreID + ""
    openWin(url,"County",500,200);
}
function JobCounty(JobID)
{

    var url = "Apend-Store-County.asp?JobID=" + JobID + ""
    openWin(url,"County",500,300);
}
function StoreTown(StoreID)
{

    var url = "Apend-Store-Town.asp?StoreID=" + StoreID + ""
    openWin(url,"Town",500,200);
}
function EditMartin(ID)
{

    var url = "Edit-Question.asp?ID=" + ID + ""
    openScrollingWin(url,"Edit",800,600);
}
function openWin(strFile, strName, intWidth, intHeight)
{

    var strProperties = 'toolbar=no,width=' + Math.round(intWidth) + ',height=' + Math.round(intHeight) + ',left=30,top=150,' + 'status=no,scrollbars=no,resizable=no,menubar=no';
    tmpWin = window.open(strFile,strName,strProperties);
    tmpWin.focus();

}

function openScrollingWin(strFile, strName, intWidth, intHeight)
{

    var strProperties = 'toolbar=no,width=' + Math.round(intWidth) + ',height=' + Math.round(intHeight) + ',left=30,top=150,' + 'status=yes,scrollbars=yes,resizable=yes,menubar=no';
    tmpWin = window.open(strFile,strName,strProperties);
    tmpWin.focus();

}

	