//start login.js
$(document).ready(function(){

	 $("#login_button").click(function(){
		  if(submit_login($("#username").val(),$("#password").val()) == false){
				$("#login_message").show();
				$("#login_message").html("username and/or password is needed");
			}
	 });
	 
	 	 $("#logout_button").click(function(){
	          $.ajax({ 
	             type: "GET", 
	             url: "../ajax/logout.php",  
	             success: function(msg){
					window.location = '../';
	             } 
	           }); 
	 });
	 $("#logout_button1").click(function(){
	          $.ajax({ 
	             type: "GET", 
	             url: "ajax/logout.php",  
	             success: function(msg){
					window.location = '../';
	             } 
	           }); 
	 });
});
/*
function trimAll(sString){ 
     while (sString.substring(0,1) == ' '){ 
          sString = sString.substring(1, sString.length); 
     } 
     while (sString.substring(sString.length-1, sString.length) == ' '){ 
          sString = sString.substring(0,sString.length-1); 
     } 
     return sString; 
}*/
//end in login.js

//start admin.js
$(document).ready(function(){
	  
	 $("#update_account").click(function(){
		  checkAdminInfo()
	 });
	 
	 $("#checkAll").click(function(){
		  checkAll();
	 });	
	 
});

function promptLoad(){
	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
}

function stopLoad(){
	document.getElementById('divContainer').style.width='0px';
	document.getElementById('divContainer').style.height='0px';
	document.getElementById('divContainer').innerHTML = "";
}

function hideSearch(){
	$("#search_span").slideUp();
}

function showSearch(){
	$("#search_span").slideDown();
}

function updateStatus(setToStatus,ids){
	//ids = "";
	//userCheck = document.getElementsByName('userCheckbox');
	
	//for($i=0; $i<userCheck.length; $i++){
		//if(userCheck[$i].checked == true)
			//ids += userCheck[$i].value + "|";
	//}	
	//alert (ids)
	//if(ids != ""){
	
	message = document.getElementById("update_span"+ids);
	//message.style.display = "block"; 
	message.innerHTML = "<img src='../images/load.gif'>";	
	
	arguments = "idSet="+ids+"&status="+setToStatus; 
	alert(arguments)
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/update_user_status.php",  
				 data: arguments, 
				 success: function(msg){ 
					if(setToStatus == 1)
						message.innerHTML = "<a href='javascript:updateStatus(1,"+ids+");'>deactivate</a>";//"user status updated!";
					else
						message.innerHTML = "<a href='javascript:updateStatus(1,"+ids+");'>activate</a>";//"user status updated!";
					//window.location.reload(true);
				 } 
			}); 		
	//}
}

function deactivateUser(id){
	arguments = "id="+id; 
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/deactivateUser.php",  
				 data: arguments, 
				 success: function(msg){ 
					window.location.reload(true);
				 } 
			}); 		
	//}
}

function Notice(noticeId,id,amount){
	arguments = "id="+id+"&notice="+noticeId+"&amount="+amount; 
	//alert(arguments)
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/sendNotice.php",  
				 data: arguments, 
				 success: function(msg){ 
					//window.location.reload(true);
					 alert(msg)
					 window.location.reload(true);
				 } 
			}); 		
	//}
}

function updateSiteStatus(setToStatus,ids){
	//elementId = "siteupdate_span"+ids;
	message = document.getElementById("siteupdate_span"+ids);
	message.innerHTML = "<img src='../images/load.gif'>";	
	
	arguments = "idSet="+ids+"&status="+setToStatus; 
	
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/update_site_status.php",  
				 data: arguments, 
				 success: function(msg){ 
					if(setToStatus == 1)
						message.innerHTML = "<a href='javascript:updateSiteStatus(1,"+ids+");'>deactivate</a>";//"site status updated!";
					else
						message.innerHTML = "<a href='javascript:updateSiteStatus(1,"+ids+");'>activate</a>";//"site status updated!";
				 } 
			}); 		
}

function updateRssStatus(setToStatus,ids){
	//elementId = "siteupdate_span"+ids;
	message = document.getElementById("rssupdate_span"+ids);
	message.innerHTML = "<img src='../images/load.gif'>";	
	
	arguments = "idSet="+ids+"&status="+setToStatus;
	
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/update_rss_status.php",  
				 data: arguments, 
				 success: function(msg){ 
					if(setToStatus == 1)
						message.innerHTML = "<a href='javascript:updateRssStatus(1,"+ids+");'>deactivate</a>";//"site status updated!";
					else
						message.innerHTML = "<a href='javascript:updateRssStatus(1,"+ids+");'>activate</a>";//"site status updated!";
				 } 
			}); 		
}

function checkAll(){

	userCheck = document.getElementsByName('userCheckbox');
	
	if(document.getElementById('checkAll').checked == true){
		for($i=0; $i<userCheck.length; $i++){
			userCheck[$i].checked = true;
		}	
	}
	else{
		for($i=0; $i<userCheck.length; $i++){
			userCheck[$i].checked = false;
		}	
	}
}

function enablePayment(element){
  textbox = "txt"+element.value;
  if(element.checked == true){  
    document.getElementById(textbox).readOnly = false;
  }
  else{  
    document.getElementById(textbox).value = "";
    document.getElementById(textbox).readOnly = true;
  }
  computeTotal();
}

function checkAllAffiliates(){

	checkboxSet = document.getElementsByName('affiliateCheckbox');
	
	if(document.getElementById('checkAllAffiliates').checked == true){
		for($i=0; $i<checkboxSet.length; $i++){
			checkboxSet[$i].checked = true;
      textbox = "txt"+checkboxSet[$i].value;
      document.getElementById(textbox).readOnly = false;
		}	
	}
	else{
		for($i=0; $i<checkboxSet.length; $i++){
			checkboxSet[$i].checked = false;
      textbox = "txt"+checkboxSet[$i].value;
      document.getElementById(textbox).value = "";
      document.getElementById(textbox).readOnly = true;
		}	
	}
  computeTotal();
}

function computeTotal(){

	total = 0;
	checkboxSet = document.getElementsByName('affiliateCheckbox');
  
		for($i=0; $i<checkboxSet.length; $i++){
      if(checkboxSet[$i].checked == true){  
        textbox = "commission"+checkboxSet[$i].value;
        total += Number(document.getElementById(textbox).value);
      }
		}	

    
   document.getElementById("totalPayment").innerHTML = "$"+total;
}

