// JavaScript Document


var message="Function Disabled!";

///////////////////////////////////

function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


  
function onKeyDown(e) {
  // current pressed key
  //var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();

  if (e.ctrlKey ) {
	  alert('please do not copy paste the email address');
    e.returnValue = false;
  }

}
var check = 0;
var totstyle;
function add_to_cart(obj)
{
	var type = 1;
	var fabric_id = obj.value;

	var a = 1;

	if(obj.checked == true)
		a = 1;
	else 
		a = 0;

	if(fabric_id != "")
	{
		URL = 'left_cart.php';
		URL += "?fabric_id="+fabric_id+"&a="+a;
		
		new Ajax.Request(URL, {
			method: 'get',
			onSuccess: function(transport) 
			{
				show_cart();
			},
			onLoading: function() 
			{
				$('trolley_head').innerHTML = "Updating cart...";
			}
		});
	}
	else
	{
		//alert("Please choose a fabric")	
	}
}



function show_cart()
{
	URL = 'show_cart.php';

	new Ajax.Request(URL, {
		method: 'get',
		onSuccess: function(transport) 
		{
			$('trolley_head').innerHTML = "";
			if(transport.responseText != "")
			{
				arr = transport.responseText.split("|");
				var cnt = 0;
				var capprice = 0.00;
				$("trolley").innerHTML = "";
				
				
				var imgsrc = "";
				
				var type = $("type").value
				
				for(var i=0; i<arr.length; i++)
				{
					
					var response = arr[i].evalJSON();
					var id = response.id;
					var imgsrc = "images/uploadedfabrics/thumb/"+response.image;
					var title = response.title;
					var price = response.price;
					var main = "main"+id;
					var titlediv = "titlediv"+id;
					var pricediv = "pricediv"+id;
					var imgelement = "imgelement"+id;
					main = document.createElement("div");
					main.setAttribute("id", id);
					main.align = "center";
					titlediv = document.createElement("div");
					titlediv.innerHTML = title;
					pricediv = document.createElement("div");
					pricediv.innerHTML = "Price: &pound;"+price;
					splitdiv = document.createElement("div");
					splitdiv.innerHTML = "&nbsp;";
					
					imgelement = document.createElement("img");
					imgelement.setAttribute("src", imgsrc);
					imgelement.style.width="51px";
					imgelement.style.height="34px";
					
					imgelement.onclick = function() {$('preview').innerHTML = "";pre = document.createElement("img");pre.style.width="110px"; pre.style.height="75px";pre.setAttribute("src", this.src);	$('preview').appendChild(pre);};
					main.appendChild(imgelement);
					main.appendChild(titlediv);
					main.appendChild(pricediv);
					main.appendChild(splitdiv);
					$('trolley').appendChild(main);
					try
					{
						var ids = "id"+id;
						$(ids).checked = true;
					}
					catch(e) {}
					
					capprice += parseInt(price);
					cnt++;
				}
				$("caption").innerHTML = "Total: "+cnt+"<br />Price: &pound;&nbsp;"+capprice;
				preview(imgsrc);
				$("can_submit").value = 1;
			}
			else
			{
				$('trolley').innerHTML = "Empty cart";
				$('preview').innerHTML = "";
				$("caption").innerHTML = "";
				$("can_submit").value = 0;
				
			}
		}
	});
}


function preview(imgsrc)
{
	$('preview').innerHTML = "";pre = document.createElement("img");pre.style.width="110px"; pre.style.height="75px";pre.setAttribute("src", imgsrc);	$('preview').appendChild(pre);
}

function add_style(obj)
{
	if(obj.checked)
	{
		var style_id = obj.value;
		var style_name = obj.name;
		
		//alert(style_name);
		
		if(style_name == 'whitecuff')
		{
			switch(style_id)
			{
				case "Yes":
					document.styles.whitecollar[0].checked = true;
				break;
				
				case "No":
					document.styles.whitecollar[1].checked = true;
				break;
				
			}

		}
		
		if(style_id != "")
		{
			URL = 'left_cart.php';
			URL += "?style_id="+style_id+"&style_name="+style_name;
			
			
			new Ajax.Request(URL, {
				method: 'get',
				onSuccess: function(transport) 
				{
					$('style').innerHTML = "";
					//alert(transport.responseText);
					show_style();
				},
				onLoading: function() 
				{
					$('trolley_head').innerHTML = "Updating cart...";
				}
			});
		}
	}
	else if(obj.name == "initial" || obj.name == "monogram_color")
	{
		var style_id = obj.value;
		var style_name = obj.name;
		if(style_id != "")
		{
			URL = 'left_cart.php';
			URL += "?style_id="+style_id+"&style_name="+style_name;
			
			
			new Ajax.Request(URL, {
				method: 'get',
				onSuccess: function(transport) 
				{
					$('style').innerHTML = "";
					//alert(transport.responseText);
					show_style();
				},
				onLoading: function() 
				{
					$('trolley_head').innerHTML = "Updating cart...";
				}
			});
		}
	}
	else
	{
		alert("Choose a style");
	}
}


