var IE = document.all?true:false;
function eid (element) 
{
	return document.getElementById(element);
}
function jShowProductNewMenu(sender)
{
	var id = sender.id;
	var previousId = eid("jsValue").innerHTML;
	var statusId = eid("catMenu_"+id).style.display;
	
	if(statusId == 'block')
	{
		eid("catMenu_"+id).style.display = 'none';
		eid("jsValue").innerHTML = previousId;
	}
	else
	{
		eid("catMenu_"+id).style.display = 'block';
		eid("jsValue").innerHTML = id;
	}
	
	if(id != previousId && previousId != 0)
	{
		eid("catMenu_"+previousId).style.display = 'none';
	}
}
function jSubmitProductCart()
{
	var selects = document.getElementsByTagName("select");
	var selectsCount = selects.length;	
	
	for ( i = 0 ; i < selectsCount ; i ++)
	{
		name = selects[i].name;
		value = selects[i].value;
		
		if(name.match(/options_.+/))
		{
			if(value == 'Nothing')
			{	
				
				alert("You must select an option from the list");
				return false;
			}
		}
	}
	//alert('hello');
	//return false;
}
function jPopupSelect(file_id,w,h)
{
	var sb = 'Yes';
	var mb = 'No';
	var rs = 'Yes';

	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	settings = 'height='+h+',';
	settings += 'width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+sb+',';
	settings +='menubar='+mb+',';
	settings +='resizable='+rs;
	
	myPopup = window.open(file_id,"",settings);
	if (!myPopup.opener)
		 myPopup.opener = self; 
}

function Closeup(img)
{
  foto1= new Image();
  foto1.src=(img);
  Controlla(img);
}

function Controlla(img)
{
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img);
  }
  else{
    funzione="Controlla('"+img+"')";
    intervallo=setTimeout(funzione,20);
  }
}

function viewFoto(img)
{
  
  w=foto1.width+20;
  h=foto1.height+20;
  
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;

  string="width="+w+",height="+h+",top="+wint+",left="+winl;
  
  finestra=window.open(img,"",string);
}

// Printing
function Printing(id){ 
	if(window.print()){
	var d=eval(id)==null||eval(id+".closed");
	if(!d){eval(id+".print()");}}
}

myPopup = '';

function PopupReturnWindow(file_id,w,h,scl,menu,stat,tool,full,locate,resize,tbar)
{

  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var PopUp = 'POPUP';
  
  settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+scl+',';
  settings +='menubar='+menu+',';
  settings +='statusbar='+stat+',';
  settings +='toolbar='+tool+',';
  settings +='fullscreen='+full+',';
  settings +='titlebar='+tbar+',';
  settings +='locationbar='+locate+',';
  settings +='resizable='+resize;
  
  myPopup = window.open(file_id,PopUp,settings);
    if (!myPopup.opener)
         myPopup.opener = self; 
}
function PopupEvent(file_id)
{
  var h = 400;
  var w = 400;
  var sb = 'Yes';
  var rs = 'Yes';
  var mb = 'Yes';
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  
  settings = 'height='+h+',';
  settings += 'width='+w+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+sb+',';
  settings +='menubar='+mb+',';
  settings +='resizable='+rs;
    
  finish = window.open(file_id,"",settings);
}

function jConfirmSubmit(msg)
{
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
}

function populate_selectmenu(current,optionid,data,values)
{	
	var dataarray = data.split(',');
	var valuearray = values.split(',');
	var element = document.getElementById(optionid);
	dataarray[current.selectedIndex] = dataarray[current.selectedIndex].split('|');
	valuearray[current.selectedIndex] = valuearray[current.selectedIndex].split('|');
	for (count = 0; count < element.options.length;count++) element.remove(count);
	element.options[0] = new Option("","",false,false);
	for (count = 0; count < dataarray[current.selectedIndex].length;count++) element.options[count+1] = new Option(dataarray[current.selectedIndex][count],valuearray[current.selectedIndex][count],false,false);
}

