var myobj = false
var opening = false
function Em_Me(Pnum,a){
    a.innerHTML = 'Opening window, click here again if it fails'
    if(opening)
        return true;
    myobj = a;opening=true;
    w = window.open("http://www.daleysfruit.com.au/Notify.php?Num="+Pnum+'&Ref='+escape(document.referrer)+'&thpg='+escape(document.URL),"_blank","directories=no,menubar=no,status=no,toolbar=no,height=240,width=300,top=200,left=300",false)
    w.focus()
	return false
}
function ChkQty(minQty,txbox,maxQty){
    q = document.getElementById(txbox)
    if(minQty > parseInt(q.value))
    {
        q.style.background = 'Red'
        alert("Please enter a quantity "+minQty+" or greater")
        q.value=minQty
        q.select()
        q.focus()
        return false
    }
    if(maxQty&&(maxQty<parseInt(q.value)))
    {
        q.style.background = 'Red'
        alert("Currently "+maxQty+" is the max Qty you can order\n\n Please mention in the special instructions if you require more.")
        q.value=maxQty
        q.select()
        q.focus()
    	return false
    }
    return true;
}
function Preview(a)
{
    a.style.background='white'
    d=document;f=document.forms.r;com=f.comment.value;
    if(com.length>255)
    {
        f.comment.value = f.comment.value.match(/.{0,255}/)
        alert('Please Keep Tips Brief')
    }
    tname=(f.FullName.value)?' | <i>'+f.FullName.value:'<i>';
    tstate=(f.State.value)?', '+f.State.value:'';
    tsuburb=(f.City.value)?' - '+f.City.value+'</i>':'</i>';
    d.getElementById('b').innerHTML=com+tname+tsuburb+tstate;
}
function HeaderChange(a)
{
    if(a.selectedIndex)
    {
        document.getElementById('h').innerHTML = document.getElementById('pl').innerHTML = a.options[a.selectedIndex].text
        a.style.background='white'
    }
    else
    {
        document.getElementById('h').innerHTML = document.getElementById('pl').innerHTML = 'Select Variety'
        a.style.background='Red'
    }
}
function Final_Check()
{
    e=''
    f = document.forms.r
    if(f.Variety)
        if(f.Variety.selectedIndex==0)
        {
            f.Variety.style.background='Red'
            e+="\n- Select variety"
        }
    if(!f.comment.value)
    {
        f.comment.style.background='Red'
        e+="\n- Comment"
    }
    if(!f.FullName.value)
    {
        f.FullName.style.background='Red'
        e+="\n- Full Name"
    }
    if(!f.City.value)
    {
        f.City.style.background='Red'
        e+="\n- Suburb"
    }
    if(!f.State.value)
    {
        f.State.style.background='Red'
        e+="\n- State"
    }
    if(!echeck(f.Email.value))
    {
        f.Email.style.background='Red'
        e+="\n- Valid Email"
    }
    if(!e)
    {
	    if(!confirm('Please Confirm you are giving a Tip not asking a Question.'))
	    {
	    	alert('Go to our Forum (Top Left Hand Links) to ask questions');
			return false;	
	   	}
		alert('Thanks, We will review your tip and put it up soon')
        f.action='/commen.php'
        return true
    }
    else
    {
        alert('Please correct fields highlighted in Red'+e)
        return false
    }

}
function ni(s,t)
{
	t=(t)?1:0;
	new Image().src = "http://www.daleysfruit.com.au/Eimage/"+s+"/"+t+"/s.jpg";
	return true;
}
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){
    return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }

	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	 return true
}
function load()
{
	var form = document.getElementById('format');
	var bound = document.getElementById('boundary');
	var h = 500;
	if(window.innerHeight==null&&window.innerHeight!=0) /*internet explorer*/
		var newh = document.documentElement.clientHeight - 80
	else /*firefox and opera*/
		var newh = window.innerHeight - 80
	if(newh>100)
		form.style.height = bound.style.height = newh+'px'
}