/*
    Javascript support for Logix website
    Authors: Lucian Grecu, Eugene Brukson
    Date: May, June 2008
*/

//ajax powered product page big product showcase  
var loadedProduct = 0;
function loadProduct(id) { 
	url = "index.php?n=builder&o=get_product&id=" + id;
	loadedProduct = id;
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_loadProduct;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}

}
function _loadProduct() {
	if(checkReadyState(xmlhttp)) {
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		x=response.getElementsByTagName("table");
		el = document.getElementById("productDetails");
		el.innerHTML = getXMLNode(x);

		x=response.getElementsByTagName("title");
		el = document.getElementById("productTitle");
		el.innerHTML = getXMLNode(x);
		
		x=response.getElementsByTagName("image");
		el = document.getElementById("homeProductImage");
		el.src = getXMLNode(x);  

		x=response.getElementsByTagName("plan");
		el = document.getElementById("productPlanThumb");
		el.innerHTML = getXMLNode(x);
		
		el = document.getElementById("footnote");
		if (loadedProduct == 2 || loadedProduct == 3) el.style.display = 'block'; else el.style.display = 'none'; 

	}
}

//ajax powered home page small product showcase
var currentProductID = 1;
var homeProducts = [];
function showProduct(id) { 

//		el = document.getElementById("prodImage" + homeProducts[id][0]);
//        el.src = homeProducts[id][3];
//
		for (i=0; i< homeProducts.length; i++)
		{
			el = document.getElementById("cell" +  homeProducts[i][0]);
			el.setAttribute("class", "homepageProduct");
			el.innerHTML = '<a href="#" class="prodImage" onclick="showProduct('+i+');"><img src="' + homeProducts[i][2] + '" border="0" width="50" height="50"></a>';
		}

		txt = '<table cellpadding="0" cellspacing="0" border="0" style="height: 400px;">';
		txt += '<tr><td height=45 width=45></td><td height=45 valign="bottom"><span style="font-size: 24px; color: #6c9c31">'+homeProducts[id][1]+'</span></td><td height=45 width=45><a href="#self" onclick="closeWait();"><img src="images/pop_button_close.gif" onmouseover="this.src=\'images/pop_button_close_over.gif\';" onmouseout="this.src=\'images/pop_button_close.gif\';" border="0"></a></td></tr>';
		txt += '<tr><td width=45></td><td height=280 width="300" align="left" valign="middle"><img src="'+homeProducts[id][3]+'"></td><tdwidth=45></td></tr>';
		txt += '<tr><td width=45></td><td height="60" valign="middle" align="right"><a href="index.php?n=builder&o=main&id='+homeProducts[id][0]+'" class="button_medgrey" style="width: 120px;" id="homeProductUrl">LEARN MORE</a></td><tdwidth=45></td></tr>';
		txt += "</table>";
		
//		el = document.getElementById("homeProductName");
//		el.innerHTML = homeProducts[id][1];
//		
//		el = document.getElementById("homeProductImage");
//		el.src = homeProducts[id][3];
		
//		el = document.getElementById("prodImage" +  + homeProducts[id][0]);
//		el.src = homeProducts[id][3];
//		el = document.getElementById("prodLink" +  + homeProducts[id][0]);
//		el.onmouseout = "";
		el = document.getElementById("cell" + homeProducts[id][0]);
		el.setAttribute("class", "homepageProduct_disabled");
		el.innerHTML = '<a href="#" class="prodImage" onclick="showProduct('+id+');"><img style="border: 1px solid #C5D7AD;" src="' + homeProducts[id][2] + '" width="50" height="50"></a>';

//		el = document.getElementById("homeProductUrl");
//		el.href= "index.php?n=builder&o=main&id=" + homeProducts[id][0];

		showWait(txt, 390, 500);

}


function selectPlan(id) {  //ajax driven home plan display
    url = "index.php?n=builder&o=get_plan&id=" + id;
    initObj();
    if (xmlhttp!=null) {
      xmlhttp.onreadystatechange=_selectPlan;
      xmlhttp.open("GET",url,true);
      xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
      xmlhttp.send(null);
    }

}

