
//--------------------------------------------------------------
function awButtonSubmit(id1, event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13 || keyCode == 3) 
    {
		event.returnValue=false;
		id1.returnValue=false;
	   	id1.click();
		if (document.all && document.getElementById)
		{
		}
	}
}  

//--------------------------------------------------------------
function awDualButtonSubmit(id1, id2, event)
{
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13 || keyCode == 3) 
    {
		event.returnValue=false;
		if (id1 != undefined)
		{
			id1.returnValue=false;
	   		id1.click();
	   	}
	   	else if (id2 != undefined)
	   	{
			id2.returnValue=false;
	   		id2.click();
	   	}
	}
}  

//--------------------------------------------------------------
function SetQSBox(Obj, Val)
{
    obj.value = Val;
}  


var isInput;

//--------------------------------------------------------------
function IsInputSubmit()
{
	if (isInput)
	{
		return true;
	}
	else
	{
		return false;
	}
}  

var isQSInput;

//--------------------------------------------------------------
function awQSClick(rootpath, Keywords, InitialValue)
{

	if (isQSInput)
	{
		isQSInput=true;
		if (Keywords.value == InitialValue)
		{
			document.location = rootpath + "/Default.aspx?sID=5";
		}
		else
		{
		isInput = true;
		}
	}
	else
	{
		return false;
	}
	
}  
//--------------------------------------------------------------
function awSearch(sID,text)
	{
	if ((text == "") || (text == "Search") || (text == "Keywords")) 
		{
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID;
		document.location = rootpath + "/Default.aspx?sID=" + sID;
		}
	else 
		{
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID + "&Search=" + text;
		document.location = rootpath + "/Default.aspx?sID=" + sID + "&Search=" + text;
		}
	//document.forms[0].submit();
	}
	
//--------------------------------------------------------------
function awAdvSearch(sID,text,secs,cats)
	{
	if ((text == "") || (text == "Search") || (text == "Keywords")) 
		{
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID;
		document.location = rootpath + "/Default.aspx?sID=" + sID;
		}
	else 
		{
		s = "&Search=" + text
		if (secs != "") {s = s + "&SectionList=" + secs;}
		if (cats != "") {s = s + "&CategoryList=" + cats;}
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID + s;
		document.location = rootpath + "/Default.aspx?sID=" + sID + s;
		}
	//document.forms[0].submit();
	}
	
//--------------------------------------------------------------
function awRegister(sID,text)
	{
	if ((text == "") || (text == "Register") || (text == "Your email address") ) 
		{
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID;
		document.location = rootpath + "/Default.aspx?sID=" + sID;
		}
	else 
		{
		//document.forms[0].action = rootpath + "/Default.aspx?sID=" + sID + "&Reg=" + text;
		document.location = rootpath + "/Default.aspx?sID=" + sID + "&Reg=" + text;
		}
	//document.forms[0].submit();
	}

//--------------------------------------------------------------
function awReplace(argvalue, x, y) {
	if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
		return false;  
		}    
	while (argvalue.indexOf(x) != -1) {
		var leading = argvalue.substring(0, argvalue.indexOf(x));
		var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, argvalue.length);    
		argvalue = leading + y + trailing;  
		}  
		return argvalue;
	}
//--------------------------------------------------------------
function awNewWindow(url,name,param) {
	window.open(url,name,param);
	return;
	} 
	
//--------------------------------------------------------------
// Form validation 
//--------------------------------------------------------------

	var toComplete="Please supply the following information:\n\n";
	var incomplete="no";

	/* 
	define fields to validate at the page
	 
	var TextboxToValidate = ["Forename", "Surname","Password"];
	var TextboxDefaultValue = ["Forename", "Surname", ""];
	var TextboxLength = [2, 3, 5];
	var TextboxAlertMsg = ["Forename (should have at least 2 symbols)", "Surname (should have at least 3 symbols)", "Password (should have at least 5 symbols)"];
	var EmailToValidate = "Email"
	var PasswordToValidate = ["Password", "Password1"];
	*/

	function awValidateForm (thisform)
	{
	var i, j;
		for (i=0; i < TextboxToValidate.length; i++)
		{
			for (j=0; j < thisform.elements.length; j++)
			{	
				if (TextboxToValidate[i] == thisform.elements[j].name)
				{
					if ((thisform.elements[j].value == "") || (thisform.elements[j].value == TextboxDefaultValue[i]) || (thisform.elements[j].value.length < TextboxLength[i]))
					{
					toComplete+=TextboxAlertMsg[i]+"\n";
					incomplete="yes";
					}
				}
			}
		}
		checkEmail(thisform, EmailToValidate);
		checkPassword(thisform, PasswordToValidate);
		
		if (incomplete == "no")
		{
			thisform.submit();
		}
		else
		{
			alert(toComplete);
			incomplete="no";
			toComplete="Please entry the following fields correctly:\n\n";
			return;	
		}
	}

	function checkEmail(thisform, email)
	{
	if (email != "") {
	for (x=0; x < thisform.elements.length; x++)
	{	
		if (thisform.elements[x].name == email)
			{
			emailStr = thisform.elements[x].value;
			}
	}	
	//if (emailStr != "")
	//{
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!emailReg1.test(emailStr) && emailReg2.test(emailStr)) // if syntax is valid
			return true;
		else
			{
			toComplete+="Valid Email address\n";
			incomplete="yes";
			}
		return true;
		}
	//}
	}

	function checkPassword(thisform, pswpair)
	{
	var i;
	var psw, psw1;

	if (pswpair.length = 2) {
	for (i=0; i < thisform.elements.length; i++)
	{	
		if (thisform.elements[i].name == pswpair[0])
			{
			psw = thisform.elements[i].value;
			}
	}
	for (i=0; i < thisform.elements.length; i++)
	{	
		if (thisform.elements[i].name == pswpair[1])
			{
			psw1 = thisform.elements[i].value;
			}
	}	

	if (psw == psw1) 
		return true;
	else
		{
		toComplete+="Both password fields should be the same\n";
		incomplete="yes";
		}
	return true;
	}
	}
	
	//--------------------------------------------------------------	
