function xmlhttpPost(strURL, idx, p) 
{
	var xmlHttpReq = false;
  var self = this;
  
  
  if (window.XMLHttpRequest) 
  {
      self.xmlHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) 
  {
      self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  self.xmlHttpReq.open('POST', strURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

  self.xmlHttpReq.onreadystatechange = function() 
  {
      if (self.xmlHttpReq.readyState == 4) 
      {
      	updatepage(self.xmlHttpReq.responseText, idx);
      }
  }
  
  self.xmlHttpReq.send(getquerystring(idx, p));
}

function getquerystring(idx, p)
{
	if(idx=="order")
	{
		var IE = document.all ? true : false
		
		if (!IE) 
			document.captureEvents(Event.MOUSEMOVE)
		
		var tempX = 0;
		var tempY = 0;
		
		
	  if (IE) 
	  {
	    tempX = event.clientX + document.documentElement.scrollLeft;
	    tempY = event.clientY + document.documentElement.scrollTop;
	  } 
	  else 
	  {
	    tempY = 500 + document.documentElement.scrollTop;
	  }  
	  
	  if (tempX < 0){tempX = 0}
	  if (tempY < 0){tempY = 0}  
	  
	  var margin_top = (tempY-50)+'px';
	  var margin = margin_top+" 0px 0px 400px";
	  
//		document.getElementById("popup1").style.margin = margin;
//		document.getElementById('popup1').style.visibility='visible';
//		document.getElementById("middletd").className='tdalpha';
//alert('dddd');
		qstr = 'x1=' + escape(p);
	}
	
	if(idx=="select_region")
	{
		document.getElementById('ann_city_id').innerHTML = "<center><img src='/images/loading.gif' alt='' /></center>";
		reg_id = document.getElementById("country_id").value;
		
		qstr = 'reg_id=' + escape(reg_id) + '&lang_code=' + p;
		
	}
	
	
	
	return qstr;
}

function updatepage(str, idx)
{
	if(idx == "select_region")
	{
		document.getElementById('ann_city_id').innerHTML = str;
	}
		
	if(idx == "order")
	{
//		document.getElementById('popup1').style.visibility='hidden';
//		document.getElementById("middletd").className='tdnonalpha';
		document.getElementById("basket_count").innerHTML=str;
	}
}

function ShowCode(prod)
{
		if(prod=='all')
		{
			document.getElementById('show_code_c').style.display='block';
			
			var ids_arr = document.getElementById("regions_id").value.split('***');
			
			if(ids_arr[1].length<2)
			var st = "0"+ids_arr[1];
			else st = ids_arr[1];
			
			if(document.getElementById("pcat_id").value.length<2)
			var mt = "0"+document.getElementById("pcat_id").value;
			else mt = document.getElementById("pcat_id").value;
			
			document.getElementById('show_code').innerHTML = st+''+mt;
		}
		//qstr = 'reg_id=' + escape(reg_id) + '&lang_code=' + p;
}

function fillProducts1(value,lng)
{
	//alert(value+'*'+lng);
	 var notice = $('ProductBoxes');
	 notice.innerHTML ='Loading..';
	 var ids_arr = value.split('***');
	URL = '/ajax/ProductCodes.php?regions_id='+ids_arr[0]+"&regions_code="+ids_arr[1]+"&lang="+lng+'&chk='+Math.random();
	new Ajax.Request(URL, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('ProductBoxes');
	  //  alert(transport.responseText);
	   var ids_arr = transport.responseText.split('***');
	    notice.innerHTML = ids_arr[0];
					
	  }
	
	});

	
}

var is_opera = /opera\/9/i.test(navigator.userAgent);
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);

function setCVisibleProd3(prod)
{
	document.getElementById(prod).style.visibility='visible';
	
}
 
function setCHiddenProd(prod)
{
	javascript:document.getElementById(prod).style.visibility='hidden';
}


function Clickheretoprint()
{
		var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,resizable=yes,"; 
		    disp_setting+="scrollbars=yes,width=750, height=600, left=100, top=25"; 
		var content_vlue = document.getElementById("print_content").innerHTML; 
		var fact_bot = document.getElementById("fact_bot").value; 
		
		var docprint=window.open("","",disp_setting);
			docprint.document.open(); 
			docprint.document.write('<html><head><title></title><style> input { display:none; } body,td{font-size:10px} </style>');
			docprint.document.write('</head><body onLoad="self.print()">');
			docprint.document.write('<div><img src="/images/logo_adm.gif" alt="" width="160"></div><center>');
			docprint.document.write(content_vlue);
			docprint.document.write('<br><br><br><div>');
			docprint.document.write(fact_bot);
			docprint.document.write('</div></center></body></html>'); 
			//docprint.document.getElementById("datadiv").style.display='block'; 
			//docprint.document.getElementById("statustd").style.display='none'; 
			docprint.document.close(); 
			docprint.focus(); 
}
function checkVotingForm()
{
	var checked = 0;
	var val = document.voting_form.voting;
	for (i=0; i<val.length; i++)
	{
		if(val[i].checked) 
			checked = 1;
	}
	
	if(document.getElementById('vote_text').value.length > 10 && checked)
		return true;
	else
	{
		document.getElementById('popup8').style.visibility = 'visible';
		return false;
	}
}
function basketDelivery()
{
	var price = parseInt(document.getElementById("countries_sel").value);
	var total = parseInt(document.getElementById("total_id").value);
	document.getElementById("delprice_td").innerHTML = price;
	document.getElementById("totalprice_td").innerHTML = total+price;
}
function checkAll(formName)
{
	for(i=0;i<document.forms[formName].elements.length;i++)
	{
		if(document.forms[formName].chkall.checked)
			document.forms[formName].elements[i].checked=true;
		else
			document.forms[formName].elements[i].checked=false;
	}
}	

