// JScript source code
var strNormal="#6f6f6f"
var objSrcLayer=null;
var strSrcQuest="";
var blnOnQuestion=false;
var intWidth=0;
var intHeight=0;
var intQuestId=0;
var STR_QUOT=String.fromCharCode(34);
var flagConfirm = false; 
var gStrAns = "";
function showAns(objLayer,strAns,strQuest)
{
	var hasForm=false;										//THIS DETERMINES IF THE USER HAS CLICKED ON NO TO FILLIN OR VIEW THE FEEDBACK FORM
	var objTd=document.getElementById("showAns");			//THIS OBJECT WILL NOW POINT TO THE TD IN WHICH THE ANSWERS ARE TO BE DISPLAYED
	gStrAns ="";
	strAns = unescape(strAns);
	gStrAns = strAns;
	try
	{
		var a=document.forms[0].txtFirstName.value;
		hasForm=true;
	}
	catch (e)
	{
	}
	
	if(hasForm)
	{
		with(document.forms[0])
		{
			if(allTrim(txtFirstName.value)!="" || allTrim(txtLastName.value)!="" || allTrim(txtEmailID.value)!="" || allTrim(txtComment.value)!="")
			{
				anchrObject=getAnchorPosition("Table3"); 
		        anchrObject.y = anchrObject.y - 120;
		        anchrObject.x = anchrObject.x ;
		        showAlert('FAQ','Do you want to clear the form values to display the answer?','YESNO',350,200,anchrObject,'Confirmation','undefined');
			}
			else
			{
				objTd.innerHTML=strAns;
				showNOLink();					
			}
		}
	}
	else
	{
		objTd.innerHTML=strAns;
		showNOLink();
	}
}

function Confirmation(val)
{
    var objTd;
    if(val.toLowerCase() == "yes")
    {
        objTd=document.getElementById("showAns");
        objTd.innerHTML=gStrAns;
        showNOLink();
    }
}
	
//-----------THIS DISPLAYS THE LINE "Have we answered your question? NO" at the bottom
function showNOLink()
{
	var yesNoInnerHTML="<b><font color='#FFFFFF'>Have we answered your question?</font>&nbsp;<a href='javascript:showQuestion();'><font color='#FFFF00'>NO</font></a></b>";
	var objTd1=document.getElementById("yesNo");
	objTd1.innerHTML=yesNoInnerHTML;			
}
//----------function to map the elements events
function mapEvents(objForm)
{
	with(objForm)
	{
		txtTitle.onchange=onChangeTitle;
		txtFirstName.onkeypress=validName;
		txtLastName.onkeypress=validName;
		txtEmailID.onkeypress=validEMail;
		txtComment.onkeypress=onKeyPressQuery;
		onsubmit=postPage;
	}
}
//------------------------	
function bodyonload()
{
	if(objBrowser.ns4)
	{
		with(document.layers.ilayAns)
		{
			intWidth=clip.width;
			intHeight=clip.height;
			document.layers.layAns.resizeTo(intWidth,intHeight);
			visibility="show";
		}
		for(intIndex=0;intIndex < document.layers.length; intIndex++)
		{
			intPos=document.layers[intIndex].name.indexOf("layQuestion_");
			if( intPos != -1)
				document.layers[intIndex].visibility="show";
		}
		document.layers.ILayYesNo.visibility="show";
	}
}
//-----------------
function postData()
{
	document.frmContact.action="../common/executeemail.asp";
	postPage();
}
//-------------	
function postPage()
{
    var blnSubmit=validate();
	if (blnSubmit)
	{
		document.frmContact.submit();
	}
	else return blnSubmit;
}
//--------------Reloads the window if Nav4 resized
function MM_reloadPage(init)
{  
 if (init==true) 
	with (navigator) 
	{
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
		{
		    document.MM_pgW=innerWidth; 
			document.MM_pgH=innerHeight; 
			onresize=MM_reloadPage; 
		}
	}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
		location.reload();
 }
 MM_reloadPage(true);
 //--------------------------
 function Browser()
{
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
	this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera   
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
	this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
	this.ie = (this.ie4 || this.ie5 || this.ie6)
	this.mac=(this.agent.indexOf("mac")>-1)
	this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ns4=(!this.dom && document.layers)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
	this.usedom= this.ns6//Use dom creation
	this.reuse = this.ie||this.usedom //Reuse layers
	this.px=this.dom&&!this.op5?"px":""
	return this
}
	var objBrowser=new Browser();
	var intWidth=(screen.width==1024)?500:300;
	var blnValueEntered=false;
