var test;
 var urlstring;
 var spliturl;
 var str;
    var scripts = document.getElementsByTagName("script");
	for(i=0;i<scripts.length;i++){
		if (scripts[i].src.match(/changeinsurance/) && !scripts[i].loaded) 
		{
			urlstring=scripts[i].src;
			spliturl=scripts[i].src.split("/widget/");
		    str=spliturl[0];
			break;
        }
	}
       

var APP_SERVER= str;
var APP_NAME = "widget";
var LOCAL_URL = APP_SERVER+"/"+APP_NAME;
var DEMO_PROFILE_SWF_URL = LOCAL_URL+"/flash/"  + "comm.swf";

//alert(DEMO_PROFILE_SWF_URL);

function populateTags(pTagHtml){
	
	var tagDiv =document.getElementById("home-tag-cloud");tagDiv.innerHTML=pTagHtml;
}

var html=new Array();

	html.push('<div>');
	//css
	html.push('<link href="'+LOCAL_URL+'/css/searchwidget_new.css" rel="stylesheet" type="text/css" media="all" />');
	//js
	html.push('<script src="'+LOCAL_URL+'/js/widget-tabs.js"></script>');
	

    html.push('<div class="container">');
	html.push('<div id="sasqcontent">');//<!-- Content div starts here -->
	
		html.push('<div class="straight-ans" style="background:url('+LOCAL_URL+'/images/qa-widget/widget-box-bg.gif) no-repeat;">');//<!-- Straight ans div starts here -->
			html.push('<div><h2><img src="'+LOCAL_URL+'/images/qa-widget/widget-box-header.gif" alt="Straight Answers" title="Straight Answers" border="0"></h2>');
			html.push('<img class="header-details" src="'+LOCAL_URL+'/images/qa-widget/widget-header-detail.gif" alt="Get a straight answer to your insurance question" title="Get a straight answer to your insurance question" border="0">');
			
			html.push('</div>');
			html.push('<div id="search-tab" class="left search-tab"><div id="search-img" class="search-act" onclick="javascript:search();">Search Answers</div></div>');
			
			html.push('<div id="ask-tab" class="left ask-tab"><div id="ask-img" class="ask-up" onclick="javascript:ask();">'+"Ask "+userName+'</div></div>');
			html.push('<div class="clear"></div>');

			html.push('<div id="search-content">');//<!-- Search Tab content div starts here -->
				html.push('<form name="" action="" onSubmit="javascript:getSearchResults(str,userName); return false;">');
					html.push('<label><input type="text" maxlength="75" onclick="this.value=\'\'; this.style.color=\'#000\';"  value="Enter your search term here" id="search-input" ></label>');
					html.push('<input type="image" class="search-btn" src="'+LOCAL_URL+'/images/qa-widget/straight-ans-searchup.gif" onmouseover="this.src=\''+LOCAL_URL+"/images/qa-widget/straight-ans-searchov.gif\'"+'" onmouseout="this.src=\''+LOCAL_URL+"/images/qa-widget/straight-ans-searchup.gif\'"+'" align="right">');
				html.push('</form>');
				html.push('<div class="top-categories">');
					html.push('<h4 class="left"><img src="'+LOCAL_URL+'/images/qa-widget/top-categories.gif" alt="Top categories"border="0"></h4>');
					html.push('<p class="left links categories" style="background:transparent url('+LOCAL_URL+'/images/qa-widget/common-bullet.gif) no-repeat scroll 23px 5px;"><a onclick="showallCategories();">See all categories</a></p>');
					html.push('<div id="home-tag-cloud" class="left"></div>');//<!-- Tag Cloud -->
				html.push('</div>');
			html.push('</div>');<!-- Search Tab content div ends here -->

			html.push('<div id="ask-content" style="display:none;">');//<!--Ask Tab content div starts here -->
				html.push('<form name="form1" action="" >');
					html.push('<textarea id="ask-input" onclick="this.value=\'\';this.style.color=\'#000000\';">Enter your insurance question here e.g. How can I reduce my premium?</textarea><br>');
					html.push('<label class="clear your-province">*Your province:<select class="province" name="province" id="province"><option selected="selected">Select province</option>');
					html.push('<option>Alberta</option><option>British Columbia</option><option>Manitoba</option><option>New Brunswick</option><option>Newfoundland and Labrador</option><option>Northwest Territories</option><option>Nova Scotia</option><option>Nunavut</option><option>Ontario</option><option>Prince Edward Island</option><option>Quebec</option><option>Saskatchewan</option><option>Yukon Territory</option></select></label>');
					html.push('<label class="clear name-input">*Your name:<input type="text" maxlength="45" id="ask-name-input" onclick="this.style.color=\'#000\'";></label>');
					html.push('<label class="clear email-input">*Your email:<input type="text" maxlength="45" id="ask-email-input" onclick="this.style.color=\'#000\'";></label>');
					html.push('<img class="ask-btn" src="'+LOCAL_URL+'/images/qa-widget/straight-ans-askup.gif" onclick="askquestion()" onmouseover="this.src=\''+LOCAL_URL+"/images/qa-widget/straight-ans-askov.gif\'"+'" onmouseout="this.src=\''+LOCAL_URL+"/images/qa-widget/straight-ans-askup.gif\'"+'">');
				html.push('</form>');
				html.push('<div class="ask-message" id="infodiv" style="display:none;"></div>');
				
			html.push('</div>');<!-- Ask Tab content div ends here -->


			html.push('<div id="thank-you" style="display:none;" class="thank-you">');//<!--Thank you content div starts here -->
				html.push('<img src="'+LOCAL_URL+'/images/qa-widget/thank-you.gif" border="0" style="padding:15px 0 0 0;"><br class="clear">');
				html.push('<p>Thank you for submitting your question to us.  We&#146;ll get back to you shortly.</p>');
				html.push('<form name="" action="">');
					
					html.push('<img onclick="javascript:showask();" class="ask-another" src="'+LOCAL_URL+'/images/qa-widget/ask-another-quesup.gif" onmouseover="this.src=\''+LOCAL_URL+"/images/qa-widget/ask-another-quesov.gif\'"+'" onmouseout="this.src=\''+LOCAL_URL+"/images/qa-widget/ask-another-quesup.gif\'"+'">');
					html.push('<img onclick="javascript:showsearch();" class="search-another" src="'+LOCAL_URL+'/images/qa-widget/search-ansup.gif" onmouseover="this.src=\''+LOCAL_URL+"/images/qa-widget/search-ansov.gif\'"+'" onmouseout="this.src=\''+LOCAL_URL+"/images/qa-widget/search-ansup.gif\'"+'">');
				html.push('</form>');
			html.push('</div>');//<!-- Thank you div ends here -->

		html.push('</div>');<!-- Straight Ans div ends here -->

	
	html.push('<div class="clear"></div>');
	
