var http = getXmlHttpObject();
var http_request= false; 
var wheretoreplace="rajax1";
var aux_ele="";
function changetext(id, newText) { //normmy function
	var elemento=document.getElementById(id);
	if(elemento)
	{
	elemento.innerHTML=newText;
	}
}
function handleHttpResponse()
{
//alert(wheretoreplace);
    if (http.readyState == 1)
    {
        document.getElementById(wheretoreplace).innerHTML = '<img src="images/loading.gif" alt="please wait...">';
    }
    if (http.readyState == 4)
    {	
        results = http.responseText;
        document.getElementById(wheretoreplace).innerHTML = results;
		if(wheretoreplace=="rajax1"||aux_ele!="")
		{	
			finishfunction();
		}
		//imagelunch();
    }
}

function sendQuerystring(div,pagina)
{
    wheretoreplace=div;
	//alert(wheretoreplace);
    http.open("GET", "auxfiles/" + pagina, true);
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
}
function getXmlHttpObject()
{
    var xmlhttp;

    /*@cc_on
    @if (@_jscript_version >= 5)
    try{
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
    try{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e){
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
        try{
            xmlhttp = new XMLHttpRequest();
        }
        catch (e){
            xmlhttp = false;
        }
    }
    return xmlhttp;
}
// method to send by post

   
   function makePOSTRequest(url, parameters,div) {
   wheretoreplace=div;
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
	

   function alertContents() {
      if (http_request.readyState == 4) 
	  {
         if (http_request.status == 200) 
		 {
            //alert(http.responseText);
            result = http_request.responseText;
            document.getElementById(wheretoreplace).innerHTML = result; 
			review_search();
         } else 
		 {
            alert('There was a problem with the request.');
         } 
       }
     if(http_request.readyState == 1)
	{
		document.getElementById(wheretoreplace).innerHTML = '<img src="images/loading.gif" alt="please wait...">';
	}
     
   }


   
    function get_edit(id,team) 
	{
      var question= "naam=" + getval("member_naam") +"&email=" + getval("member_email");
      makePOSTRequest("include/team_members.php?edit="+id+"&teamm="+team, question);
   }
   
   function getval(id)
   {
	var elemento=document.getElementById(id);
	if(elemento)
	{
	      return encodeURI(elemento.value);
	}else
	{
	      return "";
	}
   }
   
   function submit_form(id)
   {
	var elemento=document.getElementById(id);
	if(elemento)
	{
	      elemento.submit();
	}   
   }

   function send_test_mail(id)
   {
	var elemento=document.getElementById(id);
	if(elemento)
	{    
		if(checkEmail(elemento))
			sendQuerystring("rajax1",'test_mail.php?remote=1&mail='+elemento.value);		
		else
			alert('Please insert a valid mail');
	}   
   }

//*** functions made to show all content for  products

<!--
function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}
//-->
function _search()
{
     var poststr = "s_merk=" + getval("s_merk") + "&prod_name=" + getval("prod_name") +	"&prod_desc=" + getval("prod_desc")+ "&prod_range=" + getval("prod_range")+ "&prod_range2=" + getval("prod_range2");
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list.php?'+ poststr);
}
function _search1()
{
     var poststr = "s_merk=" + getval("s_merk") + "&prod_name=" + getval("prod_name") +	"&prod_desc=" + getval("prod_desc")+ "&prod_range=" + getval("prod_range")+ "&prod_range2=" + getval("prod_range2");
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list_all.php?'+ poststr);
}
function _search2(option)
{
     var poststr = "s_merk=" + option;
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list.php?'+ poststr);
}
function _search3(option)
{
     var poststr = "ofert=1";
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list_all.php?'+ poststr);
}
/*
new 18/12/2008
*/
function _search4()
{
     var poststr = "NewItem=1";
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list_all.php?'+ poststr);
}

function _search5(option)
{
     var poststr = "prod_range=" + option;
	 var search_flag=document.getElementById('search_flag');
	 search_flag.value=poststr;
     sendQuerystring("content-inner",'product_list.php?'+ poststr);
}

function login() 
{
      var question= "login=" + getval("username") +"&password=" + getval("userpass");
      makePOSTRequest("auxfiles/login.php?login=1", question,'form-login');
}
function review_search()
{
		
	var loged=getval('notlogin'); //verificamos si hizo el login
	if(loged!=0)
	{
		//var search_options=getval('search_flag');
		//if(search_options!='0')
			sendQuerystring("content-inner",'get_page.php?mc='+loged);
	}
	
}

function handleHttpResponse_category()
{
	 var cat_combo=document.getElementById('prod_range');
	 var searchbutton=document.getElementById('searchSubmit');
		var value_aux="";
    if (http.readyState == 4)
    {	
        results = http.responseText;
		var arr_results=results.split(";;");
		cat_combo.options.length = 0;
/*		var option_element= new Option('Alle', '-1',true,true);
		cat_combo.options[0] =option_element; */
		
		for(var ic=0;ic<arr_results.length;ic++)
		{
			if(ic==0)
				option_element= new Option(arr_results[ic], '-1',true,true);
			else
				option_element= new Option(arr_results[ic], arr_results[ic],false);
				cat_combo.options[ic] =option_element;
		} 
		
    }
	searchbutton.disabled=false;
}

function handleHttpResponse_category2()
{
	 var cat_combo2=document.getElementById('prod_range2');
	 var searchbutton=document.getElementById('searchSubmit');
		var value_aux="";
    if (http.readyState == 4)
    {	
        results = http.responseText;
		var arr_results=results.split(";;");
		cat_combo2.options.length = 0;
/*		var option_element= new Option('Alle', '-1',true,true);
		cat_combo.options[0] =option_element; */
		
		for(var ic=0;ic<arr_results.length;ic++)
		{
			if(ic==0)
				option_element= new Option(arr_results[ic], '-1',true,true);
			else
				option_element= new Option(arr_results[ic], arr_results[ic],false);
				cat_combo2.options[ic] =option_element;
		} 
		
    }
	searchbutton.disabled=false;
}

function fill_sub(valor)
{
	//alert(wheretoreplace);
    http.open("GET", "auxfiles/cat_list.php?merk=" + valor, true);
    http.onreadystatechange = handleHttpResponse_category;
    http.send(null);
	 var searchbutton=document.getElementById('searchSubmit');
	searchbutton.disabled=true;
}
function fill_sub2(valor)
{
	//alert(wheretoreplace);
    http.open("GET", "auxfiles/cat_list2.php?merk=" + valor, true);
    http.onreadystatechange = handleHttpResponse_category2;
    http.send(null);
	 var searchbutton=document.getElementById('searchSubmit');
	searchbutton.disabled=true;
}
var idSC='0';
function add_sc(id)
{
	idSC=id;
	 var cantidad=document.getElementById('amount'+id);
     var imagen=document.getElementById('prodim'+id);
	 if(cantidad.value>0&&cantidad.value!='')
	 {
		imagen.className=''; 
	 }else
	 {
 		imagen.className='hidediv'; 
	 }
 	sendQuerystringsc('SCammount','sc.php?cod_sc='+id+'&amo_sc='+cantidad.value);
}

function sendQuerystringsc(div,pagina)
{
		
    wheretoreplace=div;
	//alert(wheretoreplace);
    http.open("GET", "auxfiles/" + pagina, true);
    http.onreadystatechange = handleHttpResponseSC;
    http.send(null);
}
function handleHttpResponseSC()
{
//alert(wheretoreplace);
	identity=MM_findObj('productst'+idSC);
    if (http.readyState == 1)
    {
		if(identity)
		{
			identity.className='SCactived'; 	
			
		}
		
        document.getElementById(wheretoreplace).innerHTML = '<img src="images/loading.gif" alt="please wait...">';
    }
    if (http.readyState == 4)
    {	
		if(identity)
		{
			identity.className=''; 	
		}
        results = http.responseText;
        document.getElementById(wheretoreplace).innerHTML = results;
		if(wheretoreplace=="rajax1"||aux_ele!="")
		{	
			finishfunction();
		}
    }
}
function settocero(id)
{
	 var cantidad=document.getElementById('amount'+id);
	 cantidad.value="";
}
var elemento=0;
function changepic()
{
	var imagen=document.getElementById('img2');
	if(imagen)
		if(elemento==0)
		{
			imagen.src="files/images/ccaa35308.jpg";
			elemento=1;
			}
		else
		{
			imagen.src="files/images/ccaa30011.jpg";
			elemento=0;
		}
}
function imagelunch()
{
	 var imagen=document.getElementById('img2');
		if(imagen)
		{
			//setInterval("changepic()",2000);
		}
}
function loadimages()
{
	
	var imagenescod=document.getElementById('imagenescod');
	 if(imagenesprod)
	 {
 		var arr_results=imagenescod.value.split(";");
		for(var ic=0;ic<arr_results.length;ic++)
		{
			loadimages(arr_results[ic]);
		}
	 }
	
	}
