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()
{
	if(!document.getElementById('format'))
		return false;
	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'
}
function im(a)
{
		var tran = document.createElement('img')
		if(document.body.offsetHeight)
			tran.style.height = document.body.offsetHeight.toString()+'px'
	tran.setAttribute('src','http://www.daleysfruit.com.au/images/trans.png');
	tran.setAttribute('id','tra')
	document.body.appendChild(tran);
	if(window.XMLHttpRequest)
		var req = new XMLHttpRequest();
	else	
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	req.onreadystatechange = HandleSend
	req.open("get", '/Feedback.php?i='+a+'&h=1', true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	req.send();
	function HandleSend()
	{
    	if(req.readyState==4)
	    {
		    if (req.status==200)
		    {
		    	if(req.responseText)
		    	{
					var winW = 630, winH = 460;
					if (window.innerWidth)
					{
						winW = window.innerWidth
						winH = window.innerHeight
					}
					else if (document.documentElement && document.documentElement.clientWidth)
					{
						winW = document.documentElement.clientWidth
						winH = document.documentElement.clientHeight
					}
					else if (document.body)
					{
						winW = document.body.clientWidth
						winH = document.body.clientHeight
					}
						if (window.pageYOffset)
						{
							  pos = window.pageYOffset
						}
						else if (document.documentElement && document.documentElement.scrollTop)
						{
							pos = document.documentElement.scrollTop
						}
						else if (document.body)
						{
							  pos = document.body.scrollTop
						}
					var widthW = 380
					var themargins = (winW - widthW)/2;
		    		var nDiv = document.createElement('div')
					nDiv.style.left = themargins +'px'
		    		pos = pos+10;
		    		nDiv.style.top = pos+'px'
		    		nDiv.style.width = widthW+'px'
		    		winH = winH - 80
		    		nDiv.style.height = winH+'px'
					nDiv.setAttribute('id','com');
					var closeit = '<a style="text-align:right;display:block;color:red;font-weight:bolder;font-size:1.4em" href="#" onclick="return clNOW()" >CLOSE</a>'
    				nDiv.innerHTML = closeit+'<br />'+req.responseText+'<br />'+closeit
					document.body.appendChild(nDiv);
		    	}	
		    	return true
			}
		}
	}
	return false
}
function clNOW()
{
	document.body.removeChild(document.getElementById('com'))
	document.body.removeChild(document.getElementById('tra'))
	return false;
}
function l(a)
{
	if(window.XMLHttpRequest)
		var req = new XMLHttpRequest();
	else	
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	req.onreadystatechange = HandleSend
	req.open("get", '/Rate.php?i='+a, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	req.send();
	function HandleSend()
	{
    	if(req.readyState==4)
	    {
		    if (req.status==200)
		    {
		    	if(req.responseText)
		    	{
		    		var theId = a.replace(/^\d/,'')
		    		if(!document.getElementById(theId))
		    		{
		    			alert(a+' '+theId+req.responseText)
	    			}
		    		document.getElementById(theId).innerHTML = '<br /><i><b>'+req.responseText+'</b> people found this review useful</i>'; 
				}
			}	
		}	
	}
	return false;	
}
