// JavaScript Document

/**************************************************

	Global variables 
	
***************************************************/
var userIsLogged 	= 0 ;
var adID 			= "";
var response_id 	= "";
var title 			= "";	
var loggd 			= "";

if ( window.location.hostname == 'localhost' )
{
	var BASE_URL 	= "http://localhost/maduqa7/";
}
else
{
	var BASE_URL 	= "http://www.maduqa.com/";
}




/**************************************************

	The function is executed on load of any page;
	It checks if the user is logged in or not,
	Then loads the relevant DIVs
	
***************************************************/
function OnLoad()
{
	xmlhttp = createXmlHttpRequestObject();	
		
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4 ) 
		{// do something
			
			var xmlDoc 			= xmlhttp.responseXML.documentElement;
			
			var loggedInArray 	= xmlDoc.getElementsByTagName("registered");
			
			for(var i=0; i < loggedInArray.length; i++)
			{
				var isloggd = loggedInArray.item(i).firstChild.data;
				
				if( isloggd == 'y' ){loggd = 'y';}
				else{loggd = 'n';}
				
				var inviteURL = BASE_URL+"includes/php/oIndexInviteFriends.php?isLogged="+loggd;
				var headerURL = BASE_URL+"includes/php/oAjaxHeader.php?LoggedIn="+loggd;
				var introURL = BASE_URL+"includes/php/oIndexIntroAjax.php?isLogged="+loggd;
				
				xmlreqGET( inviteURL, "indexInviteSlice" );
				xmlreqGET( headerURL, "ajaxHeader" );
				xmlreqGET( introURL, "intro" );	
			}
		}	
		else
		{// error
		}
	}
	xmlhttp.open("GET", BASE_URL+'includes/php/isLoggedIn.php', true);
	xmlhttp.send(null);
}




/**************************************************

	The following procedures create xmlhttp objects
	creates an XMLHttpRequest instance 
	
***************************************************/
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
	// try to create XMLHttpRequest object
	xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
	// assume IE6 or older
	var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
									"MSXML2.XMLHTTP.5.0",
									"MSXML2.XMLHTTP.4.0",
									"MSXML2.XMLHTTP.3.0",
									"MSXML2.XMLHTTP",
									"Microsoft.XMLHTTP");
	// try every prog id until one works
	for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
	{
	  try 
	  { 
		// try to create XMLHttpRequest object
		xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
	  } 
	  catch (e) {}
	}
  }
  // return the created object or display an error message
  if (!xmlHttp)
  {
	alert("Error creating the XMLHttpRequest object.");
  }
  else 
  {
	return xmlHttp;
  }
}
function getxmlhttp ()
{
	//Create a boolean variable to check for a valid Microsoft active x instance.
	var xmlhttp = false;
	//Check if we are using internet explorer.
	try 
	{
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		//If not, then use the older active x object.
		try 
		{
			//If we are using internet explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			//Else we must be using a non-internet explorer browser.
			xmlhttp = false;
		}
	}
	// If not using IE, create a
	// JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}




/*****************************************************************
*
*	The function to update the status of the user every 10seconds.
*	The function checks if the user is still logged into the system
*
*******************************************************************/
function update() 
{		
	var pageURL = BASE_URL+'update.php';
	
	xmlhttp = getxmlhttp();	
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ) 
		{// do something
		}	
		else
		{// error
		}
	}
	xmlhttp.open("GET", pageURL, true);
	xmlhttp.send(null);

}	

setInterval("update();", 10000); // Update every 10 seconds	


/*************************************************************
	This function updates the status of the user.
	It checks if the user is still logged in or not.
	Then it changes the display at the header 
	and the index page.
	Displays or hides some DIVs depending on the login status
	
***************************************************************/


function AjaxHeader(oStatus)
{
	var loggd = "";
	
	if( oStatus == 1 )
	{			
		loggd = 'y';
	}
	else if ( oStatus == 0 )
	{
		loggd = 'n';
	}			
	
	var inviteURL = BASE_URL+"includes/php/oIndexInviteFriends.php?isLogged="+loggd;
	var headerURL = BASE_URL+"includes/php/oAjaxHeader.php?LoggedIn="+loggd;
	var introURL = BASE_URL+"includes/php/oIndexIntroAjax.php?isLogged="+loggd;
	
	xmlreqGET( inviteURL, "indexInviteSlice" );
	xmlreqGET( headerURL, "ajaxHeader" );
	xmlreqGET( introURL, "intro" );	

}



/************************************************************
	
	The procedure below solves the problem of having to call
	Several xmlhttp objects at the same time in the same page.
	It uses array to store the objects then pops them while 
	processing the retuirned data.

*************************************************************/

var xmlreqs = new Array(); 

function CXMLReq(type, xmlhttp) 
{ 
	this.type = type; 
	this.xmlhttp = xmlhttp; 
} 

function xmlreqGET(url, obj) 
{ 
	var xmlhttp=false; 
	
	if( !isblank(obj)  )
	{
		if( document.getElementById(obj) != null )		
		document.getElementById(obj).innerHTML = '<div style="font: normal 10px Tahoma; color:#ccc; margin: 5px; display: block;  text-align:center; width: 90%; height: 90%; vertical-align:middle;"><img src="'+BASE_URL+'images/loading.gif" /> wait...</div>';
	}
	
	if (window.XMLHttpRequest) 
	{ // Mozilla, etc. 
		xmlhttp=new XMLHttpRequest();
		
		xmlhttp.onreadystatechange = function()
		{
			if (typeof(window['xmlreqs']) == "undefined") 
			
			return; var xmldoc = null; 
				
			for (var i=0; i < xmlreqs.length; i++) 
			{ 
				if (xmlreqs[i].xmlhttp.readyState == 4) 
				{ 
					if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status == 304) 
					{ 
						if (document.implementation && document.implementation.createDocument) 
						{ 
							xmldoc = document.implementation.createDocument("", "", null); 
						} 
						else if (window.ActiveXObject) 
						{ 
							xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 
						} 						
						//xmldoc = xmlreqs[i].xmlhttp.responseXML; 						
						if( !isblank(obj) )
						{
							if( document.getElementById(obj) != null )
							document.getElementById(obj).innerHTML = xmlhttp.responseText;
						}
						xmlreqs.splice(i,1); i--; 						
						//handle_response(xmldoc); 
					} 
					else 
					{ // error 
						xmlreqs.splice(i,1); i--; 
					} 
				} 
			} 			
		}
		
		xmlhttp.open("GET",url,true); 
		
		xmlhttp.send(null); 
	} 
	else if (window.ActiveXObject) 
	{ // IE 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		
		if (xmlhttp) 
		{ 
			xmlhttp.onreadystatechange = xmlhttpChange; 
			xmlhttp.open("GET",url,true); 
			xmlhttp.send(); 
		} 
	} 
	
	var xmlreq = new CXMLReq('', xmlhttp); 
	
	xmlreqs.push(xmlreq); 
} 


function xmlreqPOST(url,data) 
{ 
	var xmlhttp=false; 
	
	if (window.XMLHttpRequest) 
	{ // Mozilla etc. 
		xmlhttp=new XMLHttpRequest(); 
		xmlhttp.onreadystatechange=xmlhttpChange; 
		xmlhttp.open("POST",url,true); 
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		xmlhttp.send(data); 
	} 
	else if (window.ActiveXObject) 
	{ // IE 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		
		if (xmlhttp) 
		{ 
			xmlhttp.onreadystatechange=xmlhttpChange; 
			xmlhttp.open("POST",url,true); 
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			xmlhttp.send(data); 
		} 
	} 
	
	var xmlreq = new CXMLReq('', xmlhttp); 
	
	xmlreqs.push(xmlreq); 
} 

