// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/smart-forms.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.

// If you find my script useful, you can support my site in the following ways:
// 1. Vote for the script at HotScripts.com (you can do it on my site)
// 2. Link to the homepage of this script or to the homepage of my site:
//    http://www.php-development.ru/javascripts/smart-forms.php
//    http://www.php-development.ru/
//    You will get 50% commission on all orders made by your referrals.
//    More information can be found here:
//    http://www.php-development.ru/affiliates.php


function set_action_complete_adresa_livrare()
{
	var adresa_livrare_var = $("adresa_livrare");
	
	if(adresa_livrare_var.checked == true)
	{
		$("street_address_2").value = $F("street_address");
		$("postcode_2").value = $F("postcode");
		$("city_2").value = $F("city");
		
		
		$("state_2").selectedIndex = $("state").selectedIndex;
		$("country_2").selectedIndex = $("country").selectedIndex;
	}
	else
	{
		$("street_address_2").value = "";
		$("postcode_2").value = "";
		$("city_2").value = "";
				
		$("state_2").selectedIndex = "Bucuresti";
		$("country_2").selectedIndex = "174";
	}
	
}

function set_action_add_kit_to_cart(kit_id)
{
	var nr_products = $F("nr_products_"+kit_id);
	var pars = "nr_products="+nr_products;
	
	for(var i=0;i<nr_products;i++)
	{
		var products_id = $F("products_id_"+kit_id+"_"+i);
		var products_qty = $F("products_qty_"+kit_id+"_"+i);
		
		pars+="&products_id_"+i+"="+products_id+"&products_qty_"+i+"="+products_qty;
	}
	
	var qty = $F("qty_"+kit_id);
	
	pars += "&qty="+qty;	
	
	var XTCsid = $F("XTCsid");
	
	//alert(pars);
	pars+="&action_list=add_kits_to_cart&kit_id="+kit_id+"&XTCsid="+XTCsid;
	
	
	var url = "ajax.php";
	
	
	var myAjax = new Ajax.Request( url,
		
													{ method: 'post',
													  parameters: pars,
													  onComplete: set_action_add_kit_to_cart_from_server
													}
		
												);
	
	
}

function set_action_add_kit_to_cart_from_server(originalRequest)
{
	Try.these(
			function () {				
				
				var jsonObject = eval('(' + originalRequest.responseText + ')');				
								
				action_returned = jsonObject["action_returned"];	
				kit_id = jsonObject["kit_id"];							
												
				switch(action_returned)
				{

					case "add_kits_to_cart_ok":
					
					var div_to_update = $("alert_msg_"+kit_id);	
					
					
					
					var link_shopping_cart = $F("link_shopping_cart");
					
					div_to_update.innerHTML = "Kitul a fost adaugat in cosul de cumparaturi. <a class='subcat_link' href='"+link_shopping_cart+"'>Mergi la cosul de cumparaturi.</a>";
					
					
					div_to_update.style.display = "block";
						
					break;
					
					case "add_kits_to_cart_not_ok":

					break;
								
				}//switch(action_returned)
				
								
				
			}//function ()			
			
			
	);
}




function set_action_pages_form(value_page)
{
	var frm = document.form_show_all_products;
	frm.show_products_pages.value = value_page;
	
	frm.submit();
	return false;
}

function set_action_choose_state(id_country, id_state)
{
	var country = document.getElementById(id_country).value;
	
	var url = "ajax.php";
	var pars = "action_list=get_states&country="+country+"&id_state="+id_state;
	
	var state = document.getElementById(id_state);		
	
	state.options[0] = new Option("Loading...", "0");
	state.selectedIndex = 0;
	state.disabled = true;
	
	var myAjax = new Ajax.Request( url,

											{ method: 'get',
											  parameters: pars,
											  onComplete: set_action_choose_state_from_server
											}

										 );			
	
	
}

function set_action_choose_state_from_server(originalRequest)
{
	var xml = originalRequest.responseXML;//we have the xml object
	
	var respNode = xml.getElementsByTagName("response")[0];		
	var items = respNode.getElementsByTagName("item");
	
	var state_id = items[0].getElementsByTagName("name")[0].firstChild.nodeValue;
	
	var state = $(state_id);
	
	state.options[0] = new Option("Choose", "0");
	state.options.length  = 1;

	
	
	if(items.length > 0)
	{

		for (var i=1; i<items.length; i++)
		{
		  if (items[i].getElementsByTagName("name")[0].firstChild==null)
		  {
			  //city_id.options[i] = new Option("","");
		  }
		  else
		  {
			   var name = items[i].getElementsByTagName("name")[0].firstChild.nodeValue;
			   var value = items[i].getElementsByTagName("value")[0].firstChild.nodeValue;		   

			   state.options[i] = new Option(name, value);
		   }
		}
		
	}
	else
	{
		//state.options[1] = new Option("--Other City--", "-1");
		//state.options.length  = 2;
	}

	
	state.disabled = false;	
}




