var sharehide = 0;

var domain = "http://www.seogoogleguru.com/web_marketing/";

function share()
{
	if(sharehide==0)
	{
		var pconf = {  
			defaultContent: 'TEXTAREA_ID'  
		};  		
		document.getElementById('divWildfirePost').style.display = 'block';
		document.getElementById('shareincomecalci').innerHTML= "Hide";
		Wildfire.initPost('1081551', 'divWildfirePost', 301, 226, pconf);  
		sharehide=1;
	}
	else
	{
		sharehide=0;
		document.getElementById('divWildfirePost').style.display = 'none';
		document.getElementById('shareincomecalci').innerHTML= "Share this";
	}
}

function calculate() 
{ 
		
		var visitors = document.getElementById('incomecalci_txtVisitors').value; 
		var rate = document.getElementById('incomecalci_txtConRate').value; 
		var values = document.getElementById('incomecalci_txtValues').value; 
		
		//need to check if visitors like '0111' (start with 0 that is invalid value)
		var first_char=visitors.charAt(0);
		if(visitors == '' || rate == '' || values == '')
		{
			document.getElementById('incomecalci_msg').innerHTML = 'Please enter all values';
			document.getElementById('incomecalci_txtAnswer').value = '';			
		}
		else if(!IsNumeric3(visitors) || visitors == 0 || first_char == 0)
		{
			document.getElementById('incomecalci_msg').innerHTML = 'Invalid value for visitors';
			document.getElementById('incomecalci_txtAnswer').value = '';			
		}
		else if(!IsNumeric(rate))
		{
			document.getElementById('incomecalci_msg').innerHTML = 'All values must be numeric';
			document.getElementById('incomecalci_txtAnswer').value = '';			
		}
		else if(rate < 0 || rate > 100)
		{
			document.getElementById('incomecalci_msg').innerHTML = 'Invalid conversations rate';
			document.getElementById('incomecalci_txtAnswer').value = '';		
		}		
		else if(!IsNumeric(values) || values == 0)
		{
			document.getElementById('incomecalci_msg').innerHTML = 'Invalid value for values field';
			document.getElementById('incomecalci_txtAnswer').value = '';			
		}
		else
		{
			//document.getElementById('incomecalci_msg').innerHTML = '&nbsp;';			
			document.getElementById('incomecalci_msg').innerHTML = 'Embed Code: <input type="text" name="incomecalciembedcode" id="incomecalciembedcode" class="incomecalciembedcode" onclick="selectembedcode(\'incomecalciembedcode\')" value=\' <div id="SEOGoogleGuru" width="301" height="329" style="width:301px; height:329px;">Loading...</div><script language="javascript" src="http://www.seogoogleguru.com/web_marketing/calculator.js"></script>\' />';
			var ans = ((visitors * rate)/100) * values; 	
			
			if(isNaN(ans))
			{
				document.getElementById('incomecalci_txtAnswer').value = ans;
			}			
			else
			{		
				ans = parseInt(ans);
				if(ans > 1000000000)
				{					
					ans = ans / 1000000000;
					ans = ans.toString();
					if(ans.indexOf(".") > -1)
					{
						ans = parseFloat(ans);
						ans = ans.toFixed(2);				
					}
					ans = ans + "B";
				}
				else				
				if(ans > 1000000)
				{					
					ans = ans / 1000000;
					ans = ans.toString();
					if(ans.indexOf(".") > -1)
					{
						ans = parseFloat(ans);
						ans = ans.toFixed(2);				
					}
					ans = ans + "M";
				}			
				
				document.getElementById('incomecalci_txtAnswer').value = '$' + ans;
			}
		}
}
 