function xmlhttpChange() 
{ 
	if (typeof(window['xmlreqs']) == "undefined") 
		return; var xmldoc = null; 
		
	for (var i=0; i < xmlreqs.length; i++) 
	{ 
		if (xmlreqs[i].xmlhttp.readyState == 4) 
		{ 
			if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status == 304) 
			{ 
				if (document.implementation && document.implementation.createDocument) 
				{ 
					xmldoc = document.implementation.createDocument("", "", null); 
				} 
				else if (window.ActiveXObject) 
				{ 
					xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 
				} 
				
				xmldoc = xmlreqs[i].xmlhttp.responseXML; 
				xmlreqs.splice(i,1); i--; 
				
				//handle_response(xmldoc); 
			} 
			else 
			{ // error 
				xmlreqs.splice(i,1); i--; 
			} 
		} 
	} 
}


/**************************************************

	validate email addresses
	
***************************************************/
function validate(address) 
{
   	var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
	if(reg.test(address) == false) 	{  return false;   	}
   	else{ return true; }
}





/**************************************************

	contact user
	
***************************************************/
function contactUser(userAdID)
{	
	adID = userAdID;
	
	$.post(
			BASE_URL+'includes/php/isLoggedIn.php', 	{ } , 
			function (data)	
			{ 			
				$(data).find('userLogin').each(function()	
				{
					var isloggd = $(this).find('registered').text()					
					if( isloggd == 'y' )
					{ 
						jQuery.facebox(function() {	jQuery.get(BASE_URL+'includes/php/contactUserUI.php', function(data) { jQuery.facebox(data).html();	})	}) 	
					}
					else
					{ 
						jQuery.facebox(function() {	jQuery.get(BASE_URL+'includes/php/loginUI.php?whichMod=contactUser', function(data) {jQuery.facebox(data).html();})	})	
					}
				});
			});
}

/***********************************************************************************************************88*

ad_det.PHP: 

SEND EMAILS FROM THE ad_det.PHP PAGE

****************************************************************************************************************/
/*
	email the advertiser of the product fom the ad_det.php page
	the page that displays more infor about the advert from the classifieds section
	
	email user	
*/
function email_the_user(f)
{	
	document.getElementById("emailerr").style.display = "none";
	document.getElementById("emptymsg").style.display = "none";
	document.getElementById("invalidemailerr").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'txt_your_email' ) {
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) {			
					document.getElementById("emailerr").style.display = "inline"; return false; }
				else { var email = e.value; }
			}
			if( e.name == 'txt_your_msg' ) 	{
				var oCurrentMessage	= tinyMCE.get('txt_your_msg').getContent(); 			
				//first check if the field is empty
				if ((oCurrentMessage == null) || ( oCurrentMessage == "") || isblank( oCurrentMessage ))  { document.getElementById("emptymsg").style.display = "inline"; return false; }
				else { var msg = oCurrentMessage; 	}
			}
			if( e.name == 'advertiser_email' ) 	{ var advertiser_email = e.value; }
			if( e.name == 'txt_subject' ) { 	var subject = e.value; 	}
			if( e.name == 'the_link' ) 	{ var the_link = e.value;  }
		}
	}	
	if ( !validate( email ) ){  document.getElementById("invalidemailerr").style.display = "inline"; return false;  }	
	document.getElementById('cat_top').innerHTML = '<div style="display:block;font: bold 16px Tahoma; color:#ccc; padding: 10px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(   function()   { 	jQuery.post(  BASE_URL+'includes/php/oEmailUser.php', {'op':'tell_advertiser', 'the_link': the_link, 'email': email , 'advertiser_email': advertiser_email , 'subject': subject, 'msg': msg  },  	function(data) { document.getElementById('cat_top').innerHTML = '<div style="display:block;font: bold 16px Tahoma; color:#ccc; padding: 10px">Your message has been sent.</div>'; 	});  });
	closeFaceBox()		
}

/*
	Tell a friend sbout a product/alssified from the ad_det.php page
	email tell a friend/user
*/

function email_tell_a_friend(f)
{
	document.getElementById("friend_emailerr").style.display = "none";
	document.getElementById("friend_emptymsg").style.display = "none";
	document.getElementById("friend_invalidemailerr").style.display = "none";
	document.getElementById("friend_to_emailerr").style.display = "none";
	document.getElementById("friend_to_invalidemailerr").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'friend_txt_your_email' )	{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) { document.getElementById("friend_emailerr").style.display = "inline"; 	return false; }
				else { 	var email = e.value; }
			}
			if( e.name == 'friend_txt_recepient' ) 	{
				//first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value))  	{ document.getElementById("friend_to_emailerr").style.display = "inline"; return false; 	}
				else { var recepient = e.value;  }
			}
			if( e.name == 'friend_txt_subject' ) { 
				//first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value))  	{ 	return false; 	}
				else {	var subject = e.value; 	}
			}
			if( e.name == 'friend_txt_your_msg' ) {
				var oCurrentMessage	= tinyMCE.get('friend_txt_your_msg').getContent();				
				//first check if the field is empty
				if ((oCurrentMessage == null) || ( oCurrentMessage == "") || isblank( oCurrentMessage ))  { 	document.getElementById("friend_emptymsg").style.display = "inline";  return false; 	}
				else { 	var msg = oCurrentMessage;	}
			}
			if( e.name == 'friend_the_link' ) {	var the_link = e.value; 	}
		}
	}
	
	if ( !validate( email ) ) 	{ 	document.getElementById("friend_invalidemailerr").style.display = "inline"; return false; }
	if ( !validate( recepient ) ) { document.getElementById("friend_to_invalidemailerr").style.display = "inline"; 	return false; }
	
	document.getElementById('dog_top').innerHTML = '<div style="display:block;font: bold 16px Tahoma; color:#ccc; padding: 10px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(  function()   {	jQuery.post( 	BASE_URL+'includes/php/oEmailUser.php', { 'op':'tell_a_friend', 'the_link': the_link, 'email': email , 'recepient': recepient , 'subject': subject, 'msg': msg  }, 	function(data) { document.getElementById('dog_top').innerHTML = '<div style="display:block;font: bold 16px Tahoma; color:#ccc; padding: 10px">Message has been sent.</div>'; });  	});
	closeFaceBox()
}

/***********************************************************************************************************88*

GETPRODUCT.PHP: 

SEND EMAILS FROM THE GETPRODUCT.PHP PAGE

****************************************************************************************************************/
/*
	Send email to the shop owner from the getproduct.php page
	The page that dis[plays prodyuct infor from the shop
	shop email user
*/

