	var http_request = false;   function makeRequest(url, parameters, div, showdomains,showto) {
      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;
      }
	  document.getElementById(div).innerHTML='<img src="images/ajax-loader.gif">';
	  http_request.onreadystatechange = function(){
	  	alertContents(url,div,parameters, showdomains,showto);
	  }	  
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }
var i;var j;   function alertContents(url,div,params, showdomains,showto) {		i=1;j=1;
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
		 	//alert(http_request.responseText);
				result = http_request.responseText;							if(url=='ajax.type_Articles.php'&&document.getElementById('Articles_value')){				console.log(params);				var key=params.split("&");				key=key[0];				console.log(key);				key=key.split("=");				key=key[1];				console.log(key);				if(key!=null){				console.log(key);				//document.getElementById('Articles_value').value=key;						}else{				//document.getElementById('Articles_value').value="";				}}				if(url=='ajax.type_News.php'&&document.getElementById('News_value')){				var key=params.split("&");				key=key[0];				key=key.split("=");				key=key[1];									if(key==null){								document.getElementById('News_value').value=key;				}}				if(url=='ajax.type_Photos.php'&&document.getElementById('Photos_value')){				var key=params.split("&");				key=key[0];				key=key.split("=");				key=key[1];				document.getElementById('Photos_value').value=key;				}				if(url=='ajax.type_Videos.php'&&document.getElementById('Videos_value')){				var key=params.split("&");				key=key[0];				key=key.split("=");				key=key[1];				document.getElementById('Videos_value').value=key;				}				if(url=='ajax.type_Wiki.php'&&document.getElementById('Wiki_value')){				var key=params.split("&");				key=key[0];				key=key.split("=");				key=key[1];				document.getElementById('Wiki_value').value=key;				}				
				if(url=='ajax.ads_update.php'){
					makeRequest('ajax.ads.php','?campaign='+document.getElementById('campaign_id').value+'&set='+document.getElementById('set_id').value+'&group='+document.getElementById('group_id').value,'div_ads');
				}	  				if(url=='ajax.delete.php'){					window.location='index.php';				}
								if (result != '') {
					if (url == 'ajax.traffic.php') {
						//break result up into html and javasript parts						result = result.replace('<!-- START Script Block for Chart MSLine1 -->','');
						result = result.replace('<!-- END Script Block for Chart MSLine1 -->','');
						result = result.split('<script type="text/javascript">');
						html = result[0];
						js = result[1];
						js = js.replace('</script>','');

						document.getElementById(div).innerHTML = html;
						eval(js);
					}
					else if(url == 'ajax.site_analysis.php'){
						result = result.split('<script type="text/javascript">');
						html = result[0];
						js = result[1];
						js = js.replace('</script>','');
						document.getElementById(div).innerHTML = html;
						eval(js);					
					}
					else {
						document.getElementById(div).innerHTML = result;
					}
				}
				if(showdomains=='false'&&showto=='false'){					document.getElementById(div).innerHTML = result;				}								if (showdomains == 'true') {					
					if (showto == 'true') {
						if (document.getElementById('group1_id').value != '0') {
							makeRequest('ajax.domains.php', '?showto=true&group=' + document.getElementById('group1_id').value, 'div1_domains');
						}
						else 
							if (document.getElementById('set1_id').value != '0') {
								makeRequest('ajax.domains.php', '?showto=true&set=' + document.getElementById('set1_id').value, 'div1_domains');
							}
							else 
								if (document.getElementById('campaign1_id').value != '0') {
									makeRequest('ajax.domains.php', '?showto=true&campaign=' + document.getElementById('campaign1_id').value, 'div1_domains');
								}
								else{
									document.getElementById('div1_sets').innerHTML="<input type='hidden' name='set1_id' id='set1_id' value='0'>";
									document.getElementById('div1_groups').innerHTML="<input type='hidden' name='group1_id' id='group1_id' value='0'>";
								}					
					}
					if(div=='main_sets'||div=='main_groups') {
						if (document.getElementById('group_id').value != '0') {
							makeRequest('ajax.domains.php', '?campaign=' + document.getElementById('campaign_id').value + 'set=' + document.getElementById('set_id').value + '&group=' + document.getElementById('group_id').value, 'div_domains');
						}
						else 
							if (document.getElementById('set_id').value != '0') {
								makeRequest('ajax.domains.php', '?campaign=' + document.getElementById('campaign_id').value + '&set=' + document.getElementById('set_id').value, 'div_domains');
							}
							else 
								if (document.getElementById('campaign_id').value != '0') {
									makeRequest('ajax.domains.php', '?campaign=' + document.getElementById('campaign_id').value, 'div_domains');
								}
					}
					
				}
				if (document.getElementById('group_id')&&document.getElementById('group_id').value != 0) {
					params = "?campaign=" + document.getElementById('campaign_id').value + "&set=" + document.getElementById('set_id').value + "&group=" + document.getElementById('group_id').value;
				}
				else if (div!='div1_groups'&&document.getElementById('set_id')&&document.getElementById('set_id').value != 0) {
					params = "?campaign=" + document.getElementById('campaign_id').value + "&set=" + document.getElementById('set_id').value;					
				}
				else if (document.getElementById('campaign_id')&&document.getElementById('campaign_id').value != 0) {
					params = "?campaign=" + document.getElementById('campaign_id').value;					
				}
			if(div=='div_domains'){
				makeRequest("ajax.stats.php",params,"div_content");
			}			} else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(url,obj,div,action) {if(demo==true){	alert("Saving currently disabled.");	return false;}
	  var getstr = "";
      for (i = 0; i < obj.childNodes.length; i++) {
		 if (obj.childNodes[i].tagName == "TEXTAREA") {
               getstr += obj.childNodes[i].name + "=" + escape(encodeURI(obj.childNodes[i].value)) + "&";		 	
		 }
		 if (obj.childNodes[i].tagName == "INPUT") {
			if (obj.childNodes[i].type == "submit") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }            
			if (obj.childNodes[i].type == "hidden") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
			if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + escape(encodeURI(obj.childNodes[i].value)) + "&";
            }
  			if (obj.childNodes[i].type == "button") {
  				getstr += obj.childNodes[i].name + "=" + escape(encodeURI(obj.childNodes[i].value)) + "&";
  			}
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }

//console.log(obj.childNodes[i].tagName+' - '+obj.childNodes[i].type);
		  if (obj.childNodes[i].tagName == "DIV") {
		  	obj_sub=obj.childNodes[i];
	  	for (j = 0; j < obj_sub.childNodes.length; j++) {
	  	
	  		if (obj_sub.childNodes[j].tagName == "TEXTAREA") {
	  			getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  		}
	  		if (obj_sub.childNodes[j].tagName == "INPUT") {
	  			if (obj_sub.childNodes[j].type == "submit") {
	  				getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  			}
	  			if (obj_sub.childNodes[j].type == "hidden") {
					getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  			}
	  			if (obj_sub.childNodes[j].type == "text") {
	  				getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  			}
	  			if (obj_sub.childNodes[j].type == "button") {
	  				getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  			}
	  			if (obj_sub.childNodes[j].type == "checkbox") {
	  				if (obj_sub.childNodes[j].checked) {
	  					getstr += obj_sub.childNodes[j].name + "=" + escape(encodeURI(obj_sub.childNodes[j].value)) + "&";
	  				}
	  				else {
	  					getstr += obj_sub.childNodes[j].name + "=&";
	  				}
	  			}
	  			if (obj_sub.childNodes[j].type == "radio") {
	  				if (obj_sub.childNodes[j].checked) {
	  					getstr += obj_sub.childNodes[j].name + "=" + obj_sub.childNodes[j].value + "&";
	  				}
	  			}
	  		}
	  		if (obj_sub.childNodes[j].tagName == "SELECT") {
	  			var sel = obj_sub.childNodes[j];
	  			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	  		}
		  if (obj_sub.childNodes[j].tagName == "DIV") {
		  	obj_sub1=obj_sub.childNodes[j];
	  	for (k = 0; k < obj_sub1.childNodes.length; k++) {

	  		if (obj_sub1.childNodes[k].tagName == "TEXTAREA") {
	  			getstr += obj_sub1.childNodes[k].name + "=" + escape(encodeURI(obj_sub1.childNodes[k].value)) + "&";
	  		}
	  		if (obj_sub1.childNodes[k].tagName == "INPUT") {
	  			if (obj_sub1.childNodes[k].type == "submit") {
	  				getstr += obj_sub1.childNodes[k].name + "=" + obj_sub1.childNodes[k].value + "&";
	  			}
	  			if (obj_sub1.childNodes[k].type == "hidden") {
					getstr += obj_sub1.childNodes[k].name + "=" + obj_sub1.childNodes[k].value + "&";
	  			}
	  			if (obj_sub1.childNodes[k].type == "text") {
	  				getstr += obj_sub1.childNodes[k].name + "=" + escape(encodeURI(obj_sub1.childNodes[k].value)) + "&";
	  			}
	  			if (obj_sub1.childNodes[k].type == "button") {
	  				getstr += obj_sub1.childNodes[k].name + "=" + escape(encodeURI(obj_sub1.childNodes[k].value)) + "&";
	  			}
	  			if (obj_sub1.childNodes[k].type == "checkbox") {
	  				if (obj_sub1.childNodes[k].checked) {
	  					getstr += obj_sub1.childNodes[k].name + "=" + obj_sub1.childNodes[k].value + "&";
	  				}
	  				else {
	  					getstr += obj_sub1.childNodes[k].name + "=&";
	  				}
	  			}
	  			if (obj_sub1.childNodes[k].type == "radio") {
	  				if (obj_sub1.childNodes[k].checked) {
	  					getstr += obj_sub1.childNodes[k].name + "=" + obj_sub1.childNodes[k].value + "&";
	  				}
	  			}
	  		}
	  		if (obj_sub1.childNodes[k].tagName == "SELECT") {
	  			var sel = obj_sub1.childNodes[k];	  			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	  		}
		  if (obj_sub1.childNodes[k].tagName == "DIV") {
		  	obj_sub2=obj_sub1.childNodes[k];
	  	for (l = 0; l < obj_sub2.childNodes.length; l++) {

	  		if (obj_sub2.childNodes[l].tagName == "TEXTAREA") {
	  			getstr += obj_sub2.childNodes[l].name + "=" + escape(encodeURI(obj_sub2.childNodes[l].value)) + "&";
	  		}
	  		if (obj_sub2.childNodes[l].tagName == "INPUT") {
	  			if (obj_sub2.childNodes[l].type == "submit") {
	  				getstr += obj_sub2.childNodes[l].name + "=" + obj_sub2.childNodes[l].value + "&";
	  			}
	  			if (obj_sub2.childNodes[l].type == "hidden") {
					getstr += obj_sub2.childNodes[l].name + "=" + obj_sub2.childNodes[l].value + "&";
	  			}
	  			if (obj_sub2.childNodes[l].type == "text") {
	  				getstr += obj_sub2.childNodes[l].name + "=" + escape(encodeURI(obj_sub2.childNodes[l].value)) + "&";
	  			}
	  			if (obj_sub2.childNodes[l].type == "button") {
	  				getstr += obj_sub2.childNodes[l].name + "=" + escape(encodeURI(obj_sub2.childNodes[l].value)) + "&";
	  			}
	  			if (obj_sub2.childNodes[l].type == "checkbox") {
	  				if (obj_sub2.childNodes[l].checked) {
	  					getstr += obj_sub2.childNodes[l].name + "=" + obj_sub2.childNodes[l].value + "&";
	  				}
	  				else {
	  					getstr += obj_sub2.childNodes[l].name + "=&";
	  				}
	  			}
	  			if (obj_sub2.childNodes[l].type == "radio") {
	  				if (obj_sub2.childNodes[l].checked) {
	  					getstr += obj_sub2.childNodes[l].name + "=" + obj_sub2.childNodes[l].value + "&";
	  				}
	  			}
	  		}
	  		if (obj_sub2.childNodes[l].tagName == "SELECT") {
	  			var sel = obj_sub2.childNodes[l];
	  			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	  		}
	  		
	  	}
	  }		  		
	  	}
	  }	  		
	  	}
	  }

         
      }	  	  getstr=escape_string(getstr);
		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;
		}

		document.getElementById(div).innerHTML = '<img src="images/ajax-loader.gif">';
		http_request.onreadystatechange = function(){
			alertContents(url, div, getstr);
		}
		//if(url=='ajax.links.php'){
		//	getstr+='&domain='.document.getElementById('domain_id').value+'&group='.document.getElementById('group_id').value+'&set='.document.getElementById('set_id').value+'&campaign='.document.getElementById('campaign_id').value;
		//}
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", getstr.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(getstr);
	}
   //}

/* this function helps chang set/group lists */
	function changeTo(suffix){
		self = document.getElementById('self'+suffix).checked;
		if(self==false){
			document.getElementById('div_external').style.display = 'block';
		}else{
			document.getElementById('div_external').style.display = 'none';			
		}
	}
/* this function helps chang set/group lists */
	function changeInternal(suffix){
		self = document.getElementById('internalcheck'+suffix).checked;
		if(self==false){
			document.getElementById('div_from').style.display = 'none';
			document.getElementById('div_external').style.display = 'block';
			document.getElementById('self'+suffix).checked='checked';			
		}else{
			document.getElementById('div_from').style.display = 'block';
			document.getElementById('div_external').style.display = 'none';			
		}
	}function escape_string(str){   return str.replace(/['\"]/g, "");}
/* this function help ajax file upload */
	function ajaxFileUpload(campaign_id,set_id,group_id,domain,i)
	{
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'ajax.fileupload.php',
				secureuri:false,
				fileElementId:'fileToUpload'+i,
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							alert(data.msg);
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			},campaign_id,set_id,group_id,domain
		)
		
		return false;
	}