function IsNumeric(sText)
{
//for convertions ratio..
   var ValidChars = '0123456789.';
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function IsNumeric3(sText)
{
//for visitors field..
   var ValidChars = '1234567890';
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function loadjscssfile(filename, filetype)
{
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css")
 { //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function showembedcode()
{
	document.getElementById('incomecalci_msg').innerHTML = 'Embed Code: <input type="text" name="incomecalciembedcode" id="incomecalciembedcode" class="incomecalciembedcode" onclick="selectembedcode(\'incomecalciembedcode\')" value=\' <div id="SEOGoogleGuru" width="301" height="329" style="width:301px; height:329px;">Loading...</div><script language="javascript" src="http://www.seogoogleguru.com/web_marketing/calculator.js"></script>\' />';
}
function selectembedcode(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}



loadjscssfile("http://cdn.gigya.com/wildfire/js/wfapiv2.js", "js") ////dynamically load and add this .css file
//loadjscssfile("http://www.seogoogleguru.com/web_marketing/style.css", "css") ////dynamically load and add this .css file
loadjscssfile(domain+"style.css", "css") ////dynamically load and add this .css file

//load the html content
var html = '<center><div id="incomecalci_main" class="incomecalci_main"><div id="incomecalci_header" class="incomecalci_header"><img src="http://www.seogoogleguru.com/web_marketing/images/logo.jpg" alt="Web Marketing Calculator" height="47" width="301" border="0"/></div><div id="incomecalci_content" class="incomecalci_content"><table class="incomecalci_tablecss" cellpadding="0" cellspacing="0" border="0"><tr><td class="incomecalci_tdcss1" ><span class="incomecalci_lblcss">Visitors:</span></td><td><div class="txtboxdiv"><input class="txtbox" id="incomecalci_txtVisitors" type="text" name="txtVisitors" size="11" maxlength="10" tabindex="1"/></div><div style="font-size:8pt; color:#FFFFFF; float:left;" >&nbsp;&nbsp;&nbsp;# expected monthly visitors</div></td></tr><tr><td class="incomecalci_tdcss1" ><span class="incomecalci_lblcss">Conversations:</span></td><td><div class="txtboxdiv3"><input class="txtbox" id="incomecalci_txtConRate" type="text" name="txtConRate" size="11" maxlength="10" tabindex="2"/>						</div>							<div style="font-size:8pt; color:#FFFFFF; float:left;" >&nbsp;&nbsp;&nbsp;% visitors that turn to a sale</div></td>	</tr><tr><td class="incomecalci_tdcss1" ><span class="incomecalci_lblcss">Values:</span></td><td><div class="txtboxdiv4">							<input class="txtbox" id="incomecalci_txtValues" type="text" name="txtValues" size="11" maxlength="7" tabindex="3"/>						</div>						<div style="font-size:8pt; color:#FFFFFF; float:left;" >&nbsp;&nbsp;&nbsp;$ value for each visitor</div>					</td>							</tr>												<tr>										<td colspan="2" class="incomecalci_tdcss2" style="height:60px;">					<div class="txtboxdiv2">							<input class="txtbox2" id="incomecalci_txtAnswer" type="text" name="txtAnswer" maxlength="11" readonly="true" size="11" value="Your Profits!"/>						</div>					<img src="http://www.seogoogleguru.com/web_marketing/images/btnCalculate.png" alt="Calculate" onclick="calculate();" tabindex="4" border="0"/>					</td>				</tr>											</table>	<div id="incomecalci_msg" class="incomecalci_msgdiv">&nbsp;</div>		<table cellpadding="0" cellspacing="0" border="0" width="90%" style="margin:10px;">			<tr><td>			<div id="shareincomecalci" style="padding-top:5px;border:none;cursor:pointer;color:#FFFFFF;font-size:8pt;border:none" onclick="share();">Share this</div>						</td>			<td><div align="right" style="border:none;color:#FFFFFF; font-size:8pt;">&#169; <a href="http://www.seogoogleguru.com/seo-services/" target="_blank" /> SEOGoogleGuru.com</a></td></tr></table></div><div id="divWildfirePost" style="position:absolute; top:77px; left:0px;" ></div></div>  </div><textarea rows="1" cols="1" id="TEXTAREA_ID" style="display: none"> <a href="'+window.location+'"><img style="border:0px;" src="'+domain+'tumbnail.jpg" /> Web Marketing Calculator - cool new tool. Free!</a></textarea> </center>     ';
document.getElementById('SEOGoogleGuru').innerHTML = html;
showembedcode();