function shop_email_user(f)
{	
	document.getElementById("email_err").style.display = "none";
	document.getElementById("msg_err").style.display = "none";
	document.getElementById("invalid_email_err").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'email' )	{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 	{ 	document.getElementById("email_err").style.display = "inline"; 	return false; }
				else { 	var email = e.value; }
			}
			if( e.name == 'msg' ){
				//first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) { document.getElementById("msg_err").style.display = "inline"; return false; }
				else { 	var msg = e.value; 	}
			}
			if( e.name == 'shop_email' ) { 	var shop_email = e.value; 	}
			if( e.name == 'subject' ) { 	var subject = e.value; 	}
			if( e.name == 'the_link' ) 	{ 	var the_link = e.value; }
		}
	}	
	if ( !validate( email ) ) { document.getElementById("invalid_email_err").style.display = "inline"; 	return false; 	}	
	document.getElementById('shop_cat_top').innerHTML = '<div style="display:block;font: bold 14px Tahoma; color:#ccc; padding: 15px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(   function()   {	jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'tell_shop', 'the_link': the_link, 'email': email , 'shop_email': shop_email , 'subject': subject, 'msg': msg  }, function(data) { jQuery.facebox(data).html(); 	}); });
	closeFaceBox()		
}

/*
	send email from the getprodcu.php page
	the page that displays more product infor from the shop
	gets an aary of emails and sends the emails
	
	shop email tell a friend
*/
function shop_tell_friend(f)
{	
	document.getElementById("tell_email_err").style.display = "none";
	document.getElementById("tell_msg_err").style.display = "none";
	document.getElementById("tell_invalid_email_err").style.display = "none";
	document.getElementById("tell_friend_email_err").style.display = "none";
	document.getElementById("tell_invalid_friend_email_err").style.display = "none"; 
	
	for(var i = 0; i < f.length; i++) 
	{ 
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'tell_email' ) {
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)){ document.getElementById("tell_email_err").style.display = "inline"; return false; }
				else { 	var email = e.value; }
			}
			if( e.name == 'tell_friend_email' )	{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) {	document.getElementById("tell_friend_email_err").style.display = "inline"; 	return false; }
				else { 	var friend_email_array = e.value; }
			}
			if( e.name == 'tell_msg' ) 	{
				//first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value))  { document.getElementById("tell_msg_err").style.display = "inline";  	return false;  	}
				else { 	var msg = e.value; 	}
			}		
			if( e.name == 'tell_subject' ) 	{ 	var subject = e.value; 	}
			if( e.name == 'tell_the_link' ) { var the_link = e.value; 	}
		}
	}
	
	var my_array = friend_email_array.split(","); 	
	for(var i = 0; i < my_array.length; i++) {
		var oEmail = my_array[i].replace(/^\s*/, "").replace(/\s*$/, "");		
		if ( !validate( oEmail ) ) 	{ document.getElementById("tell_invalid_email_err").style.display = "inline"; return false;	}
	}	
	if ( !validate( email ) ) { document.getElementById("tell_invalid_email_err").style.display = "inline"; return false; 	}	
	document.getElementById('shop_cat_top').innerHTML = '<div style="display:block;font: bold 14px Tahoma; color:#ccc; padding: 15px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(   function()  { 	jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'tell_shop_friend', 'the_link': the_link, 'email': email , 'email_array': friend_email_array , 'subject': subject, 'msg': msg  }, function(data)	{ 	jQuery.facebox(data).html();	});  });
	closeFaceBox()		
}

/*
	send an email to the maduqa admin from the getproduct.php page
	The page that displays more infor on the product
	its an  overlay / popup
	
	shop email admin
*/
function shop_tell_admin(f){
	document.getElementById("report_email_err").style.display = "none";
	document.getElementById("report_msg_err").style.display = "none";
	document.getElementById("report_invalid_email_err").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{ 
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'report_email' ) {
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) {			
					document.getElementById("report_email_err").style.display = "inline"; return false;
				}
				else { var email = e.value; }
			}
			if( e.name == 'report_msg' ) {
				//first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) { document.getElementById("report_msg_err").style.display = "inline"; return false; }
				else{ var msg = e.value; }
			}		
			if( e.name == 'report_subject' ) { var subject = e.value; }
			if( e.name == 'report_the_link' ) { var the_link = e.value; }
		}
	}	
	if ( !validate( email ) ) { document.getElementById("report_invalid_email_err").style.display = "inline"; return false; }	
	document.getElementById('shop_cat_top_report').innerHTML = '<div style="display:block;font: bold 14px Tahoma; color:#ccc; padding: 15px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(  function()  { jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'tell_shop_report', 'the_link': the_link, 'email': email , 'subject': subject, 'msg': msg  }, function(data){ 	jQuery.facebox(data).html();    }); 	});
	closeFaceBox()		
}










/***********************************************************************************************************88*

GETSHOP.PHP: 

SEND EMAILS FROM THE GETSHOP.PHP PAGE

****************************************************************************************************************/
/*
	Send email to the shop owner from the getproduct.php page
	The page that dis[plays prodyuct infor from the shop
	shop email user
*/

function from_shop_email_owner(f)
{	
	document.getElementById("shop_email_err").style.display = "none";
	document.getElementById("shop_msg_err").style.display = "none";
	document.getElementById("shop_invalid_email_err").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'shop_email' )	{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 	{ 	document.getElementById("shop_email_err").style.display = "inline"; 	return false; }
				else { 	var email = e.value; }
			}
			if( e.name == 'shop_msg' ){
				var oCurrentMessage	= tinyMCE.get('shop_msg').getContent();
				//first check if the field is empty
				if (( oCurrentMessage == null) || ( oCurrentMessage == "") || isblank( oCurrentMessage )) { document.getElementById("shop_msg_err").style.display = "inline"; return false; }
				else { 	var msg = oCurrentMessage; 	}
			}
			if( e.name == 'shop_shop_email' ) { 	var shop_email = e.value; 	}
			if( e.name == 'shop_owner_email' ) { 	var shop_owner_email = e.value; 	}
			if( e.name == 'shop_subject' ) { 	var subject = e.value; 	}
			if( e.name == 'shop_the_link' ) 	{ 	var the_link = e.value; }
		}
	}	
	if ( !validate( email ) ) { document.getElementById("shop_invalid_email_err").style.display = "inline"; 	return false; 	}	
	document.getElementById('shop_cat1_top').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding: 5px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(   function()   {	jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'from_shop_to_owner', 'shop_owner_email': shop_owner_email, 'the_link': the_link, 'email': email , 'shop_email': shop_email , 'subject': subject, 'msg': msg  }, function(data) { jQuery.facebox(data).html(); 	}); });
	closeFaceBox()	
	document.getElementById('shop_cat1_top').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding:0"></div>';
	document.getElementById("shop_cat1_top").style.display = "none";
	
}