function _selectPlan() {
    if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("description");
        el = document.getElementById("planDescription");
        el.innerHTML = getXMLNode(x);

        x=response.getElementsByTagName("name");
        el = document.getElementById("planName");
        el.innerHTML = getXMLNode(x);
        
        x=response.getElementsByTagName("image");
        el = document.getElementById("planImage");
        el.src = getXMLNode(x);
    
        x=response.getElementsByTagName("id");
        id = getXMLNode(x);
        
        x=response.getElementsByTagName("thumb");
        el = document.getElementById("planImage" + id);
        el.src = getXMLNode(x);

    }
}


function showVideo() {
	el = document.getElementById('divVideo');  
	if (!el) {
		el = document.createElement("div");
		el.id = "divVideo";
    }
		el.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"   width="620" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"><param name="movie" value="swf/logixVid.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />  <embed src="swf/logixVid.swf" quality="high" bgcolor="#ffffff" width="620" height="405" name="logixVid" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain"  type="application/x-shockwave-flash"  pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
		el.style.width = "620px";
		el.style.height = "420px";
		el.style.border = "0px solid #ccc";
		el.style.position = "absolute";
		tmp = document.getElementById('videoSpacer');

		el.style.top = (findPosY(tmp) + 80) + "px";
		el.style.left = (findPosX(tmp) + 0) + "px";
		bdy = document.getElementsByTagName("body");
		bdy[0].appendChild(el);
	
	el.style.display = "block";

}
function closeVideo() {
	el = document.getElementById('divVideo');
	el.style.display = "none";
}


function showDistributors(StateID) {
	showWait();
    url = "index.php?n=distributor&o=get_distributors&id=" + StateID;
    initObj();
    if (xmlhttp!=null) {
      xmlhttp.onreadystatechange=_showDistributors;
      xmlhttp.open("GET",url,true);
      xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
      xmlhttp.send(null);
    }
}
function showDistributorsMexico() {
	showWait();
    url = "index.php?n=distributor&o=get_distributors_mexico";
    initObj();
    if (xmlhttp!=null) {
      xmlhttp.onreadystatechange=_showDistributors;
      xmlhttp.open("GET",url,true);
      xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
      xmlhttp.send(null);
    }
}
function _showDistributors() {
    if(checkReadyState(xmlhttp)) {
        var response = xmlhttp.responseXML.documentElement;
        response.normalize;
        x=response.getElementsByTagName("content");
        el=  document.getElementById("DistributorList");
        el.innerHTML = getXMLNode(x);

		x1=response.getElementsByTagName("gmap_id");
		x2=response.getElementsByTagName("gmap_long");
		x3=response.getElementsByTagName("gmap_lat");
		for (i=0; i<x1.length ;i++ )
		{
			try
			{
				if (x2[i] && x3[i] && x3[i].firstChild.data && x2[i].firstChild.data) showDistributorsGoogleMap(x1[i].firstChild.data, x3[i].firstChild.data , x2[i].firstChild.data);	
			}
			catch (ex)
			{
				;
			}
			
		}
		closeWait();	
		window.location='#masterList';
	}
}

function showDistributorsGoogleMap(id, longitude, latitude) {
	if (parseInt(longitude) && parseInt(latitude))
	{
		 if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map_canvas" + id));
			center = new GLatLng(latitude, longitude);
			map.setCenter(center, 13);
			marker = new GMarker(center, {draggable: false});
			map.addControl(new GSmallMapControl());
			map.addOverlay(marker);
		  }
	}
}


function showContactDesigner(id) {
	txt = "<div class='designer-contact-popup'><div class='title'><a href='#self' onclick='closeWait();'>close  </a></div>";
	txt += "<form action='index.php?o=contact-designer&id="+id+"' method='post'>";
	txt += "<table cellpadding='0' cellspacing='4' border='0'>";
	txt += "<tr><td>Your Name:</td><td><input name='Name' value='' type='text' size=50></td></tr>";
	txt += "<tr><td>Your Email:</td><td><input name='Email' value='' type='text' size=50></td></tr>";
	txt += "<tr><td>Subject:</td><td><input name='Subject' value='' type='text' size=50></td></tr>";
	txt += "<tr><td>Message:</td><td><textarea name='Message' rows=6 cols=30></textarea></td></tr>";
	txt += "<tr><td colspan='2'><input type='submit' value='Send Message'></td></tr>";
	txt += "</form>";
	txt += "</table>";
	txt += "</div>";

	showWait(txt);
}