function getCookie(c_name)
{
			if (document.cookie.length>0)
			  {
			  c_start=document.cookie.indexOf(c_name + "=")
			  if (c_start!=-1)
			    { 
			    c_start=c_start + c_name.length+1 
			    c_end=document.cookie.indexOf(";",c_start)
			    if (c_end==-1) c_end=document.cookie.length
			    return unescape(document.cookie.substring(c_start,c_end))
			    } 
			  }
			return ""
}
function setCookie(c_name,value,expiredays)
{
		var exdate=new Date()
			exdate.setDate(exdate.getDate()+expiredays)
			document.cookie=c_name+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function showLogin(obj)
{
	var f = document.forms['login'];
	var login_field = f.elements["mail"];
	var password_field = f.elements["pass"];
	/*var checkmail = getCookie('mail');
	if (checkmail=="") {*/
    document.getElementById(obj).style.display = 'block';
    login_field.focus(); 
	/*} else { 
	window.location.href = "http://mailitcomponents.com/visitoraccount/profile/"; }*/
	return true;
}
function ShowCookie(cookname) 
{
	var cooknameshow = getCookie(cookname);
	alert(cooknameshow);
}
function hideLogin()
{
	if(document.getElementById('login-form')) document.getElementById('login-form').style.display = 'none';
	return false;
}
// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}
// make asynchronous HTTP request using the XMLHttpRequest object 
function process()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // retrieve the name typed by the user on the form
   
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "http://mailitcomponents.com/reg_check.php", true);  
    // make the server request
    xmlHttp.send(null);
    showresponse();
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('process()', 500);
	return false;
}

function shoppingcart_content()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // retrieve the name typed by the user on the form
   
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "http://mailitcomponents.com/cart_check.php", true);  
    // make the server request
    xmlHttp.send(null);
    showresponsecart();
  }
  else
    // if the connection is busy, try again after one second  
  setTimeout('shoppingcart_content()', 1000);
  return false;
}

function showresponse() 
{
	if (xmlHttp.readyState == 4)
  	{
  		
    	if(xmlHttp.responseText == "false") {
    		showLogin('login-form');
    	} else 
    	  if(xmlHttp.responseText == "true") {
    	  	location.href="http://mailitcomponents.com/visitoraccount/profile/"
    	  } else {
    	  	document.write("");
    	  }
    	
  	} else {
  		
  		setTimeout('showresponse()', 500);
  		
  	}
	return false;
}

function showresponsecart() 
{	
	var i = true;
	if (xmlHttp.readyState == 4)
  	{
  	   	if(xmlHttp.responseText != null && xmlHttp.responseText != 0) {
    		document.getElementById('shop_count').innerHTML = ' ('+ xmlHttp.responseText +')';
  	   	}
  	} else {
  		if(i != false) {
  		setTimeout('showresponsecart()', 500);
  		i = false;
  		}
  	}
	return false;
}

function ratenew(id,value) {
	// proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
  	var theUL = document.getElementById('unit_ul'+id); // the UL
	theUL.innerHTML = '<h1>loading...</h1>';
    xmlHttp.open("GET", 'rpc.php?j='+value+'&q='+id, true);  
    // make the server request
    xmlHttp.send(null);
    showresponserating(id);
  } else {
  setTimeout('ratenew('+id+','+value+')', 1000);
  }
  return false;
}

function showresponserating(id) {
	if (xmlHttp.readyState == 4)
  	{
  		var xmlDoc=xmlHttp.responseXML.documentElement;
  		var liupdate = xmlDoc.getElementsByTagName("liupdate")[0].childNodes[0].nodeValue;
  		var barwidth = xmlDoc.getElementsByTagName("barwidth")[0].childNodes[0].nodeValue;
  		var barinfo = xmlDoc.getElementsByTagName("barinfo")[0].childNodes[0].nodeValue;
  		var currating = xmlDoc.getElementsByTagName("currating")[0].childNodes[0].nodeValue;
  		var theUL = document.getElementById('unit_ul'+id); // the UL
		theUL.innerHTML = '<ul id="unit_ul'+id+'" class="unit-rating" style="width:'+barwidth+'px;"><li class="current-rating" style="width:'+currating+'px;"></li></ul>';	
  	} else {
  		setTimeout('showresponserating('+id+')', 500);
 	}
	return false;
}

function check(checkbox) {
	document.getElementById("products_selected").value = "";
	
	//nowchecked = document.getElementById(checkbox.value);
	
	/*if(checkbox.checked == true) {
		nowchecked.checked=true;
	} else {
		nowchecked.checked=false;
	}*/
	
	var selectedprodsarray = new Array();
	var count;
	for(var i=0; i < document.storeform.selectedprods.length; i++){
		if(document.storeform.selectedprods[i].checked)
		selectedprodsarray[i]=document.storeform.selectedprods[i].value;
	}
	
	for (count in selectedprodsarray) {
		document.getElementById("products_selected").value += selectedprodsarray[count] + ",";
	}
	
	return false;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


if(window.addEventListener) // Onload for Mozilla, Netscape, Firefox
	  window.onload=shoppingcart_content();
if (window.attachEvent) // Onload for IE, Opera, Safari
	window.attachEvent("onload", shoppingcart_content); 
   