//
//
	function glossary()
	{
		w= screen.availWidth-220;
		h = screen.availHeight-200;
		url = 'index.php?main_page=popup_attribute&pID=&lib_id=&att_id=&view_links=A'; window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',screenX=0,screenY=0,top=0,left=0');
	}

	function login_links()
	{
		var cookiestring=""+document.cookie;
	

		var index1=cookiestring.indexOf("custloggedin");
		
		if (index1==-1)
		 {
			document.write('<a href="index.php?main_page=create_account" class="greylightsmall"><b>Register</b></a>&nbsp;|&nbsp;<a href="index.php?main_page=login" class="greylightsmall"><b>Sign in</b></a>');
		 }
		 else
		 {
			var index2=cookiestring.indexOf("cust_name");
			if(index2==-1)
			 {
					var customer_name ='';
			 }
			 else
			 {
					var index3 = cookiestring.indexOf(';' , index2);
					if(index3==-1) index3 = cookiestring.length;
					var customer_name = cookiestring.substring(index2+9+1, index3);
					
			 }

			document.write('Hi <b>'+customer_name+'</b>  &nbsp;&nbsp;&nbsp; <a href="index.php?main_page=logoff" class="greylightsmall">Logout</a>&nbsp;');
		 }
	}


function shipping_info()
{
   window.open("http://www.jddiamonds.com/store07/contents/shipping_information.html","shippingInfo", "width=770, height=500,toolbar=0, left=0,top=0, menubar=no, scrollbars=yes, resizable=yes");
}

function paging(url)
{
	pageno = document.frmsearchdiamond.diamond_page.value;
	document.frm_diamonds.action = url+'&page='+pageno;
	document.frm_diamonds.submit();
}

function next(url){
	pageno = document.frmsearchdiamond.diamond_page.selectedIndex+2;
	document.frm_diamonds.action = url+'&page='+pageno;
	document.frm_diamonds.submit();
}

function prev(url){
	pageno = document.frmsearchdiamond.diamond_page.selectedIndex;
	document.frm_diamonds.action = url+'&page='+pageno;
	document.frm_diamonds.submit();
}

function print_page()
{
   window.open("","printWin", "width=770, height=500,toolbar=0, left=0,top=0, menubar=no, scrollbars=yes, resizable=yes"); 
	var a = window.setTimeout("document.frmPrint.submit();",500); 
}


	function CreateBookmarkLink(url,title) 
	{
		if (window.sidebar) 
		{ 
			window.sidebar.addPanel(title, url,"");	
		} 
		else if( window.external ) 
		{ 
			window.external.AddFavorite( url, title); 
		}	
		else if(window.opera && window.print) 
		{ 
			return true; 
		} 
	} 

/////////////////////////////
	function Trim(TRIM_VALUE)
	{
		if(TRIM_VALUE.length < 1)
		{
			return"";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
		{
			return "";
		}
		else
		{
			return TRIM_VALUE;
		}
	}

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

	function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0)
		{
			return"";
		}
		var iTemp = v_length -1;
		while(iTemp > -1)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
			}
			else
			{
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			}
			iTemp = iTemp-1;
		}
		return strTemp;
	}

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

	function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
		{
			return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";
		var iTemp = 0;
		while(iTemp < v_length)
		{
			if(VALUE.charAt(iTemp) == w_space)
			{
				///
			}
			else
			{
				strTemp = VALUE.substring(iTemp,v_length);
				break;
			}
			iTemp = iTemp + 1;
		}
		return strTemp;
	}
	  
	//////////////////

	function check_email(emailaddress)
	{
		var emailStr = emailaddress;
		var checkTLD=1;
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		var emailPat=/^(.+)@(.+)$/;
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

		var validChars="\[^\\s" + specialChars + "\]";

		var quotedUser="(\"[^\"]*\")";

		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+';

		var word="(" + atom + "|" + quotedUser + ")";

		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat);

		if (matchArray==null) 
		{
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}
			
		var user=matchArray[1];
		var domain=matchArray[2];

		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		alert("The username contains invalid characters.");
		return false;
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
		alert("The domain name contains invalid characters.");
		return false;
		   }
		}

		if (user.match(userPat)==null) {

		alert("The email doesn't seem to be valid.");
		return false;
		}

		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {

		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		alert("Destination IP address is invalid!");
		return false;
		   }
		}
		return;
		}
				 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
		alert("The domain name does not seem to be valid.");
		return false;
		   }
		}

		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
		}

		if (len<2) {
		alert("This address is missing a hostname!");
		return false;
		}
		return true;
	}  
//////////////////////////////

	function setemail()
	{
		if(document.frmsubscribe.email.value=="email address")
		{
			document.frmsubscribe.email.value="";
		}
	}

	function getemail()
	{
		if(document.frmsubscribe.email.value=="email address" || Trim(document.frmsubscribe.email.value)=="")
		{
			document.frmsubscribe.email.value="email address";
		}
	}

	function subscribe()
	{
		if(Trim(document.frmsubscribe.email.value)=="")
		{
			alert("Please enter your email address to receive best deals");
			document.frmsubscribe.email.focus();
			return;
		}
		else if(check_email(Trim(document.frmsubscribe.email.value)))
		{
			document.frmsubscribe.submit();
		}
	}

			function show_default_image()
			{
				var x = document.getElementsByTagName('div');
				for (var i=0;i<x.length;i++)
				{
					var div_name =x[i].id;
					if(div_name.substr(0,8)  == "prod_img")
					{
							x[i].style.display = 'none';
					}
				}
				prod_img0.style.display = 'inline';
			}


			function show_alt_images(show_div)
			{
				var x = document.getElementsByTagName('div');
				for (var i=0;i<x.length;i++)
				{
					var div_name =x[i].id;
					if(div_name.substr(0,8)  == "prod_img")
					{
						if (x[i].id == show_div)
						{
							x[i].style.display = 'inline';
						}
						else
						{
							x[i].style.display = 'none';
						}
					}
				}
			}


//////////AJAX	bof
    function show_ajax(php_url, prodid) {
        var httpRequest;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            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;
        }

			var queryString = "?products_id=" + prodid;
			httpRequest.onreadystatechange = function() { alertContents(httpRequest, div_name); };
			httpRequest.open('GET', php_url + queryString, true);
			httpRequest.send('');

    }

    function alertContents(httpRequest, div_name, heading) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
				//alert(httpRequest.responseText); 
				document.getElementById(div_name).innerHTML = httpRequest.responseText;
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
	//////AJAX EOF