//--------------------
function onChangeTitle()
{
	blnValueEntered=true;
}
//----------
function validName(objEvent)
{
	var chrKeyCode="", intKeyCode=0;
	if(objBrowser.ie)intKeyCode = event.keyCode;
	else if(objBrowser.ns4 || objBrowser.ns6)intKeyCode = objEvent.which;
		
	chrKeyCode=String.fromCharCode(intKeyCode);

	if(!((chrKeyCode >= "A" && chrKeyCode <= "Z") 
		|| (chrKeyCode >= "a" && chrKeyCode <= "z") 
		|| chrKeyCode == " " || intKeyCode == 8))
	{
		if(objBrowser.ie) event.returnValue=false;
		else if(objBrowser.ns4 || objBrowser.ns6)	return false;
	}
	else 	blnValueEntered=true;
}
//---------------------function to enter the valid characters in email field

function validEMail(objEvent)
{
	var chrKeyCode="", intKeyCode=0;
	if(objBrowser.ie)intKeyCode = event.keyCode;
	else if(objBrowser.ns4 || objBrowser.ns6)intKeyCode = objEvent.which;
		
	chrKeyCode=String.fromCharCode(intKeyCode);

	if(!((chrKeyCode >= "A" && chrKeyCode <= "Z") 
		|| (chrKeyCode >= "a" && chrKeyCode <= "z")
		||(chrKeyCode >= "0" && chrKeyCode <= "9") 
		|| chrKeyCode == "." || chrKeyCode == "@" 
		|| chrKeyCode == "_" || intKeyCode == 8 || intKeyCode==45))
	{
		blnValueEntered=true;
		if(objBrowser.ie) event.returnValue=false;
		else if(objBrowser.ns4 || objBrowser.ns6)	return false;
	}
	else blnValueEntered=true;
}
//---------------------
function onKeyPressQuery(ObjEvent)
{
	blnValueEntered=true;
}
//---------
function checkName(srcControl/*Source Element(Textbox Object)*/,
										 intMinLength /*Minimum characters to be entered*/,
										 strCaption /*Field Name or Caption */,
										 intMaxLength /*Maximum characters to be entered*/,
										 intOptional /*Field is mandatory (1) or not mandatory(0)*/)
{
	var blnError=false;
	anchrObject=getAnchorPosition("showAns");
	if(strCaption=="Forename")
	{
	    anchrObject.y = anchrObject.y - 135;
	    anchrObject.x = anchrObject.x - 98;
	}
	else if(strCaption=="Surname")
	{
	    anchrObject.y = anchrObject.y - 90;
	    anchrObject.x = anchrObject.x - 75;
	}
	else if(strCaption=="E-mail address")
	{
	    anchrObject.y = anchrObject.y - 85;
	    anchrObject.x = anchrObject.x - 98;
	}
	else if(strCaption=="Query")
	{
	    anchrObject.y = anchrObject.y - 30;
	    anchrObject.x = anchrObject.x - 98;
	}
	
	if(allTrim(srcControl.value) == "" && intOptional == 1)
	{
		showAlert('FAQ','Please enter the ' + strCaption + '.','OK',200,200,anchrObject,'','undefined');
		blnError=true;
	}
	else if(allTrim(srcControl.value).length < intMinLength && intMinLength > 0 && intOptional == 1)
	{
		showAlert('FAQ',strCaption + ' must have atleast ' + intMinLength + ' characters.','OK',200,200,anchrObject,'','undefined');
		blnError=true;
	}
	else if(allTrim(srcControl.value).length > intMaxLength && intMaxLength > 0)
	{
		showAlert('FAQ',strCaption + ' can not have more than ' + intMaxLength + ' characters.','OK',200,200,anchrObject,'','undefined');
		blnError=true;
	}
	
	if(blnError){srcControl.value=allTrim(srcControl.value);srcControl.focus();}
	
	return blnError;
}
//--------------
//function to remove the leading spaces
function leftTrim(strValue)
{
	while(strValue.charAt(0)==' ')
	strValue = strValue.substr(1,strValue.length-1);
	return(strValue) ;
}
//function to remove the trailing spaces
function rightTrim(strValue)
{
	while(strValue.charAt(strValue.length-1)==' ')
	strValue = strValue.substr(0,strValue.length-1);

	return(strValue) ;
}
//function to remove the leading and trailing spaces
function allTrim(strValue)
{
	return(rightTrim(leftTrim(strValue)));
}
//------------------
function refresh()
{
	if(objBrowser.ie || objBrowser.ns6)
		document.frmContact.reset();
	else if(objBrowser.ns4)
		document.layers.ilayAns.document.layers.layAns.document.frmContact.reset();
	blnValueEntered=false;
}
//---------------
function validate()
{
    var objDocument;
	if(objBrowser.ns4)objDocument=document.layers.ilayAns.document.layers.layAns.document;
	else if (objBrowser.ie || objBrowser.ns6)objDocument=window.document;
	
	with(objDocument)
	{
		if (checkName(frmContact.txtFirstName,2,"Forename",30,1))return false;
		if (checkName(frmContact.txtLastName,2,"Surname",30,0))return false;
		if (checkName(frmContact.txtEmailID,0,"E-mail address",50,1))return false;
		if (checkName(frmContact.txtComment,5,"Query",1000,1))return false;
		
		if(!emailOnly(allTrim(frmContact.txtEmailID.value),"Email Address","showAns","FAQ"))
		{
			frmContact.txtEmailID.focus();
			return false;
		}
		if(!validcharOnly(frmContact.txtComment.value,"Query","showAns","FAQ"))
		{
			frmContact.txtComment.focus();
			return false;
		}
		else
		{
		    if(frmContact.txtComment.value.length > 1000)
			{
				anchrObject=getAnchorPosition("showAns"); 
		        anchrObject.y = anchrObject.y - 40;
		        anchrObject.x = anchrObject.x - 100;
		        showAlert('FAQ','Query can not be more than 1000 characters.','OK',200,200,anchrObject,'','undefined');
				return false ;
			}
		}
		return true;
	}
}	
//-------
function showQuestion()
{
	var strHTML,txtStyle,txtAreaStyle;
	if(blnValueEntered) return;
	if(objBrowser.ns4)
	{
		txtStyle='size="11"';
		txtAreaStyle='cols="10"';
	}
	else if(objBrowser.ie || objBrowser.ns6)
	{
		txtStyle='class="txtboxes"';
		txtAreaStyle='class="txtboxes"';
	}
	
	strHTML='<form  name="frmContact" method="post">'+
					'<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
					'<tr align="left"><td width=20>&nbsp;</td>'+
					'<td class="cContentTextNormal" colspan="3" height="25" valign="top" align="center"><font color=#ffffff><b>Enter Your Question</b> </font></td>'+
					'</tr>'+
					'<tr><td align=center class="cContentTextNormal"><font color="#ffffff">*</font></td>'+
					'<td class="cContentTextNormal" colspan="3" height="50" align="left" valign="middle"><font color="#ffffff">Indicates mandatory fields.</font></td>'+
					'</tr>'+
					'<tr><td>&nbsp;</td>'+
					'<td class="cContentTextNormal" width="20%" align="left" height="25" valign="top"><font color=#ffffff>Title&nbsp;</font></td>'+
					'<td class="txtBoxesNetscape" width="80%" height="25" align="left" valign="top">'+
					'<select name="txtTitle" class="txtBoxes">'+
					'<option value="1">Mr.</option>'+
					'<option value="2">Mrs.</option>'+
					'<option value="3">Ms.</option>'+						
					'<option value="4">Miss</option>'+
					'</select>'+
					'</td>'+
					'</tr>'+
					'<tr><td align=center valign=top class="cContentTextNormal"><font color="#ffffff">*</font></td>'+
					'<td class="cContentTextNormal" width="20%" height="25" align="left" valign="top"><font color="#ffffff">Forename&nbsp;</font></td>'+
					'<td class="txtBoxesNetscape" width="90%" height="25" align="left" valign="top">'+
					'<input id="IDText" class="txtBoxes" type="text" name="txtFirstName" maxlength="50" size=40 onkeypress="return checkNameText(event);">' +
					'</td>'+
					'</tr>'+
					'<tr><td>&nbsp;</td>'+
					'<td class="cContentTextNormal" width="20%" height="25" align="left" valign="top"><font color="#ffffff">Surname&nbsp;</font></td>'+
					'<td class="txtBoxesNetscape" width="80%" height="25" align="left" valign="top">'+
					'<input id="IDText" class="txtBoxes" type="text" name="txtLastName" maxlength="50" size=40 onkeypress="return checkNameText(event);">' +
					'</td>'+
					'</tr>'+
					'<tr><td align=center valign=top class="cContentTextNormal"><font color="#ffffff">*</font></td>'+
					'<td class="cContentTextNormal" width="20%" height="25" align="left" valign="top"><font color=#ffffff>E-Mail&nbsp;</font></td>'+
					'<td class="txtBoxesNetscape" width="80%" height="25" align="left" valign="top">'+
					'<input id="IDText" class="txtBoxes" type="text" name="txtEmailID" maxlength="50" size=40>'+
					'</td>'+
					'</tr>'+
					'<tr><td align=center valign=top class="cContentTextNormal"><font color="#ffffff">*</font></td>'+
				    '<td class="cContentTextNormal" width="20%" height="25" align="left" valign="top"><font color=#ffffff>Query&nbsp;</font></td>'+
					'<td class="cContentTextNormal" width="80%" height="25" align="left" valign="top">'+
					'</td>'+
					'</tr>'+
					'<tr>'+
					'<td>'+
					'</td>'+
					'<td colspan="2" class="txtBoxesNetscape">'+
					'<textarea id="IDText" class="txtBoxes" name="txtComment" rows="15" cols="50"></textarea>'+
					'</td>'+
					'</tr>'+
					'<tr align="center" valign="middle">'+
					'<td colspan="4" height="25" valign="bottom">'+
					'<a href="Javascript:postData()"><img alt="Submit" src="'+ gSTR_IMG_PATH +'buttons/buttonFaqSubmit.gif"  name="Submit" border=0></a>'+
					'&nbsp;'+
					'<a href="Javascript:refresh();"><img id="Reset" alt="Reset" src="'+ gSTR_IMG_PATH +'buttons/buttonFaqReset.gif" name="Reset" border=0></a>'+
					'</td>'+
					'</tr>'+
					'</table>'+
					'<input type="hidden" name="actiontype" value="i">'+
					'<input type="hidden" name="actionform" value="faqquestion">'+
					'<input type="hidden" name="pagename" value="faq.asp">'+
					'<input type="hidden" name="txtCenter" value="'+gstr_centre_code+'"'+
					'</form>'
					
					var objTd=document.getElementById("showAns");
					objTd.innerHTML=strHTML;
					
					var objTd=document.getElementById("yesNo");
					objTd.innerHTML="&nbsp;";
}