function saveAffiliateTransactions(){
  promptLoad();
	checkboxSet = document.getElementsByName('affiliateCheckbox');
  affiliates = "";
  transactions = "";
  affiliateIds = "";
  transactionIds = "";
  goodTranId = true;
		for($i=0; $i<checkboxSet.length; $i++){
      if(checkboxSet[$i].checked == true){
        transactions += document.getElementById(textbox).value;
        affiliateIds += checkboxSet[$i].value+"|";
        textbox = "txt"+checkboxSet[$i].value;
        transactionIds += document.getElementById(textbox).value+"|";
          if (trimAll(document.getElementById(textbox).value).length <= 5) 
            goodTranId = false;
      } 
		}	
    
  if(affiliateIds == "" || !goodTranId){
    document.getElementById("affiliate_msg").innerHTML = "<b>Error occured:</b> Please make sure you have selected an affiliate transaction and have entered its correct Transaction ID.";
    stopLoad();
    return;
  }
  
    var arguments = "affiliateIds="+affiliateIds+"&transactionIds="+transactionIds;
    setDateNow = document.getElementById("dateNow").value;
     
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/saveAffiliateTransactions.php",  
		 data: arguments, 
		 success: function(msg){ 
        stopLoad();
        document.getElementById("affiliate_msg").innerHTML = "";
        
        ids = msg.split("|");
        for($i=0; $i<ids.length; $i++){
          if(ids[$i] != ""){
            afStatus = "spanStatus"+ids[$i];
            afCheckBox = "spanAfCheckbox"+ids[$i];
            afTextBox = "spanAfTextBox"+ids[$i];
            
            document.getElementById(afStatus).innerHTML = "<img src='../images/accept.gif' title='paid'>";
            document.getElementById(afCheckBox).innerHTML = "paid:<br/>"+setDateNow;
            document.getElementById(afTextBox).innerHTML = document.getElementById("txt"+ids[$i]).value;
            document.getElementById("totalPayment").innerHTML = "0";
          }
        }
        
		 } 
	}); 
}

function updateAdminAccount(newpass){
	firstname = document.getElementById("admin_first_name").value;
	lastname = document.getElementById("admin_last_name").value;
	username = document.getElementById("admin_username").value;
	affiliatename = document.getElementById("affiliate_name").value;
	email = document.getElementById("admin_email").value;
	street = document.getElementById("admin_street").value;
	city = document.getElementById("admin_city").value;
	state = document.getElementById("admin_state").value;
	country = document.getElementById("admin_country").value;
	zip = document.getElementById("admin_zip").value;	
	password = document.getElementById("admin_new_pass1").value;
	message = document.getElementById("error_message");
	
	message.innerHTML = "<img src='../images/loading.gif'>";
	
    var arguments = "firstname="+firstname+"&lastname="+lastname+"&username="+username+"&email="+email+"&street="+street+"&city="+city+"&state="+state+"&country="+country+"&zip="+zip+"&password="+password+"&ifnewpass="+newpass+"&affiliatename="+affiliatename; 
 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/update_account.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
			window.location.reload();
		 } 
	}); 
}

function checkAdminInfo(){
	radioPass = document.getElementsByName('passRadio');
	for($i=0; $i<radioPass.length; $i++){
		if(radioPass[$i].checked == true)
			newPassAction = radioPass[$i].value;
	}	
	
	if(newPassAction == "yes"){
		if(checkAdminGeneralInfo() && checkNewPass())
			updateAdminAccount(1);
	}
	else{
		if(checkAdminGeneralInfo())
			updateAdminAccount(0);
	}
}

function checkNewPass(){

	message = document.getElementById("error_message");
	pass1 = document.getElementById("admin_new_pass1").value;
	pass2 = document.getElementById("admin_new_pass2").value;
	
	if(trimAll(pass1) == "" && trimAll(pass2 ) == ""){
		message.innerHTML = "Password cannot be blank.";
		return false;
	}
	else{
		if(trimAll(pass1) != trimAll(pass2 )){
			message.innerHTML = "Please confirm password.";
			return false;
		}
	}
	
	return true;
}

function checkAdminGeneralInfo(){
	firstname = document.getElementById("admin_first_name").value;
	lastname = document.getElementById("admin_last_name").value;
	username = document.getElementById("admin_username").value;
	email = document.getElementById("admin_email").value;
	street = document.getElementById("admin_street").value;
	city = document.getElementById("admin_city").value;
	state = document.getElementById("admin_state").value;
	country = document.getElementById("admin_country").value;
	zip = document.getElementById("admin_zip").value;
	message = document.getElementById("error_message");
	
	//if(trimAll(firstname) == "" || trimAll(lastname) == "" || trimAll(username) == "" || trimAll(email) == "" || trimAll(street) == "" || trimAll(city) == "" || trimAll(state) == "" || trimAll(country) == "" || trimAll(zip) == ""){
	if(trimAll(firstname) == "" || trimAll(lastname) == "" || trimAll(username) == "" || trimAll(email) == ""){
		message.innerHTML = "Please fill-up the required fields.";
		return false;
	}
	else{
		if(email_checker("admin_email") == false){
			message.innerHTML = "Please enter a valid email";
			return false;
		}
	}
	
	return true;
}

function showNewPassForm(){
	
	radioPass = document.getElementsByName('passRadio');
	for($i=0; $i<radioPass.length; $i++){
		if(radioPass[$i].checked == true)
			newPassAction = radioPass[$i].value;
	}
	
	if(newPassAction == "yes")
		document.getElementById('spanChangePass').style.display = "block";
	else
		document.getElementById('spanChangePass').style.display = "none";
	
}

function trimAll(sString){ 
     while (sString.substring(0,1) == ' '){ 
          sString = sString.substring(1, sString.length); 
     } 
     while (sString.substring(sString.length-1, sString.length) == ' '){ 
          sString = sString.substring(0,sString.length-1); 
     } 
     return sString; 
}

function email_checker(elementID){
	if(trimAll(document.getElementById(elementID).value) == ""){
		return false;
	}
	else{
		if(document.getElementById(elementID).value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)){
			return true;
		}
		else{
			return false;
		}
	}
}

function showSites(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "q="+str; 
 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/getSites.php",  
   data: arguments, 
   success: function(msg){       
      if(str != 'owner'){
        document.getElementById("users_dd").innerHTML  = "";
        document.getElementById("status_dd").innerHTML  = "";
        document.getElementById("sites_span").innerHTML  = "";
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";
        message.innerHTML = msg;
        }
      else{
        displaySites(element);
        }
   } 
  }); 	
        
}

function displaySites(element){

 message = document.getElementById("sites_span");
 user = document.getElementById("usersites_span");
 users = document.getElementById("users_dd");
 status = document.getElementById("status_dd");
 users.innerHTML = "";
 status.innerHTML = "";
  //if(element.value == 'owner'){
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/showSitesOwner.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 
   /*
    }
   else{
      message.innerHTML = "";
      user.innerHTML = "";
      document.getElementById('divContainer').style.width='0';
      document.getElementById('divContainer').style.height='0';
      document.getElementById('divContainer').innerHTML = "";
   }
   */
}

