function checkprice(price,extraprice)
{
	price = price - extraprice;
	if(price<60)
	{
		alert("Sorry, you have to make a minimum purchase of more than S$60 before you can do a checkout.");
		return false;
	}
	else
	{
		return true;
	}
	
}

function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}
function hide(divname){
	document.getElementById(divname).style.visibility = 'hidden';
}

function show(divname){
	document.getElementById(divname).style.visibility = 'visible';
}

function outImg(tb, id){
	var tbdiv;
	tbdiv = tb + id;
	document.getElementById(tbdiv).className= 'panel-thumb';
}

function changeImg(tb, id, thumb){
	var imgdiv;
	var tbdiv;
	imgdiv = "Image" + id;
	tbdiv = tb + id;
	document.getElementById(tbdiv).className= 'panel-thumb-on';
	document.getElementById(imgdiv).innerHTML = "";
	document.getElementById(imgdiv).innerHTML = "<img src='" + thumb + "' width='200' height='200' border='0'>";
}

function getmail(){
	document.getElementById("maildiv").style.display = "none";
	document.getElementById("loaddiv").style.display = "block";
	var flag = true;
	if(document.getElementById("txtname").value == "")
	{
		document.getElementById("loaddiv").style.display = "none";
		document.getElementById("blanknamediv").style.display = "block";
		flag = false;
	}
	else
	{
		if(document.getElementById("txtemail").value == "" || document.getElementById("ddlDOBDay").value == "- Day -" || document.getElementById("ddlDOBMth").value == "- Month -" || document.getElementById("DropDownYear").value == "- Year -" )
		{
			document.getElementById("loaddiv").style.display = "none";
			document.getElementById("blankdiv").style.display = "block";
			flag = false;
		}
		else
		{
			var at="@"
			var dot="."
			var str = document.getElementById("txtemail").value;
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			}

			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			}

			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			}

			 if (str.indexOf(at,(lat+1))!=-1){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			 }

			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			 }

			 if (str.indexOf(dot,(lat+2))==-1){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			 }
		
			 if (str.indexOf(" ")!=-1){
			   document.getElementById("loaddiv").style.display = "none";
			   document.getElementById("emaildiv").style.display = "block";
			   flag = false;
			 }
		}
	}
	
	if(flag==true)
	{
		var url;
		var dob = document.getElementById("ddlDOBDay").value + document.getElementById("ddlDOBMth").value + document.getElementById("DropDownYear").value;
		url = "getEmail.aspx?n=" + document.getElementById("txtname").value  + "&v=" + document.getElementById("txtemail").value  + "&c=" + dob;
		setTimeout("getEmail('"+url+"')", 500);
		clearTimeout();
	}
}

function showmail()
{
	document.getElementById("emaildiv").style.display = "none";
	document.getElementById("blankdiv").style.display = "none";
	document.getElementById("blanknamediv").style.display = "none";
	document.getElementById("maildiv").style.display = "block";
}

function updateCart(id){
	var qty;
	qty = document.getElementById('qtybox' + id).value;
	
	if(id=="123208")
	{
		if(qty>1)
		{
			qty = 1;	
		}
	}
	document.getElementById("cartlist").innerHTML = "<div align='center' style='padding-top:20px;padding-bottom:5px;'><img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'><br/><img src='images/updating-loader.gif' width='142' height='15' /></div>";
	
	url = "cartupdate.aspx?id=" + id + "&qty=" + qty;
	setTimeout("getCart('"+url+"')", 500);
	clearTimeout();
}

function checkoutupdateCart(id){
	var qty;
	qty = document.getElementById('qtybox' + id).value;
	
	if(id=="123208")
	{
		if(qty>1)
		{
			qty = 1;	
		}
	}
	document.getElementById("cartlist").innerHTML = "<div align='center' style='padding-top:20px;padding-bottom:5px;'><img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'><br/><img src='images/updating-loader.gif' width='142' height='15' /></div>";
	
	url = "checkoutupdate.aspx?id=" + id + "&qty=" + qty;
	setTimeout("getCart('"+url+"')", 500);
	clearTimeout();
}

