/*
 * File: standard.js
 * Include with: <script SRC="js/standard.js"></script>
*/
function displayTerms() {
	var n=open('/inc/terms.php','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}
function displayCredits() {
	var n=open('/inc/credits.php','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}
function displayReferences() {
	var n=open('/inc/references.php','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}
function openDragWin(winName)	{
	var n=open('dragon.php','Dragons','width=600,height=410,status=1,toolbar=1,menubar=1,scrollbars=1,resizable=1');

}
function openWin(winName)	{
var thisWin;
thisWin = winName;
// Open window
	window.open(winName, "Popup", "width=280, height=250, resizable=no");
}
function closeWin()	{
//  NB - user receives Warning Message if the current window wasn't opened by a parent browser window
//  adapt URL and uncomment following line if you want to select parent window's URL
//	window.opener.location = "http://jnewton9.valuehost.co.uk/sereno/client_page.php";
	this.window.close();
}
// A utility function that returns true if a string contains only
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}
// Removes first chars from string
// s = string to remove prefix from, n is no of chars to strip from string
function stripPrefixAndUnderscore(s, n)
{
	noRemove = n;
	stripped = s.substring(n,s.length);
	str = stripped.replace(/_/, " ");
	
	return str;
}

// If there is a form on the page, it's first element is given the focus
// Calling HTML: - <BODY onLoad="firstFocus()"> 
function firstFocus()
{
   if (document.forms.length > 0)
   {
      var TForm = document.forms[0];
      for (i=0;i<TForm.length;i++)
      {
         if ((TForm.elements[i].type=="text")||
           (TForm.elements[i].type=="textarea")||
           (TForm.elements[i].type.toString().charAt(0)=="s"))
         {
            document.forms[0].elements[i].focus();
            break;
         }
      }
   }
}

// Detects if enter is pressed, and submits the form if it is.
// Allows calling HTML to specify which form on a page to submit.
// Calling HTML in final form element on page, where 'frmClientLogin' is the name of the form:- <input type="password" name="txtPassword" onKeyPress="checkEnterToSubmit(event, frmClientLogin)" />
function checkEnterToSubmit(event, formname)
{ 
	var frm = formname;	
	var code = 0;
		code = event.keyCode;
	if (code==13)
		submitForm(frm);
}

// 
function submitForm(formname){
var frmname = formname;
var frm = "document." + frmname;
    if (verify(eval(frm))){
    	eval(frm).submit();
	}
}

// This is the function that performs form verification.
// Checks any text or text area element against pre-defined 
// 'optional', 'max' and 'min' properties.
// Doesn't do radio buttons or check boxes.
// NB - 'max' and 'min' refer to NUMERIC values.
// NB - calls stripPrefixAndUnderscore to remove first 3 chars of field name - eg txtSurname -> Surname
function verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
        if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && !e.optional) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + stripPrefixAndUnderscore(e.name,3);
                continue;
            }
            // Now check for fields that are supposed to be numeric.
            if (e.numeric || (e.min != null) || (e.max != null)) {
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + stripPrefixAndUnderscore(e.name) + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }
    }
    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    if (!empty_fields && !errors) return true;
    msg  = "______________________________________________________\n\n"
    msg += "Your form isn't quite complete yet.\n";
    msg += "Please sort out the issues below and try again:\n";
    msg += "______________________________________________________\n\n"
    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

// for development - generate an alert box.
function underDevelopment(){
	alert("Currently in development.\nPlease check later.");
}

// rollover a table row and change its colour
// eg of use: 		  <tr bgcolor='<?=$colour?>' onclick="window.location.href='job.php?expand=<?=$this_job_code?>';" onmouseover="do_over(this,'<?=$colourOver?>');" onmouseout="do_over(this,'<?=$colour?>');" style="">
function do_over(obj,colour) {
	 obj.style.backgroundColor = colour; obj.style.color = 'black'; obj.style.cursor = 'hand'; obj.style.title = 'Ha Ha';
}

function do_out(obj) {
	obj.style.backgroundColor = ''; obj.style.color = '';
}


// Macromed
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_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_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 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;
}
// Videos
function pop(url) {
		var n=open(url,'MediaPlayer','width=670,height=374,status=yes,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}
function pop1() {
var n=open('http://www.vetmedin.co.uk/vet_login/video/ogrady1/pop_speaker2.htm','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}
function pop2() {
var n=open('http://www.vetmedin.co.uk/vet_login/video/ogrady2/pop_speaker2.htm','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}
function pop3() {
var n=open('http://www.vetmedin.co.uk/vet_login/video/smith/pop_speaker2.htm','slide','width=600,height=410,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}

// news popup
function pop_news(){
 var n=open('news_pop_content.php','BreakingNews','width=600,height=369,status=yes,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}

// announcement shown the first time a user visits the site. Shown once per visit, at start of visit
function pop_ecard(ecd_no){
/*var ecd_no = int(ecd_no);*/
var url = "ecard/index.php?ecd=" + ecd_no;
 var n=open(url,'ecard','width=540,height=438,status=yes,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}

// announcement shown the first time a user visits the site. Shown once per visit, at start of visit
function pop_announce(){
 var n=open('/inc/pop_announce.php','Announcement','width=600,height=374,status=yes,toolbar=no,menubar=no,scrollbars=no,resizable=no');
}

function pop_masterclass() {
		var n=open('masterclass_popup.php','Masterclass','width=480,height=460,status=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
}

function textLimit(field, maxlen) {
 if (field.value.length > maxlen + 1)
 alert('Sorry - you have reached the maximum character length.');
if (field.value.length > maxlen)
 field.value = field.value.substring(0, maxlen);
 }