function getSitesbyOwner(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "u="+str; 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/getSitesbyOwner.php",  
   data: arguments, 
   success: function(msg){   
   
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";

        message.innerHTML = msg;
        displaySitesStatus(element);
   } 
  }); 
  
}

function displaySitesStatus(element){

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 message = document.getElementById("status_dd");
 
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/displaySitesStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 	
    
}


function getSitesbyOwnerStatus(str)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 filter2a = document.getElementById("filter2").value;
 message = document.getElementById("txtHint");
 arguments = "s="+str+"&id="+filter2a+"&sid="+Math.random();
 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/getSitesbyOwnerStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
        
 } 
 
 function displayAllAffiliates(element){
  document.getElementById('divContainer').style.width='815px';
  document.getElementById('divContainer').style.height='1500px';
  document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>"; 
  
  message = document.getElementById("txtHint");
  
  arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/all_affiliates.php",  
  				 data: arguments, 
  				 success: function(msg){ 
            document.getElementById('divContainer').style.width='0';
            document.getElementById('divContainer').style.height='0';
            document.getElementById('divContainer').innerHTML = "";  
            document.getElementById('affiliate_span').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
  }
 
 function displayUserAffiliates(element){
  document.getElementById('divContainer').style.width='815px';
  document.getElementById('divContainer').style.height='1500px';
  document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
  message = document.getElementById("affiliate_span");
  
  if(element.value == 'user'){
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/users.php",  
  				 data: arguments, 
  				 success: function(msg){ 
            document.getElementById('divContainer').style.width='0';
            document.getElementById('divContainer').style.height='0';
            document.getElementById('divContainer').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
    }
   else if(element.value == 'product'){
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/products.php",  
  				 data: arguments, 
  				 success: function(msg){ 
            document.getElementById('divContainer').style.width='0';
            document.getElementById('divContainer').style.height='0';
            document.getElementById('divContainer').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
    }
    else {
    	displayAllAffiliates(element);
    }
}

function showProductAffiliates(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "q="+str; 
 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/ProductAffiliates.php",  
   data: arguments, 
   success: function(msg){       
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";
        
        message.innerHTML = msg;
   } 
  }); 	
        
}

function showUserAffiliates(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "q="+str; 
 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/UserAffiliates.php",  
   data: arguments, 
   success: function(msg){       
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";
        
        message.innerHTML = msg;
   } 
  }); 	
        
}

function stop(siteId, fromUserId, toUserId){
   document.getElementById('divContainer').style.width='815px';
	 document.getElementById('divContainer').style.height='1500px';
	 document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
	 message = document.getElementById("usersites_span");
    	arguments = "siteId="+siteId+"&fromUserId="+fromUserId+"&toUserId="+toUserId; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/stopSite.php",  
  				 data: arguments, 
  				 success: function(msg){ 
            document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
            window.location.reload();
  				 } 
  			}); 	
}

//used in products pages
function ValidateLink(product_site){
//alert(document.getElementById(product_site).value);
  var v = new RegExp();
  v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
  //var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
  if (!v.test(document.getElementById(product_site).value))
  {
  msg="You must supply a valid URL.It should be in following format \n http://www.sitename.com";
  //document.getElementById(product_site).focus();
  alert(msg)
  setTimeout(function(){document.getElementById(product_site).focus()}, 10);
  //return false;
  }
} 

function ValidateAfLink(affiliate_link){
  var v = new RegExp();
  v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
  //var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
  if (!v.test(document.getElementById(affiliate_link).value))
  {
  msg="You must supply a valid URL.It should be in following format \n http://www.sitename.com";
  //document.getElementById(product_site).focus();
  alert(msg)
  setTimeout(function(){document.getElementById(affiliate_link).focus()}, 10);
  //return false;
  }
} 

function test_PDC(PDC_id) {
 var value = document.getElementById(PDC_id).value;// get input value
  // Change the backgroundColor of the input field based on whether or not
  // the value of the input field is a number.
  if(isNaN(value)) {
      alert("This field only allow numeric input!")
      setTimeout(function(){document.getElementById(PDC_id).focus()}, 10);
      //document.getElementById(PDC_id).style.backgroundColor = 'red';
  }
}

function test_price(product_price) {
 var value = document.getElementById(product_price).value;// get input value
  // Change the backgroundColor of the input field based on whether or not
  // the value of the input field is a number.
  if(isNaN(value)) {
      alert("This field only allow numeric input!")
      setTimeout(function(){document.getElementById(product_price).focus()}, 10);
      //document.getElementById(PDC_id).style.backgroundColor = 'red';
  }
}

function test_commission(commission) {
 var value = document.getElementById(commission).value;// get input value
  // Change the backgroundColor of the input field based on whether or not
  // the value of the input field is a number.
  if(isNaN(value)) {
      alert("This field only allow numeric input!")
      setTimeout(function(){document.getElementById(commission).focus()}, 10);
      //document.getElementById(PDC_id).style.backgroundColor = 'red';
  }
}

//for rss
function showRSS(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "choice="+str;
  $.ajax({ 
   type: "GET", 
   url: "../ajax/getRssChoice.php",  
   data: arguments, 
   success: function(msg){       
      if(str != 'owner' && str != 'category'){
        document.getElementById("rssowner_span").innerHTML  = "";
        document.getElementById("owner_rssstatus_span").innerHTML  = "";
				document.getElementById("rsscategory_span").innerHTML  = "";
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";
        if(document.getElementById("rssowner_span1") != null)
				document.getElementById("rssowner_span1").innerHTML  = "";
				if(document.getElementById("owner_rssstatus_span1") != null)
				document.getElementById("owner_rssstatus_span1").innerHTML  = "";
				if(document.getElementById("rsscategory_span1") != null)
				document.getElementById("rsscategory_span1").innerHTML  = "";
				if(document.getElementById("category_rssstatus_span") != null)
				document.getElementById("category_rssstatus_span").innerHTML  = "";
				if(document.getElementById("rsscategory_span1") != null)
				document.getElementById("rsscategory_span1").innerHTML  = "";
				if(document.getElementById("category_rssstatus_span1") != null)
				document.getElementById("category_rssstatus_span1").innerHTML  = "";
        message.innerHTML = msg;
      } else if (str == 'owner'){
				if(document.getElementById("rsscategory_span") != null)
				document.getElementById("rsscategory_span").innerHTML  = "";
				if(document.getElementById("category_rssstatus_span") != null)
				document.getElementById("category_rssstatus_span").innerHTML  = "";
				if(document.getElementById("rsscategory_span1") != null)
				document.getElementById("rsscategory_span1").innerHTML  = "";
				if(document.getElementById("category_rssstatus_span1") != null)
				document.getElementById("category_rssstatus_span1").innerHTML  = "";
				if(document.getElementById("rssowner_span1") != null)
				document.getElementById("rssowner_span1").innerHTML  = "";
				if(document.getElementById("owner_rssstatus_span1") != null)
				document.getElementById("owner_rssstatus_span1").innerHTML  = "";
        displayRssOwner(element);
      } else if (str == 'category'){
				if(document.getElementById("rssowner_span") != null)
				document.getElementById("rssowner_span").innerHTML  = "";
				if(document.getElementById("owner_rssstatus_span") != null)
				document.getElementById("owner_rssstatus_span").innerHTML  = "";
				if(document.getElementById("rssowner_span1") != null)
				document.getElementById("rssowner_span1").innerHTML  = "";
				if(document.getElementById("owner_rssstatus_span1") != null)
				document.getElementById("owner_rssstatus_span1").innerHTML  = "";
			  displayRssCategory(element);
			}
   } 
  }); 	
        
}

