function defaults(passed)
{
      var pattern = /function[^(]*\(([^)]*)\)/;
      var args = passed.callee.toString().match(pattern)[1].split(/\s*,\s*/);
      var str = "", i = 1;
      for ( ; i < arguments.length; i++) {
          if (typeof passed[i-1] == "undefined") {
              str += args[i-1] + "=" + fix(arguments[i]) + ";";
          }
      }
     return str;

     function fix(x) {
         if (typeof x == "string")
             return "'" + x.replace(/\'/g, "\\'") + "'";
         return x;
     }
}

function EnterTextareaInput (theObject, txt)
{
	if (theObject.value == txt)
	{
		theObject.value = '';
		theObject.style.color = '#303849';
		theObject.focus();
	}
}

function LeavingTextareaInput(theObject, txt)
{
	if (theObject.value == '')
	{
		theObject.style.color = '#586074';
		theObject.value = txt;	
	}
}

function EnterInput (theObject, txt)
{
	if (theObject.value == txt)
	{
		theObject.value = '';
		theObject.style.color = '#303849';
		theObject.focus();
	}
}

function LeavingInput(theObject, txt)
{
	if (theObject.value == '')
	{
		theObject.style.color = '#586074';
		theObject.value = txt;	
	}

	if (theObject.id == 'theDomain' && $('theHiddenDomain').value != $('theDomain').value)
	{
		for (sCounter = 0; sCounter < 5; sCounter++)
		{
			$('theHiddenKeyword['+ sCounter +']').value = 'One Very Strange Keyword';
			
			$('GoogleResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
			$('MSNResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
			$('YahooResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
	
			$('GoogleResult['+ sCounter +']').innerHTML = '';
			$('MSNResult['+ sCounter +']').innerHTML = '';
			$('YahooResult['+ sCounter +']').innerHTML = '';
		}

		$('conclusionOne').style.display = 'none';
		$('conclusionTwo').style.display = 'none';
		$('conclusionThree').style.display = 'none';
		$('conclusionFour').style.display = 'none';
	}
	
	for (sCounter = 0; sCounter < 5; sCounter++)
	{
		if ($('theKeyword['+ sCounter +']') && $('theKeyword['+ sCounter +']').value != $('theHiddenKeyword['+ sCounter +']').value)
		{
			$('GoogleResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
			$('MSNResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
			$('YahooResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
	
			$('GoogleResult['+ sCounter +']').innerHTML = '';
			$('MSNResult['+ sCounter +']').innerHTML = '';
			$('YahooResult['+ sCounter +']').innerHTML = '';

			$('conclusionOne').style.display = 'none';
			$('conclusionTwo').style.display = 'none';
			$('conclusionThree').style.display = 'none';
			$('conclusionFour').style.display = 'none';
		}
	}
}

function theMasterSearch (sCounter)	
{
	if ($('theDomain') && $('theDomain').value && $('theDefaultDomain').value != $('theDomain').value)
	{
		if (sCounter == 0)
		{
			$('startSearch').innerHTML = '<img src="/sImages/WaitingBlueIcon.gif" alt="" />';

			$('conclusionOne').style.display = 'none';
			$('conclusionTwo').style.display = 'none';
			$('conclusionThree').style.display = 'none';
			$('conclusionFour').style.display = 'none';
			setTimeout('conclusion();', 1000);
		}
	
		var domain = $('theDomain').value;
		if (domain.indexOf('http://') != -1)
		{
			domain = domain.replace('http://', '');
			$('theDomain').value = domain;
		}

		$('theHiddenDomain').value = $('theDomain').value;
		if (sCounter <= 4)
		{
			if ($('theKeyword['+ sCounter +']') && $('theKeyword['+ sCounter +']').value)
			{
				if ($('theKeyword['+ sCounter +']').value != $('theHiddenKeyword['+ sCounter +']').value && $('theKeyword['+ sCounter +']').value != $('theDefaultKeyword['+ sCounter +']').value)
				{
					$('theHiddenKeyword['+ sCounter +']').value = $('theKeyword['+ sCounter +']').value;
	
					$('GoogleResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
					$('GoogleResult['+ sCounter +']').innerHTML = '<img src="/sImages/WaitingIcon.gif" alt="" />';
		
					$('MSNResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
					$('MSNResult['+ sCounter +']').innerHTML = '<img src="/sImages/WaitingIcon.gif" alt="" />';
		
					$('YahooResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
					$('YahooResult['+ sCounter +']').innerHTML = '<img src="/sImages/WaitingIcon.gif" alt="" />';

					xajax_MasterSearch(domain, $('theKeyword['+ sCounter +']').value, sCounter);
					setTimeout('theMasterSearch('+ (sCounter+1) +');', 500);
				}
				else
				{
					setTimeout('theMasterSearch('+ (sCounter+1) +');', 50);
				}
			}
			else
			{
				$('GoogleResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
				$('MSNResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
				$('YahooResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
	
				$('GoogleResult['+ sCounter +']').innerHTML = '';
				$('MSNResult['+ sCounter +']').innerHTML = '';
				$('YahooResult['+ sCounter +']').innerHTML = '';

				setTimeout('theMasterSearch('+ (sCounter+1) +');', 50);
			}					
		}
	}
	else
	{
		alert('Fill in domain');
	}
}	

function logIn ()
{
	if ($('userzEmail') && $('userzEmail').value && $('userzPassword') && $('userzPassword').value)
	{
		$('theForm').submit();
	}
	else
	{
		alert('Please enter your e-mail and password.');
	}
}

function contactUs ()
{
	if ($('contactEmail') && $('contactEmail').value && $('contactName') && $('contactName').value && $('contactQuestion') && $('contactQuestion').value)
	{
		var formValues = new Array;
		formValues['contactName'] = $('contactName').value;
		formValues['contactEmail'] = $('contactEmail').value;
		formValues['contactCompany'] = ($('contactCompany')) ? $('contactCompany').value : null;
		formValues['contactIndustry'] = ($('contactIndustry')) ? $('contactIndustry').value : null;
		formValues['contactQuestion'] = ($('contactQuestion')) ? $('contactQuestion').value : null;		

 		xajax_contactInterface('send', formValues);
	}
	else
	{
		alert('Please enter your name, e-mail and question.');
	}
}

function signUp ()
{
	if ($('userzName') && $('userzName').value && $('userzEmail') && $('userzEmail').value && $('userzPassword') && $('userzPassword').value)
	{
		var formValues = new Array;
		formValues['userzName'] = $('userzName').value;
		formValues['userzCompany'] = ($('userzCompany')) ? $('userzCompany').value : null;
		formValues['userzEmail'] = $('userzEmail').value;
		formValues['userzPassword'] = $('userzPassword').value;

 		xajax_userzInterface('create', formValues);
	}
	else
	{
		alert('Please input your name, e-mail and password');
	}
}

function forgotPassword ()
{
	if ($('userzEmail') && $('userzEmail').value)
	{
		var formValues = new Array;
		formValues['userzEmail'] = $('userzEmail').value;

 		xajax_userzInterface('forgotPassword', formValues);
	}
	else
	{
		alert('Please enter your e-mail');
	}
}

function conclusion ()
{
	var theConclusion = 0;
	var showConclusion = 0;
	var activeKeywords = 0;

	for (sCounter = 0; sCounter < 5; sCounter++)
	{
		if ($('theKeyword['+ sCounter +']') && $('theKeyword['+ sCounter +']').value)
		{
			if ($('GoogleResult['+ sCounter +']').innerHTML.indexOf('WaitingIcon') == -1 && $('MSNResult['+ sCounter +']').innerHTML.indexOf('WaitingIcon') == -1 && $('YahooResult['+ sCounter +']').innerHTML.indexOf('WaitingIcon') == -1)
			{
				theConclusion += ($('GoogleResult['+ sCounter +']').innerHTML == '&gt;20') ? 21 : $('GoogleResult['+ sCounter +']').innerHTML-0;
				theConclusion += ($('MSNResult['+ sCounter +']').innerHTML == '&gt;20') ? 21 : $('MSNResult['+ sCounter +']').innerHTML-0;
				theConclusion += ($('YahooResult['+ sCounter +']').innerHTML == '&gt;20') ? 21 : $('YahooResult['+ sCounter +']').innerHTML-0;
				
				showConclusion++;
				activeKeywords++;
			}
		}
		else
		{
			showConclusion++;
		}	
	}

	if (showConclusion == 5)
	{
		$('startSearch').innerHTML = $('startSearchShadow').innerHTML;
		theConclusion = theConclusion/(activeKeywords*3);
		if (theConclusion > 15)
		{
			$('conclusionFour').style.display = 'block';
		}
		else if (theConclusion > 10)
		{
			$('conclusionThree').style.display = 'block';
		}
		else if (theConclusion > 4)
		{
			$('conclusionTwo').style.display = 'block';
		}
		else
		{
			$('conclusionOne').style.display = 'block';
		}
	}
	else
	{
		setTimeout('conclusion();', 500);
	}
}

function startOver ()
{
	for (sCounter = 0; sCounter < 5; sCounter++)
	{
		$('theHiddenKeyword['+ sCounter +']').value = 'One Very Strange Keyword';
		
		$('GoogleResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
		$('MSNResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
		$('YahooResult['+ sCounter +']').style.background = 'url(/sImages/greyButton.png)';
		
		$('GoogleResult['+ sCounter +']').innerHTML = '';
		$('MSNResult['+ sCounter +']').innerHTML = '';
		$('YahooResult['+ sCounter +']').innerHTML = '';
		
		$('theKeyword['+ sCounter +']').style.color = '#586074';
		$('theKeyword['+ sCounter +']').value = $('theDefaultKeyword['+ sCounter +']').value;
	}

	$('theDomain').value = '';
	$('theDomain').focus();

	$('conclusionOne').style.display = 'none';
	$('conclusionTwo').style.display = 'none';
	$('conclusionThree').style.display = 'none';
	$('conclusionFour').style.display = 'none';
}

var loadImage1 = new Image;
loadImage1.src = '/sImages/greenButton.png';

var loadImage2 = new Image;
loadImage2.src = '/sImages/greyButton.png';

var loadImage3 = new Image;
loadImage3.src = '/sImages/redButton.png';

var loadImage4 = new Image;
loadImage4.src = '/sImages/sBackground.png';

var loadImage45 = new Image;
loadImage45.src = '/sImages/logoBackground.png';

var loadImage5 = new Image;
loadImage5.src = '/sImages/regBackground.png';

var loadImage6 = new Image;
loadImage6.src = '/sImages/startOverButton.png';

var loadImage7 = new Image;
loadImage7.src = '/sImages/passBackground.png';

var loadImage8 = new Image;
loadImage8.src = '/sImages/searchButton.png';

var loadImage9 = new Image;
loadImage9.src = '/sImages/WaitingIcon.gif';

var loadImage10 = new Image;
loadImage10.src = '/sImages/WaitingBlueIcon.gif';

var loadImage11= new Image;
loadImage11.src = '/sImages/WaitingWhiteIcon.gif';

function onLoad ()
{
	$('loadingDiv').style.display = 'none';
	$('masterDiv').style.display = 'block';
}

function KeyCheck (e, objId)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch (KeyID)
	{
		case 9:
			break;
		case 13:
			if (objId == 'userzPassword' && !$('userzName'))
			{
				logIn();
				return false;
			}
			break;
	}
}

/* -- Adobe GoLive JavaScript Library */

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (var i=0; i<array.length; i+=2) {
			img = null; var n = array[i];
			if (d.images) {img = d.images[n];}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}
CSStopExecution=false;
function CSAction(array) {return CSAction2(CSAct, array);}
function CSAction2(fct, array) { 
	var result;
	for (var i=0;i<array.length;i++) {
		if(CSStopExecution) return false; 
		var aa = fct[array[i]];
		if (aa == null) return false;
		var ta = new Array;
		for(var j=1;j<aa.length;j++) {
			if((aa[j]!=null)&&(typeof(aa[j])=="object")&&(aa[j].length==2)){
				if(aa[j][0]=="VAR"){ta[j]=CSStateArray[aa[j][1]];}
				else{if(aa[j][0]=="ACT"){ta[j]=CSAction(new Array(new String(aa[j][1])));}
				else ta[j]=aa[j];}
			} else ta[j]=aa[j];
		}			
		result=aa[0](ta);
	}
	return result;
}
CSAct = new Object;
CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
CSIsW3CDOM = ((document.getElementById) && !(IsIE()&&CSBVers<6)) ? true : false;
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { if (CSIsW3CDOM) return document.getElementById(s).style; else return CSFindElement(s,0);  }
CSIImg=false;
function CSInitImgID() {if (!CSIImg && document.images) { for (var i=0; i<document.images.length; i++) { if (!document.images[i].id) document.images[i].id=document.images[i].name; } CSIImg = true;}}
function CSFindElement(n,ly) { if (CSBVers<4) return document[n];
	if (CSIsW3CDOM) {CSInitImgID();return(document.getElementById(n));}
	var curDoc = ly?ly.document:document; var elem = curDoc[n];
	if (!elem) {for (var i=0;i<curDoc.layers.length;i++) {elem=CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}
function CSGetImage(n) {if(document.images) {return ((!IsIE()&&CSBVers<5)?CSFindElement(n,0):document.images[n]);} else {return null;}}
CSDInit=false;
function CSIDOM() { if (CSDInit)return; CSDInit=true; if(document.getElementsByTagName) {var n = document.getElementsByTagName('DIV'); for (var i=0;i<n.length;i++) {CSICSS2Prop(n[i].id);}}}
function CSICSS2Prop(id) { var n = document.getElementsByTagName('STYLE');for (var i=0;i<n.length;i++) { var cn = n[i].childNodes; for (var j=0;j<cn.length;j++) { CSSetCSS2Props(CSFetchStyle(cn[j].data, id),id); }}}
function CSFetchStyle(sc, id) {
	var s=sc; while(s.indexOf("#")!=-1) { s=s.substring(s.indexOf("#")+1,sc.length); if (s.substring(0,s.indexOf("{")).toUpperCase().indexOf(id.toUpperCase())!=-1) return(s.substring(s.indexOf("{")+1,s.indexOf("}")));}
	return "";
}
function CSGetStyleAttrValue (si, id, st) {
	var s=si.toUpperCase();
	var myID=id.toUpperCase()+":";
	var id1=s.indexOf(myID,st);
	if (id1==-1) return "";
	var ch=s.charAt(id1-1);
	if (ch!=" " && ch!="\t" && ch!="\n" && ch!=";" && ch!="{")
		return CSGetStyleAttrValue (si, id, id1+1);
	var start=id1+myID.length;
	ch=s.charAt(start);
	while(ch==" " || ch=="\t" || ch=="\n") {start++; ch=s.charAt(start);}
	s=s.substring(start,si.length);
	var id2=s.indexOf(";");
	return ((id2==-1)?s:s.substring(0,id2));
}
function CSSetCSS2Props(si, id) {
	var el=document.getElementById(id);
	if (el==null) return;
	var style=document.getElementById(id).style;
	if (style) {
		if (style.left=="") style.left=CSGetStyleAttrValue(si,"left",0);
		if (style.top=="") style.top=CSGetStyleAttrValue(si,"top",0);
		if (style.width=="") style.width=CSGetStyleAttrValue(si,"width",0);
		if (style.height=="") style.height=CSGetStyleAttrValue(si,"height",0);
		if (style.visibility=="") style.visibility=CSGetStyleAttrValue(si,"visibility",0);
		if (style.zIndex=="") style.zIndex=CSGetStyleAttrValue(si,"z-index",0);
	}
}
function CSClickReturn () {
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return true; /* dont follow link */
	else return false; /* dont follow link */
}