// function loadContent added by Mathew Carter on Friday, 4th August 2006
function loadContent(file)
{
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}
function changeImage(filename)
{
	document.mainimage.src = filename;
}
function jChangeImage(filename, zoom)
{
	var newImg = new Image();
	newImg.src = filename;
	document.mainimage.height = newImg.height;
	document.mainimage.width = newImg.width;
	document.mainimage.src = filename;
	document.getElementById("mainimagelink").href = filename;

	
	
	/*if(zoom == 'zoom')
		document.getElementById("mainimagelink").setAttribute("class", "jqzoom");
	else
		document.getElementById("mainimagelink").setAttribute("class", "");*/
}

function toggledisplay(hiddenid,plusid)
{
	var element = document.getElementById(hiddenid);
	if (element.style.display == 'none') 
	{
		element.style.display = '';
		if (plusid != '') plusid.innerHTML = '-';
	}
	else 
	{
		element.style.display = 'none';
		if (plusid != '') plusid.innerHTML = '+';
	}
}
function jPostRequiredFields()
{
	var formfields = new Array('reviewer_name','country','comments');
	var formmessages = new Array('Please enter your name','Please enter your country','Please enter comments');
	var returnval=true;
	var alertstr = '';
	for (i=0;i<formfields.length;i++)
	{
		if (document.getElementById(formfields[i]).value == '')
		{
			alertstr+=formmessages[i]+"\n";
			returnval = false;
		}

	}
	
	if (returnval==false) 
	{
		alert(alertstr);
		return false;
	}
	else 
	{
		//alert('true'); //testing	
		return true;
	}
}
function jPostRequiredTopicFields()
{
	var formfields = new Array('reviewer_name','title','country','message');
	var formmessages = new Array('Please enter your name','Please enter TOPIC title', 'Please enter your country','Please enter the content of the topic');
	var returnval=true;
	var alertstr = '';
	for (i=0;i<formfields.length;i++)
	{
		if (document.getElementById(formfields[i]).value == '')
		{
			alertstr+=formmessages[i]+"\n";
			returnval = false;
		}

	}
	
	if (returnval==false) 
	{
		alert(alertstr);
		return false;
	}
	else 
	{
		//alert('true'); //testing	
		return true;
	}
}

/*	if element is an option list and its related qty is not '' then error */
function validate (sender) {
	var errors = '';
	var name = ''; // name of current element
	var id = 0; // id of element
	for (var i=0; i<sender.elements.length; i++) {
		name = sender.elements[i].getAttribute('name');
		if (sender.elements[i].name.match(/^options_/)) {
			id = parseInt(name.replace(/^options_/, ''));
			if ((eid('qty_'+id).value != '' && sender.elements[i].selectedIndex == 0)
					|| (eid('qty_'+id).value == '' && sender.elements[i].selectedIndex > 0)) {
				eid('qty_'+id).style.background = '#FF9900';
				sender.elements[i].style.background = '#FF9900';
				sender.elements[i].focus();
				alert('You need to specify both a quantity and an option (or neither).');
				return false;
			}
		}
	}
}
/*	reset paired fields after flagging an error (usually onclick of one of the pair) */
function set_white (sender) {
	sender.style.background = 'white';
	var id = sender.getAttribute('name').split('_'); id = id[1];
	if (sender.name.match(/^options_/)) {
		eid('qty_'+id).style.background = 'white';
	} else if (sender.name.match(/^qty_/)) {
		if (eid('options_'+id) != undefined) {
			eid('options_'+id).style.background = 'white';
		}
	}
}
function validateFrm(sender)
{
	var error = '';
	if(eid("email").value == "") error += " * You must have an Email address\n";
	if(eid("name").value == "") error += " * You must have your Name\n";
	if(eid("country_id").value == "") error += " * Please select the country you are from\n";
	if(error != '')
	{
		var msg = "Please complete the following fields\n";
		alert(msg+error);
		return false ;
	}
	else
	{
		document.frm.submit();
		return true;
	}
}
function currencyFrm(sender)
{
	document.getElementById("currencyForm").submit();
}

function jConfirmFrm(msg)
{
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
}

var c=0;
var t;
var timer_is_on = 0;
var speed = 60;