function displayRssOwner(element){

 message = document.getElementById("rssowner_span");
 //user = document.getElementById("usersites_span");
 //users = document.getElementById("users_dd");
 //status = document.getElementById("status_dd");
 //users.innerHTML = "";
 //status.innerHTML = "";
  //if(element.value == 'owner'){
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/getRssOwner.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 
}

function showRssOwner(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "owner="+str; 
 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/displayRssbyOwner.php",  
   data: arguments, 
   success: function(msg){   
   
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";
        message.innerHTML = msg;
        displayRssStatus(element);
   } 
  }); 
  
}

function displayRssStatus(element){
	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 message = document.getElementById("owner_rssstatus_span");
 
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/getRssStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 	
    
}

function showRssOwnerStatus(str)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 filter2a = document.getElementById("filter2").value;
 message = document.getElementById("txtHint");
 arguments = "status="+str+"&id="+filter2a+"&sid="+Math.random();
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/displayRssbyOwnerStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
        
 } 
 
 function displayRssCategory(element){

 message = document.getElementById("rsscategory_span");
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/getRssCategory.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 
}

function showRssCategory(element)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 str = element.value;
 message = document.getElementById("txtHint");
 arguments = "category="+str; 
 
  $.ajax({ 
   type: "GET", 
   url: "../ajax/displayRssbyCategory.php",  
   data: arguments, 
   success: function(msg){   
   
        document.getElementById('divContainer').style.width='0';
        document.getElementById('divContainer').style.height='0';
        document.getElementById('divContainer').innerHTML = "";

        message.innerHTML = msg;
        displayRssStatusCategory(element);
   } 
  }); 
  
}

function displayRssStatusCategory(element){
	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 message = document.getElementById("category_rssstatus_span");
 
    	arguments = ""; 
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/getRssCategoryStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
  					message.innerHTML = msg;
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  				 } 
  			}); 	
    
}

function showCategoryRssStatus(str)
{ 

	document.getElementById('divContainer').style.width='815px';
	document.getElementById('divContainer').style.height='1500px';
	document.getElementById('divContainer').innerHTML = "<img src='../images/preload.gif'>";
  
 filter4a = document.getElementById("filter4").value;
 message = document.getElementById("txtHint");
 arguments = "status="+str+"&category="+filter4a+"&sid="+Math.random();
  			  $.ajax({ 
  				 type: "GET", 
  				 url: "../ajax/displayRssbyCategoryStatus.php",  
  				 data: arguments, 
  				 success: function(msg){ 
          	document.getElementById('divContainer').style.width='0';
          	document.getElementById('divContainer').style.height='0';
          	document.getElementById('divContainer').innerHTML = "";
  					message.innerHTML = msg;
  				 } 
  			}); 	
        
 } 
//end rss
//end admin.js

//start of user.js
//general
 function errorMessage(){
    alert("Sorry, but this site is still inactive. Please contact the administrators.");
 }
 
 function prePrompt(){
	document.getElementById('divContainerUser').style.width='815px';
	document.getElementById('divContainerUser').style.height='1500px';
	document.getElementById('divContainerUser').innerHTML = "<img src='../images/preload_user.gif'>";	
	//window.location = '../images/preload.gif';
 }
 
 function postPrompt(){
	document.getElementById('divContainerUser').style.width='0px';
	document.getElementById('divContainerUser').style.height='0px';
	document.getElementById('divContainerUser').innerHTML = "";
 }
 
	 
function config(option){
	$('#hiddenOption').val(option);
	$('#deleteIds').val("");
	promptCallback("start");
}

function concatValue(element, newVal){
	if(element.checked){
		array = ($('#deleteIds').val()).split("|");
		good = 1
		for(i=0; i<array.length; i++){
			if(array[i] == newVal)
				good = 0
		}
		if(good == 1)
		$('#deleteIds').val($('#deleteIds').val()+newVal+"|");
	}
	
	else{
		array = ($('#deleteIds').val()).split("|");
		good = 1
		for(i=0; i<array.length; i++){
			if(array[i] == newVal)
			$('#deleteIds').val(($('#deleteIds').val()).replace(array[i]+"|",""));
		}	
	}
		
}

function changePlan(currentCost, newCost, days){
	alert(Math.ceil((((currentCost/31)*days)/newCost)*31))
	
	//add to billing_date: 31
	//do this after payment confirmation
	//change privelege
	//solve for 10 days on downgrade
	//create script for removal (not necessary)
	
	
}

function selectAll(){

	checkboxSet = document.getElementsByName('checkboxes');
	
	if(document.getElementById('checkAll').checked == true){
		for($i=0; $i<checkboxSet.length; $i++){
			checkboxSet[$i].checked = true;
			$('#deleteIds').val($('#deleteIds').val()+checkboxSet[$i].value+"|");
		}	
	}
	else{
		for($i=0; $i<checkboxSet.length; $i++){
			checkboxSet[$i].checked = false;
			$('#deleteIds').val("");
		}	
	}
}