/*
	send email from the getprodcu.php page
	the page that displays more product infor from the shop
	gets an aary of emails and sends the emails
	
	shop email tell a friend
*/
function from_shop_tell_friend(f)
{	
	document.getElementById("shop_tell_email_err").style.display = "none";
	document.getElementById("shop_tell_msg_err").style.display = "none";
	document.getElementById("shop_tell_invalid_email_err").style.display = "none";
	document.getElementById("shop_tell_friend_email_err").style.display = "none";
	document.getElementById("shop_tell_invalid_friend_email_err").style.display = "none"; 
	
	for(var i = 0; i < f.length; i++) 
	{ 
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'shop_tell_email' ) {
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)){ document.getElementById("shop_tell_email_err").style.display = "inline"; return false; }
				else { 	var email = e.value; }
			}
			if( e.name == 'shop_tell_friend_email' )	{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) {	document.getElementById("shop_tell_friend_email_err").style.display = "inline"; 	return false; }
				else { 	var friend_email_array = e.value; }
			}
			if( e.name == 'shop_tell_msg' ) 	{
				var oCurrentMessage	= tinyMCE.get('shop_tell_msg').getContent();
				//first check if the field is empty
				if ((oCurrentMessage == null) || (oCurrentMessage == "") || isblank(oCurrentMessage))  { document.getElementById("shop_tell_msg_err").style.display = "inline";  	return false;  	}
				else { 	var msg = oCurrentMessage; 	}
			}		
			if( e.name == 'shop_tell_subject' ) 	{ 	var subject = e.value; 	}
			if( e.name == 'shop_tell_the_link' ) { var the_link = e.value; 	}
		}
	}
	//alert(msg)
	var my_array = friend_email_array.split(","); 	
	for(var i = 0; i < my_array.length; i++) {
		var oEmail = my_array[i].replace(/^\s*/, "").replace(/\s*$/, "");		
		if ( !validate( oEmail ) ) 	{ document.getElementById("shop_tell_invalid_friend_email_err").style.display = "inline"; return false;	}
	}	
	if ( !validate( email ) ) { document.getElementById("shop_tell_invalid_email_err").style.display = "inline"; return false; 	}	
	document.getElementById('shop_dog1_top').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding: 5px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(   function()  { 	jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'tell_friend_from_shop', 'the_link': the_link, 'email': email , 'email_array': friend_email_array , 'subject': subject, 'msg': msg  }, function(data)	{ 	jQuery.facebox(data).html();	});  });
	//closeFaceBox()
	document.getElementById('shop_dog1_top').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding:0"></div>';
	document.getElementById("shop_dog1_top").style.display = "none";
}

/*
	send an email to the maduqa admin from the getproduct.php page
	The page that displays more infor on the product
	its an  overlay / popup
	
	shop email admin
*/
function from_shop_tell_admin(f)
{
	document.getElementById("from_shop_report_email_err").style.display = "none";
	document.getElementById("from_shop_report_msg_err").style.display = "none";
	document.getElementById("from_shop_report_invalid_email_err").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{ 
		var e = f.elements[i];
		
		if ( e.tagName == "TEXTAREA" || ( e.tagName == "INPUT"   &&  ( e.type == "text" || e.type == "hidden" ) &&  !e.optional && e.type != "submit" && e.type != "button"   ) ) 	
		{
			if( e.name == 'from_shop_report_email' ) {
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) {			
					document.getElementById("from_shop_report_email_err").style.display = "inline"; return false;
				}
				else { var email = e.value; }
			}
			if( e.name == 'from_shop_report_msg' ) {
				var oCurrentMessage	= tinyMCE.get('from_shop_report_msg').getContent();
				//first check if the field is empty
				if (( oCurrentMessage == null) || ( oCurrentMessage == "") || isblank( oCurrentMessage )) { document.getElementById("from_shop_report_msg_err").style.display = "inline"; return false; }
				else{ var msg = oCurrentMessage; }
			}		
			if( e.name == 'from_shop_report_subject' ) { var subject = e.value; }
			if( e.name == 'from_shop_report_the_link' ) { var the_link = e.value; }
		}
	}	
	if ( !validate( email ) ) { document.getElementById("from_shop_report_invalid_email_err").style.display = "inline"; return false; }	
	document.getElementById('shop_rabbit1_top_report').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding: 2px"><img src="'+BASE_URL+'images/loading_2.gif" /> Sending message....</div>';
	jQuery.facebox(  function()  { jQuery.post( BASE_URL+'includes/php/oEmailUser.php', {'op':'from_shop_report', 'the_link': the_link, 'email': email , 'subject': subject, 'msg': msg  }, function(data){ 	jQuery.facebox(data).html();  document.getElementById("shop_rabbit1_top_report").style.display = "none";    }); 	});
	closeFaceBox()
	document.getElementById('shop_rabbit1_top_report').innerHTML = '<div style="display:block;font: bold 12px Tahoma; color:#ccc; padding: 0px"></div>';
}









/**************************************************

	login to maduqa
	
***************************************************/
function Login(f)
{	//alert(f)
	document.getElementById("emailerr").style.display = "none";
	document.getElementById("passworderr").style.display = "none";
	document.getElementById("invalidemailerr").style.display = "none";
	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		
		if ( e.tagName == "INPUT"  &&  ( e.type == "text" || e.type == "password" || e.type == "hidden") &&  !e.optional && e.type != "submit" && e.type != "button"   ) 	
		{
			if( e.name == 'email' )	
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value))
				{			
					document.getElementById("emailerr").style.display = "inline";
					return false;
				}
				else
				{
					var email = e.value;
				}
			}
			if( e.name == 'password' )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("passworderr").style.display = "inline";
					return false;
				}
				else
				{
					var password = e.value;
				}
			}
			if( e.name == 'which' )	
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					//document.getElementById("emailerr").style.display = "inline";
					return false;
				}
				else
				{
					var which = e.value;
				}
			}
		}
	}
	
	if ( !validate( email ) )
	{
		document.getElementById("invalidemailerr").style.display = "inline";
		return false;
	}
	
	jQuery.facebox(function(){			
		$.post(
				BASE_URL+'includes/php/eLogin.php', 
				{'email': email , 'password': password } , 
				function (data)	{ 
					$(data).find('userLogin').each(function(){
						var loginSuccess = $(this).find('registered').text()
						var userID = $(this).find('userID').text()
						var fname = $(this).find('fname').text()														
						var lname = $(this).find('lname').text()						
						
						if( loginSuccess == 'y' )
						{
							var IsLogged = 1;	
							AjaxHeader(IsLogged); 
							closeFaceBox();
						}	
							
						
						if( which == 'contactUser' ){afterLogin( loginSuccess, contactUser(adID), contactUser(adID))}
						if( which == 'productChat' ){afterLogin( loginSuccess, sendMessage(),checkUsername())}
						if( which == 'tellAfriend' ){afterLogin( loginSuccess, tellAfriend(),tellAfriend())	}
						if( which == 'inviteYourFriends' ){afterLogin( loginSuccess, inviteYourFriends(),inviteYourFriends())}
						if( which == 'AddToWishList' )
						{	
							afterLogin( loginSuccess, AddToWishList(adID),AddToWishList(adID))
						}
						if( which == 'mainLogin' )
						{	
							if( loginSuccess == 'y' )
							{
								closeFaceBox();
								var IsLogged = 1;	
								AjaxHeader(IsLogged); 
							}
							else
							{
								waitLogin();
							}
						}
					});
				}
			)				
	});	
}





/**************************************************

	what to do after login to maduqa
	
***************************************************/
function afterLogin( loginFeedBack, func0ne, funcTwo)
{
	if( loginFeedBack == 'y' ){	func0ne;	}
	else{ funcTwo; }
}




/**************************************************

	contact user
	
***************************************************/
function contactUserMsg(f){
	for(var i = 0; i < f.length; i++) 	{
		var e = f.elements[i];	
		if( e.id == 'msg' )	{
			// first check if the field is empty
			if ((e.value == null) || (e.value == "") || isblank(e.value)) 	{			
				//alert('Insert msg.');
				document.getElementById("pmsgerr").style.display = "inline";
				return false;
			}else{
				var msg = e.value;
			}
		}
	}	
	jQuery.facebox(function() {	jQuery.post( BASE_URL+'includes/php/postUserMsg.php', {'msg': msg , 'adID': adID }, function(data) { /*jQuery.facebox(data)*/ }); });
	closeFaceBox()
}





/**************************************************

	check if blank
	
***************************************************/
function isblank(s)
{
	for(var i = 0; i < s.length; i++) 
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}





