function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function P7_Snap() { //v2.67 by PVII
 var g,x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,tw,q0,xx,yy,w1,pa='px',args=P7_Snap.arguments;a=parseInt(a);
 if(document.layers||window.opera){pa='';}for(k=0;k<(args.length);k+=4){
 if((g=MM_findObj(args[k]))!=null){if((el=MM_findObj(args[k+1]))!=null){
 a=parseInt(args[k+2]);b=parseInt(args[k+3]);x=0;y=0;ox=0;oy=0;p="";tx=1;
 da="document.all['"+args[k]+"']";if(document.getElementById){
 d="document.getElementsByName('"+args[k]+"')[0]";if(!eval(d)){
 d="document.getElementById('"+args[k]+"')";if(!eval(d)){d=da;}}
 }else if(document.all){d=da;}if(document.all||document.getElementById){while(tx==1){
 p+=".offsetParent";if(eval(d+p)){x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
 }else{tx=0;}}ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);tw=x+ox+y+oy;
 if(tw==0||(navigator.appVersion.indexOf("MSIE 4")>-1&&navigator.appVersion.indexOf("Mac")>-1)){
  ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);}else{
  w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
  x=document.body.scrollLeft+event.clientX+bx;y=document.body.scrollTop+event.clientY;}}
 }else if(document.layers){x=g.x;y=g.y;q0=document.layers,dd="";for(var s=0;s<q0.length;s++){
  dd='document.'+q0[s].name;if(eval(dd+'.document.'+args[k])){x+=eval(dd+'.left');y+=eval(dd+'.top');
  break;}}}e=(document.layers)?el:el.style;xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
 if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
  xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);}
 e.left=xx+pa;e.top=yy+pa;}}}
}

function JumpPage(tnid){
	var tnid = tnid.options[tnid.selectedIndex].value;
	window.location = ""+tnid+"";
}

function ShowLayer1(){
	document.getElementById('Layer01').style.visibility = "visible";
}

function HideLayer1(){
	document.getElementById('Layer01').style.visibility = "hidden";
}

function ShowLayer2(){
	document.getElementById('Layer02').style.visibility = "visible";
}

function HideLayer2(){
	document.getElementById('Layer02').style.visibility = "hidden";
}

function ShowLayer3(){
	document.getElementById('Layer03').style.visibility = "visible";
}

function HideLayer3(){
	document.getElementById('Layer03').style.visibility = "hidden";
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("Invalid email")
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Invalid email")
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid email")
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid email")
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid email")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid email")
		return false
	}
	if (str.indexOf(" ")!=-1){
		alert("Invalid email")
		return false
	}
	return true
}

function chkTellFriend(theform){
	if (theform.yourname.value == ""){
		alert("Please enter your name.");
		theform.yourname.focus();
		return false;
	} else if (theform.youremail.value == ""){
		alert("Please enter your email.");
		theform.youremail.focus();
		return false;
	} else if (echeck(theform.youremail.value)==false){
		theform.youremail.focus();
		return false;
	} else if (theform.friendemail01.value == "" && theform.friendemail02.value == "" && theform.friendemail03.value == "" && theform.friendemail04.value == "" && theform.friendemail05.value == ""){
		alert("Please enter at lease 1 friend email.");
		return false;
	} else if (theform.friendemail01.value != "" && echeck(theform.friendemail01.value)==false){
		theform.friendemail01.focus();
		return false;
	} else if (theform.friendemail02.value != "" && echeck(theform.friendemail02.value)==false){
		theform.friendemail02.focus();
		return false;
	} else if (theform.friendemail03.value != "" && echeck(theform.friendemail03.value)==false){
		theform.friendemail03.focus();
		return false;
	} else if (theform.friendemail04.value != "" && echeck(theform.friendemail04.value)==false){
		theform.friendemail04.focus();
		return false;
	} else if (theform.friendemail05.value != "" && echeck(theform.friendemail05.value)==false){
		theform.friendemail05.focus();
		return false;
	} else {
		return true;
	}
}

