    //Get data
    function get_query(query){
    	//alert(query);
    	var html = document.getElementsByTagName('head').item(0) || document.body;
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('id', 'temp_js');
        js.setAttribute('src', query);
        if (!html.appendChild(js)) document.write('<scr'+'ipt src="+query+" type="text/javascript"></scr'+'ipt>');
    }                 

    // Clear email subscription box on focus
    function clear_subscription(obj){
        if(obj.value=="Email subscription"){
            obj.value="";
            ES(obj.id).color="#000000";
        }
    }
    function init(){
        if(EL('subscriber')) {
            if(EL('subscriber').value!="Email subscription") ES('subscriber').color="#000000";
        }
    }
    
    function chk_subscription(){
        defocus();
        mail=EL("subscriber").value;
        if(mail=="") {
            alert("Please enter your email address to subscribe");
            EL("subscriber").focus();
            return false;
        } else {
            if(checkMail(EL("subscriber"),"The email address you entered does not appear to be valid\nPlease check and try again!")){
                get_query("http://www.elephant-tele.com/php/subscribe.php?email="+escape(mail));
            }
            /*
            at=mail.indexOf('@',1);dot=0;chr='';
            if (at>0){dot=mail.indexOf('.',at+2);}
            if (dot>0){chr=mail.substring(dot+1,mail.length);}
            if (mail==''||at<1||dot==-1||chr==''){
                alert('The email address you entered does not appear to be valid\nPlease check and try again!');
                EL("subscriber").focus();
                return false;
            } else {
                get_query("http://www.barbara-bertagnolli.co.uk/ebay/subscribe.php?email="+escape(mail));
                //popWin=window.open("","popWin","top=300,left=300,width=550,height=135,toolbars=no");
                return false;
            }
            */
            return false;
        }
    }
    
    
    //SELECT
    function validateSelect(obj,message){
    	if (obj.options[obj.selectedIndex].text=="") {
    		alert(message);
    		obj.focus();
    		return false;
    	} else return true;
    }
    //TEXT
    function validateText(obj,message) {
    	if (obj.value=="") {
    		alert(message);
    		obj.focus();
    		return false;
    	} else return true
    }
    //EMAIL
    function checkMail(obj,message){
    	mail=obj.value;at=mail.indexOf("@",1);dot=0;chr="";
    	if (at>0) dot=mail.indexOf(".",at+2)
    	if (dot>0) chr=mail.substring(dot+1,mail.length)
    	if (mail==""||at<1||dot==-1||chr=="") {
    		alert(message);obj.focus();return false;
    	} else return true;
    }
    //VALIDATE UK POSTCODE
    function checkPostcode(obj,message) {
    	PC=obj.value;OK=true;VC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";VN="0123456789";PL=PC.length;PN=0;
    	// Last Character
    	if (VC.indexOf(PC.substring(PL-1,PL)) == -1) {OK=falsePN=PL;}
    	// Last-1 Character
    	if (VC.indexOf(PC.substring(PL-2,PL-1)) == -1) {OK=false;PN=PL-1;}
    	// Last-2 Number 0-9
    	if (VN.indexOf(PC.substring(PL-3,PL-2)) == -1) {OK=false;PN=PL-2;}
    	// Last-3 Space
    	if (PC.substring(PL-4,PL-3) != " ") {OK=false;PN=PL-3;}
    	//Process first half
    	PCS=PC.substring(0,PL-4)
    	//1
    	if (PCS.length>1){if (VC.indexOf(PCS.substring(0,1)) == -1) {OK=false;}}
    	else {OK=false;}
    	//2
    	if (PCS.length>2){if ((VC.indexOf(PCS.substring(1,2)) == -1)&&(VN.indexOf(PCS.substring(1,2)) == -1)) {OK=false;}}
    	else if (PCS.length==2){ //if length=2 must be digit
    		if (VN.indexOf(PCS.substring(1,2)) == -1) {OK=false;}
    	}
    	//3
        if (PCS.length>3){ //if length=4 must be digit
    		if (VN.indexOf(PCS.substring(2,3)) == -1) {OK=false;}
    	}
    	else if (PCS.length==3){if ((VC.indexOf(PCS.substring(2,3)) == -1)&&(VN.indexOf(PCS.substring(2,3)) == -1)) {OK=false;}	
            //if length=3 and 2=chr, must be digit
    		else if ((VC.indexOf(PCS.substring(1,2))>0)&&(VC.indexOf(PCS.substring(2,3))>0)) {OK=false;}
    	}
    	//4
    	if (PCS.length==4){
    		if ((VC.indexOf(PCS.substring(3,4)) == -1)&&(VN.indexOf(PCS.substring(3,4)) == -1)) {OK=false;}	
    		else if (VN.indexOf(PCS.substring(1,2))>0) {OK=false;}
    	}
    	else if(PCS.length>4){OK=false;}
    	if(OK){return true;} else {alert(message);obj.focus();return false;}
    }
    //ALPHANUMERIC
    function validateAlphanumeric(obj,message){
        VC="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        VF=obj.value.toUpperCase();
        for(i=0;i<VF.length;i++){
            if(VC.indexOf(VF.substring(i,i+1))==-1){alert(message);obj.focus();return false;}
        }
        return true;
    }
    
    
    
    
    
    function defocus(){window.focus();}
    function EL(obj){return document.getElementById(obj);}
    function ES(obj){return document.getElementById(obj).style;}
    function EH(obj){return document.getElementById(obj).innerHTML;}
    function HE(obj,content){EL(obj).innerHTML=content;}