/**************************************************

	tell a friend
	
***************************************************/
function tellAfriend(userAdID)
{	
	adID = userAdID;
	
	$.post(
			BASE_URL+'includes/php/isLoggedIn.php', 	{ } , 
			function (data)	
			{ 			
				$(data).find('userLogin').each(function()	
				{
					var isloggd = $(this).find('registered').text()					
					if( isloggd == 'y' )
					{					
						jQuery.facebox(function() {	jQuery.get(BASE_URL+'includes/php/oTellAfriendUI.php?ad_id='+adID, function(data) { 	jQuery.facebox(data).html();  }) })		
					}else{		
						jQuery.facebox(function() {	jQuery.get(BASE_URL+'includes/php/loginUI.php?whichMod=tellAfriend', function(data) { jQuery.facebox(data).html(); 	}) })
					}
				});
			});
}





/**************************************************

	tell friends
	
***************************************************/
function tellYourFriends(f)
{	
	var ArrayValues 		= Array();
	var ArrayInvalidEmails 	= "";
	var ArrayBlankEmails 	= "";
	var emailCount 			= 0;
	
	for(var i = 0; i < f.length; i++)
	{
		var e = f.elements[i];
		
		if (  e.id == "email" && e.tagName == "INPUT" && e.type == "text" && e.type != "checkbox" )	{
			if ((e.value == null) || (e.value == "") || isblank(e.value)) {
				alert('Kindly, fill in all the emails.');
				return false;
			}else{
				//alert(e.name + e.value);
				if ( validate( e.value ) )	{
					ArrayValues[emailCount] = e.value;
					emailCount++;					
				}else{
					ArrayInvalidEmails =  ArrayInvalidEmails + "\n" + e.value ;
				}
			}
		}
		
		if (  e.id == "ad_id" && e.tagName == "INPUT" && e.type == "hidden" && e.type != "checkbox" ){
			//alert('xxxx'+e.value);
			var ad_id = e.value;
		}
	}

	if ( ArrayInvalidEmails == "" )
	{			
		document.getElementById('values').value = ArrayValues;
		
		var valsArray = $('#values').val();	
		//alert('xxx')
		jQuery.facebox(function() {
			jQuery.post(BASE_URL+'includes/php/oTellAfriendSQL.php', {'values': valsArray , 'ad_id': ad_id } , function(data) { closeFaceBox() })  
		})			
	}
	else
	{
		alert( ArrayInvalidEmails + ' \n These emails are not valid.');	return false;
	}
	
}




/**************************************************

	validate  emails
	
***************************************************/
function validate(address) 
{
   //var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
   //var address = document.forms[form_id].elements[email].value;
   
   if(reg.test(address) == false)  
   {
	  //alert( address + ' \n This is not a valid email.');
	  return false;
   }
   else
	return true;
}






/**************************************************

	invite friends
	
***************************************************/
function inviteYourFriends()
{
	$.post(
			BASE_URL+'includes/php/isLoggedIn.php', 	{ } , 
			function (data)	
			{ 			
				$(data).find('userLogin').each(function()	
				{
					var isloggd = $(this).find('registered').text()					
					if( isloggd == 'y' )
					{						
						jQuery.facebox(function() {
							jQuery.get(BASE_URL+'includes/php/oInviteYourFriendsUI.php', function(data) { jQuery.facebox(data).html();	})
						})							
					}
					else
					{		
						jQuery.facebox(function() {
							jQuery.get(BASE_URL+'includes/php/loginUI.php?whichMod=inviteYourFriends', function(data) {
								jQuery.facebox(data).html();
							})
						})		
					}
				});
			});
}







/**************************************************

	friends UI
	
***************************************************/
function inviteYourFriendsUI(f)
{
	var ArrayValues = Array();
	var ArrayInvalidEmails = "";
	var ArrayBlankEmails = "";
	var emailCount = 0;
	
	for(var i = 0; i < f.length; i++)
	{
		var e = f.elements[i];
		
		if (  e.id == "email" && e.tagName == "INPUT" && e.type == "text" && e.type != "checkbox" )	
		{
			if ((e.value == null) || (e.value == "") || isblank(e.value)) 
			{
				alert('Kindly, fill in all the emails.');
				return false;
			}
			else
			{
				//alert(e.name + e.value);
				if ( validate( e.value ) )
				{
					ArrayValues[emailCount] = e.value;
					emailCount++;					
				}
				else
				{
					ArrayInvalidEmails =  ArrayInvalidEmails + "\n" + e.value ;
				}
			}
		}
	}

	if ( ArrayInvalidEmails == "" )
	{			
		document.getElementById('values').value = ArrayValues;		
		var valsArray = $('#values').val();
		
		jQuery.facebox(function() {
			jQuery.post( BASE_URL+'includes/php/oInviteYourFriendsSQL.php', {'values': valsArray  } , function(data) { closeFaceBox()	})
		})	
	}
	else
	{
		alert( ArrayInvalidEmails + ' \n These emails are not valid.');
		return false;
	}	
}






/**************************************************

	LOGIN TO MADUQA
	
***************************************************/
function loginToMaduqa()
{
	jQuery.facebox(function() {
		jQuery.get(BASE_URL+'includes/php/oLoginToMaduqaUI.php', function(data) {
			jQuery.facebox(data).html();
		})
	})
}





/**************************************************

	login to maduqa UI
	
***************************************************/
function LoginToMaduqaUI(f)
{
	var ArrayValues = Array();
	var ArrayInvalidEmails = "";
	var ArrayBlankEmails = "";
	var emailCount = 0;
	
	for(var i = 0; i < f.length; i++)
	{
		var e = f.elements[i];
		
		if (  e.id == "email" && e.tagName == "INPUT" && e.type == "text" && e.type != "checkbox" )	
		{
			if ((e.value == null) || (e.value == "") || isblank(e.value)) 
			{
				alert('Kindly, fill in the emails.');
				return false;
			}
			else
			{				
				//alert(e.name + e.value);
				if ( validate( e.value ) )
				{
					var email = e.value;				
				}
				else
				{
					ArrayInvalidEmails =  ArrayInvalidEmails + "\n" + e.value ;
				}
			}
		}
		if (  e.id == "password" && e.tagName == "INPUT" && e.type == "password" && e.type != "checkbox" )
		{
			if ((e.value == null) || (e.value == "") || isblank(e.value)) 
			{
				alert('Kindly, fill in the password.');
				return false;
			}
			else
			{
				var password = e.value;
			}
		}
	}

	if ( ArrayInvalidEmails == "" )
	{		
		jQuery.facebox(function() {
			jQuery.post(
						BASE_URL+'includes/php/oLoginToMaduqaSQL.php', 
						{'email': email , 'password': password } , 
						function(data){							
							jQuery.facebox(function() {
							  jQuery.get('includes/php/welcome.php', function(data) {
								jQuery.facebox(data)
							  })
							}) 
						})
		})	
		setTimeout ("closeFaceBox()", 5000);
	}else{
		alert( ArrayInvalidEmails + ' \n This email is not valid.');return false;
	}
}




/**************************************************

	Close layer
	
***************************************************/
function closeFaceBox()
{
	$(document).trigger('close.facebox')
     	return false
}