function promptCallback(v,m){
 
option = $('#hiddenOption').val();
siteid = $('#hiddenSiteId').val();
sitecategory = $('#hiddenSiteCategory').val();

//ajax tweak for ie
var randomnumber = Math.floor(Math.random()*1000001);
		
	if(option == 'adsense'){
		arguments = "siteid="+siteid+"&option="+option+"&rand="+randomnumber; 
		  $.ajax({ 
		     beforeSend: function(){
			   prePrompt();
			 },
			 complete: function(){
			   postPrompt();
			 },
			 type: "GET", 
			 url: "../ajax/configOption.php",  
			 data: arguments, 
			 success: function(msg){ 
				 $.prompt(msg,{ buttons: {close:'close'}});
			 } 
		}); 
	} //end of adsense
	
	if(option == 'banners'){
		arguments = "siteid="+siteid+"&option="+option+"&rand="+randomnumber; 
		  $.ajax({ 
		     beforeSend: function(){
			   //prePrompt();
			 },
			 complete: function(){
			   //postPrompt();
			 },
			 type: "GET", 
			 url: "../ajax/configOption.php",  
			 data: arguments, 
			 success: function(msg){ 
				 $.prompt(msg,{ buttons: {close:'close'}});
				 //$.prompt('Example 11',{prefix:'impromptu'}).children('#impromptu').corner();
			 } 
		}); 
	}
	
	if(option == 'links'){
		arguments = "siteid="+siteid+"&sitecategory="+sitecategory+"&option="+option+"&rand="+randomnumber; 
		//alert(arguments);
		  $.ajax({ 
		     beforeSend: function(){
			   prePrompt();
			 },
			 complete: function(){
			   postPrompt();
			 },
			 type: "GET", 
			 url: "../ajax/configOption.php",  
			 data: arguments, 
			 success: function(msg){ 
				 $.prompt(msg,{ buttons: {close:'close'}});
			 } 
		}); 
	}
	
			
	if(option == 'rss'){
		arguments = "siteid="+siteid+"&option="+option+"&rand="+randomnumber; 
		  $.ajax({ 
		     beforeSend: function(){
			   prePrompt();
			 },
			 complete: function(){
			   postPrompt();
			 },
			 type: "GET", 
			 url: "../ajax/configOption.php",  
			 data: arguments, 
			 success: function(msg){ 
				 $.prompt(msg,{ buttons: {close:'close'}});
			 } 
		}); 
	}
	
}

function setHeaderImg(siteId){
	optionCheck = document.getElementsByName('header_img');
	message = document.getElementById("result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	for($i=0; $i<optionCheck.length; $i++){
			//alert(optionCheck[$i].value)
		if(optionCheck[$i].checked == true){
			
			//alert(optionCheck[$i].value)
			arguments = "siteid="+siteId+"&image="+optionCheck[$i].value; 
			  $.ajax({ 
				 type: "GET", 
				 url: "../ajax/setHeaderImg.php",  
				 data: arguments, 
				 success: function(msg){ 
					message.innerHTML = msg;
				 } 
			});	
		}
	}	
}