function set_action_reset_filter(field_id)
{
	var frm = document.dropdown_filter;
	
	var field_form = eval('document.dropdown_filter.'+field_id);
	field_form.value = 0;
	
	frm.submit();
	return false;
}

function set_class_general(element_obj,new_class_name)
{
	element_obj.setAttribute("class", new_class_name);
	element_obj.setAttribute("className", new_class_name);
}

function set_action_filter_mouse(div_id, action_mouse, id_field, value_field)
{
	var div_id_object = document.getElementById(div_id);
	
	var frm = document.dropdown_filter;
	
	switch(action_mouse)
	{
		case "over":
		set_class_general(div_id_object,'filter_over');
		break;
		
		case "out":
		set_class_general(div_id_object,'filter_out');
		break;
		
		case "click":
		
			var field_form = eval('document.dropdown_filter.'+id_field);
			field_form.value = value_field;
			frm.submit();
			return false;
			
		break;
	}
	
	
}

delay = 101;

i = 0;
do_not_hide = "";
menu_array = Array();



// ----- Popup Control ---------------------------------------------------------

function at_display(x)
{
  win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function at_show_aux(parent, child, width_left)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  var top  = (c["at_position"] == "y") ? p.offsetHeight+3 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth - 219 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left-2+'px';
  c.style.visibility = "visible";
}

// ----- Show -----
i = 0;
function at_show()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);
  i++;
  at_show_aux(p.id, c.id, 1);

/*
  if (p.id == "menu_subcat_1_name_3" || p.id == "menu_cat_1_names" || p.id == "menu_subcat_1_3	")
  {
    at_show_aux("menu_cat_1", "menu_cat_1_names");
	do_not_hide = "menu_cat_1_names";
	document.getElementById("debug").innerHTML += i+"|it should also show menu_cat"+"<br>";

	main_cat = document.getElementById("menu_cat_1");
	  clearTimeout(main_cat["at_timeout"]);
  }
  else
  {
	do_not_hide = "";
  }
*/
//  document.getElementById("debug").innerHTML += "<tr><td>"+this.id+":"+"at_show</td><td>:"+i+"|</td><td>"+c["at_position"] +"|</td><td>parent:"+p.id+"|</td><td>child:"+c.id+"</td><br>";

//  document.getElementById("debug").innerHTML += i+"|"+"at_show:"+"|"+this.id+":"+c["at_position"] +"|parent:"+p.id+"|child:"+c.id+"<br>";

  clearTimeout(c["at_timeout"]);
}

// ----- Show Grandson -----

function at_show_grandson()
{//if you go over a menu, you show all it's children.
//if the menu you are over is a subchild, you should also show it's grandfather.
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  g1 = document.getElementById(this["at_grandparent1"]);
  g2 = document.getElementById(this["at_grandparent2"]);

  at_show_aux(g1.id, g2.id, 150);

  clearTimeout(g2["at_timeout"]);

  at_show_aux(p.id, c.id, 150);

i++;
// document.getElementById("debug").innerHTML += i+"|"+"at_show_grandson:"+"|"+this.id+":"+c["at_position"] +"|grandparent1:"+g1.id+"|grandparent2:"+g2.id+"|parent:"+p.id+"|child:"+c.id+"<br>";


  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function at_hide()
{//if you get out of a menu, you close all it's children
	i++;
	
	c = document.getElementById(this["at_child"]);

	c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);

  
//  document.getElementById("debug").innerHTML += i+"|"+"at_hide:"+"|"+this.id+":"+c["at_position"]+"|parent:"+p.id+"|child:"+c.id+"<br>";

}

// ----- Hide Grandson -----
function at_hide_grandson()
{//if you get out of a menu, you close all it's children
  c = document.getElementById(this["at_child"]);
  p = document.getElementById(this["at_grandparent2"]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", delay);
  p["at_timeout"] = setTimeout("document.getElementById('"+p.id+"').style.visibility = 'hidden'", delay);
}

// ----- Click -----

function at_click()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id, "1");
  else c.style.visibility = "hidden";

  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field