/**************************************************

	add to wish list
	
***************************************************/
function AddToWishList(userAdID)
{
	adID = userAdID;
	
	$.post(
			BASE_URL+'includes/php/isLoggedIn.php', 	{ } , 
			function (data)	
			{ 			
				$(data).find('userLogin').each(function()	
				{
					var isloggd = $(this).find('registered').text()					
					if( isloggd == 'y' )
					{
						jQuery.facebox(function() {
							jQuery.get(BASE_URL+'includes/php/oAddToWishList.php?ad_id='+adID, function(data) {
								jQuery.facebox(data).html();
							})
						})
					}		
					else
					{
						jQuery.facebox(function() {
							jQuery.get(BASE_URL+'includes/php/loginUI.php?whichMod=AddToWishList', function(data) {
								jQuery.facebox(data).html();
							})
						})
					}
				});
			});
}

function doNotAddToWishListUI(f)
{
	closeFaceBox();
}

function AddToWishListUI(f)
{
	for(var i = 0; i < f.length; i++)
	{
		var e = f.elements[i];
		if ( e.tagName == "INPUT" )
		{
			if ( e.name == 'ad_id' ) 
			{
				var ad_id = e.value;
			}
		}
	}
	
	$(document).ready(function(){			
		jQuery.facebox(function() {		
			$.post(
					BASE_URL+'includes/php/oAddToWishList.php', 
					{'p_ad_id': ad_id } , 
					function (data)	{ 
						closeFaceBox();
					}
				);
		});
	});
}

function registerToMaduqa()
{
	jQuery.facebox(function() {
			jQuery.get(BASE_URL+'includes/php/oRegisterUI.php', function(data) {
				jQuery.facebox(data).html();
			})
		})
}

function mainHeaderLogin()
{	
	jQuery.facebox(function() {	jQuery.get(BASE_URL+'includes/php/loginUI.php?whichMod=mainLogin', function(data) { jQuery.facebox(data).html(); 	}) })
}

function waitLogin()
{
	
	setTimeout("mainHeaderLogin()",500);
}
function mainLogin()
{
	setTimeout("closeFaceBox()",500);
}



/**************************************************

	get a shop product
	
***************************************************/
function getProductFromShop(pID)
{						
	jQuery.facebox(function() {	jQuery.get(BASE_URL+'getproduct.php?pID='+pID, function(data) { 	jQuery.facebox(data).html();  }) })						
}



function getModels()
{	
	var make = $('#make').val();
	var adcat = "veh";
			var modelSet = $('#model');
			if (make.length == 0) 
			{
				modelSet.attr("disabled",true);
				$(modelSet).emptySelect();				
				$('#model').children().remove();
				modelSet.append('<option selected="selected">-Select Model -</option>');				
			}
			else
			{
				
				modelSet.attr("disabled",false);
				modelSet.children().remove();
				modelSet.append('<option selected="selected">- Select Model -</option>');
				$.ajax({
						 type: "GET",
						 url: BASE_URL+'ad_manp.php?make_id='+make,
						 dataType: "xml",
						 success: function(xml){
						 	//alert(xml);							
							$(xml).find('item').each(function(){
								var model_id = $(this).find('link').text()
								var model = $(this).find('title').text()
								//alert(model_id);							
								modelSet.append("<option value='"+model_id+"'>"+model+"</option>");							
							});			
						}
				});
			}
}




//// VEHICLES DATA
//	$(function(){
//		$('#makex').change(function(){
//			alert('xxx')			
//			var make = $('#makem').val();
//			var adcat = "veh";
//			var modelSet = $('#model');
//			if (make.length == 0) 
//			{
//				modelSet.attr("disabled",true);
//				$(modelSet).emptySelect();				
//				$('#model').children().remove();
//				modelSet.append('<option selected="selected">-Select Model --</option>');				
//			}
//			else
//			{
//				
//				modelSet.attr("disabled",false);
//				modelSet.children().remove();
//				modelSet.append('<option selected="selected">- Select Model ----</option>');
//				$.ajax({
//						 type: "GET",
//						 url: 'ad_manp.php?make_id='+make,
//						 dataType: "xml",
//						 success: function(xml){
//						 	//alert(xml);							
//							$(xml).find('item').each(function(){
//								var model_id = $(this).find('link').text()
//								var model = $(this).find('title').text()
//								//alert(model_id);							
//								modelSet.append("<option value='"+model_id+"'>"+model+"</option>");							
//							});			
//						}
//				});
//			}
//		})
//	});
	
	$("div.generic").click(function () {              
         $(".active_generic").removeClass("active_generic");             
         $(this).addClass("active_generic");              
         $(".generic_content").hide();               
         var content_show = $(this).attr("title");  
         $("#"+content_show).show();           
     });
	 
	 function validateFloat(obj, nLength, nPrecision)
    {
    	var strVal = new String(obj.value);
    	var nIndexOfDot = strVal.indexOf('.');
    	var nValidLength = nIndexOfDot==-1?strVal.length:strVal.length+1
		
    	if(nValidLength<strVal.length)
		{
			alert('Maximum length can be '+nLength);
			strVal = strVal.substring(0,nValidLength);
		}
		if(strVal.charAt(strVal.length-1)!='.' || nIndexOfDot!=(strVal.length-1))
		{
			if(isNaN(parseFloat(strVal)))
			{
				strVal='0';
			}
			obj.value=parseFloat(strVal);
		}
		if(-1!=nIndexOfDot && strVal.substring(nIndexOfDot+1).length>nPrecision)
		{
			strVal=strVal.substring(0, strVal.length-1);
			obj.value=strVal;
		}
	}
	
	function isblank(s)
	{
		for(var i = 0; i < s.length; i++) 
		{
			var c = s.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
		return true;
	}



/*

This function validates the entries for submitting ads
from the ads_desc.php file.

*/


function check_ad(f)
{		
	var ok = true;
	//alert(f.id);
	if( f == "frmPostAdCat_1_3" )
	{
		//alert(f);
	}
	
	//Run through a list of all objects contained within the form.
	for(var i = 0; i < f.length; i++) 
	{
		document.getElementById("titleerr").style.display = "none";
		document.getElementById("caterr").style.display = "none";
		document.getElementById("subcaterr").style.display = "none";
		document.getElementById("txnerr").style.display = "none";
		document.getElementById("priceerr").style.display = "none";
		document.getElementById('errTerms').style.display = 'none';
		
		var e = f.elements[i];
		
		if (  ( (e.tagName == "INPUT") || (e.tagName == "TEXTAREA") || (e.tagName == "SELECT") ) &&  !e.optional && e.type != "submit" && e.type != "file"   ) 
		{
			if( e.name =="title" )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("titleerr").style.display = "inline";
					return false;
				}
			}
			if( e.name =="category" )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("caterr").style.display = "inline";
					return false;
				}
			}
			if( e.name =="sub_cat" )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("subcaterr").style.display = "inline";
					return false;
				}
			}
			if( e.name =="txn_id" )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("txnerr").style.display = "inline";
					return false;
				}
			}
			if( e.name =="price" )
			{
				// first check if the field is empty
				if ((e.value == null) || (e.value == "") || isblank(e.value)) 
				{
					document.getElementById("priceerr").style.display = "inline";
					return false;
				}
			}
			if( e.id == "terms" )
			{
				if( e.checked != 1)
				{
					alert('You MUST accept the Terms & Conditions to post an advert.');
					document.getElementById('errTerms').style.display = 'inline';
					return false
				}
			}
		}
	}
}




/*********************
//* jQuery Multi Level CSS Menu (horizontal)- By Dynamic Drive DHTML code library: http://www.dynamicdrive.com
//* Menu instructions page: http://www.dynamicdrive.com/dynamicindex1/ddlevelsmenu/
//* Last modified: Sept 6th, 08'. Usage Terms: http://www.dynamicdrive.com/style/csslibrary/tos/
*********************/