function timedCount()
{
	jFrontPageSlideShowImg();
	c=c+1;
	t=setTimeout("timedCount()",4000);
}

function doTimer()
{
	if (!timer_is_on)
	  {
	  timer_is_on=1;
	  timedCount();
	  }
}
function imageToFade()
{
	if(IE == false)
	{
		document.frontPageImg.style.opacity = 0.4;
		document.frontPageImg.style.filter = 'alpha(opacity=40)';
	}
}
function imageFader()
{
	setTimeout("imageToFade()",500);
}

function jFrontPageSlideShowImg()
{
	//frontPageImageBlank.jpg
	imageFader();
	
	//document.frontPageImg.style.opacity = 0.8;
	//document.frontPageImg.style.filter = 'alpha(opacity=80)';
	//document.frontPageImg.style.opacity = 0.5;
	//document.frontPageImg.style.filter = 'alpha(opacity=50)';
	
	var id = eid("imageID").title;
 	var data = "action=slideShow";
 	data += "&id="+id;
	$.ajax({
	type: "POST",
	url: "/inc/ajax/slideShowAjax.php",
	dataType: "json",
	data: data,
	cache: false,
	success: function(msg)
	{
		eid("frontPageImage").innerHTML = msg.html;
	}
	});
}
function jShowSubMenu(top_category)
{
	
}


var initial_delay = 0;
var scroll_delay =90;
var max_indent = 70;


function scroll ()
{
	
    msg =   msg . substring (1, msg . length)
              + msg . substring (0, 1);

    document . scrollbox_form . scrollbox . value =  msg;
    window . setTimeout ("scroll ()", scroll_delay);

}

function start_scroll (map)
{
	if(map == "map") load_maps();
	//for (var i = 1; i <= max_indent; i ++)
	//{
	//	msg = " " + msg;
	//}
   
	//if(document.scrollbox_form != null)
	//{
	//	 scrollbox = document.scrollbox_form.scrollbox;
	//	 window . setTimeout ("scroll ()", initial_delay);
	//}
	//Run the scroll function after initial_delay
   
}

function checkComment()
{
	var errors = "";
	if(eid("commentName").value == "")
	{
		errors += 'Name Can Not Be Blank \n';
	}
	if(eid("commentContent").value == "")
	{
		errors += 'Content Can Not Be Blank \n';
	}
	if(errors != "")
	{
		alert(errors);
		return false;
	}
	else
	{
		return true;
	}
}

function submitBrandListingFilterForm()
{
	var value = document.getElementById("brandListing").value;
	if(value != 0)
	{
		document.getElementById("brandListingForm").submit();
	}
	
	
}

function jLinkClick(page)
{
	window.location = page;	
}


function jGetSubMenu(category, categoryName, option)
{
	if(option == 'tooltip')	
		var linkClass = 'subMenuLink';
	else var linkClass = '';
	
	var data = 'top_category_id='+category+'&top_category='+categoryName+'&linkClass='+linkClass;
	
	$.ajax({
	type: "POST",
	url: "/inc/ajax/subMenuAjax.php",
	dataType: "html",
	data: data,
	
	success: function(r){
		if(option == 'tooltip')
		{	
			if( r!= '')
			{
				document.getElementById("tooltip").innerHTML = r;
			}
			else
			{
				document.getElementById("tooltip").style.display = 'none';
			}
		}
		else
		{
			document.getElementById("subMenu").innerHTML = r;
			document.getElementById("menuArrow").innerHTML = '<img src="images/others/menuArrow.png"/>';
		}
	}
	});
}
function jTab(sender)
{
	var childrenTab = '';
	var childNodeArray = document.getElementById('tabs').getElementsByTagName('DIV');
	for (x in childNodeArray) //The div for all the Tabs
	{
		//childrenTab = document.getElementById(childNodeArray[x].id).getElementsByTagName('DIV');
		//alert(childNodeArray[x].id);
		if(childNodeArray[x].id != null)
		{//alert(sender.id+"Tab");
			
			if(childNodeArray[x].id == sender.id+"Tab") //The div of the specific Tab.
			{
				childNodeArray[x].style.display = 'block';		
				
				/*for (y in childrenTab)
				{
					childrenTab[y].style.display = 'block';
				}*/
			}
			else
			{
				childNodeArray[x].style.display = 'none';
				/*alert(childNodeArray[x].id);
				var childrenTab2 = document.getElementById(childNodeArray[x].id).getElementsByTagName('DIV');
				for (z in childrenTab2)
				{
					childrenTab2[z].style.display = 'none';
				}*/
				/*for (y in childrenTab)
				{
					childrenTab[y].style.display = 'none';
				}*/

			}
		}
	}
	var linkChildNodeArray = document.getElementById('css-tabs').getElementsByTagName('A');
	for (x in linkChildNodeArray)
	{
		if(linkChildNodeArray[x].id != null)
		{
			if(linkChildNodeArray[x].id == sender.id)
			{
				linkChildNodeArray[x].style.background = "#fff";
				linkChildNodeArray[x].style.borderBottom = "solid 1px #fff";
			}
			else
			{
				linkChildNodeArray[x].style.background = "#efefef";
				linkChildNodeArray[x].style.borderBottom = "solid 1px #666";
			}
		}
	}
	jStats('product_'+sender.id+'_tab', document.getElementById("product_id").value);
}

