/* Default code for disable Right Click Mouse Button */
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")

/* Disable Mouse Click Code ends here */


$(function(){
	$('#headernav a')
		.css( {backgroundPosition: "-20px 35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(20px 110px)"}, {duration:800})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(10px 35px)"}, {duration:800, complete:function(){
				$(this).css({backgroundPosition: "-10px 35px"})
			}})
		})
	
	
	$('#navcontainer a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-270px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500, complete:function(){
				$(this).css({backgroundPosition: "0 0"})
			}})
		})
	})
		

empty = function(txtid) {
	document.getElementById(txtid).value = "";	
}



findcat = function(val)
{
	var url;
	url="fetch.php?val="+val;
	var xmlHttp;
	try {  
	// Firefox, Opera 8.0+, Safari 
		 xmlHttp=new XMLHttpRequest();  
	}
	catch (e){ 
	 // Internet Explorer  
		try	{    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){    
			try	{     	
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			 catch (e) {      
				  alert("Your browser does not support AJAX!");
				  return flase;
			 }
		}
	  }
	  xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
			document.getElementById('findcat').innerHTML=xmlHttp.responseText; 
		}
	  }
	  xmlHttp.open("Get",url,true);
	  xmlHttp.send(null);	
}

/*******************************************************************************************************************
********************************************************************************************************************
function name 		:: 	tooltip
function paramter 	::	product id
Description			::	This will help to display short desc, description of product will come from DB using AJAX. 

********************************************************************************************************************
*******************************************************************************************************************/

//window.onload = init;
var tempx;
var tempy;
var final;
var div = document.getElementById('Tipss');

displayTip = function(id) {
	var div = document.getElementById('Tipss');
	div.style.display = "block";
	/*var url = "nyiombo-map.php?id="+id;
	var xmlHttp;
	if(window.XMLHttpRequest)
	{ 
		  // Firefox, Opera 8.0+, Safari
		   xmlHttp=new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject)
	{
		   // Internet Explorer 
			 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");     
	}
	else
	{
		  alert("Your browser does not support AJAX!");
		  return false; 
	}
	 
	xmlHttp.onreadystatechange=function()
	{
		  if(xmlHttp.readyState==4)
		  {
				if(xmlHttp.status == 200)
				{
					div.innerHTML = "";
					div.innerHTML=  xmlHttp.responseText ;
				}
		  }
	}
	xmlHttp.open("Get",url,true);
	xmlHttp.send(null);*/ 
	//div.innerHTML = tempx + "::::" + tempy;
}

hideTip = function() {
		var div = document.getElementById('Tipss');
		div.style.display = "none";
}

function init(){

  if (window.Event) {
	if (navigator.appName == "Microsoft Internet Explorer") 
		document.captureMousePosition;
	else
	    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
	/*
	if (navigator.appName == "Microsoft Internet Explorer") 
	{
		tempx = window.event.offsetX + 125;
		tempy = window.event.offsetY + 100;
		document.getElementById('Tipss').style.left = tempx + 8 + 'px';
	  	document.getElementById('Tipss').style.top = tempy + 8 + 'px';
	}
	else
	{ */
	  tempx = (window.Event) ? e.pageX : event.clientX;
	  tempy = (window.Event) ? e.pageY : event.clientY;
	  document.getElementById('Tipss').style.left = tempx + 8 + 'px';
	  document.getElementById('Tipss').style.top = tempy + 8 + 'px';
	//}
}



/*******************************************************************************************************************
********************************************************************************************************************
function name 		::  imgswap
function paramter 	::	Image name
Description			::	This will help us to swap product images

********************************************************************************************************************
*******************************************************************************************************************/

imgswap = function (src, imgid, color)
{
	document.getElementById("imgColors").value = color;
	document.getElementById(imgid).src = "tempex/album/images/"+src;
}


/*******************************************************************************************************************
********************************************************************************************************************
function name 		::  validate (Contact Us)
function paramter 	::	field ID
Description			::	This will help us to swap validate images

********************************************************************************************************************
*******************************************************************************************************************/

validate = function(id, cntr) {
	var eid = "e" + id;
	var val = document.getElementById(id).value;
	var alphaExp = /^[a-zA-Z]+$/;
	var cond = "errCon"+cntr;
	//var s = document.getElementById(cond).value;
	
	
	document.getElementById(eid).style.display = "block";
	if(id != "txtFromEmail") {
		if(val == "") {
			document.getElementById(cond).value = 0;
			document.getElementById(eid).src = "images/no.gif";
			document.getElementById(id).focus();
		}
		else if(id == "txtFromName" || id=="txtFromCompany") {
			if(!(document.getElementById(id).value.match(alphaExp))) {
				document.getElementById(cond).value = 0;
				document.getElementById(eid).src = "images/no.gif";
				document.getElementById(id).focus();
			}
			else {
				document.getElementById(cond).value = 1;
				document.getElementById(eid).src = "images/yes.gif";
			}
		}
		else if(id == "txtFromTel" || id == "txtFromFax") {
			var alphaExp = /^[0-9-+()]+$/;
			var len = val.length;
			if(!(document.getElementById(id).value.match(alphaExp))) {
				document.getElementById(cond).value = 0;
				document.getElementById(eid).src = "images/no.gif";
				document.getElementById(id).focus();
			}
			else {
				if((len > 5) && (len < 15)) {
					document.getElementById(cond).value = 1;
					document.getElementById(eid).src = "images/yes.gif";
					return;
				}
				else {
					document.getElementById(cond).value = 0;
					document.getElementById(eid).src = "images/no.gif";
					document.getElementById(id).focus();
					return;
				}
					
			}
		}
		else {
			document.getElementById(cond).value = 1;
			document.getElementById(eid).src = "images/yes.gif";
		}
	} else {
				if(document.getElementById(id).value.indexOf("@")==-1 ||document.getElementById(id).value.indexOf(".")==-1 || document.getElementById(id).value.indexOf("")==-1 ) {
					document.getElementById(cond).value = 0;
					document.getElementById(eid).src = "images/no.gif";
					document.getElementById(id).focus();
			    }
				else {
					document.getElementById(cond).value = 1;
					document.getElementById(eid).src = "images/yes.gif";
				}
	}
}

/*******************************************************************************************************************
********************************************************************************************************************
function name 		::  contact()
function paramter 	::	NO
Description			::	This will help us to check form validation before submitting.

********************************************************************************************************************
*******************************************************************************************************************/

contact = function() {

	var count=0;
	while(count++ < 7) {
		var cond = "errCon"+count;
		if(document.getElementById(cond).value == "0") 
			return false;
	}
	return true;
}