// --------------------- Email Only field Function ----------------------

function  emailOnly(emailvalue,fieldname,controlName,Title)
{
	 var anchrObject;
	if(emailVerify(emailvalue,controlName,Title))
		return(true);
	else
	{
	    anchrObject=getAnchorPosition(controlName); 
		anchrObject.y = anchrObject.y - 85;
		anchrObject.x = anchrObject.x - 98;
		showAlert(Title,'Please enter a valid email address.','OK',250,200,anchrObject,'','undefined');
		return(false) ;
	}
}

// --------------------- Email Verification Function ----------------------

 function emailVerify(emailid,ctrName,title)
{
 
  var strEmail = emailid ;
  if(!validcharOnly(strEmail,"Email Address",ctrName,title))
  return false ; 
  if(strEmail.charAt(strEmail.length-1) == ".")
	return false ;
  for(i=0;i<strEmail.length-1;i++)
  {	
	if(strEmail.charAt(i) == " ")
		return false ;
  }
  pos = strEmail.search("@");
  if(pos != -1)
  {
	part = strEmail.slice(pos+1) ;
	flag = -1;
	pos = part.search("@") ;
	if(pos != -1)
		return false ;
	for(i=0;i<part.length;i++)
	{
		if(part.charAt(i)=='.')
		{	
			flag = 0 ;
			break;
		}
	}
	if(flag != -1)
		return(true) ;
	else
		return(false) ;
  }
  else
	return(false) ;
}

// --------------------- Character validation Function ----------------------

function validcharOnly(charvalue,fieldname,controlName,boxTitle)
{
	invalid = "~/:<>|^!;"
	charvalue = allTrim(charvalue) ;
	for(i=0;i<invalid.length;i++)
	{
		for(j=0;j<invalid.length;j++)
		{
			if(charvalue.charAt(j) ==  invalid.charAt(i))
			{
			    anchrObject=getAnchorPosition(controlName); 
			    anchrObject.y = anchrObject.y - 40;
			    anchrObject.x = anchrObject.x - 100;
			    showAlert(boxTitle,'Only valid characters are allowed in '+fieldname,'OK',250,200,anchrObject,'','undefined');
				return(false);
			}
		}
	}
	for(i=0;i<charvalue.length;i++)
	{
		if(charvalue.charAt(i) == 66 || charvalue.charAt(i) == 39)
		{
			anchrObject=getAnchorPosition(controlName); 
			anchrObject.y = anchrObject.y - 40;
			anchrObject.x = anchrObject.x - 100;
			showAlert(boxTitle,'Only valid characters are allowed in ' +fieldname,'OK',300,250,anchrObject,'','undefined');
			return(false);
		}
	}
	return(true);
}	