function compare_prod(alert_text, lang_code)
{
	var formName = 'prod_list';
	var id_str = '';
	var count = 0;
	document.getElementById('id_s').value = '';
	
	for(i=0;i<document.forms[formName].elements.length;i++)
	{
		if(document.forms[formName].elements[i].checked && document.forms[formName].elements[i].value > 0)
		{
			count++;
			id_str += document.forms[formName].elements[i].value+';';
		}
	}
	
	if(count > 1)
	{
		document.getElementById('id_s').value = id_str;
		window.open('/compare.php?id_s='+id_str+lang_code, 'compare', 'width=800,height=600,scrollbars=yes,location=no,resizable=yes');
	}
	else alert(alert_text);

	return false;
}
function view_attr(id)
{
	var ids = document.getElementById('ids').value;
	ids = ids.substr(3);
	var ids_arr = ids.split('***');
	
	for(var i=0; i<ids_arr.length; i++)
		document.getElementById('popup'+ids_arr[i]).style.display='none';
	
	document.getElementById('popup'+id).style.display='block';

	return false;
}

var chooseCategoryText = "Choose category here";

function loadComboByQuery( strQuery, comboId, selectedId, query2 )
{
	reqUrl =  '/ajax/ajaxQuery.php?query=' + strQuery;
	
	if( query2 != null )
	{
		reqUrl += '&query2=' + query2;
	}
	
	
	
	new Ajax.Request(  reqUrl , 
	{
		method: 'get',

		onSuccess: function(transport) 
	  	{
	  		// FIRST ROW - Choose category here
  			//$(comboId).options.length=1;
  			$(comboId).innerHTML= '';
  			var option = new Option( chooseCategoryText, 0,  ( ! selectedId ) ? 1 : 0 );
			$(comboId).options[0] = option;
			/// END OF FIRST ROW

	  		var longstring= transport.responseText;
			var brokenstring = longstring.split( "\r\n");

			var arrLength = brokenstring.length;

			var optG;
			
			//var asdf = '';
			var selectedInd = 0;
			var currSelectableIndex = 1;
						
			for( var i = 0; i < arrLength; i += 1 )
			{
				
				try
				{
					var dblBrokenString = brokenstring[i].split( ";,;");

					if( query2 == null )
					{
						
						var option = new Option(dblBrokenString[1], dblBrokenString[0] );
						
						
						//asdf += selectedId + ' ' + dblBrokenString[0] + ' ';
						
						if ( selectedId == dblBrokenString[0] )
						{
							selectedInd = currSelectableIndex;
						}
						
						 $(comboId).options[i + 1] = option;
						 
						 currSelectableIndex += 1;
					}
					else
					{
						//alert(selectedId);
					
						if( dblBrokenString[2] > 0 ) // optgroup
						{
							
							optG = document.createElement("optgroup");
							optG.label = dblBrokenString[1];
							
							$(comboId).appendChild(optG); //// ????
						}
						else // option
						{
							var option = new Option(dblBrokenString[1], dblBrokenString[0] );
							option.value = dblBrokenString[0];
							option.innerText = dblBrokenString[1];
							if(selectedId == dblBrokenString[0])
							{
								option.selected = true;
								selectedInd = currSelectableIndex;
							}
							optG.appendChild( option );
							
							currSelectableIndex += 1;
						}
					}
				}
				catch(e)
				{
					//alert(e.message);
				}
			}
			
			$(comboId).selectedIndex = selectedInd;
			
			if( selectedInd > 0 )
			{
				
				document.getElementById(comboId).onchange();
				//alert('aaa');
				//loadComboByQuery('SELECT brand_id AS id, brand_name AS name FROM brand WHERE brand_pid = 0  ', 'subBrand', 0) ;
			}
			
			
			
			
	  	}
	});
}

function setCookie(name, value, expDays) 
{
	
	var exp = new Date();     //set new date object
	var exp2 = new Date();     //set new date object
	if( expDays != null )
	{
		exp.setTime( exp.getTime() + (1000 * 60 * 60 * 24 * expDays) );
		exp2.setTime( exp.getTime() - 20000 );
		
	}
	document.cookie = name + "=" + escape(value) + "; path=/" + ((expDays == null) ? "" : "; expires=" + exp2.toGMTString() );
	document.cookie = name + "=" + escape(value) + "; path=/" + ((expDays == null) ? "" : "; expires=" + exp.toGMTString() );
	
}