function removeCart(id){
	var qty;
	qty = 0;
	document.getElementById("cartlist").innerHTML = "<div align='center' style='padding-top:20px;padding-bottom:5px;'><img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'><br/><img src='images/updating-loader.gif' width='142' height='15' /></div>";
	
	url = "cartupdate.aspx?id=" + id + "&qty=" + qty;
	setTimeout("getCart('"+url+"')", 500);
	clearTimeout();
}

function checkoutremoveCart(id){
	var qty;
	qty = 0;
	document.getElementById("cartlist").innerHTML = "<div align='center' style='padding-top:20px;padding-bottom:5px;'><img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'><br/><img src='images/updating-loader.gif' width='142' height='15' /></div>";
	
	url = "checkoutupdate.aspx?id=" + id + "&qty=" + qty;
	setTimeout("getCart('"+url+"')", 500);
	clearTimeout();
}
function getCatList()
{
	var one;
	var two;
	var three;
	var url;
	
	document.getElementById('CatalogsSpace').style.display = 'none';
	document.getElementById('CatalogsName').style.visibility = "hidden";
	document.getElementById('Catalogs').innerHTML = "<div align='left'><span class='normaltext'> <img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'></span></div>";
	
	if (document.getElementById('DropDownMain').value !=0)
	{
		one = document.getElementById('DropDownMain').value;
		if (document.getElementById("SecondCatSpace").style.display != 'none')
		{
			if(document.getElementById('DropDownSecond').value !=0)
			{
				two = document.getElementById('DropDownSecond').value;
				if (document.getElementById("ThirdCatSpace").style.display != 'none')
				{
					three = document.getElementById('DropDownThird').value;
				}
				else
				{
					three = 0;	
				}
				document.getElementById('CatalogsSpace').style.display = 'block';
				url = "getCategoryList.aspx?one=" + one + "&two=" + two + "&three=" + three;
				setTimeout("getCatalogs('"+url+"')", 500);
				clearTimeout();
				
			}
			else
			{
				document.getElementById('CatalogsSpace').style.display = 'none';
			}
		}
		else
		{
			document.getElementById('CatalogsSpace').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('CatalogsSpace').style.display = 'none';
	}

}

function maincat(wordId)
{
	var chosen;
	var url;
	
	chosen = document.getElementById("DropDownMain").value;
	url = "getCategory.aspx?q=" + chosen;
	document.getElementById('SecondCatName').style.visibility = "hidden";
	document.getElementById('SecondCatDD').innerHTML = "";
	document.getElementById('ThirdCatName').style.visibility = "hidden";
	document.getElementById('ThirdCatDD').innerHTML = "";
	document.getElementById("ThirdCatList").style.display = 'none';
	document.getElementById("ThirdCatSpace").style.display = 'none';
		
	if(chosen!=0)
	{
		document.getElementById('SecondCatDD').innerHTML = "<div align='left'><span class='normaltext'> <img src='images/ajax-loader.gif' 	alt='please wait' width='16' height='16'></span></div>";
		document.getElementById("SecondCatList").style.display = 'block';
		document.getElementById("SecondCatSpace").style.display = 'block';
	
	
		setTimeout("getCat('"+url+"')", 500);
		clearTimeout();
		
		
	
	}
	else
	{
		document.getElementById("SecondCatList").style.display = 'none';
		document.getElementById("SecondCatSpace").style.display = 'none';
	}
}

function formatchange(){
	document.getElementById('contentmain').innerHTML  = "";
	document.getElementById('contentmain').innerHTML = document.getElementById('loader').innerHTML;
	
	
	var file1;
	file1 = document.getElementById('DropDownMain').value + ".xml";
	
	setTimeout("getFormat('"+file1+"')", 500);
	clearTimeout();
}

function getCart(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processMainCart;
	
    //actually send the request to the server
    http.send(null);	
}

function getEmail(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processMainEmail;
	
    //actually send the request to the server
    http.send(null);	
}

function getFormat(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processMainFormat;
	
    //actually send the request to the server
    http.send(null);	
}


function getCat(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processMainCat;
	
    //actually send the request to the server
    http.send(null);	
}

function getCatalogs(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processCatalogs;
	
    //actually send the request to the server
    http.send(null);	
}

function subcat(wordId)
{
	var chosen1;
	var chosen2;
	var second;
	var url;
	var secondhidden;
	
	chosen1 = document.getElementById("DropDownMain").value;
	chosen2 = document.getElementById("DropDownSecond").value;
	secondhidden = "second" + chosen2;
	second = document.getElementById(secondhidden).value;
	
	url = "getSubCategory.aspx?q=" + chosen1 + "&w=" + chosen2;
	document.getElementById('ThirdCatName').style.visibility = "hidden";
	document.getElementById('ThirdCatDD').innerHTML = "";
	
	if(chosen2!=0 && second !=-1)
	{
	
		document.getElementById('ThirdCatDD').innerHTML = "<div align='left'><span class='normaltext'> <img src='images/ajax-loader.gif' 	alt='please wait' width='16' height='16'></span></div>";
		document.getElementById("ThirdCatList").style.display = 'block';
		document.getElementById("ThirdCatSpace").style.display = 'block';
	
	
		setTimeout("getSubCat('"+url+"')", 500);
		clearTimeout();
	}
	else
	{
		document.getElementById("ThirdCatList").style.display = 'none';
		document.getElementById("ThirdCatSpace").style.display = 'none';	
	}
}

function getSubCat(wordId)
{
	//make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    http.open('get', wordId);
	
    //assign a handler for the response
    http.onreadystatechange = processSubCat;
	
    //actually send the request to the server
    http.send(null);	
}





// Ajax Intialization Here
function createRequestObject() {
    var tmpXmlHttpObject;
    
    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest) { 
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();
	
    } else if (window.ActiveXObject) { 
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return tmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
var http = createRequestObject();

function processMainCart() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
        document.getElementById('cartlist').innerHTML = response;
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}


function processMainCat() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
		document.getElementById('SecondCatName').style.visibility = "visible";
		document.getElementById('SecondCatDD').innerHTML = "";
        document.getElementById('SecondCatDD').innerHTML = response;
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}

