function setOptionSelected(opt_name, new_opt_id) {
	
	person_country_hidden = document.getElementById('person_country_hidden');
	if (person_country_hidden) {
		document.getElementById('person_country_hidden').value=new_opt_id;	
	}


	if (document.getElementById(opt_name)) {
		var opt = document.getElementById(opt_name).options;
	
		for (i=0;i<opt.length;i++) {
	
			if (opt[i].value == new_opt_id) {
				 opt[i].selected = true;
				 return;
			}
		}
	}
}

//--------------------------------------------
  var QueryString = new Array();
  QueryString["_"]="";

  function unspace(qs_element)
  {
  return qs_element.split( '+' ).join( ' ' );
  }

  if ( location.search.length > 1 ) {
  var qs_query = location.search.substring( 1, location.search.length );
  var qs_pairs = qs_query.split( '&' );
  for ( var qs_index = 0; qs_index < qs_pairs.length; qs_index++ )
  {
  var qs_element = qs_pairs[qs_index].split( '=' );
  QueryString[qs_element[0]] = unspace( unescape( qs_element[1] ) );
  }
 }
//--------------------------------------------
//Usage:  var myVar = QueryString["parameter"];

function isValidEmail(field)
{
  var re = new RegExp("^(([a-zA-Z0-9\._-]+)\@([^\.]+)\.(.+))");
  if (field.value == "-") isValid = true;
  //else var isValid = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
   else var isValid = field.value.match(re);
  if (!isValid)
  {
	/*alert(not_valid_email_variable);
	field.focus();
	field.select();*/
	return false;
  }
  else
  {
	 return true;
  }
}

function addProductToCart(form_id,tab_id){

	openBinPopup(tab_id);
	addToBin(form_id);

}

/* functions which are necessary for product ordering */
function openBinPopup(tab_id){

	w=window.open("?action=check_continue&tab="+tab_id+"", "BinInfo", "toolbar=no,width=250,height=200,directories=no,status=no,scrollbars=no, resizable=yes, menubar=no, location=no");
}
function addToBin(form_id) {
	document.forms[form_id].submit();
}

var elem_name = "quickorder_block";
function pageStatus() {

	document.getElementById('is_loaded').value=1;

	setInterval( 'blink_( elem_name )', 500 );
}

/*
function checkout(tab_id){
	window.opener.location='?action=order&tab='+tab_id+'';
}
*/

function recalculateBin(mode){
	document.getElementById('update_data').value=1;
	orderNextStep(mode);
}
/**
* deleting product from shopping cart
*/
function removeFromBin(product_id){

	document.getElementById('remove_product_id').value=product_id;
	document.forms['bin'].submit();
}

function orderNextStep(mode){
//alert('Order next step');
//alert(mode)
if (mode == 2) {
//	alert(document.getElementById('order_address_block'));
	if (document.getElementById('order_address_block') == '[object]') {
	if (document.getElementById('order_address_block').style.display == 'none') {
		document.getElementById('check_person').value=1;

	}else{
		document.getElementById('check_person').value=0;

	}
	}
	//alert('check person is :'+document.getElementById('check_person').value);

}
	document.getElementById('order_step').value=mode;
	//alert(document.getElementById('order_step'));
document.forms['bin'].submit();
}

function orderNextStepAbo(mode)
{
document.forms['abo_order_form'].submit();
}


function orderSubmode(submode, mode, cid){
//	alert(cid);

	document.getElementById('new_country_id').value=cid;
	//alert(document.getElementById('new_country_id'));
	//alert(cid);
	document.getElementById('order_step').value=mode;
	document.getElementById('submode').value=submode;
	document.forms['bin'].submit();
}
function openAdd(mode, action)
{
//    wnd = window.open("?PHPSESSID="+document.forms.data.PHPSESSID.value+"&mode=addAddr", "addAddr", "toolbar=no,width=420,height=300,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no");
	 wnd = window.open("?action=address&mode="+mode+"&last_action="+action, "addAddr", "toolbar=no,width=420,height=390,directories=no,status=no,scrollbars=no,resizable=no,menubar=no");
}

