//  Accompanies WG Conveyancing site

function RedirectIfNotFramed(){
    if (self == top) {
        self.location = 'http://www.warnergoodman.co.uk/for-you/conveyancing/agent-logon/';
    }
}

function validate(formname) {

	// Prompts for confirmation before deletion, where applicable
	if (typeof(formname.delconf) == 'object'){ 
		if (formname.delconf.value == "Yes"){
			if (confirm("Are you sure you want to delete this record?")) 
				return true;
			else
				return false;
		}
	}

    // this only used on Instruct Us form
	if (formname.name == 'instruct'){
		if ( (formname.Terms.checked == false) ||
		     (formname.RefName.value == "") ||
		     (formname.RefBranch.value == "") ||
		     (formname.RefNotes.value == "") ||
		     (formname.RefReference.value == "")
		   ){
		       alert("Please fill in all the fields marked with an asterisk. Thank you.")
			   return false;
		   }
	}

    // this only used on the Logon form
	// and only if there is a "Terms Read" check box

	if ( (formname.name == 'logon') && 
		 (typeof(formname.logon_terms) == 'object')
		){
		if (formname.logon_terms.checked == false){
		   alert("Please tick the box to show you have read the Terms and Conditions. Thank you.")
		   return false;
		}
	}

    // if PostCode field exists, strip out any whitespace
	if (typeof(formname.FORM_rofPostCode) == 'object'){
		oldPC = formname.FORM_rofPostCode.value
		cleanPC = oldPC.replace(" ", "")
		formname.FORM_rofPostCode.value = cleanPC
    }

    // if password editing field exists, disallow a blank one
	if (typeof(formname.FORM_logPassword) == 'object'){
		if (formname.FORM_logPassword.value == ''){
		   alert("Please enter a password. This field cannot be blank. Thank you.")
		   return false;
		}
    }

    // permit submission by default
	return true; 
}

function show(strID, x, y){  
   // Shows a hidden description div just below and 
   // to the right the activating link

   // offsets from page origin
   origLeft = 0
   origTop = 60

   myObj = document.getElementById(strID)
   myObj.style.display = "block"
   myObj.style.left = (x - origLeft) + "px"
   myObj.style.top = (y - origTop) + "px"
}

function hide(strID){  
   myObj = document.getElementById(strID)
   myObj.style.display = "none";
}

function getY(obj){
	// from www.quirksmode.org
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else {
        if (obj.y) {
		    curtop += obj.y;
        }
    }
	return curtop;
}

function getX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else {        
        if (obj.x) {
		    curleft += obj.x;
        }
    }
	return curleft;
}
