// =========================================
// Quick Info Tabs
// =========================================
function changeInfo(str) {
	if(str=='google'){
document.getElementById('infoBar').innerHTML="From now on WebCou provides a Google Toolbar button that would allow you to get a maximum of what WebCou can give you. <br />With this button you will be able to search all available coupons by company names, domain names or coupon codes. Besides you will be able to see latest discount coupons and promotional codes and search our website by the highlighted text.<br /><a href=\"http://toolbar.google.com/buttons/add?url=http://www.webcou.com/google_button.xml\" ><img src='http://www.webcou.com/images/Google-Button.png' title='Google Toolbar Button'> <b>Click Here to Add Webcou Google Toolbar Button Now!</b></a>";
	}else if (str=='review'){
document.getElementById('infoBar').innerHTML="WebCou Reviews Bookmarklet gives you one-click access to community reviews.<br />Simple add this link (<a href=\"javascript:(function(){w=open(('http://www.webcou.com/reviews/'+escape(document.domain)),'w');setTimeout('w.focus()',1000)})();\">WebCou Reviews</a>) to your favourites by dragging or right-clicking it.<br />Before purchase, click the 'WebCou Reviews' bookmark and a window will pop open with all assoicated reviews.";
	}else if (str=='coupon'){
document.getElementById('infoBar').innerHTML="WebCou Coupons Bookmarklet gives you one-click access to coupons.<br />Simple add this link (<a href=\"javascript:(function(){w=open(('http://www.webcou.com/company/'+escape(document.domain)),'w');setTimeout('w.focus()',1000)})();\">WebCou Coupons</a>) to your favourites by dragging or right-clicking it.<br />When shopping online, click the 'WebCou Coupons' bookmark and a window will pop open with all available coupons for that site.";
	}else if (str=='rss-coupon'){
document.getElementById('infoBar').innerHTML="Subscribe our Coupons, Reviews &amp; Industry News RSS Feeds at:<br /><a href='http://www.webcou.com/rss/coupons'>http://www.webcou.com/rss/coupons</a><br /><a href='http://www.webcou.com/rss/reviews'>http://www.webcou.com/rss/reviews</a><br /><a href='http://www.webcou.com/rss/news'>http://www.webcou.com/rss/news</a>";
	}else if(str=='addcoupon'){
document.getElementById('infoBar').innerHTML="<span id='addConfirm'>Submit a Coupon:</span><br /><select name='type' id='type' onclick=\"clickclear(this, '')\" onblur=\"clickrecall(this,'')\" onchange='checkReady()'><option value=''>Select a Type</option><option value='Shared Web Hosting'>Shared Web Hosting</option><option value='Reseller Web Hosting'>Reseller Web Hosting</option><option value='VPS Web Hosting'>VPS Web Hosting</option><option value='Free Web Hosting'>Free Web Hosting</option><option value='Email Hosting'>Email Hosting</option><option value='File Hosting'>File Hosting</option><option value='Adult Hosting'>Adult Hosting</option><option value='Dedicated Hosting'>Dedicated Hosting</option><option value='Colocation and Data Center'>Colocation and Data Center</option><option value='Domain Names'>Domain Names</option><option value='SSL Digital Certificates'>SSL Digital Certificates</option><option value='Web Design'>Web Design</option><option value='Web Development'>Web Development</option><option value='Web Services'>Web Services</option><option value='Software and Scripts'>Software and Scripts</option><option value='SEO and SEM'>SEO and SEM</option><option value='E-Commerce'>E-Commerce</option><option value='Others'>Others</option></select> <input type='text' id='company' name='company' value=' Company Name' onclick=\"clickclear(this, ' Company Name')\" onblur=\"clickrecall(this,' Company Name')\" size='18' maxlength=\"30\" onkeyup=\"removeChr(this); checkReady()\" > <input type='text' id='title' name='title' value=' Coupon Code' onclick=\"clickclear(this, ' Coupon Code')\" onblur=\"clickrecall(this,' Coupon Code')\" size='15'  maxlength=\"30\" onkeyup=\"removeChr(this); checkReady()\"> <input type='text' id='detail' name='detail' value=' Discount Description' onclick=\"clickclear(this, ' Discount Description')\" onblur=\"clickrecall(this,' Discount Description')\" size='50'  maxlength=\"100\" onkeyup=\"removeChr(this); checkReady()\"> <input type='submit' id='addButton' value='Submit a Coupon' disabled='disabled' title='Submit a New Conpon' onclick='doAdd()'>";
	}else if(str=='news'){
document.getElementById('infoBar').innerHTML="<div class='news'>(Mar 11) <a href='http://feedproxy.google.com/~r/thewhir/~3/sywSwi3pBzE/031110_Secure_Web_Host_FireHost_Secures_2M_in_Series_A_Funding_Round'>Secure Web Host FireHost Secures $2M in Series A Funding Round</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 11) <a href='http://feedproxy.google.com/~r/thewhir/~3/z2KKO_axRtY/031110_Trustwave_Appoints_New_Channel_Manager_for_Brazil'>Trustwave Appoints New Channel Manager for Brazil</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 11) <a href='http://feedproxy.google.com/~r/thewhir/~3/0Mr_a9STNaA/031110_Web_Host_Macquarie_Names_Data_Center_Manager'>Web Host Macquarie Names Data Center Manager</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 11) <a href='http://feedproxy.google.com/~r/thewhir/~3/1UO10uIn_BY/031110_Cloud_Software_Developer_4PSA_Opens_New_Netherlands_Office'>Cloud Software Developer 4PSA Opens New Netherlands Office</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 11) <a href='http://www.webhostingtalk.com/news/sam-ikomi-new-vice-president-data-centre-facilities-of-fusepoint/'>Sam Ikomi New Vice President, Data Centre Facilities, of Fusepoint</a> - <span class='cellSmall'>(The Hosting News) – IT services provider Fusepoint Managed Services , today announced the appointment of Sam Ikomi to the position of Vice Presiden ...</span></div><div class='news'>(Mar 11) <a href='http://www.webhostingtalk.com/news/go-daddy-domain-name-total-reaches-40-million/'>Go Daddy Domain Name Total Reaches 40 Million.</a> - <span class='cellSmall'>(The Hosting News) &amp;#8211; The Go Daddy portfolio surpassed 40 million domain names today. This marks an important Internet milestone and also dem ...</span></div><div class='news'>(Mar 10) <a href='http://feedproxy.google.com/~r/thewhir/~3/KfFstDpZkQw/031010_CA_to_Buy_Performance_and_Availability_Monitoring_Solutions_Firm_Nimsoft_for_350M'>CA to Buy Performance and Availability Monitoring Solutions Firm Nimsoft for $350M</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 10) <a href='http://feedproxy.google.com/~r/thewhir/~3/W7uZhSl0mHU/031010_CloudLinuxOS_Added_as_a_Standard_Operating_System_for_VPSNETs_Entire_Line_of_Cloud_Offerings'>CloudLinuxOS Added as a Standard Operating System for VPS.NET's Entire Line of Cloud Offerings</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 10) <a href='http://feedproxy.google.com/~r/thewhir/~3/Ehz15W0YKpI/031010_Savvis_Names_North_Asia_MD_Expands_Cloud_Infrastructure_in_Asia'>Savvis Names North Asia MD, Expands Cloud Infrastructure in Asia</a> - <span class='cellSmall'></span></div><div class='news'>(Mar 10) <a href='http://feedproxy.google.com/~r/thewhir/~3/zfsz49oAol8/031010_eNom_Selected_as_a_Registrar_for_CO_Domain_Names'>eNom Selected as a Registrar for .CO Domain Names</a> - <span class='cellSmall'></span></div><div class='news' style='text-align:right'><b><a href='/rss/news'>Subscribe News RSS Feed</a></b></div>";
document.getElementById('addTitle').innerHTML="<a href=\"javascript:changeInfo('close')\" title='Web Industry News & Promotions'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/bell.png'> News & Promotions</a> | <a href=\"javascript:changeInfo('addcoupon')\" title='Submit a Coupon'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/tag_blue_add.png'> Submit a Coupon</a> | <a href=\"javascript:changeInfo('coupon')\" title='One-Click Coupons Tool'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/icon-money.png'> One-Click Coupons</a> | <a href=\"javascript:changeInfo('review')\" title='One-Click Reviews Tool'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/icon-comments.png'> One-Click Reviews</a> | <a href=\"javascript:changeInfo('google')\" title='Google Toolbar Button'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/google_icon.gif'> Google Toolbar Button</a> | <a href=\"javascript:changeInfo('rss-coupon')\" title='RSS Feeds'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/feed.png'> RSS Feeds</a>";
	}else if(str=='close'){
document.getElementById('infoBar').innerHTML="";
document.getElementById('addTitle').innerHTML="<a href=\"javascript:changeInfo('news')\" title='Web Industry News & Promotions'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/bell.png'> News & Promotions</a> | <a href=\"javascript:changeInfo('addcoupon')\" title='Submit a Coupon'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/tag_blue_add.png'> Submit a Coupon</a> | <a href=\"javascript:changeInfo('coupon')\" title='One-Click Coupons Tool'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/icon-money.png'> One-Click Coupons</a> | <a href=\"javascript:changeInfo('review')\" title='One-Click Reviews Tool'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/icon-comments.png'> One-Click Reviews</a> | <a href=\"javascript:changeInfo('google')\" title='Google Toolbar Button'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/google_icon.gif'> Google Toolbar Button</a> | <a href=\"javascript:changeInfo('rss-coupon')\" title='RSS Feeds'><img style='vertical-align:middle;width:16px;height:16px;' src='/images/feed.png'> RSS Feeds</a>";
	}
}