function updateFooterCode(siteId){
	
	message = document.getElementById("footer_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('footer_code').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateFooterText.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateSiteName(siteId){
	
	message = document.getElementById("sitename_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('site_name').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateSiteName.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateSiteDesc(siteId){
	
	message = document.getElementById("sitedesc_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('site_desc').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateSiteDesc.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateSiteCategory(siteId){
	
	message = document.getElementById("cat_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&newCat="+document.getElementById('siteCategory').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateSiteCategory.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateMetaDesc(siteId){
	
	message = document.getElementById("desc_result_message");
	message.innerHTML = "<br><img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('meta_desc').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateMetaDesc.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateMetaKey(siteId){
	
	message = document.getElementById("key_result_message");
	message.innerHTML = "<br><img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('meta_key').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateMetaKey.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

function updateMetaOthers(siteId){
	
	message = document.getElementById("others_result_message");
	message.innerHTML = "<br><img src='../images/loading.gif'>";	
	arguments = "siteid="+siteId+"&code="+document.getElementById('meta_others').value; 
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateMetaOthers.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}

 function promptSubmit(v,m){
	optionCheck = document.getElementsByName('optionRadio');
	
	for($i=0; $i<optionCheck.length; $i++){
		if(optionCheck[$i].checked == true){
			$('#hiddenOption').val(optionCheck[$i].value);
			return true;
		}
	}	
}

function setAdsHidden(adsId){
	adsCheck = document.getElementsByName('adsRadio');
	
	for($i=0; $i<adsCheck.length; $i++){
		if(adsCheck[$i].checked == true){
			$('#hiddenAdsId').val(adsId);
			return true;
		}
	}
}

function AllowNumericOnly(element)
{
    //set of allowed characters, is case sensitive (if you want to allow some letters)
    var allowedValue = "0123456789"; 

    var numVal = "";
    
    //visit each character in the element
	
    for (i=0; i < element.value.length; i++) 
    { 
	    x = element.value.charAt(i);
	    //add if that character is in "allowedValue"
	    if (allowedValue.indexOf(x,0) != -1) numVal += x;
	}
	
	    //return the final value to the element
	    element.value = numVal; 
}
//general


//for adsense
function updateAdForm(adsid){

	arguments = "adsid="+adsid+"&showUpdateCodeForm=1"; 
	
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateAds.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}


function updateCode(adsid){

	code1 = $('#adsTextCode').val();
	name = $('#adName').val();
	status = $('#adStatus').val();
	type = $('#adType').val();
	
	var strReplaceAll = code1;
	 var intIndexOfMatch = strReplaceAll.indexOf( "#" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strReplaceAll = strReplaceAll.replace( "#", "[X]" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strReplaceAll.indexOf( "#" );
	 }
	 
	 var code2 = strReplaceAll;
	 var intIndexOfMatch = code2.indexOf( "\n" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 code2 = code2.replace( "\n", "<br>" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = code2.indexOf( "\n" );
	 }
	
	arguments = "adsid="+adsid+"&type="+type+"&status="+status+"&name="+name+"&code="+code2+"&updateCode=1"; 
	popupMessage = document.getElementById("result_message_popUp");
	message = document.getElementById("ads_div");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateAds.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			 if(msg != 'Update failed!')
				//popupMessage.innerHTML = 'Adsense has been updated!';
				 alert('Adsense has been updated!');
			 else	
				//popupMessage.innerHTML = 'Update failed!';
				 alert('Update failed!');
			 
		 } 
	}); 
}

function updatedAdStatus(adsid, status){
	
	arguments = "adsid="+adsid+"&status="+status+"&update=1"; 
	statusSpan = document.getElementById("status"+adsid);
	actionSpan = document.getElementById("action"+adsid);
	statusSpan.innerHTML = "<img src='../images/load.gif'>";	
	actionSpan.innerHTML = "<img src='../images/load.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateAds.php",  
		 data: arguments, 
		 success: function(msg){ 
			 if(msg != 'Update failed!' && msg == "0"){
				statusSpan.style.color = "#D72020";
				statusSpan.innerHTML = "inactive";
				actionSpan.innerHTML = "<a href='javascript:updatedAdStatus("+adsid+",1)'><img src='../images/accept.gif' title='activate' style='border:none;'></a>";
			 }
			 else if(msg != 'Update failed!' && msg == "1"){
				statusSpan.style.color = "#0C5CC2";
				statusSpan.innerHTML = "active";
				actionSpan.innerHTML = "<a href='javascript:updatedAdStatus("+adsid+",0)'><img src='../images/inactive.png' title='activate' style='border:none;'></a>";
			 }
		 } 
	}); 
}		

function newAd(){
	name = $('#adName').val();
	type = $('#adType').val();
	code1 = $('#adsTextCode').val();
	status = $('#adStatus').val();
	
	 var strReplaceAll = code1;
	 var intIndexOfMatch = strReplaceAll.indexOf( "#" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strReplaceAll = strReplaceAll.replace( "#", "[X]" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strReplaceAll.indexOf( "#" );
	 }
	 
	 var code2 = strReplaceAll;
	 var intIndexOfMatch = code2.indexOf( "\n" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 code2 = code2.replace( "\n", "<br>" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = code2.indexOf( "\n" );
	 }
	
	arguments = "name="+name+"&status="+status+"&type="+type+"&code="+code2+"&addNew=1"; 
	message = document.getElementById("ads_div");
	//popupMessage = document.getElementById("result_message_popUp");
	//popupMessage.innerHTML = "<img src='../images/loading.gif'>";
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateAds.php",
		 data: arguments, 
		 success: function(msg){ 
			 //message.innerHTML = msg;
			alert("New adsense has been added!");
			window.location = '../user/ads.php';
		 } 
	}); 
}

function newAdForm(){

	arguments = "add=1"; 
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateAds.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function removeAd(){
	ads_ids = $('#deleteIds').val();
	if(ads_ids != ""){
		arguments = "ads_ids="+ads_ids+"&delete=1"; 
		
		ads_table = document.getElementById("ads_div");
		message = document.getElementById("result_message");
		message.innerHTML = "<img src='../images/loading.gif'>";	
		
		  $.ajax({ 
			 type: "GET", 
			 url: "../ajax/updateAds.php",  
			 data: arguments, 
			 success: function(msg){ 
				message.innerHTML = "";
				ads_table.innerHTML = msg;
			 } 
		});
	}
	$('#deleteIds').val("");
}
function setAds(siteid){
	message = document.getElementById("result_message_popUp");
	ads = document.getElementsByName('ad');
	//positions = document.getElementsByName('positions');
	//position_ads = $('#ad').val();
	position_ads = document.getElementsByName('adsensepost');
	ads_ids = "";
	position_ids = "";
	
	message.innerHTML = "<img src='../images/loading.gif'>";	
	for($i=0; $i<ads.length; $i++){
		if(ads[$i].checked == true){
			ads_ids += ads[$i].value+"|";
			position_ids += position_ads[$i].value+"|";
		}
	}
	
	arguments = "siteid="+siteid+"&adsPosition="+position_ids+"&ads_ids="+ads_ids+"&setAd=1";
	//alert(arguments);
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateAds.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
		 } 
	}); 
}
//for adsense

//for banners

function removeBanner(){
	banners_ids = $('#deleteIds').val();
	if(banners_ids != ""){
		arguments = "banners_ids="+banners_ids+"&delete=1"; 
		
		ads_table = document.getElementById("banners_div");
		message = document.getElementById("result_message");
		message.innerHTML = "<img src='../images/loading.gif'>";	
		
		  $.ajax({ 
			 type: "GET", 
			 url: "../ajax/updateBanners.php",  
			 data: arguments, 
			 success: function(msg){ 
				message.innerHTML = "";
				ads_table.innerHTML = msg;
			 } 
		});
	}
	$('#deleteIds').val("");
}

function updateBannerForm(bannerid){

	arguments = "bannerid="+bannerid+"&showUpdateCodeForm=1"; 
	
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function updatedBannerStatus(bannerid, status){
	arguments = "bannerid="+bannerid+"&status="+status+"&update=1"; 
	statusSpan = document.getElementById("status"+bannerid);
	actionSpan = document.getElementById("action"+bannerid);
	statusSpan.innerHTML = "<img src='../images/load.gif'>";	
	actionSpan.innerHTML = "<img src='../images/load.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			 if(msg != 'Update failed!' && msg == "0"){
				statusSpan.style.color = "#D72020";
				statusSpan.innerHTML = "inactive";
				actionSpan.innerHTML = "<a href='javascript:updatedBannerStatus("+bannerid+",1)'><img src='../images/accept.gif' title='activate' style='border:none;'></a>";
			 }
			 else if(msg != 'Update failed!' && msg == "1"){
				statusSpan.style.color = "#0C5CC2";
				statusSpan.innerHTML = "active";
				actionSpan.innerHTML = "<a href='javascript:updatedBannerStatus("+bannerid+",0)'><img src='../images/inactive.png' title='activate' style='border:none;'></a>";
			 }
		 } 
	}); 
}

function updateUrl(bannerid){

	name = $('#bannerName').val();
	bannerUrl = $('#bannerTextUrl').val();
	bannerImgSrc = $('#bannerTextImgSrc').val();
	bannerImgBorder = document.getElementById('bannerCheckImgBorder').checked;
	bannerTextBorder = $('#bannerTextImgBorder').val();
	bannerImgWidth = document.getElementById('bannerCheckImgWidth').checked;
	bannerTextWidth = $('#bannerTextImgWidth').val();
	bannerImgHeight = document.getElementById('bannerCheckImgHeight').checked;
	bannerTextHeight = $('#bannerTextImgHeight').val();
	status = $('#bannerStatus').val();
	
	arguments = "bannerid="+bannerid+"&status="+status+"&name="+name+"&bannerUrl="+bannerUrl+"&bannerImgSrc="+bannerImgSrc+"&bannerImgBorder="+bannerImgBorder+"&bannerTextBorder="+bannerTextBorder+"&bannerImgWidth="+bannerImgWidth+"&bannerTextWidth="+bannerTextWidth+"&bannerImgHeight="+bannerImgHeight+"&bannerTextHeight="+bannerTextHeight+"&updateCode=1"; 
	
	popupMessage = document.getElementById("result_message_popUp");
	message = document.getElementById("banners_div");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			 if(msg != 'Update failed!')
				//popupMessage.innerHTML = 'Banner has been updated!';
				 alert('Banner has been updated!');
			 else	
				//popupMessage.innerHTML = 'Update failed!';
				 alert('Update failed!');
		 } 
	}); 
}

