// =========================================
// 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'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291939282/051608_UK_Orders_Data_Retention_for_ISPs.cfm'>UK Orders Data Retention for ISPs</a> - <span class='cellSmall'>A report issued this week by UK Prime Minister Gordon Brown will require phone and Internet companies to keep logs of Internet usage, and to make thos ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291929514/051608_VeriSign_Patents_Typo_Redirection.cfm'>VeriSign Patents Typo Redirection</a> - <span class='cellSmall'>According to reports posted Thursday, .com registry operator and security firm VeriSign won a patent this week for the controversial redirect service  ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291919217/051608_PTS_Opens_Virginia_Data_Center.cfm'>PTS Opens Virginia Data Center</a> - <span class='cellSmall'>According to reports issued Friday, Premier Technical Services will be investing $16.5 million to construct three buildings, one of which will be a ne ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291909454/051608_Host_Infrenion_Adds_Affiliate_Program.cfm'>Host Infrenion Adds Affiliate Program</a> - <span class='cellSmall'>Hosting provider Infrenion reported this week that it has introduced an affiliate marketing program for the first time.</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291864491/051608_Open-Xchange_Integrates_with_Parallels.cfm'>Open-Xchange Integrates with Parallels</a> - <span class='cellSmall'>One of the web hosting business's most notable supplier of software, Parallels announced on Friday it is integrating Open-Xchange's open source email  ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291845152/051608_GlobalSign_Adds_New_US_Partners.cfm'>GlobalSign Adds New US Partners</a> - <span class='cellSmall'></span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291828270/051608_Internap_Powers_MOLI_Networking_Site.cfm'>Internap Powers MOLI Networking Site</a> - <span class='cellSmall'>Internet business solutions provider Internap Network Services announced on Friday that MOLI, a &quot;next-generation social media and social commerce ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291736913/051608_Peak_10_to_Build_New_Data_Center.cfm'>Peak 10 to Build New Data Center</a> - <span class='cellSmall'>Data center operator and managed service provider Peak 10 announced on Friday it is expanding its Louisville operations by adding a third data center  ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291736914/051608_The_Web_Host_Industry_Week_in_Review.cfm'>The Web Host Industry Week in Review</a> - <span class='cellSmall'>The discussion of this week's most significant news  would probably do best to start with the multi-billion dollar acquisition, as this week HP announ ...</span></div><div class='news'>(May 16) <a href='http://feeds.feedburner.com/~r/thewhir/~3/291706433/051508_Yahoo_Fires_Back_at_Icahn.cfm'>Yahoo! Fires Back at Icahn</a> - <span class='cellSmall'>According to reports released Friday, Roy Bostock, the chairman of Yahoo! (yahoo.com), has released an open letter responding to Carl Icahn's efforts  ...</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;
}