// =========================================
// OnFocus Clear Text
// =========================================
function clickclear(thisfield, defaulttext) {
	thisfield.style.background='#FFF9DD';
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

// =========================================
// OnFocus Resume Text
// =========================================
function clickrecall(thisfield, defaulttext) {
	thisfield.style.background='#FFFFFF';
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

// =========================================
// JS Change Search
// =========================================
function clickReplace(str){
	document.getElementById('search').value=str;
	var catOption=document.getElementById("cat").options;
	catOption[0].selected = true;
	var comOption=document.getElementById("com").options;
	comOption[0].selected = true;
	showResult(document.getElementById('search').value, 1, '');
}

// =========================================
// Remove Characters 1
// =========================================
function removeChr(str){
	strValue = str.value
	newValue = strValue.replace('\'','');
	newValue = newValue.replace('"','');
	newValue = newValue.replace(/</,'');
	newValue = newValue.replace(/>/,'');
	newValue = newValue.replace(/\?/,'');
	newValue = newValue.replace(/&/,'and');
	if(strValue != newValue){
		str.value=newValue;
	}
}

// =========================================
// Remove Characters 2
// =========================================
function removeChr2(str){
	strValue = str.value
	newValue = newValue.replace(/</,'');
	newValue = newValue.replace(/>/,'');
	if(strValue != newValue){
		str.value=newValue;
	}
}

// =========================================
// Add Coupon Form Check Ready
// =========================================
function checkReady(){
	typeValue = document.getElementById('type').value;
	companyValue = document.getElementById('company').value;
	titleValue = document.getElementById('title').value;
	detailValue = document.getElementById('detail').value;
	
	if(typeValue == '' || companyValue == '' || titleValue == '' || detailValue == '' || companyValue == ' Company Name' || titleValue == ' Coupon Code' || detailValue == ' Discount Description'){
		document.getElementById('addButton').disabled = true;
		document.getElementById('addButton').value = 'Filling the Form...';
	}else{
		document.getElementById('addButton').value = 'Submit Now';
		document.getElementById('addButton').disabled = false;
	}
}

// =========================================
// AJAX Result
// =========================================
var xmlHttp

function showResult(str, page, cat){
	cat=document.getElementById('cat').value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="http://www.webcou.com/module/responsexml.php"
	url=url+"?q="+encodeURIComponent(str)+"&p="+page+"&c="+cat
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("result").innerHTML=xmlHttp.responseText;
		document.getElementById("search").style.color ='#000000';
		document.getElementById("cat").style.color ='#000000';
		document.getElementById("com").style.color ='#000000';
		document.getElementById('infoBar').innerHTML="";
		webSnapr.init();
	} else {
		document.getElementById("search").style.color ='#999999';		
		document.getElementById("cat").style.color ='#999999';
		document.getElementById("com").style.color ='#999999';
		document.getElementById('infoBar').innerHTML="<div style='position: fixed;z-index:103;top: 50%;left: 50%;margin: -6px 0 0 -104px;'><img src='/module/thickbox/loadingAnimation.gif' alt='Loading...'/></div>";
	}
}

	

// =========================================
// AJAX Add Coupon
// =========================================
function doAdd(){
	type=document.getElementById('type').value;
	company=document.getElementById('company').value;
	title=document.getElementById('title').value;
	detail=document.getElementById('detail').value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="http://www.webcou.com/module/doAdd.php"
	url=url+"?type="+type+"&company="+encodeURIComponent(company)+"&title="+encodeURIComponent(title)+"&detail="+encodeURIComponent(detail)
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateAdded
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function stateAdded() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("addConfirm").innerHTML=xmlHttp.responseText;
		document.getElementById('title').value = '';
		document.getElementById('detail').value = '';
		var typeOption=document.getElementById("type").options;
		typeOption[0].selected = true;
		document.getElementById('addButton').disabled = true;
		document.getElementById('addButton').value = 'Submit';
	} else {
		document.getElementById('addButton').disabled = true;
		document.getElementById('addButton').value = 'Loading...';
	}
}

// =========================================
// AJAX Vote
// =========================================
function vote(yn, id){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	document.getElementById('voteBtn'+id).innerHTML="Loading...";
	var url="http://www.webcou.com/module/vote.php"
	url=url+"?yn="+yn+"&id="+id
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=voteChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 

function voteChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		var rArray=xmlHttp.responseText.split("|");
		if(rArray){
			document.getElementById(rArray[0]).innerHTML=rArray[2];
			document.getElementById(rArray[1]).innerHTML="";		
		}
	}
}

// =========================================
// XMLHTTP Function
// =========================================
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;
}