// JavaScript Document
<!--
//----------- Mouse Position ------------//
var mouseX = '';
var mouseY = '';
function show_coords(e) {
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} 
	else {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + 
			(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
		cursor.y = e.clientY + 
			(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	}
	mouseX = cursor.x;
	mouseY = cursor.y;
}
//----------- JsHttpRequest ------------//
function doLoad(value, page, id) {
    // Send data with files to backend.
    JsHttpRequest.query( page, { q: value }, function(errors, result) {
		document.getElementById('edit').innerHTML = result;
		tinyMCE.idCounter = 0; 
		tinyMCE.execCommand("mceAddControl", false, 'pagecontent');
    } );
	// Create new JsHttpRequest object.
	/*
	var req = new JsHttpRequest();
    // Prepare request object (automatically choose GET or POST).
    req.open(null, page, true);
    // Send data to backend.
    req.send( { q: value } );
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
        if (req.readyState == 4) {
			page = page.replace('.php', '');
            getHtml('edit', page, 'page='+page+'&'+id+'&d=1&update=1');
        }
    }*/
}
function doEdit(value, page, id) {
    // Send data with files to backend.
	JsHttpRequest.query( page, { q: value }, function(errors, result) {
		document.getElementById('edit').innerHTML = result;
		/*page = page.replace('.php', '');
		getHtml('edit', page, 'page='+page+'&cid='+id+'&d=1&update=1');*/
		tinyMCE.idCounter = 0; 
		tinyMCE.execCommand("mceAddControl", false, 'pagecontent');
    } );
}
function loadTemplate(value, page, id) {
    // Create new JsHttpRequest object.
    var req = new JsHttpRequest();
    // Prepare request object (automatically choose GET or POST).
    req.open(null, page, true);
    // Send data to backend.
    req.send( { q: value } );
	// Code automatically called on load finishing.
	req.onreadystatechange = function() {
        if (req.readyState == 4) {
			page = page.replace('.php', '');
            getHtml('edit', page, 'page='+page+'&'+id+'&d=1&update=1');
        }
    }
}
//----------- Shipping Costs ------------//
function formEleDis(txt, input, newTxt){
	var elm = document.getElementById(txt);
	var obj = document.getElementById(input);
	if (obj.style.display == 'block' || obj.style.display == '') {
		elm.style.display = 'block';
		obj.style.display = 'none';
		elm.innerHTML = obj.value;
	}else{
		obj.style.display = 'block';
		elm.style.display = 'none';
	}
}
function standard(num){
	var total=0;
	var weight=0;
	cost = Math.round(($('q'+num).value * $('p'+num).value)*100)/100;
	costStr = String(cost);
	des = costStr.indexOf('.');
	if(des == -1)
		cost = cost+'.00';
	else if(costStr.substr(des+1).length == 1)
		cost = cost+'0';
	else
		cost = cost;
	$('c'+num).value = cost;
	$('cDisplay'+num).innerHTML = (cost == 0) ? '-.--' : cost;
	for(var i=23; i<fCnt; i++){
		if($('c'+i).value >= 0){
			total += Math.round($('c'+i).value * 100)/100;
			weight += $('w'+i).value * $('q'+i).value;
		}
	}
	total = Math.round(total*100)/100;
	totalStr = String(total);
	des = totalStr.indexOf('.');
	if(des == -1)
		total = total+'.00';
	else if(totalStr.substr(des+1).length == 1)
		total = total+'0';
	else
		total = total;
	weight = Math.round(weight*100)/100;
	$('prodCost').innerHTML = (total == 0) ? '-.--' : total;
	$('subTotal').value = total;
	$('upsCostDisplay').innerHTML = '--.--';
	$('totalCostDisplay').innerHTML = (total == 0) ? '-.--' : total;
	$('totalCost').value = total;
	$('weightDisplay').innerHTML = weight+'lbs';
	$('prodWeight').value = weight;
	//alert('total: '+total+' - fCnt: '+fCnt);
}
function additional(shipping){
	totalCost = parseFloat($('subTotal').value) + parseFloat(shipping);
	totalCost = Math.round(totalCost*100)/100;
	totalStr = String(totalCost);
	des = totalStr.indexOf('.');
	if(des == -1)
		totalCost = totalCost+'.00';
	else if(totalStr.substr(des+1).length == 1)
		totalCost = totalCost+'0';
	else
		totalCost = totalCost;
	shipping = Math.round(shipping*100)/100;
	shipStr = String(shipping);
	des = shipStr.indexOf('.');
	if(des == -1)
		shipping = shipping+'.00';
	else if(shipStr.substr(des+1).length == 1)
		shipping = shipping+'0';
	else
		shipping = shipping;
	$('upsCost').value = shipping;
	$('upsCostDisplay').innerHTML = shipping;
	$('totalCost').value = totalCost;
	$('totalCostDisplay').innerHTML = totalCost;
	$('reqShipMethod').value = $('shipMethUS').value;
}
//----------- Products & Services Page Flip ------------//
var topTabs = new Array();
var prodPgs = new Array();
var numberOfPages = 0;
var pageTimer = 0;
var pageID = 0;
var prodCt = 0;
function UpdatePage() {
	//pageTimer = (Math.round(pageID/26));
	pageTimer++;
	if(pageTimer % 15 == 0 && pageTimer != 0 && isHome == true){
		getHtml('bodyContent', '/content/pgcontent', 'cid='+prodPgs[prodCt]);
		//$('fback').innerHTML = $('fback').innerHTML + prodPgs[prodCt];
		prodCt = (numberOfPages == prodCt) ? 0 : prodCt + 1;
	}
	//$('fback').innerHTML = pageTimer;
}
//----------- Homepage Logo & Testimonials ------------//
function firstImage(){
	//Partner Logos
	document.getElementById('logos').src=images[0];
	document.getElementById('imageLink').href=links[0];
	//Customer Logos
	document.getElementById('custLogos').src=custImages[0];
	document.getElementById('custLink').href=custSites[0];
}
var timerID = 0;
var tStart  = null;
var play = 1;
var testCount = '';
var img = 1;
var imageCount = '';
var custimg = 1;
var custCount = '';
function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }
   if(!tStart)
      tStart   = new Date();
   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();
   tDate.setTime(tDiff);
   /*document.theTimer.theTime.value = "" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();*/
   if(tDate.getSeconds() > 4){
	   	if(imageCount == 0)
	   		img = 0;
		if(custCount == 0)
			custimg = 0;
	    document.getElementById('logos').src=images[img];
		document.getElementById('imageLink').href=links[img];
		document.getElementById('custLogos').src=custImages[custimg];
		document.getElementById('custLink').href=custSites[custimg];
		Reset();
		if(play == testCount){
			document.getElementById(last).style.visibility="hidden";
			play=0;
			document.getElementById('testimonial'+play).style.visibility="visible";
		}else{
			if(play != 0){
				document.getElementById('testimonial'+play).style.visibility="visible";
				last = 'testimonial'+(play);
				document.getElementById('testimonial'+(play-1)).style.visibility="hidden";
			}
			play++;	
		}
		if(img == imageCount){
			img=0;
		}else{
			img++;	
		}
		if(custimg == custCount){
			custimg=0;
		}else{
			custimg++;	
		}
   }
   timerID = setTimeout("UpdateTimer()", 1000);
}
function Start() {
   tStart = new Date();
   //document.theTimer.theTime.value = "00:00";
   timerID = setTimeout("UpdateTimer()", 1000);
   pgID = setInterval("UpdatePage()", 1000);
}
function StopPages(){
	clearInterval(pgID);
}
function Stop() {
   if(timerID) {
      clearTimeout(timerID);
      timerID = 0;
   }
   tStart = null;
}
function Reset() {
   tStart = null;
   //document.theTimer.theTime.value = "00:00";
}
//----------- Globals ------------//
function setHeight(bar, win, table){
	hgt = $(table).offsetHeight - barDiff;
	$(bar).style.height = hgt+'px';
	$(win).style.height = hgt+'px';
}
function setPosition(bar, win, table){
	hgt = $(table).offsetHeight - barDiff;
	$(bar).style.marginTop = Math.round(hgt/3)+'px';
	$(win).style.marginTop = Math.round(hgt/3)+'px';
}
function changeText(elm, textOne, textTwo){
	obj = $(elm);
	str = obj.innerHTML.replace(/\"/g,'\'');
	//alert(str+' - '+textOne);
	if(textOne == str){
		obj.innerHTML = textTwo;
		obj.style.letterSpacing = '0px';
	}else{
		obj.innerHTML = textOne;
		obj.style.letterSpacing = '1px';
	}
}
function changeColorAll(section, num, number, defColor, newColor){
	for(i=1; i<=number; i++){
		obj = document.getElementById(section+i);
		if (i == num) {
			obj.style.backgroundColor = newColor;
			obj.style.color = defColor;
		}else{
			obj.style.backgroundColor = defColor;
			obj.style.color = newColor;
		}
	}
}
function changeActive(obj, page, i, id, cid){
	i++;
	var elm = document.getElementById(obj);
	if (i % 2 == 0) {
		elm.onclick = function(){
			getHtml('edit', '/cms/'+page, 'page=create&cid='+cid+'&id='+id+'&d=1&active=0&ACTION=ACTIVATE');
			changeActive(obj, page, i, id, cid);
		};
		elm.innerHTML = 'Publish';
	}else{
		elm.onclick = function(){
			getHtml('edit', '/cms/'+page, 'page=create&cid='+cid+'&id='+id+'&d=1&active=1&ACTION=ACTIVATE');
			changeActive(obj, page, i, id, cid);
		};
		elm.innerHTML = 'Inactivate';
	}
}
function changeDefault(id, page, cid, i){
	i++;
	var elm = document.getElementById(id);
	if (i % 2 == 0) {
		elm.onclick = function(){
			getHtml('edit', '/cms/create', 'page=create&cid='+cid+'&d=1&active=0&ACTION=ACTIVATE');
			changeDefault(id, page, cid);
		};
		elm.innerHTML = 'Activate';
	}else{
		elm.onclick = function(){
			getHtml('edit', '/cms/create', 'page=create&cid='+cid+'&d=1&active=1&ACTION=ACTIVATE');
			changeDefault(id, page, cid);
		};
		elm.innerHTML = 'Inactivate';
	}
}
function overImage(id, image, color){
	var elm = document.getElementById(id);
	var orgImage = elm.style.backgroundImage;
	elm.style.backgroundImage = 'url(/images/admin/'+image+')';
	elm.style.color = (color) ? '#'+color : '#000000';
	
	elm.onmouseout = function(){
		elm.style.backgroundImage = orgImage;
		elm.style.color = (color == 'FFFFFF') ? '#000000' : '#FFFFFF';
	}
}
function positionElm(section, dir, num){
	document.getElementById(section).dir = num+'px';
}
function toggleDisable(section){
	if (document.getElementById(section).disabled == false) {
		document.getElementById(section).disabled = true;
	}else{
		document.getElementById(section).disabled = false;
	}
}
function popUp(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function changeColor(){
	if(document.getElementById('mainNav').value == 1){
		document.getElementById('navSection').style.visibility = 'hidden';
		document.write(1);
	}
	document.write(document.getElementById('mainNav').value)
}
function toggleDisplayAll(section, number){
	//alert(number);
	for(i=1; i<=number; i++){ //for(i=1; i<number; i++){
		var elm = document.getElementById(section+i);
		if (elm.style.display == 'block' || elm.style.display == '') {
			elm.style.display = 'none';
		}else{
			elm.style.display = 'block';
		}
	}
}
function toggleAttributeAll(start, end, number){
	//alert(number);
	for(i=1; i<number; i++){
		var elm = document.getElementById(start+i+end);
		if (elm.title == start+(number-1)+end) {
			elm.style.display = 'block';
		}else{
			elm.style.display = 'none';
		}
	}
}
function toggleDisplay(section){
	var elm = document.getElementById(section);
	if (elm.style.display == 'block' || elm.style.display == '') {
		elm.style.display = 'none';
	}else{
		elm.style.display = 'block';
	}
}
function showAll(section, number){
	for(i=1; i<=number; i++){
		var elm = document.getElementById(section+i);
		elm.style.display = 'block';
	}
}
function hideAll(section, number){
	for(i=1; i<=number; i++){
		var elm = document.getElementById(section+i);
		elm.style.display = 'none';
	}
}
function showMe(dID, num) {
	//var num = 3;
	for(var i=0; i<=num; i++){
		obj = document.getElementById('show'+i);
		if (i == dID) {
			obj.style.display = "block";
		}else{
			obj.style.display = "none";
		}
	}
}
function display(section){
	var elm = document.getElementById(section);
	elm.style.display = 'block';
}
function hide(section){
	var elm = document.getElementById(section);
	elm.style.display = 'none';
}
function hideF(e){
	if (typeof elm != "undefined"){
		elm.style.display = 'none';
	}
}
function menuHide(section){
	elm = document.getElementById(section);
	delHide = setTimeout("hideF()", 100);
	return delHide;
}
function clearHide(){
	if (typeof delHide != "undefined")
		clearTimeout(delHide)
}
function displayUndisplay (id, num){
	for(i=1; i<=num; i++){
		if(document.getElementById(id).style.display = "none"){
			document.getElementById(id).style.display = "block";
		}else{
			document.getElementById(id).style.display = "none";
		}
	}
}
function homePanes (dID, num) {
	for(i=1; i<=num; i++){
		obj = document.getElementById('mainNav'+i);
		//info = document.getElementById('show'+i);
		if (i == dID) {
			obj.style.color = '#094FA3';
			//obj.style.color = '#FFFFFF';
			obj.style.backgroundImage = 'url(images/menu_over.jpg)';
			//info.style.display = 'block';
			var last = i;
		}else{
			obj.style.color = '#000000';
			obj.style.backgroundImage = 'url(images/menu_reg.jpg)';
			//info.style.display = 'none';
		}
	}
}
//-->