function loadUrlToBlock( urlToLoad, divId, param1, param2, param3, param3 )
{
	//URL = 'http://www.google.com/search?q=Prototype';
	new Ajax.Request(  urlToLoad  , 
	{

  	method: 'get',

	  	onSuccess: function(transport) 
	  	{
	  		$(divId).innerHTML = transport.responseText;
	  	}
	});
}

function disableCombo( comboId )
{
	$(comboId).innerHTML= '';
  	var option = new Option( chooseCategoryText, 0,  0 );
	$(comboId).options[0] = option;
	$(comboId).disabled = 1;
}

function enableCombo( comboId )
{
	$(comboId).disabled = 0;
}

function brandComboChanged( selectedId )
{
	if( $('brandCombo').value > 0 )
	{ 
		loadComboByQuery('SELECT brand_id AS id, brand_name AS name FROM brand WHERE brand_pid = ' + $('brandCombo').value , 'subBrand', selectedId, 'SELECT brand_id AS id, brand_name AS name FROM brand WHERE 1 ');  
		enableCombo('subBrand'); 
	}
	else  
	{
		disableCombo('subBrand');
	}
	disableCombo('subSubBrand');
	setCookie('brandCombo', $('brandCombo').value, 100); 
}

function subBrandChanged( selectedId )
{
	if( $('subBrand').value > 0 )
	{
		loadComboByQuery('SELECT brand_id AS id, brand_name AS name FROM brand WHERE brand_pid = ' + $('subBrand').value , 'subSubBrand', selectedId, 'SELECT brand_id AS id, brand_name AS name FROM brand WHERE 1 ');   
		enableCombo('subSubBrand');
	}
	else
	{
		disableCombo('subSubBrand');
	}
	
	setCookie('subBrand', $('subBrand').value, 100);
}

function subSubBrandChanged( selectedId )
{
	setCookie('subSubBrand', $('subSubBrand').value, 100);
	
	if( $('subSubBrand').value > 0 )
	{
		$('getCatsLink').disabled = false;
	}
	else
	{
		$('getCatsLink').disabled = true;
	}
}

function addToFavorites(id, msg)
{
	
	var favCookie = getCookie( 'fav' );
	if( favCookie == null )
		favCookie = ';';
	
	favCookie += id + ';';

	setCookie('fav', favCookie, 100 ) ;
	
	alert(msg);
}

function removeFav(id, msg)
{
	var favCookie = getCookie( 'fav' );
	if( favCookie == null )
		favCookie = ';';
	
	favCookie = favCookie.replace( ';' + id + ';',  ';');

	setCookie('fav', favCookie, 100 ) ;
	
	//document.location.href = document.location.href; //alert(msg);
	//window.location.href=window.location.href;
	window.location.reload();
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}



function changeTestmonial() 
{
	$('myTestmonial').request({

  onComplete: function(transport){ 
//  	alert(transport.responseText);
  	if( transport.responseText.substr(0, 18)  ==  "<!--testimonial-->" )
  	{
  		$("myTestmonialContainer").innerHTML = transport.responseText;
  	}
  }

});
	setTimeout( "changeTestmonial()", 20*1000);
}


function fillProducts(value,lng)
{
	//alert(value+'*'+lng);
	 var notice = $('ProductBoxes');
	 notice.innerHTML ='Loading..';
	URL = '/ajax/ProductOrPricesFiller.php?filling=products&market_id='+value+"&lang="+lng+'&chk='+Math.random();
	new Ajax.Request(URL, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('ProductBoxes');
	  //  alert(transport.responseText);
	    notice.innerHTML = transport.responseText;
					
	  }
	
	});

	
}




function fillPrices(value,lng)
{
		
	//alert(value+'*'+lng);
	 var notice = $('PriceBoxes');
	 notice.innerHTML ='Loading..';
	URL = '/ajax/ProductOrPricesFiller.php?filling=prices&price_id='+value+"&lang="+lng+'&chk='+Math.random();
	new Ajax.Request(URL, {
	  method: 'get',
	  onSuccess: function(transport) {
	    var notice = $('PriceBoxes');
	 //   alert(transport.responseText);
	    notice.innerHTML = transport.responseText;
					
	  }
	
	});
}

function SetDisable(id1)
{
	if(document.getElementById('competitive_id').checked===true)
	{
		document.getElementById(id1).disabled = true
	}
	else{
		document.getElementById(id1).disabled = false
	}
}

/*function ShowCode(prod)
{
		if(prod=='all')
		{
			document.getElementById('show_code_c').style.display='block';
			
			
			if(document.getElementById("regions_id").value.length<2)
			var st = "0"+document.getElementById("regions_id").value;
			else st = document.getElementById("regions_id").value;
			
			if(document.getElementById("pcat_id").value.length<2)
			var mt = "0"+document.getElementById("pcat_id").value;
			else mt = document.getElementById("pcat_id").value;
			
			document.getElementById('show_code').innerHTML = st+''+mt;
		}
		//qstr = 'reg_id=' + escape(reg_id) + '&lang_code=' + p;
}*/