$(document).ready(function(){
	
	get_rss_feed();	
	

	
 });



function showSendfriend(){

	if(document.getElementById("sendfriend").style.display == "block"){
			$(document.getElementById("sendfriend")).fadeOut(500);
	}else{
			$(document.getElementById("sendfriend")).fadeIn(500);
	}
}

function showPartnerCode(){

	if(document.getElementById("partner-shop-code").style.display == "none"){
			$(document.getElementById("partner-shop-code")).fadeIn(500);
	}else{
			$(document.getElementById("partner-shop-code")).fadeOut(500);
	}
}

function get_rss_feed() {
	//clear the content in the div for the next feed.
	feeddiv = document.getElementById("feedContent");
	feedurl = document.getElementById("feedUrl");
	//alert(feedurl);
	$(feeddiv).empty();
 
	//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	$.get($(feedurl).val(), function(d) {
	
		//find each 'item' in the file and parse it
		$(d).find('item').each(function() {
 
			//name the current found item this for this particular loop run
			var $item = $(this);
			// grab the post title
			var title = $item.find('title').text();
			// grab the post's URL
			var link = $item.find('link').text();
			// next, the description
			var description = $item.find('description').text();
			//don't forget the pubdate
			var pubDate = $item.find('pubDate').text();
 
		// now create a var 'html' to store the markup we're using to output the feed to the browser window
			var html = "<div class=\"date-box\">" + title + pubDate + "</div>";
			html += "<div class=\"news-item-box\">" + description + "<br /><br /><a href=\"" + link + "\" target=\"_self\">Read More >><\/a></div>";
 

			//put that feed content on the screen!
			$('#feedContent').append($(html));  
		});
	});
 
};

function switcher(obj) {
			
			var hideme = document.getElementById("current_id").value;
			
			document.getElementById(hideme).style.display = "none";
			document.getElementById(obj).style.display = "block";
			//$(document.getElementById(hideme)).slideUp(500);
			//$(document.getElementById(obj)).slideDown(500);
			
			
		document.getElementById("current_id").value=obj;
 
				
}

function showOffer(){
			
				if(document.getElementById("popupoffer").style.display == "block"){
						$(document.getElementById("popupoffer")).hide(1000);
				}else{
						$(document.getElementById("popupoffer")).show(1000);
				}
			}
			
			function showresults(){

				if(document.getElementById("search-results").style.display == "block"){
						$(document.getElementById("search-results")).slideUp(1000);
				}else{
						$(document.getElementById("search-results")).slideDown(1000);
				}
			}
			
			function sendFriend(){
			
				if(document.getElementById("sendfriend").style.display == "block"){
						$(document.getElementById("sendfriend")).hide(1000);
				}else{
						$(document.getElementById("sendfriend")).show(1000);
				}
			}
			
			
			function checkFriend(){
			
					//function to check valid email address
					  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
					  strEmail = document.getElementById("friend2").value;
					
					   // search email text for regular exp matches
						if (strEmail.search(validRegExp) == -1) {
						alert('Please enter a valid email address');
						document.getElementById("friend2").style.backgroundColor = "#666666";
						document.getElementById("friend2").value = "Please enter a valid email address";
						return false;
						} 
						
						friendSender();
			
						document.getElementById("sendlink").disabled=true;
						toggle("animation");
						toggle("done_id");
						return true;
			
			}

//AJAX CALLS
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}



function toggle(obj) {

	if(document.getElementById(obj).style.display == 'none'){
		$(document.getElementById(obj)).slideDown(200);
	
	}else{
	
		$(document.getElementById(obj)).slideUp(200);
		
	}
		
}



function friendSender(){
	xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 
	var name = document.getElementById("friend1").value;
	var email = document.getElementById("friend2").value;
	var msg = document.getElementById("msg").value;

	var url="includes/ajax_friend_sender.php";
	url=url+"?sid="+Math.random()
	url=url+"&name="+name
	url=url+"&email="+email
	url=url+"&msg="+msg

	xmlHttp.onreadystatechange=activeUpdate;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}


function activeUpdate() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	  var thecode = xmlHttp.responseText;

	  toggle("done_id");
	  document.getElementById("sendlink").disabled=false;
 	  document.getElementById('done_id').innerHTML=thecode;


 } 
}


function goSearch(box, chosen){
	
	var tosearch = box;
	var val = chosen;
	
	searchstring = document.getElementById(tosearch).value;
	if(searchstring == ""){
	alert("Please type something into the search box");	
	return false;
	}else{
	
				xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null)
				 {
					alert ("Browser does not support HTTP Request")
				 return
				 }
				 
			var url="includes/ajax_search.php";
			url=url+"?sid="+Math.random();
			url=url+"&txt="+searchstring;
			url=url+"&cat="+val;
			
				showresults();
			toggle("searching");
		
			xmlHttp.onreadystatechange=activeUpdateSearch;
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)
	

	
	}
}

function activeUpdateSearch() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	  var thecode = xmlHttp.responseText;

	  toggle("searching");
	  toggle("search-done");
 	  document.getElementById('search-done').innerHTML=thecode;


 } 
}


function closeresults(){
		  
		  toggle("search-done");
		showresults();
	
}









