var winW=0;
var winH=0;
var lpos=0;
var tpos=0;
var targdiv="";

var currentemail='<a href="mailto:info@buycarvings.com">info@buycarvings.com</a>';
var currentelno='01822 833764';
function inform(){
	if(document.passes.id.value!="" && document.passes.pass.value!=""){
		document.passes.submit();
		}
		else{
			alert('please enter values in both boxes')
		}
}


function createPassCookie(value){
	var name='id';
	var days=30;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
	location='http://www.iwebdesigns.co.uk/index.html';
}

function checkPassCookie(){
	if(!readCookie('id')){
			location='http://www.iwebdesigns.co.uk';
		}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function myemail(){
	document.getElementById('myemailbox').innerHTML=currentemail;
	document.getElementById('phonebox').innerHTML='call us on '+currentelno;
}

function searchveg(){
	if(document.getElementById('tagbox').value!=""){
		location='http://www.iwebdesigns.co.uk/pages/searchresults.php?tag='+document.getElementById('tagbox').value;
	}
}

function searchlink(status,prod,cat,typename,xprod,tag){
	location='catalogue.php?status='+status+'&prod='+prod+'&cat='+cat+'&typename='+typename+'&xprod='+xprod+'&tag='+tag;
}

function winsize(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
 			}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
			}
	}
}

function findcenter(sizestring){
	var myReg= new RegExp("width=(.*) height=(.*)");
	var results= sizestring.match(myReg);
	
	lpos=Math.round(parseFloat((winW-results[1])/2));
	tpos=Math.round(parseFloat((winH-results[2])/2));
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}

function showmenu(oBj,num){
	var pos=findPos(oBj);
	document.getElementById('menubox').innerHTML=menu[num];
	targdiv=oBj;
	targdiv.style.backgroundColor='#7D9851';
	targdiv.style.color='#fff';
	document.getElementById('menubox').style.left=pos[0]+'px';
	document.getElementById('menubox').style.top=(pos[1]+40)+'px';
	document.getElementById('menubox').style.display='block';
}

function showthismenu(){
	targdiv.style.backgroundColor='#7D9851';
	targdiv.style.color='#fff';
	document.getElementById('menubox').style.display='block';
}

function hidemenu(){
	targdiv.style.backgroundColor='#fff';
	targdiv.style.color='#373737';
	document.getElementById('menubox').style.display='none';
}

function showmenu2(oBj,num){
	var pos=findPos(document.getElementById('menurow'));
	document.getElementById('dropbox').innerHTML=menu[num];
	targdiv=oBj;
	targdiv.style.backgroundColor='#9FC167';
	targdiv.style.color='#fff';
	document.getElementById('dropbox').style.left=(pos[0]+5)+'px';
	document.getElementById('dropbox').style.top=(pos[1]+40)+'px';
	document.getElementById('dropbox').style.display='block';
}

function showthismenu2(){
	targdiv.style.backgroundColor='#9FC167';
	targdiv.style.color='#fff';
	document.getElementById('dropbox').style.display='block';
}

function hidemenu2(){
	targdiv.style.backgroundColor='#fff';
	targdiv.style.color='#373737';
	document.getElementById('dropbox').style.display='none';
}

function selecteditem(prodname,wood){
	document.getElementById('selectedbox').innerHTML='Item currently selected is '+prodname+' in '+wood;
}