//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'images/orange_down_arrow.jpg', 22], right:['rightarrowclass', 'images/Small_icons/arrow-right.gif']}

var jquerycssmenu={

fadesettings: {overduration: 350, outduration: 100}, //duration of fade in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
	jQuery(document).ready(function($){
		var $mainmenu=$("#"+menuid+">ul")
		var $headers=$mainmenu.find("ul").parent()
		$headers.each(function(i){
			var $curobj=$(this)
			var $subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
			this.istopheader=$curobj.parents("ul").length==1? true : false
			$subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			$curobj.children("span:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
				'<img style ="padding:5px 5px 0 5px;" src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
				+ '" style="border:0;" />'
			)
			$curobj.hover(
				function(e){
					var $targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					$targetul.css({left:menuleft+"px"}).fadeIn(jquerycssmenu.fadesettings.overduration)
				},
				function(e){
					$(this).children("ul:eq(0)").fadeOut(jquerycssmenu.fadesettings.outduration)
				}
			) //end hover
		}) //end $headers.each()
		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myjquerymenu" on page:
jquerycssmenu.buildmenu("myjquerymenu", arrowimages)


var tooltip=function(){
	var id = 'tt';
	var top = -10;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();





// JavaScript Document
// A utility function that returns true if a string contains only
// whitespace characters.
function isblank(s)
{
	for(var i = 0; i < s.length; i++) 
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
return true;
}
// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{
	var msg;
	var empty_fields = "";
	var errors = "";
// Loop through the elements of the form, looking for all
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Also, if any of these elements have a "min" or a "max" property defined,
// then verify that they are numbers and that they are in the right range.
// Put together error messages for fields that are wrong.
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		if (  ( (e.tagName == "INPUT") || (e.tagName == "TEXTAREA") || (e.tagName == "SELECT") ) &&  !e.optional && e.type != "submit" && e.type != "file"   ) 
		{
			// first check if the field is empty
			if ((e.value == null) || (e.value == "") || isblank(e.value)) 
			{
				empty_fields += "\n " + e.rel;
				continue;
			}
			// Now check for fields that are supposed to be numeric.
			if (e.numeric || (e.min != null) || (e.max != null)) 
			{
				var v = parseFloat(e.value);
				if (isNaN(v) ||	((e.min != null) && (v < e.min)) ||((e.max != null) && (v > e.max))) 
				{
					errors += "- The field " + e.name + " must be a number";
					if (e.min != null)
						errors += " that is greater than " + e.min;
					if (e.max != null && e.min != null)
						errors += " and less than " + e.max;
					else if (e.max != null)
						errors += " that is less than " + e.max;
						errors += ".\n";
				}
			}
		}
	}
// Now, if there were any errors, then display the messages, and
// return false to prevent the form from being submitted. Otherwise
// return true.
if (!empty_fields && !errors)
{
		/*f.submit()*/
		return true;
}
msg = "______________________________________________________\n\n"
msg += "The form was not submitted because of the following error(s).\n";
msg += "Please correct these error(s) and re-submit.\n";
msg += "______________________________________________________\n\n"
if (empty_fields) 
{
	msg += "- The following required field(s) are empty:"
	+ empty_fields + "\n";
	if (errors) msg += "\n";
}
msg += errors;
alert(msg);
return false;
}






// JavaScript Document
//xmlhttp.js

if ( window.location.hostname == 'localhost' )
{
	var BASE_URL 	= "http://localhost/maduqa7/";
}
else
{
	var BASE_URL 	= "http://www.maduqa.com/";
}

//Function to create an XMLHttp Object.
function getxmlhttp ()
{
	//Create a boolean variable to check for a valid Microsoft active x instance.
	var xmlhttp = false;
	//Check if we are using internet explorer.
	try 
	{
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		//If not, then use the older active x object.
		try 
		{
			//If we are using internet explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			//Else we must be using a non-internet explorer browser.
			xmlhttp = false;
		}
	}
	// If not using IE, create a
	// JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
//Function to process an XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str)
{
	//Get an XMLHttpRequest object for use.

	document.getElementById(obj).innerHTML = '<div style="font: normal 15px Tahoma; color:#336699; margin: 20px 10px 10px 20px"><img src="'+BASE_URL+'images/loading.gif" /> Fetching Contents. Please wait....</div>';
	xmlhttp = getxmlhttp ();
	if (getOrPost == "get")
	{
		//xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				document.getElementById(obj).innerHTML = xmlhttp.responseText;
				
				//tinyMCE.init({
//						mode : "textareas",
//						theme : "simple"
//					});
				
				tinyMCE.init({
						mode : "textareas",
						theme : "advanced",
						theme_advanced_buttons1 : "mymenubutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
						theme_advanced_buttons2 : "",
						theme_advanced_buttons3 : "",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom"
					});
			}
			else
			{
				obj.innerHTML = xmlhttp.responseText;
				//alert("xxxx" + xmlhttp.responseText);
				
				//tinyMCE.init({
//						mode : "textareas",
//						theme : "simple"
//					});
				
				tinyMCE.init({
						mode : "textareas",
						theme : "advanced",
						theme_advanced_buttons1 : "mymenubutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
						theme_advanced_buttons2 : "",
						theme_advanced_buttons3 : "",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom"
					});
			}
		}
		xmlhttp.open("GET", serverPage, true);
		xmlhttp.send(null);
	}
	else 
	{
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			//alert("xxxx" + xmlhttp.responseText);
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				if( !isblank(obj) )
				{
					document.getElementById(obj).innerHTML = xmlhttp.responseText;
					//tinyMCE.init({
//						mode : "textareas",
//						theme : "simple"
//					});
//					
					tinyMCE.init({
						mode : "textareas",
						theme : "advanced",
						theme_advanced_buttons1 : "mymenubutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
						theme_advanced_buttons2 : "",
						theme_advanced_buttons3 : "",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom"
					});

				}
			}
			else
			{
				if( !isblank(obj) )
				{
					obj.innerHTML = xmlhttp.responseText;
//						tinyMCE.init({
//							mode : "textareas",
//							theme : "simple"
//						});
					
					tinyMCE.init({
						mode : "textareas",
						theme : "advanced",
						theme_advanced_buttons1 : "mymenubutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink",
						theme_advanced_buttons2 : "",
						theme_advanced_buttons3 : "",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom"
					});
					//alert("xxxx" + xmlhttp.responseText);
				}
			}
		}
		xmlhttp.send(str);
	}
}