function showEmail(thefield){
	//document.getElementById('sendername').innerHTML = thefield.value+" ";
	//document.getElementById('sendername2').innerHTML = thefield.value;
	document.getElementById('emailrow').style.display = 'block';
}

function chkRegister(theform){
	if (theform.txtEmail.value == ""){
		alert("Please enter email.");
		theform.txtEmail.focus();
		return false;
	} else if (echeck(theform.txtEmail.value)==false){
		theform.txtEmail.focus();
		return false;
	} else if (theform.txtPassword.value == ""){
		alert("Please enter password.");
		theform.txtPassword.focus();
		return false;
	} else if (theform.txtCFMPassword.value == ""){
		alert("Please enter confirm password.");
		theform.txtCFMPassword.focus();
		return false;
	} else if (theform.txtPassword.value.length < 6){
		alert("Minimum of 6 characters in length.");
		theform.txtPassword.focus();
		return false;
	} else if (theform.txtCFMPassword.value.length < 6){
		alert("Minimum of 6 characters in length.");
		theform.txtCFMPassword.focus();
		return false;
	} else if (theform.txtPassword.value != theform.txtCFMPassword.value){
		alert("Password not match.");
		return false;
	} else if (theform.txtName.value == ""){
		alert("Please enter name.");
		theform.txtName.focus();
		return false;
	} else if (theform.prefix.value == "" || theform.txtMobile.value == ""){
		alert("Please enter mobile number.");
		return false;
	} else if (theform.txtAddress1.value == ""){
		alert("Please enter address.");
		theform.txtAddress1.focus();
		return false;
	} else if (theform.txtPostcode.value == ""){
		alert("Please enter postcode.");
		theform.txtPostcode.focus();
		return false;
	} else if (theform.txtTown.value == ""){
		alert("Please enter town.");
		theform.txtTown.focus();
		return false;
	} else if (theform.state.value == ""){
		alert("Please select state.");
		theform.state.focus();
		return false;
	} else if (theform.country.value == ""){
		alert("Please select country.");
		theform.country.focus();
		return false;
	} else {
		return true;
	}
}

function chkUpload(theform){
	if (theform.txtPhoto.value == ""){
		alert("Please select an image file.");
		return false;
	} else {
		return true;
	}
}

function chkLogin(theform){
	if (theform.txtEmail.value == ""){
		alert("Please enter email.");
		theform.txtEmail.focus();
		return false;
	} else if (echeck(theform.txtEmail.value)==false){
		theform.txtEmail.focus();
		return false;
	} else if (theform.txtPassword.value == ""){
		alert("Please enter password.");
		theform.txtPassword.focus();
		return false;
	} else if (theform.txtPassword.value.length < 6){
		alert("Minimum of 6 characters in length.");
		theform.txtPassword.focus();
		return false;
	} else {
		return true;
	}
}