function jEnquiryMail()
{
	var data = 'subject='+document.getElementById("enquirySubject").value;
	data += '&body='+document.getElementById("enquiryBody").value;
	data += '&from='+document.getElementById("customerEmail").value;
	data += '&name='+document.getElementById("customerName").value;
	
	$.ajax({
	type: "POST",
	url: "/inc/ajax/publicAjax.php",
	dataType: "html",
	data: data,	
	success: function(r){
		document.getElementById("enquiryTab").innerHTML = "Your enquiry has been sent. We'll contact you soon.";
		//alert(r);
	}
	});	
}
var optionTips=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 180;
	var speed = 60;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt, image,w,v,content;
	var ie = document.all ? true : false;
	return{
		show:function(image,content){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			//alert(content);
			tt.style.display = 'block';
			tt.innerHTML = '<img src="'+image+'" /><br />'+content;
			tt.style.width = maxw + 'px';
			
			if(ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){optionTips.fade(1)},timer);
		},
		pos:function(e){
			var totalWidth = document.documentElement.clientWidth;
			var totalHeight = document.documentElement.clientHeight;
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h - 3) + 'px';
			if(l >= (totalWidth - maxw - 20))
			{
				tt.style.left = (l - maxw)+30 + 'px';
			}
			else
			{
				tt.style.left = (l-20) - maxw  + 'px';
			}
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){optionTips.fade(-1)},timer);
		}
	};
}();
/*
function jShowProductMenu(type)
{
	switch(type)
	{
		case 'show':
			eid("leftNavigationMenu").style.display = 'block';
			eid("leftNavigationMenu").style.marginLeft = '250px';
			eid("leftNavigationMenu").style.marginTop = '-26px';
			eid("leftNavigationMenu").style.position = 'absolute';
		break;
		case 'hidden':
			eid("leftNavigationMenu").style.display = 'none';
		break;
	}
}
*/
function jFrontPageShowMenu(action)
{
	//alert(eid("frontPageProductMenuContainer").style.display);
	switch(action)
	{
		case 'show':
			eid("frontPageProductMenuContainer").style.display = '';
		break
		case 'hide':
			eid("frontPageProductMenuContainer").style.display = 'none';
		break
	}
}
function jShowMsn(sender)
{
	if(eid("msnInfo").style.display == 'none')
	{
		eid("msnInfo").style.display = '';
	}
	else
	{
		eid("msnInfo").style.display = 'none';
	}
}
function jStats(sender, id)
{
	//onclick="jStats(\'youtube\');"
	var moreInfo = "action=stats";
	moreInfo += "&area="+sender;
	moreInfo += "&ip="+eid('ip').value;
	moreInfo += "&id="+id;

	$.ajax({
	type: "POST",
	url: "/inc/ajax/trackingStats.php",
	dataType: "json",
	data: moreInfo,
	
	success: function(msg){
	}
	});
}