function processMainEmail() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
		document.getElementById("loaddiv").style.display = "none";
		document.getElementById("maildiv").style.display = "none";
		document.getElementById('thanksdiv').style.display = "block";
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}


function processMainFormat() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
        document.getElementById('contentmain').innerHTML = response;
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}

function processCatalogs() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
		if(response != "<select id='DropDownCatalogs' name='DropDownCatalogs'></select>" )
		{
			document.getElementById('CatalogsName').style.visibility = "visible";
			document.getElementById('Catalogs').innerHTML = "";
        	document.getElementById('Catalogs').innerHTML = response;
		}
		else
		{
			document.getElementById('CatalogsName').style.visibility = "hidden";
			document.getElementById('CatalogsSpace').style.display = 'none';
			document.getElementById('Catalogs').innerHTML = "<div align='left'><span class='normaltext'> <img src='images/ajax-loader.gif' alt='please wait' width='16' height='16'></span></div>";
		}
		
		
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}


function processSubCat() {
    //check if the response has been received from the server
    if(http.readyState == 4){
	
        //read and assign the response from the server
        var response = http.responseText;
		
        //do additional parsing of the response, if needed
		
        //in this case simply assign the response to the contents of the <div> on the page. 
		if(response != "<select id='DropDownThird' name='DropDownThird'></select>" )
		{
			document.getElementById('ThirdCatName').style.visibility = "visible";
			document.getElementById('ThirdCatDD').innerHTML = "";
        	document.getElementById('ThirdCatDD').innerHTML = response;
		}
		else
		{
			document.getElementById('ThirdCatName').style.visibility = "hidden";
			document.getElementById('ThirdCatDD').innerHTML = "";
			document.getElementById("ThirdCatList").style.display = 'none';
			document.getElementById("ThirdCatSpace").style.display = 'none';
		}
		
        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}


