var ans_id = '';
function getIframeDoc(iframeName)
	{
		if(window.frames[iframeName].document)
			{
				return window.frames[iframeName].document;
			}
		else if(document.getElementById(iframeId).contentWindow.document)
			{
				return document.getElementById(iframeId).contentWindow.document;
			}
		else
			{
				document.getElementById(iframeId).contentDocument;
			}
	}
function savedAnswer()
	{
		var doc = getIframeDoc('wpt_ans_saver');
		if(doc.getElementById('question'))
			{
				var lid = doc.getElementById('question').innerHTML;
				var the_ans = doc.getElementById('answer').innerHTML;
				document.getElementById('q'+lid).style.backgroundColor = '#cc3300';
				colindex = 0;
				setTimeout('animate("'+lid+'");');
				document.getElementById('ans'+lid).innerHTML = the_ans;
			}
		else if(doc.getElementById('delQ'))
			{
				document.getElementById('q'+doc.getElementById('delQ').innerHTML).style.display='none';
				document.location.href= document.location.href;
			}
		else if(doc.getElementById('savedQ'))
			{
				document.getElementById('wpt_faq_frm_cont').innerHTML = doc.getElementById('savedQ').innerHTML;
			}
		else if(doc.getElementById('savedQCaptcha'))
			{
				document.getElementById('captchaError').innerHTML = '<span style="color: red; font-weight:bold">Invalid Security Code</span>'+doc.getElementById('savedQCaptcha').innerHTML;
			}
	}

// JavaScript Document
//SendF USAGE SendF('fieldname of field not to be checked / optional fields', 'form id', 'field with email format checking' ,'email.value:==:cemail.value:Emails not matching!!');

function SendF(elem, f_name, chkemail, splchk)
	{
		var rev_switch;
		elements = elem.split("|||");
		elem = elements[0];
		if(elements[1])
			{
				rev_switch = elements[1];
			}
		var chk, x=document.getElementById(f_name);
		if(splchk)
		{
		var checks = splchk.split("|");
		var retval;
		for(var j=0;j<checks.length;j++)
			{
				flds = checks[j].split(":");
				str = "x."+flds[0]+flds[1]+"x."+flds[2];
				temp_retval = eval(str);
				if(!(temp_retval))
					{
						alert(flds[3]);
						return false;
					}
			}
		}
		if(chkemail)
			{
				var res = chkemailformat(eval("x."+chkemail+".value"));
				if (!res)
					{
						return false;
					}
			}
	for (var i=0;i<x.length;i++)
		  {
		  	elem.match(x.elements[i].name) ? (chk=false) : (chk=true);
			if(!rev_switch)
				{
					if(chk)
						{
							if(!x.elements[i].value && x.elements[i].name)
								{
									window.alert("Missing field \""+capWords(x.elements[i].name.replace("_", " "))+"\""); 
									return false;
								}
						}
				}
			else
				{
					if(!chk)
						{
							if(!x.elements[i].value && x.elements[i].name)
								{
									window.alert("Missing field \""+capWords(x.elements[i].name.replace("_", " "))+"\""); 
									return false;
								}
						}
				}
		  }		  
		return true;
	}

function chkemailformat(test)
	{
		var p=test.indexOf('@');
		if (p<1 || p==(test.length-1)) 
			{
				window.alert('Email must contain an e-mail address.');
				return false;
			}
		else
			{
				return true;
			}
	}

function capWords(str) {
var inputString = str; // The input text field
var tmpStr, tmpChar, preString, postString, strlen;
tmpStr = inputString.toLowerCase();
stringLen = tmpStr.length;
if (stringLen > 0)
{
  for (i = 0; i < stringLen; i++)
  {
    if (i == 0)
	{
      tmpChar = tmpStr.substring(0,1).toUpperCase();
      postString = tmpStr.substring(1,stringLen);
      tmpStr = tmpChar + postString;
    }
    else
	{
      tmpChar = tmpStr.substring(i,i+1);
      if (tmpChar == " " && i < (stringLen-1))
	  {
      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
      preString = tmpStr.substring(0,i+1);
      postString = tmpStr.substring(i+2,stringLen);
      tmpStr = preString + tmpChar + postString;
      }
    }
  }
}
return tmpStr;
}