function at_attach(parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function at_attach_sub(grand_parent1, grand_parent2, parent, child, showtype, position, cursor)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_grandparent1"]     = grand_parent1;
  p["at_grandparent2"]     = grand_parent2;
  c["at_grandparent1"]     = grand_parent1;
  c["at_grandparent2"]     = grand_parent2;
  
  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;

  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {

    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show_grandson;
      c.onmouseout  = at_hide_grandson;
      break;
  }
}



//========================================================================================================================================
//BEGIN functions for the homepage main banner
//========================================================================================================================================
var divs = new Array("container","container1", "container2");
var divs2 = new Array();
var currentDiv = 0;
// homepage main banner
//check which divs contain a commercial
function checkDivs() 
{
	//alert("aici");
	for(i=0;i<divs.length;i++)
	{
		//alert(document.getElementById(divs[i]).childNodes.length);
		if (navigator.appName == 'Microsoft Internet Explorer')
		{
			if(document.getElementById(divs[i]))
			{
				if (document.getElementById(divs[i]).childNodes.length == 5)
				{
					divs2[divs2.length] = divs[i];
				}
			}
		}
		else
		{
			if(document.getElementById(divs[i]))
			{
				if (document.getElementById(divs[i]).childNodes.length == 8)
				{
					//alert("aici");
					divs2[divs2.length] = divs[i];
				}
			}
		}
	}
	spitOutLinks();

}

// homepage main banner
//spit out the links according to the number of active ones
function spitOutLinks()
{
	var content_divs = '';

	for (i=0;i<divs2.length;i++)
	{
		//document.write(' <li class="inverted"><a href="javascript: void(0);" id="link' + i + '" onclick="javascript: selectedShow(\'' + i + '\');">test1</a></li><li class="spacer"></li>');
		
		content_divs += ' <li class="inverted"><a href="javascript: void(0);" id="link' + i + '" onclick="javascript: selectedShow(\'' + i + '\');">test1</a></li><li class="spacerli">&nbsp;</li>';

		/*
		if(i*1 == 2)	
		{
			//alert("aici");
			//document.write('</ul></div><div class="float_left" style="font-size:5px;width:5px;float:left">&nbsp;</div><div id="tab-optiuni" class="float_left" style="float:left"><ul>');

			content_divs += '</ul></div><div class="float_left" style="font-size:5px;width:5px;float:left">&nbsp;</div><div id="tab-optiuni" class="float_left" style="float:left"><ul>';
		}
		*/
	}

	document.write(content_divs);
	first();
}

// homepage main banner
//get the alternate text from the image and print out

function first()
{
	//alert(divs2.length);
	for (i=0;i<divs2.length;i++) {

		if (document.getElementById(divs2[i])) {
			if (navigator.appName == 'Microsoft Internet Explorer')
			{
				//var el = document.getElementById(divs2[i]).childNodes[2].childNodes[0].alt;
			}
			else {
				//alert(document.getElementById(divs2[i]));
				//var el = document.getElementById(divs2[i]).childNodes[3].childNodes[0].alt;
			}
			//var els = el.substring(0,16);
			var j = i+1;
			document.getElementById('link'+i).innerHTML = j;
		}
	}

	if (document.getElementById(divs2[0])) {
		document.getElementById(divs2[0]).style.display = 'block';
		document.getElementById("link0").className = 'selectatz';
	}

	timer = window.setInterval("cycle()",5000);
	cycle();
}

// homepage main banner
function cycle() {
	if(divs2.length==0) {
		return;
	}
	if (currentDiv == '') {
		currentDiv = 0;
	}

	if (currentDiv == divs2.length) {
		currentDiv = 0
	}

	for (i=0;i<divs2.length;i++) {
		if (document.getElementById(divs[i])) {
			document.getElementById(divs[i]).style.display = 'none';
			document.getElementById('link'+i).className = '';
		}
	}
	try{
	if (document.getElementById(divs[currentDiv])) {
		document.getElementById(divs[currentDiv]).style.display = 'block';
		try {
			document.getElementById('link'+currentDiv).className = 'selectatz';
		} catch(err) {
			//error processing stripped
		}
	}} catch(err) {
		//error processing stripped
	}
	currentDiv++
}

// homepage main banner
function selectedShow(id) {

	window.clearInterval(timer);

	for (i=0;i<divs2.length;i++) {
		if (document.getElementById(divs[i])) {
			document.getElementById(divs[i]).style.display = 'none';
			document.getElementById('link'+i).className = '';
		}
	}
	if (document.getElementById(divs[id])) {
		document.getElementById(divs[id]).style.display = 'block';
		document.getElementById('link'+id).className = 'selectatz';
	}
}

//========================================================================================================================================
// END functions for the homepage main banner
//========================================================================================================================================