// begin of init httpresponse
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
  	nm=args[i+1]; 
	test=args[i+2]; 
	val=MM_findObj(args[i]);
    if (val) { 
	 if ((val=val.value)!="") {
	  if (test == 'C') {
		if (val == 0) errors += '- '+nm+' is required.\n'; 
	  } else if (test.indexOf('isEmail')!=-1) { 
	  	p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { 
	    num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) {
		  p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; 
	}
  }
  if (MM_findObj('password_form')) {
    var password_form = MM_findObj('password_form').value;
    if ((password_form.length < 6) && (password_form.length != 0)) {
      errors+='- Password must be more 6 symbols.\n';
    }
  }
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function add_new_tag(type) {
	var count_list_tag = document.getElementById('count_list_tag').value;
		count_list_tag = parseInt(count_list_tag)+1;
	if (type == 'add') {
		if (document.getElementById('name_tag'+count_list_tag)) {
			document.getElementById('tagId'+count_list_tag).style.display = 'block';
			document.getElementById('name_tag'+count_list_tag).disabled = false;
			//document.getElementById('name_tag'+count_list_tag).value = '';
			document.getElementById('tag'+count_list_tag).disabled = false;
			//document.getElementById('tag'+count_list_tag).value = '';			
		} else {
			var div = document.createElement("div");
				div.id = "tagId"+count_list_tag;
				div.style.display = "block";
				div.style.padding = "2px 0";
			document.getElementById('list_tag').appendChild(div);
			var input = document.createElement("input");
				input.type = "text";
				input.name = "name_tag"+count_list_tag;
				input.id = "name_tag"+count_list_tag;
				input.style.width = "25%";
				input.style.margin = "0 10px 0 0";
			document.getElementById('tagId'+count_list_tag).appendChild(input);
			var input = document.createElement("input");
				input.type = "text";
				input.name = "tag"+count_list_tag;
				input.id = "tag"+count_list_tag;
				input.style.width = "65%";
			document.getElementById('tagId'+count_list_tag).appendChild(input);
			var input = document.createElement("input");
				input.type = "hidden";
				input.name = "product_tag"+count_list_tag;
				input.id = "product_tag"+count_list_tag;
			document.getElementById('tagId'+count_list_tag).appendChild(input);
		}
		document.getElementById('count_list_tag').value = count_list_tag;
	} else if ((type == 'del') && (count_list_tag != 1)) {
		document.getElementById('tagId'+(count_list_tag-1)).style.display = 'none';
		document.getElementById('name_tag'+(count_list_tag-1)).disabled = true;
		document.getElementById('tag'+(count_list_tag-1)).disabled = true;
		document.getElementById('count_list_tag').value = count_list_tag - 2;
	}
}

function add_prod_img(type) {
	var count_imgs	= document.getElementById('count_list_img').value;
	count_imgs = parseInt(count_imgs)+1;
	if (type == 'add') {
		if (count_imgs < 7) {
			var div = document.createElement("div");
				div.id = "imgId"+count_imgs;
				div.style.display = "block";
				div.style.padding = "2px 0";
				div.style.width = "100%";
			document.getElementById('list_img').appendChild(div);
			/*var input = document.createElement("input");
				input.type = "file";
				input.name = "img_file"+count_imgs;
				input.id = "img_file"+count_imgs;
				input.style.width = "25%";
				input.style.margin = "0 10px 0 0";*/
			//document.getElementById('imgId'+count_imgs).appendChild(input);
			//var input = document.createElement("input");
			//	input.type = "hidden";
			//	input.name = "images_tag"+count_imgs;
			//	input.id = "images_tag"+count_imgs;
			//document.getElementById('imgId'+count_imgs).appendChild(input);
			document.getElementById('count_list_img').value = count_imgs;
		}
	} else if ((type == 'del') && (count_imgs != 1)) {
		document.getElementById('list_img').removeChild(document.getElementById('imgId'+(count_imgs-1)));
		document.getElementById('count_list_img').value = count_imgs - 2;
	}	
}

function add_prod_img2(type) {
	var count_imgs	= document.getElementById('count_list_img').value;
	count_imgs = parseInt(count_imgs)+1;
	if (type == 'add') {
		if (count_imgs < 7) {
			var div = document.createElement("div");
				div.id = "imgId"+count_imgs;
				div.style.display = "block";
				div.style.padding = "2px 0";
				div.style.width = "100%";
			document.getElementById('list_img').appendChild(div);
			var input = document.createElement("input");
				input.type = "file";
				input.name = "img_file"+count_imgs;
				input.id = "img_file"+count_imgs;
				input.style.width = "25%";
				input.style.margin = "0 10px 0 0";
			document.getElementById('imgId'+count_imgs).appendChild(input);
			//var input = document.createElement("input");
			//	input.type = "hidden";
			//	input.name = "images_tag"+count_imgs;
			//	input.id = "images_tag"+count_imgs;
			//document.getElementById('imgId'+count_imgs).appendChild(input);
			document.getElementById('count_list_img').value = count_imgs;
		}
	} else if ((type == 'del') && (count_imgs != 1)) {
		document.getElementById('list_img').removeChild(document.getElementById('imgId'+(count_imgs-1)));
		document.getElementById('count_list_img').value = count_imgs - 2;
	}	
}

function check_list_votes(votes_id) {
	jQuery('#'+votes_id).slideToggle();
}

function votes_var(type) {
	var count_votes_var = document.getElementById('count_votes_var').value;
	count_votes_var = parseInt(count_votes_var)+1;
	if (type == 'add') {
		if (document.getElementById('div_votes_var'+count_votes_var)) {
			document.getElementById('div_votes_var'+count_votes_var).style.display = 'block';
			document.getElementById('votes_var'+count_votes_var).disabled = false;
			document.getElementById('votes_var'+count_votes_var).value = '';
		} else {
			var div = document.createElement("div");
				div.id = "div_votes_var"+count_votes_var;
				div.style.display = "block";
				div.style.padding = "2px 0";
			document.getElementById('list_votes_var').appendChild(div);
			var input = document.createElement("input");
				input.type = "text";
				input.name = "votes_var"+count_votes_var;
				input.id = "votes_var"+count_votes_var;
				input.style.width = "90%";
				div.style.margin = "2px 0";
			document.getElementById('div_votes_var'+count_votes_var).appendChild(input);
			var input = document.createElement("input");
				input.type = "hidden";
				input.name = "votes_var_id"+count_votes_var;
				input.id = "votes_var_id"+count_votes_var;
			document.getElementById('div_votes_var'+count_votes_var).appendChild(input);
		}
		document.getElementById('count_votes_var').value = count_votes_var;
	} else if ((type == 'del') && (count_votes_var != 1)) {
		document.getElementById('div_votes_var'+(count_votes_var-1)).style.display = 'none';
		document.getElementById('votes_var'+(count_votes_var-1)).disabled = true;
		document.getElementById('count_votes_var').value = count_votes_var - 2;
	}
}  

function check_list_order(order_id) {
	jQuery('#'+order_id).slideToggle();
}

function checked_advanced_mode () {
	jQuery('#check_advanced_mode').slideToggle();
}