function newBannerForm(){
	arguments = "add=1"; 
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function newBanner(){
	name = $('#bannerName').val();
	url = $('#bannerUrl').val();
	imgSrc = $('#bannerImgSrc').val();
	bannerImgBorder = document.getElementById('bannerCheckImgBorder').checked;
	bannerTextBorder = $('#bannerTextImgBorder').val();
	bannerImgWidth = document.getElementById('bannerCheckImgWidth').checked;
	bannerTextWidth = $('#bannerTextImgWidth').val();
	bannerImgHeight = document.getElementById('bannerCheckImgHeight').checked;
	bannerTextHeight = $('#bannerTextImgHeight').val();
	status = $('#bannerStatus').val();
	
	arguments = "name="+name+"&bannerUrl="+url+"&bannerImgSrc="+imgSrc+"&bannerImgBorder="+bannerImgBorder+"&bannerTextBorder="+bannerTextBorder+"&bannerImgWidth="+bannerImgWidth+"&bannerTextWidth="+bannerTextWidth+"&bannerImgHeight="+bannerImgHeight+"&bannerTextHeight="+bannerTextHeight+"&bannerStatus="+status+"&addNew=1"; 
	message = document.getElementById("banners_div");
	popupMessage = document.getElementById("result_message_popUp");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
			//popupMessage.innerHTML = "New banner has been added!";
			alert('New banner has been added!');
		 } 
	}); 
}

function setBanners(siteid){
	message = document.getElementById("result_message_popUp");
	banners = document.getElementsByName('banner');
  products = document.getElementsByName('product');
	banners_ids = "";
  products_ids = "";
	
	message.innerHTML = "<img src='../images/loading.gif'>";	
	for($i=0; $i<banners.length; $i++){
		if(banners[$i].checked == true){
			banners_ids += banners[$i].value+"|";
		}
	}
  
  for($i=0; $i<products.length; $i++){
		if(products[$i].checked == true){
			products_ids += products[$i].value+"|";
		}
	} 
  
	arguments = "siteid="+siteid+"&banners_ids="+banners_ids+"&products_ids="+products_ids+"&setBanner=1";
    //alert(arguments);	
	$.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateBanners.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
		 } 
	}); 
}
//for banners

//for links
function updateLinkForm(linkid){

	arguments = "linkid="+linkid+"&showUpdateCodeForm=1"; 
	
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function updatedLinkStatus(linkid, status){
	
	arguments = "linkid="+linkid+"&status="+status+"&update=1"; 
	statusSpan = document.getElementById("status"+linkid);
	actionSpan = document.getElementById("action"+linkid);
	statusSpan.innerHTML = "<img src='../images/load.gif'>";	
	actionSpan.innerHTML = "<img src='../images/load.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 if(msg != 'Update failed!' && msg == "0"){
				statusSpan.style.color = "#D72020";
				statusSpan.innerHTML = "inactive";
				actionSpan.innerHTML = "<a href='javascript:updatedLinkStatus("+linkid+",1)'><img src='../images/accept.gif' title='activate' style='border:none;'></a>";
			 }
			 else if(msg != 'Update failed!' && msg == "1"){
				statusSpan.style.color = "#0C5CC2";
				statusSpan.innerHTML = "active";
				actionSpan.innerHTML = "<a href='javascript:updatedLinkStatus("+linkid+",0)'><img src='../images/inactive.png' title='activate' style='border:none;'></a>";
			 }
			 
		 } 
	}); 
}


function update(linkid){
	
	name = $('#linkName').val();
	desc = $('#linkDesc').val();
	url = $('#linkTextUrl').val();
	category = $('#linkCategory').val();
	status = $('#linkStatus').val();

	arguments = "linkid="+linkid+"&status="+status+"&name="+name+"&linkUrl="+url+"&linkDesc="+desc+"&categoryid="+category+"&updateCode=1";
	popupMessage = document.getElementById("result_message_popUp");
	message = document.getElementById("links_div");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			 if(msg != 'Update failed!')
				//popupMessage.innerHTML = 'Affiliate link has been updated!';
				 alert('Affiliate link has been updated!');
			 else	
				//popupMessage.innerHTML = 'Update failed!';
				 alert('Update failed!');
		 } 
	}); 
}

function newLinkForm(){


	arguments = "add=1"; 
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
	
}

function newLink(){

	name = $('#linkName').val();
	link = $('#linkUrl').val();
	desc = $('#linkDesc').val();
	status = $('#linkStatus').val();
	category = $('#linkCategory').val();
	arguments = "name="+name+"&status="+status+"&linkUrl="+link+"&linkDesc="+desc+"&categoryid="+category+"&addNew=1"; 
	message = document.getElementById("links_div");
	popupMessage = document.getElementById("result_message_popUp");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			//popupMessage.innerHTML = "New affiliate link has been added!";
			 alert("New affiliate link has been added!");
		 } 
	}); 
	
	
}

function removeLink(){
	link_ids = $('#deleteIds').val();
	if(link_ids != ""){
		arguments = "link_ids="+link_ids+"&delete=1"; 
		
		links_table = document.getElementById("links_div");
		message = document.getElementById("result_message");
		message.innerHTML = "<img src='../images/loading.gif'>";	
		
		  $.ajax({ 
			 type: "GET", 
			 url: "../ajax/updateLinks.php",  
			 data: arguments, 
			 success: function(msg){ 
				message.innerHTML = "";
				links_table.innerHTML = msg;
			 } 
		});
	}
	$('#deleteIds').val("");
}

function setLinks(siteid){
	message = document.getElementById("result_message_popUp");
	affiliateLinks = document.getElementsByName('link');
  productLinks = document.getElementsByName('product');
	link_ids = "";
  product_ids = "";
	
	message.innerHTML = "<img src='../images/loading.gif'>";	
	for($i=0; $i<affiliateLinks.length; $i++){
		if(affiliateLinks[$i].checked == true){
			link_ids += affiliateLinks[$i].value+"|";
		}
	}
  
  for($i=0; $i<productLinks.length; $i++){
		if(productLinks[$i].checked == true){
			product_ids += productLinks[$i].value+"|";
		}
	}
	arguments = "siteid="+siteid+"&link_ids="+link_ids+"&product_ids="+product_ids+"&setLink=1";
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateLinks.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
		 } 
	}); 
}
//for links

//for rss
function setRss(siteid){
	message = document.getElementById("result_message_popUp");
	rssFeeds = document.getElementsByName('rss');
	articlesNum = document.getElementsByName('articles');
	rssid = "";
	articles = "";
	
	message.innerHTML = "<img src='../images/loading.gif'>";	
	for($i=0; $i<rssFeeds.length; $i++){
		if(rssFeeds[$i].checked == true){
			rssid += rssFeeds[$i].value+"|";
			articles +=articlesNum[$i].value+"|";
		}
	}
	
	arguments = "siteid="+siteid+"&rssid="+rssid+"&articles="+articles;
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateUserRss.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
		 } 
	}); 
}
//for rss

