//Spry.Data.Region.debug = false;

try { document.execCommand('BackgroundImageCache', false, true); }
catch(e) { }

function confirmaction()
{
	return confirm(msg);
}

function $() {
	//TAKEN FROM PUBLIC DOMAIN:
	//http://www.dustindiaz.com/top-ten-javascript/
	
	//quickly grabs any element or collection of elements
	//example 1: var obj1 = document.getElementById('element1');
	//example 2: var elements = $('a','b','c',obj1,obj2,'d','e');
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function toggleDisplay(sId)
{
 var oNode = $(sId)
 if (oNode.style.display=="block")
 		oNode.style.display="none"
 else if (oNode.style.display=="none")
 		oNode.style.display="block"
 else
 		 oNode.style.display="block"
}

function validateQuestion(bSubmit)
{

try
  {
  //Run some code here

		var oForm = $("post-question")

 		if (!bSubmit)
			 bSubmit = false;
				
		
    if (!oForm)
		{
    		oForm = parent.document.getElementById("post-question")				
  		var oCompany = parent.document.getElementById("companyid")				
  		var oQ1 = parent.document.getElementById("question")
  		var oCat = parent.document.getElementById("category")
  		var oShare = parent.document.getElementById("shareholder")
  		var oNonShare = parent.document.getElementById("non-shareholder")
			var oSent = parent.document.getElementById("sentiment")
  		var oD1 = parent.document.getElementById("d1")
  		var oD2 = parent.document.getElementById("d2")
  		var oD3 = parent.document.getElementById("d3")
  		var oD4 = parent.document.getElementById("d4")
  		var oD5 = parent.document.getElementById("d5")
		}
		else
		{
  		var oCompany = $("companyid")				
  		var oQ1 = $("question")
  		var oCat = $("category")
  		var oShare = $("shareholder")
  		var oNonShare = $("non-shareholder")
			var oSent = $("sentiment")
  		var oD1 = $("d1")
  		var oD2 = $("d2")
  		var oD3 = $("d3")
  		var oD4 = $("d4")
  		var oD5 = $("d5")
		}


		if (oQ1.value == "" || oQ1.value == "Type Question to CEO")
		{
		 alert("You must complete the question!")
		 oQ1.focus()
		 return false
		}


		if (oCat.value=="")
		{
		 alert("Please pick a Category.")
		 oCat.focus()
		 return false
		}


		if (oShare.checked==false&&oNonShare.checked==false)
		{
		 alert("Please pick a Disclosure.")
		 oShare.focus()
		 return false
		}		
		

		if (oSent.value=="")
		{
		 alert("Please pick a Sentiment.")
		 oSent.focus()
		 return false
		}

		if (oD1.checked==false&&oD2.checked==false&&oD3.checked==false&&oD4.checked==false&&oD5.checked==false)
		{		
  		 alert("Please pick a Company Disclosure Rating.")
  		 oD1.focus()
  		 return false
		 }	

	if (bSubmit==true)
	{
		 oForm.submit()	
	}
	else
	{
 		//strip out common words from the current Q and separate them for SQL to search	
  	$('similarqresultsframe').src="/similarq.php?searchterm="+oQ1.value+"&companyid="+oCompany.value;
  	$('similarq').style.display="block";
	}

  }
catch(err)
  {
    //Handle errors here
    txt="There was an error on this page.\n\n";
    txt+="Error description: " + err.description + "\n\n";
    txt+="Click OK to continue.\n\n";
    alert(txt);	
  	oForm.submit()	
  }
	
}


function populateAnswerFromTemplate(sId,sText)
{
 $(sId).value=sText
}

function doFAQSearch(sId)
{

 var sQuery = "<?php echo 'this is a php AJAX test'; ?>"
 sQuery = "test ttesttt"
 
 $(sId).innerHTML = sQuery

}

function verifyAnimal()
{

 var i = $("publicspamid").value; 
 var sAnswer = $("publicverify").value;
 sAnswer = sAnswer.toLowerCase()
 var bRtn = false;

 if (i==1&&sAnswer=="horse")
 		bRtn = true;
 else if (i==2&&sAnswer=="bat")
 		bRtn = true;
 else if (i==3&&sAnswer=="bird")
 		bRtn = true;
 else if (i==4&&sAnswer=="dog")
 		bRtn = true;
 else if (i==5&&sAnswer=="camel")
 		bRtn = true;
 else if (i==6&&sAnswer=="fish")
 		bRtn = true;
 else if (i==7&&sAnswer=="cat")
 		bRtn = true;
 else if (i==8&&sAnswer=="butterfly")
 		bRtn = true;
 else if (i==9&&sAnswer=="snail")
 		bRtn = true;
 else if (i==10&&sAnswer=="rabbit")
 		bRtn = true;
 else if (i==11&&sAnswer=="elephant")
 		bRtn = true;

	//also check password strength!!!
	if ($("password_strength").childNodes[0])
	var sStrength = $("password_strength").childNodes[0].innerHTML;	
	else
	var sStrength = "";		

	if (sStrength=="Strong"	|| sStrength=="Very Strong")
		 bRtn = true
	else
 {
   	alert("Please choose a password that has both upper and lowercase letter as well as special characters to ensure your account is secure.");
  	return false
	}
	
  if (bRtn==true)
  {
  		var oForm = $("signuppublicmember")
  		oForm.submit()
  } 		 
	else
 {
   	alert("Please enter the correct type of animal to proceed. This is a very effective method to combat spam on our site and is very important to our users!");
  	return false
	}
	
}

function checkpasswordstrength()
{
	//also check password strength!!!
	if ($("password_strength").childNodes[0])
	var sStrength = $("password_strength").childNodes[0].innerHTML;	
	else
	var sStrength = "";		

	if (sStrength=="Strong"	|| sStrength=="Very Strong")
	{
  		var oForm = $("changepasswordform")
  		oForm.submit()	
	}
	else
 {
   	alert("Please choose a password that has both upper and lowercase letter as well as special characters to ensure your account is secure.");
  	return false
	}
}

function toggle_pass(passid) {
    if (window.XMLHttpRequest) {
        http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    handle = document.getElementById(passid);
    var url = 'passwordstrength.php?';
    if(handle.value.length > 0) {
        var fullurl = url + 'do=check_password_strength&pass=' + encodeURIComponent(handle.value);
        http.open("GET", fullurl, true);
        http.send(null);
        http.onreadystatechange = statechange_password;
    }else{
        document.getElementById('password_strength').innerHTML = '';
    }
}

function statechange_password() {
    if (http.readyState == 4) {
        var xmlObj = http.responseXML;
        var html = xmlObj.getElementsByTagName('result').item(0).firstChild.data;
        document.getElementById('password_strength').innerHTML = html;
    }
}