function checkNo(field) {
  	var valid = "0123456789"
  	var ok = "yes";
  	var temp;
		
  	for (var i=0; i<field.value.length; i++){
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
  	if (ok == "no"){
  		//alert("Invalid entry!  Only numbers are accepted!");
  		field.value = field.value.substring(0, field.value.length - 1);
  		field.focus();
	}
}

function checkChar(field) {
  	var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 "
  	var ok = "yes";
  	var temp;
		
  	for (var i=0; i<field.value.length; i++){
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
  	if (ok == "no"){
  		//alert("Invalid entry!  Only numbers are accepted!");
  		field.value = field.value.substring(0, field.value.length - 1);
  		field.focus();
	}
}

//Specify speed of scroll. Larger=faster (ie: 5)
var scrollspeed=cache=1

//Specify intial delay before scroller starts scrolling (in miliseconds):
var initialdelay=500

function initializeScroller(){
	dataobj=document.all? document.all.datacontainer : document.getElementById("datacontainer")
	dataobj.style.top="0px"
	setTimeout("getdataheight()", initialdelay)
}

function getdataheight(){
	thelength=dataobj.offsetHeight
	if (thelength==0)
	setTimeout("getdataheight()",10)
	else
	scrollDiv()
}

function scrollDiv(){
	dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px"
	if (parseInt(dataobj.style.top)<thelength*(-1))
	dataobj.style.top="0px"
	setTimeout("scrollDiv()",70)
}

function chkEditRegister(theform){
	if (theform.txtEmail.value == ""){
		alert("Please enter email.");
		theform.txtEmail.focus();
		return false;
	} else if (echeck(theform.txtEmail.value)==false){
		theform.txtEmail.focus();
		return false;
	} else if (theform.txtPassword.value != "" && theform.txtPassword.value.length < 6){
		alert("Minimum of 6 characters in length.");
		theform.txtPassword.focus();
		return false;
	} else if (theform.txtCFMPassword.value != "" && theform.txtCFMPassword.value.length < 6){
		alert("Minimum of 6 characters in length.");
		theform.txtCFMPassword.focus();
		return false;
	} else if (theform.txtPassword.value != theform.txtCFMPassword.value){
		alert("Password not match.");
		return false;
	} else if (theform.txtName.value == ""){
		alert("Please enter name.");
		theform.txtName.focus();
		return false;
	} else if (theform.prefix.value == "" || theform.txtMobile.value == ""){
		alert("Please enter mobile number.");
		return false;
	} else {
		return true;
	}
}

function changesize(){
	document.getElementById('vavalert').width = "330";
	document.getElementById('vavalert').height = "300";
}

function clearfield(thefield){
	thefield.value='';
}

function checkSearch(theform){
	if (theform.txtSearch.value == "Search Friend"){
		alert("Please enter a name.");
		theform.txtSearch.focus();
		return false;
	} else if (theform.txtSearch.value == ""){
		alert("Please enter a name.");
		theform.txtSearch.focus();
		return false;
	} else {
		return true;
	}
}

function chkVideo(theform){
	if (theform.fileVideo.value == ""){
		alert("Please select a video file.");
		return false;
	} else {
		return true;
	}
}

function chkChallange(theform){
	var privs = document.getElementsByName("challenge[]");
	var privschecked = false;
	for (var i = 0; i < privs.length; i++) {
		if (privs[i].checked) {
			privschecked = true;
			break;
		}
	}
	
	if (!privschecked) {
		alert("Please select a friend.");
		return false;
	} else {
		return true;
	}
}

function chkForgot(theform){
	if (theform.txtEmail.value == ""){
		alert("Please enter your email.");
		theform.txtEmail.focus();
		return false;
	} else if (echeck(theform.txtEmail.value)==false){
		theform.txtEmail.focus();
		return false;
	} else {
		return true;
	}
}

function chkAskExpert(theform){
	if (theform.txtQuestion.value == ""){
		alert("Please enter your question.");
		theform.txtQuestion.focus();
		return false;
	} else {
		return true;
	}
}

function chkTestimony(theform){
	if (theform.txtName.value == ""){
		alert("Please enter your name");
		theform.txtName.focus();
		return false;
	} else if (theform.txtPrefix.value == "" || theform.txtContact.value == ""){
		alert("Please complete your contact number");
		return false;
	} else if (echeck(theform.txtEmail.value)==false){
		theform.txtEmail.focus();
		return false;
	} else if (theform.txtAddress1.value == ""){
		alert("Please enter address.");
		theform.txtAddress1.focus();
		return false;
	} else if (theform.txtPostcode.value == ""){
		alert("Please enter postcode.");
		theform.txtPostcode.focus();
		return false;
	} else if (theform.txtTown.value == ""){
		alert("Please enter town.");
		theform.txtTown.focus();
		return false;
	} else if (theform.state.value == ""){
		alert("Please select state.");
		theform.state.focus();
		return false;
	} else if (theform.txtTestimony.value == ""){
		alert("Please enter your testimony");
		theform.txtTestimony.focus();
		return false;
	} else {
		return true;
	}
}

function chkPostcode(theform){
	if (theform.postcode.value == ""){
		alert("Please enter postcode");
		theform.postcode.focus();
		return false;
	} else if (isNaN(theform.postcode.value)){
		alert("Please enter valid postcode");
		return false;
	} else if (theform.postcode.value.length != 5){
		alert("Please enter valid postcode");
		return false;
	} else {
		return true;
	}
}