html.push('</div>');<!-- Content div ends here -->
html.push('</div>');<!-- Container div ends here -->


// css  html.push('<link src=''></link>);
 
	html.push('<div id="tagcloud"></div>');// tagcloud 
	html.push('<script src="'+LOCAL_URL+'/js/ecoverlay.js"></script>');
	html.push('<script src="'+LOCAL_URL+'/js/avivasearch.js"></script>');	

document.write(html.join(''));



function askquestion(){


          if (document.getElementById('ask-input').value ==""||document.getElementById('ask-input').value=="Enter your insurance question here e.g. How can I reduce my premium?")
          {
              
              document.getElementById("infodiv").innerHTML="Please enter question above.";
			  document.getElementById("infodiv").style.display="";
			  document.getElementById('ask-input').focus();
              return (false);
          }

		  if (document.getElementById('ask-name-input').value == "")
          {
             
			  document.getElementById("infodiv").innerHTML="Please enter your name above";
			  document.getElementById("infodiv").style.display="";
			  document.getElementById('ask-name-input').focus();
              return (false);
          }



           // check if email field is blank
          if (document.getElementById('ask-email-input').value== "")
          {
          
			  document.getElementById("infodiv").innerHTML="Please enter a valid e-mail above";
			  document.getElementById("infodiv").style.display="";
			  document.getElementById('ask-email-input').focus();
            return (false);
          }


         // test if valid email address, must have @ and .
         var checkEmail = "@.";
         var checkStr = document.getElementById('ask-email-input').value;
         var EmailValid = false;
         var EmailAt = false;
         var EmailPeriod = false;

        for (i = 0;  i < checkStr.length;  i++)
        {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkEmail.length;  j++)
        {
            if (ch == checkEmail.charAt(j) && ch == "@")
                 EmailAt = true;
            if (ch == checkEmail.charAt(j) && ch == ".")
                 EmailPeriod = true;
	        if (EmailAt && EmailPeriod)
		         break;
	        if (j == checkEmail.length)
		         break;
	    }
	
	    // if both the @ and . were in the string
        if (EmailAt && EmailPeriod)
        {
		     EmailValid = true
		     break;
	    }
    }
    if (!EmailValid)
    {
		   document.getElementById("infodiv").innerHTML="Please enter a valid e-mail above";
		   document.getElementById("infodiv").style.display="";
		   document.getElementById('ask-email-input').focus();
           
           return (false);
    }

	 if (document.getElementById('province').selectedIndex == 0)
     {
          
			 document.getElementById("infodiv").innerHTML="Please select a province";
			  document.getElementById("infodiv").style.display="";
			  document.getElementById('province').focus();
            return (false);
       }










	var var1 = escape(document.getElementById('ask-name-input').value);
	var var2 = escape(document.getElementById('ask-input').value);
	var var3 = escape(document.getElementById('ask-email-input').value);
	var var5 = emailId;
		var var6 = userName;

	var var4 = document.getElementById('province').selectedIndex;

       
                 document.getElementById('comm').postData(LOCAL_URL+'/ask.php','askquest='+var2+'&uname='+var1+'&email='+var3+'&province='+var4+'&bmail='+var5+'&bname='+var6);    
   	   
		document.getElementById('thank-you').style.display='block';
		document.getElementById('search-content').style.display='none';
		document.getElementById('ask-content').style.display='none';
		document.getElementById('search-tab').style.display='none';
		document.getElementById('ask-tab').style.display='none';
	
	}



	function showsearch()
	{

        document.getElementById('thank-you').style.display='none';
		document.getElementById('search-content').style.display='block';
		//document.getElementById('ask-content').style.display='none';
		document.getElementById('search-tab').style.display='block';
		document.getElementById('ask-tab').style.display='block';
		document.getElementById('search-img').className="search-act";
        document.getElementById('ask-img').className="ask-up";
		document.getElementById('ask-name-input').value="";
		document.getElementById('ask-input').value="";
		document.getElementById('ask-email-input').value="";


	}


	function showask()
	{

        document.getElementById('thank-you').style.display='none';
		//document.getElementById('search-content').style.display='none';
		document.getElementById('ask-content').style.display='block';
		document.getElementById('search-tab').style.display='block';
		document.getElementById('ask-tab').style.display='block';
		document.getElementById('search-img').className="search-up";
        document.getElementById('ask-img').className="ask-act";
		document.getElementById('ask-name-input').value="";
		document.getElementById('ask-input').value="";
		document.getElementById('ask-email-input').value="";


	
	}



	function xxx(){
	
}