//for templates
function showTemplate(id){
	arguments = "id="+id;
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/showTemplates.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{ prefix: 'temp', buttons: {close: "close" }});
		 } 
	}); 
}

function setTemplate(id,imgPath){
	
	tempId = document.getElementById("hiddenTempId");
	tempId.value = id;
		
	currentTemp = document.getElementById("currentTemplate");

	currentTemp.innerHTML = "<img border='0' src='../images/templates/"+imgPath+"'>";
}

function updateTemplate(siteid, tempid, userid){
		
	message = document.getElementById("result_message");
	imgSpan = document.getElementById("currentTemplate");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	
	arguments = "tempid="+tempid+"&siteid="+siteid+"&userid="+userid;
	//alert(arguments)
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateTemplates.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = 'Updated Successfully!';
			 imgSpan.innerHTML = msg;
		 } 
	}); 
}

//for user rss
function updatedRssStatus(rssid, status){
	arguments = "rssid="+rssid+"&status="+status+"&update=1"; 
	statusSpan = document.getElementById("status"+rssid);
	actionSpan = document.getElementById("action"+rssid);
	statusSpan.innerHTML = "<img src='../images/load.gif'>";	
	actionSpan.innerHTML = "<img src='../images/load.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateRss.php",  
		 data: arguments, 
		 success: function(msg){
			 if(msg != 'Update failed!' && msg == "0"){
				statusSpan.style.color = "#D72020";
				statusSpan.innerHTML = "inactive";
				actionSpan.innerHTML = "<a href='javascript:updatedRssStatus("+rssid+",1)'><img src='../images/accept.gif' title='activate' style='border:none;'></a>";
			 }
			 else if(msg != 'Update failed!' && msg == "1"){
				statusSpan.style.color = "#0C5CC2";
				statusSpan.innerHTML = "active";
				actionSpan.innerHTML = "<a href='javascript:updatedRssStatus("+rssid+",0)'><img src='../images/inactive.png' title='activate' style='border:none;'></a>";
			 }
		 } 
	}); 
}

function removeRss(){
	rss_ids = $('#deleteIds').val();
	if(rss_ids != ""){
		arguments = "rss_ids="+rss_ids+"&delete=1";
		ads_table = document.getElementById("rss_div");
		message = document.getElementById("result_message");
		message.innerHTML = "<img src='../images/loading.gif'>";	
		  $.ajax({ 
			 type: "GET", 
			 url: "../ajax/updateRss.php",  
			 data: arguments, 
			 success: function(msg){
				message.innerHTML = "";
				ads_table.innerHTML = msg;
			 } 
		});
	}
	$('#deleteIds').val("");
}

function updateRssForm(rssid){

	arguments = "rssid="+rssid+"&showUpdateCodeForm=1";
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateRss.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function updateRss(rssid){

	rsstitle = $('#rssTitle').val();
	rsssource = $('#rssSource').val();
	status = $('#rssStatus').val();
	
	arguments = "rssid="+rssid+"&status="+status+"&rsstitle="+rsstitle+"&rsssource="+rsssource+"&updateCode=1"; 
	//alert (arguments)
	popupMessage = document.getElementById("result_message_popUp");
	message = document.getElementById("rss_div");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateRss.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			 if(msg != 'Update failed!')
				alert('Rss Feed has been updated!');
			 else	
				alert('Update failed!');
		 } 
	}); 
}

function newRssForm(){
	arguments = "add=1"; 
	  $.ajax({ 
		 beforeSend: function(){
		   prePrompt();
		 },
		 complete: function(){
		   postPrompt();
		 },
		 type: "GET", 
		 url: "../ajax/updateRss.php",  
		 data: arguments, 
		 success: function(msg){ 
			 $.prompt(msg,{buttons: {close: "close" }});
		 } 
	});
}

function newRss(){
	rsstitle = $('#rssTitle').val();
	rsssource = $('#rssSource').val();
	status = $('#rssStatus').val();
	
	arguments = "rsstitle="+rsstitle+"&rsssource="+rsssource+"&status="+status+"&addNew=1"; 
	message = document.getElementById("rss_div");
	popupMessage = document.getElementById("result_message_popUp");
	popupMessage.innerHTML = "<img src='../images/loading.gif'>";	
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateRss.php",  
		 data: arguments, 
		 success: function(msg){ 
			 message.innerHTML = msg;
			popupMessage.innerHTML = "New Rss Feed has been added!";
		 } 
	}); 
}

//to edit user status in admin-member area
function updateUserStatus(userId){
	message = document.getElementById("user_status_result");
	message.innerHTML = "<img src='../images/loading.gif'>";	
	arguments = "userid="+userId+"&newStatus="+document.getElementById('user_status').value;
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/updateUserStatus.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}
//end of user.js

function contactByEmail(email){
	message = document.getElementById("email_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";
	
if(email_checker("email") == false){
	message.innerHTML = "<span style='color: #ff0000; font-size: 12px; font-style: italic;'>Please enter a valid email.</span>";
	//return false;
} else {

var strReplaceAll = document.getElementById('message').value;
	 var intIndexOfMatch = strReplaceAll.indexOf( "\n" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strReplaceAll = strReplaceAll.replace( "\n", "<br>" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strReplaceAll.indexOf( "\n" );
	 }

	arguments = "email="+document.getElementById('email').value+"&name="+document.getElementById('name').value+"&message="+strReplaceAll; 
	//alert(arguments)
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/contactByEmail.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
}	
}

function upgradeEmail(){
	var plan = "";
	message = document.getElementById("email_result_message");
	message.innerHTML = "<img src='../images/loading.gif'>";

var strReplaceAll = document.getElementById('message').value;
	 var intIndexOfMatch = strReplaceAll.indexOf( "\n" );
	 // Loop over the string value replacing out each matching
	 // substring.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strReplaceAll = strReplaceAll.replace( "\n", "<br>" )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strReplaceAll.indexOf( "\n" );
	 }
	 requestedPlan = document.getElementsByName('requested_plan');
	 for($i=0; $i<requestedPlan.length; $i++){
		if(requestedPlan[$i].checked == true)
			plan = requestedPlan[$i].value;
	}

	arguments = "id="+document.getElementById('id').value+"&plan="+plan+"&email="+document.getElementById('email').value+"&message="+strReplaceAll; 
	//alert(plan)
	  $.ajax({ 
		 type: "GET", 
		 url: "../ajax/upgradeMail.php",  
		 data: arguments, 
		 success: function(msg){ 
			message.innerHTML = msg;
		 } 
	});	
	
}