function changeDelivery(mode, action)
{
	if (action == 'seminar_order')
	{
		document.getElementById('submode').value='change_delivery';
		document.seminar_order_form.submit();
	}
	else if (action == 'abo')
	{
		document.getElementById('submode').value='change_delivery';
		document.abo_order_form.submit();
	}
	else
	{
		document.getElementById('update_data').value=1;
		orderNextStep(mode);
	}
}

function changePayment(mode, action)
{
	if (action == 'seminar_order')
	{
		document.getElementById('submode').value='change_payment';
		document.seminar_order_form.submit();
	}
	else if (action == 'abo')
	{
		document.getElementById('submode').value='change_payment';
		document.abo_order_form.submit();
	}
	else
	{
		document.getElementById('update_data').value=1;
		orderNextStep(mode);
	}
}
/* ^^^ */


function editIc($var_name)
{
	// window.location='admins/?action=ic_var_edit&sub_action=edit_var&name='+$var_name;
	newWindow = window.open('admins/?action=ic_var_edit&sub_action=edit_var&name='+$var_name, "subWind", "HEIGHT=400,WIDTH=880,statusbar,menubar,toolbar,scrollbars,resizable");
	newWindow.focus();
}

function ShowGalleryImage($image)
{
	var win=window.open( $image, "aaa", "width=480,height=480,resizable=yes,scrolling=yes");
	win.focus();
}

function fullScreen()
{
 url = "?action=full_screen";
 var winFull = window.open( url, "winFullScreen", "width="+ screen.width +",height="+ screen.height +",resizable" );
 winFull.focus();
}
function fullScreenClose() {
	//alert('close');
	window.close();
}

function newWin(url, width, height) {
	var winNew = window.open( url, "winFullScreen", "width="+ width +",height="+ height +",resizable,scrolling,scrollbars" );
 	winNew.focus();
}

function popup_text(title, text, width, height, charset) {
	var win = window.open("", "popup", "width="+ width +",height="+ height +",location=no,menubar=no,resizable=yes,scrolling=yes,scrollbars=yes" );
	doc=win.document;
	doc.writeln('<html><head><title>'+title+'</title>');
	if (charset!=undefined) doc.writeln('<meta http-equiv="content-type" content="text/html; charset='+charset+'" />');
	doc.writeln('<link rel="stylesheet" type="text/css" href="css/style.css" /><link rel="shortcut icon" href="favicon.ico"></head><body>');
	doc.writeln(text);
	doc.writeln('</body></html>');
	doc.close();
 	win.focus();
}

var spaces = " \t\r\n"+String.fromCharCode(160);

function isSpaceCharacter(ch) {
  return spaces.indexOf(ch) >-1;
}

function trim(str) {
   var s = new String(str);

   while (s.length>0 && isSpaceCharacter("" + s.charAt(s.length-1))) {
	 s = s.substring(0,s.length-1);
   }

   while (s.length>0 && isSpaceCharacter(""+s.charAt(0))){
	 s = s.substring(1);
   }

   return s
 }


function isEmpty(elem){
  return trim(elem.value).length==0;
}

function blink( elem_name )
{
	//var elem = document.getElementById( elem_name);
	setInterval( 'blink_( elem_name )', 1500 );
}
function blink_(el)
{
	var element1 = document.getElementById( elem_name+'1' );
	var element2 = document.getElementById( elem_name+'2' );
	//alert(document.getElementById( elem_name+'2' ));
	if (document.getElementById(elem_name + '2') != null) {
		if (element2.style.visibility == "hidden") {
			element2.style.visibility = "visible";
			element1.style.visibility = "hidden";
		}
		else {
			element2.style.visibility = "hidden";
			element1.style.visibility = "visible";
		}
	}
}

function flashPopup(id){
	window.open("?action=video&id="+id, "", "toolbar=no,width=715,height=395,directories=no,status=no,scrollbars=no, resizable=yes, menubar=no, location=no");

}