function show_style()
{
	totstyle = 0;
	URL = 'show_style.php';
	new Ajax.Request(URL, {
		method: 'get',
		onSuccess: function(transport) 
		{
			$('trolley_head').innerHTML = "";
			
			var page = window.location.href.split("/");
			
			page = page[(page.length)-1];
			
			if(page == "selectionlist.php")
			{
				$("trolley").style.width="130px";
				$("trolley").className="selectionlist";
			}
			
			
			if(transport.responseText != "")
			{
				
				//alert(transport.responseText);
				arr = transport.responseText.split("|");
				
				$('style').innerHTML = "";
				for(var x=0; x<arr.length; x++, totstyle++)
				{
					var response = arr[x].evalJSON();
					var id = response.id;
					//alert(response.image);

					var title = response.title;
					var cat = response.category;
					
					if(title != "" && title != null)
					{
						var image = "images/trolley_preview/"+response.image;
						var m = String(id);
						var i = "img"+String(id);
						var t = "t"+String(id);
						var c = "c"+String(id);
											
						main = document.createElement("div");
						main.setAttribute("id", m);
						img = document.createElement("img");
						img.setAttribute("id", i);
						img.setAttribute("src", image);
						divt = document.createElement("div");
						divt.innerHTML = title;
						divc = document.createElement("div");
						divt.innerHTML = title;
						splitdiv = document.createElement("div");
						splitdiv.style.height="80px";
						splitdiv.innerHTML = "&nbsp;";
						main.appendChild(img);
						main.appendChild(divt);
						main.appendChild(divc);
						main.appendChild(splitdiv);
						$('style').appendChild(main);
					}
					else
					{
						var image = response.image;
						//alert(id + " " + image);
						main = document.createElement("div");
						main.setAttribute("id", m);
						//img = document.createElement("img");
						//img.setAttribute("id", i);
						//img.setAttribute("src", image);
						divt = document.createElement("div");
						divt.style.padding = "20px";
						divt.align = "left";
						divt.innerHTML = id + " " + image + "<br>";
						//divc = document.createElement("div");
						//divt.innerHTML = title;
						splitdiv = document.createElement("div");
						splitdiv.style.height="80px";
						splitdiv.innerHTML = "&nbsp;";
						//main.appendChild(img);
						main.appendChild(divt);
						//main.appendChild(divc);
						main.appendChild(splitdiv);
						$('style').appendChild(main);
						
					}
				}
			}
			else
			{
				
			}
		}
	});
}

function validate_form(frm)
{
	
}

function makeRequest(id) 
{
}




function makeRequest1() 
{
	
		var httpRequest;

		if (window.XMLHttpRequest) 
		{
			httpRequest = new XMLHttpRequest();
			if (httpRequest.overrideMimeType) 
			{
				httpRequest.overrideMimeType('text/xml');
			}
		} 
		else if (window.ActiveXObject) 
		{
			try 
			{
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) 
			{
				try 
				{
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e) {}
			}
		}
	
		if (!httpRequest) 
		{
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
		
		
		url = "logout.php";
	
		httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
		httpRequest.open('GET', url, true);
		httpRequest.send('');
	
}

function alertContents(httpRequest) 
{
	
}

function charsonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	
	//alert(unicode);
	
	if (unicode!=8)
	{ //if the key isn't the backspace key (which we should allow)
		if (unicode < 65 || unicode > 122) //if not a number
			return false //disable key press
	}
}

function checkForInt(evt) 
{
	var charCode = ( evt.which ) ? evt.which : event.keyCode;
	return ( charCode >= 48 && charCode <= 57 );
}