function randselect() 
{							
	do 
	{												
		i=Math.floor(Math.random()*item.length); 
	}
	while(typeof(item[i])=="undefined");	
	return i;								
}
//--------------------------------------------------------------	
function awHomeRandomImage(ID, imgAlt, ImgID) 
{
	document.write("<img id='"+ ImgID +"' src='" + ID + "' alt='" + imgAlt + "' title='' />");
}


//---Dropdown menu------------//	
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
if(ie7) {
	var scrollspeed = 20; 
	var step=2;
} else  {
	var scrollspeed = 40;
	var step=3;
}

var iens6=document.all||document.getElementById
var ns4=document.layers


var contentobj
var contentheight
var theobj
var theheight
var thename
var thecontainer
var theScroller
var timerup
var timerdown
var timerupname
var timerdownname

function director(incomingScroller,theFunction) {
stopall()
theScroller=incomingScroller
theobj = "contentobj"+theScroller

theheight = "contentheight"+theScroller

if(iens6){

	thename = "content"+theScroller
	theobj=document.getElementById? document.getElementById(thename):document.all.thename
	theheight=theobj.offsetHeight;
	if (document.getElementById&&!document.all){
   	
	}
}else if(ns4){

	thename = "nscontent"+theScroller
	thecontainer = "nscontainer"+theScroller
	theobj = eval("document."+thecontainer+".document."+thename)
	theheight=theobj.clip.height
	step=50
}
	if(theFunction=="sd") {
		timerdown="window.down"+theScroller
		timerdownname="down"+theScroller
		scrolldown()
	}else if(theFunction=="su") {
		timerup="window.up"+theScroller
		timerupname="up"+theScroller
		scrollup()
	}else if(theFunction=="sa") {
		stopall()
	}else if(theFunction=="st") {
		shifttotop()
	}
}
function scrolldown() {
	
	var calcheight = parseInt(theobj.style.top)
	//
	if(iens6&&parseInt(theobj.style.top)>=(theheight*(-1)+194)){
		
		var nexted = parseInt(theobj.style.top)-step;
		theobj.style.top=nexted+"px";
			
	
		}else if(ns4&&theobj.top>=(theheight*(-1)+194)){
		
		
		theobj.top-=step
	
	}
		
	
	timerdownname = setTimeout("scrolldown()",scrollspeed)
}
function scrollup() {
	if(iens6&&parseInt(theobj.style.top)<0){
	var nexted = parseInt(theobj.style.top)+step
		theobj.style.top=nexted+"px";
	}else if(ns4&&theobj.top<0){ 
		theobj.top+=step
	}
	timerupname = setTimeout("scrollup()",scrollspeed)	
}
function stopall() {
	if(timerup){
		clearTimeout(timerupname)
	}
	if(timerdown){
		clearTimeout(timerdownname)
	}
}
function shifttotop(){
	stopall()
	if (iens6) {
		theobj.style.top=0
	}else{
		theobj.top=0
	}
}

function getcontent_height(){
if (iens6)
contentheight=crossobj.offsetHeight
else if (ns4)
document.nscontainer.document.nscontent.visibility="show"
}
window.onload=getcontent_height


//---------------------------------------------------------------------------
function peoplesearch(thesearch)
{
	var thesearch;
	window.location.href= thesearch;
}

function nav()
   {
   var w = document.myform.mylist.selectedIndex;
   var url_add = document.myform.mylist.options[w].value;
   window.location.href = url_add;
   }
   
   function singleSubmit(trgForm)
{
    trgForm.submitButton.disabled = true;
    trgForm.resetButton.disabled = true;
}



function resetDynamicFields()
{
	document.cpiForm.OrderId.value=Math.round(Math.random()*10000000000);
	document.cpiForm.TimeStamp.value=new Date().valueOf();
}



  function load() {
              document.getElementById('cpiForm').submit();
document.cpiForm.submit();
        }