function isblank(s)
{
	for(var i = 0; i < s.length; i++) 
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

//Add this function to your script tag
function generateTinyMCE(id) {
 if (!tinyMCE.get(id))
   tinyMCE.execCommand('mceAddControl', false, id);
 else
   tinyMCE.execCommand('mceRemoveControl', false, id);
}




/////////////////from ads.php ///////////////////////////////
var xmlhttp
	
	var catId 
	
	if ( window.location.hostname == 'localhost' )
	{
		var BASE_URL 	= "http://localhost/maduqa7/";
	}
	else
	{
		var BASE_URL 	= "http://www.maduqa.com/";
	}

	function getXML(str)
	{
		//xmlhttp = GetXmlHttpObject();
		xmlhttp = createXmlHttpRequestObject();
		
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		
		url=str+"&sid="+Math.random();
		
		xmlhttp.onreadystatechange=stateChanged;
		
		xmlhttp.open("GET",url,true);
		
		xmlhttp.send(null);
	}
	
	function stateChanged()
	{
		if (xmlhttp.readyState==4)
		{
			var xmlDoc = xmlhttp.responseXML.documentElement;
			
			var selSubCat = document.frmAds.sub_cat;
			
			var titleArray = xmlDoc.getElementsByTagName("title");
			
			var linkArray = xmlDoc.getElementsByTagName("link");		  
		  
			for(var i=0; i < titleArray.length; i++)
			{	
				var subCategory = titleArray.item(i).firstChild.data;
				
				var subCatId 	= linkArray.item(i).firstChild.data;
				
				selSubCat.options[selSubCat.options.length] = new Option(subCategory , subCatId);
			}	
	  	}
	}
	
	function GetXmlHttpObject()
	{
		if (window.XMLHttpRequest)
	  	{
	  		// code for IE7+, Firefox, Chrome, Opera, Safari
	  		return new XMLHttpRequest();
	 	}
		if (window.ActiveXObject)
	  	{
	  		// code for IE6, IE5
	  		return new ActiveXObject("Microsoft.XMLHTTP");
	  	}
		return null;
	}
	
	function getAJAXXMLHandler()
	{
		var xmlHttp = null;
		
		try {
			if (window.XMLHttpRequest) 
			{ // Mozilla, Safari,...
				xmlHttp = new XMLHttpRequest();
		
				if (xmlHttp.overrideMimeType)
					xmlHttp.overrideMimeType('text/xml');
				else
					xmlHttp = null;
			} else if (window.ActiveXObject) 
			{ // IE
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				}
			}
		} catch ( e ) {}
		
		return xmlHttp;
	}
	
	/* 
	creates an XMLHttpRequest instance 
	*/
	
	function createXmlHttpRequestObject() 
	{
	  // will store the reference to the XMLHttpRequest object
	  var xmlHttp;
	  // this should work for all browsers except IE6 and older
	  try
	  {
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	  }
	  catch(e)
	  {
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
		{
		  try 
		  { 
			// try to create XMLHttpRequest object
			xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
		  } 
		  catch (e) {}
		}
	  }
	  // return the created object or display an error message
	  if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	  else 
		return xmlHttp;
	}
	
	function getSubCat()
	{		
		catId = document.frmAds.selcategory.options[document.frmAds.selcategory.selectedIndex].value;
		
		var selSubCat = document.frmAds.sub_cat;
		
		selSubCat.options.length = 0;
		
		selSubCat.options[selSubCat.options.length] = new Option('-Select subcategory-' , '');
		
		document.getElementById('subCategory').value  = "";
		
		//document.getElementById('test').innerHTML = "";
		
		var url = BASE_URL+'ad_manp.php?cat_id='+catId;
		
		document.getElementById('Category').value  = catId;
		
		getXML(url)	;		
		
	}
	
	function loadAdpage()
	{
		var subCatId 	= document.frmAds.sub_cat.options[document.frmAds.sub_cat.selectedIndex].value;
		
		//var subcatURL 	= BASE_URL+'ads_desc.php?category='+catId+'&sub_category='+subCatId;
		
		//subcatURL		= subcatURL+"&sid="+Math.random();		
		
		//processajax (subcatURL, 'test', 'post', '2');
		
		document.getElementById('subCategory').value  = subCatId;

	}	
	
	function isblank(s)
	{
		for(var i = 0; i < s.length; i++) 

		{
			var c = s.charAt(i);
			if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
		return true;
	}
	
	//Add this function to your script tag
function generateTinyMCE(id) {
 if (!tinyMCE.get(id))
   tinyMCE.execCommand('mceAddControl', false, id);
 else
   tinyMCE.execCommand('mceRemoveControl', false, id);
}

function submitResults(f,section){		
				
	if(section == 'ads'){
		//var f = document.getElementById("frmSearch");
		//alert('xxx' + section);
		for( var i = 0; i < f.length; i++ ){
			var e = f.elements[i];						
			if( e.id == 'searchCategory' ){
				if( e.value =="" || e.value ==" "){
					alert("Kindly select the category.");					
					return false;
				}				
				var cat_id = e.value;
			}			
			if( e.id == 'searchWord' ){
				if( e.value =="" || e.value ==" " || e.value =="Search..." ){
					alert("Kindly type the search word.");					
					return false;
				}				
				var searchWord = e.value;
			}
		}		
		document.getElementById("hSearchCategory").value = cat_id;
		document.getElementById("hSearchWord").value = searchWord;
		document.getElementById("adssection").value = section;
		
		document.forms["frmSearch"].submit();	
	}
	if( section == 'shops' )
	{
		//var f = document.getElementById("frmSearchShops");
		for( var i = 0; i < f.length; i++ ){
			var e = f.elements[i];									
			if( e.id == 'searchWord' ){
				if( e.value =="" || e.value ==" " || e.value =="Search..." ){
					alert("Kindly type the search word.");					
					return false;
				}				
				var searchWord = e.value;
			}
		}
		//alert('vvv')
		//document.getElementById("hSearchCategory").value = cat_id;
		document.getElementById("hSearchWordShops").value = searchWord;
		document.getElementById("section").value = section;
		
		//document.forms["frmSearchShops"].submit();
		f.submit()
		//alert('kkk')
	}
}

function getCartQuantity(x)
{
	//alert( x.options[x.selectedIndex].value)
	document.getElementById('txtQuantity').value = x.options[x.selectedIndex].value;
}

function addToCart( productID )
{
	//alert('bbb' + productID );	
	var quantity = document.getElementById('txtQuantity').value;
	
	jQuery.facebox( function() {									
								jQuery.get(BASE_URL+'cart/cart.manipulation.php?productID='+productID+'&quantity='+quantity, 
										   function(data) { 	
										   					//closeFaceBox();
															jQuery.facebox(data).html();  
														}) 
								})	
	//$('#shoppingCart').load(BASE_URL+'cart/cart.manipulation.php', {'productID': productID, 'quantity': quantity  }   ,	function (data)	{  jQuery.facebox(data).html();  }   );

}

function onLoadCart()
{
	//alert('bbb' + productID );	
	$('#shoppingCart').load(BASE_URL+'cart/cart.manipulation.php', {'action': 'onLoad'  }   ,	function (data)	{ }   );

}

function deleteItemFromCart( cartID )
{
	//alert('bbb' + productID );	
	$('#shoppingCart').load(BASE_URL+'cart/cart.manipulation.php', { cartID: cartID,'action': 'delItem'  }   ,	function (data)	{ }   );

}

function updateNewQty( val, itemID )
{
	//alert(val)
	document.getElementById(itemID).value = val;
	//document.getElementById('qty').value;
}

function updateItemFromCart( cartID )
{
	newQty = document.getElementById(cartID).value;
	
	if( newQty == "" || newQty == " " )
	{
		return false;
	}
	else
	{
		$('#shoppingCart').load(BASE_URL+'cart/cart.manipulation.php', { cartID: cartID, newQty: newQty,'action': 'updateItem'  }   ,	function (data)	{ }   );
	}
}

function checkoutUpdateItemFromCart( f , action, cartID )
{
	document.getElementById( 'update_' + cartID ).value = action;	
	f.submit();
}

function CheckoutDeleteItemFromCart( f , action, cartID )
{
	document.getElementById( 'delete_' + cartID ).value = action;	
	f.submit();
}


