function launchWindow(id) {

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask1').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	//$('#mask1').fadeIn(1000);	
	//$('#mask1').fadeTo("slow",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
		  
	//Set the popup window to center
	$(id).css('top',  120);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(2000); 
	

}
function toggleDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}

function checkoutmembership () { 
	var member	= document.frm_membercheckout;
	if (member.checkoutemail.value =='') {
		alert('Please Enter Your Emailid!');
		member.checkoutemail.focus();
		return false;
	}
	else if(IsEmail(member.checkoutemail.value)==false) {
		alert("Please Enter Valid EmailId!");
		member.checkoutemail.focus();
		return false;
	}
	else if (member.checkoutpassword.value == '') { 
		alert('Please Enter Your Password!');
		member.checkoutpassword.focus();
		return false;
	}
}
function IsEmail(oObject) {
	var emailStr=oObject;
	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];
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid. Please check or register fresh");
		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 true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.");
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		alert("The address must end in a three-letter domain, or two letter country.");
		return false;
	}
	if (len<2) {
		var errStr="This address is missing a hostname!";
		alert(errStr);
		return false;
	}
	return true;
}

xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function HideDIV(d) { document.getElementById(d).style.display = "none"; }
function DisplayDIV(d) { 
	if (document.layers) {
	// When the page scrolls in Netscape, the event's mouse position
	// reflects the absolute position on the screen. innerHight/Width
	// is the position from the top/left of the screen that the user is
	// looking at. pageX/YOffset is the amount that the user has 
	// scrolled into the page. So the values will be in relation to
	// each other as the total offsets into the page, no matter if
	// the user has scrolled or not.
	xMousePos = e.pageX;
	yMousePos = e.pageY;
	xMousePosMax = window.innerWidth+window.pageXOffset;
	yMousePosMax = window.innerHeight+window.pageYOffset;
	} 
	else if (document.all) {
	// When the page scrolls in IE, the event's mouse position 
	// reflects the position from the top/left of the screen the 
	// user is looking at. scrollLeft/Top is the amount the user
	// has scrolled into the page. clientWidth/Height is the height/
	// width of the current page the user is looking at. So, to be
	// consistent with Netscape (above), add the scroll offsets to
	// both so we end up with an absolute value on the page, no 
	// matter if the user has scrolled or not.
	xMousePos = window.event.x+document.body.scrollLeft;
	yMousePos = window.event.y+document.body.scrollTop;
	xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
	yMousePosMax = document.body.clientHeight+document.body.scrollTop;
	} 
	else if (document.getElementById) {
	// Netscape 6 behaves the same as Netscape 4 in this regard 
	xMousePos = e.pageX;
	yMousePos = e.pageY;
	xMousePosMax = window.innerWidth+window.pageXOffset;
	yMousePosMax = window.innerHeight+window.pageYOffset;
	}
	//alert(xMousePos);
	//alert(yMousePos);
	//alert(xMousePosMax);
	//alert(yMousePosMax);
	document.getElementById(d).style.left = xMousePos;
	document.getElementById(d).style.top = yMousePos+10;
	document.getElementById(d).style.display = "block"; 
}
function HideDIV1(d) { document.getElementById(d).style.display = "none"; }
function DisplayDIV1(d) { 
	document.getElementById(d).style.display = "block"; 
}
function handleResponse_addtocart() { 
	if(httpaddtocart.readyState == 4) {
		if(httpaddtocart.status == 200) {
			var response = httpaddtocart.responseText;
			var ship_option = response.split('@@@'); 
			var divid = "devimage"+ship_option[2];
			var divadded = "productinfo"+ship_option[2];
			var load1	=	"<table bgcolor='#f7f8f9' cellspacing='0'>";
			load1	+=	"<tr><td align='left'>";
			load1	+=	"<img src='http://www.amzer.com/images/cart-icon.gif' border='0'></td></tr>";
			load1	+=	" </table>";
			var cartload = "<table width='170' border='0' align='left' cellpadding='0' cellspacing='0'>";
            cartload += "<tr><td width='42'><img src='http://www.amzer.com/images/cart-top-icon.gif' width='42' height='33' /></td><td valign='bottom' class='crt-txt'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' class='crt-txt'>You have <span class='sku-price'>"+ship_option[0]+" items</span></td>";
			cartload += "</tr><tr><td align='center' height='4'></td></tr><tr><td align='left' class='sku-name-txt'>Total<span class='sku-price'>$"+ship_option[1]+"</span></td></tr>";
			cartload += " </table></td></tr><tr><td rowspan='3'></td><td align='left' style='padding-top:2px;'><a class='leftlinkheads' href='http://www.amzer.com/review-order.htm'><img src='http://www.amzer.com/images/view-cart-btn.gif' border='0'/></a></td></tr></table>";
			orderID11 = document.getElementById('shopping_cartinfo');
			orderID11.innerHTML		=	'';
			orderID11.innerHTML		=	cartload;
			orderID11.style.display	=	'block';
			imageID = document.getElementById(divid);
			imageID.innerHTML		=	'';
			imageID.innerHTML		=	load1;
			imageID.style.display	=	'block';
			imageID1 = document.getElementById(divadded);
			imageID1.innerHTML		=	'';
			imageID1.innerHTML		=	"<table border='0' cellpadding='0' cellspacing='0'><tr><td align='center' style='padding:4px 0;' valign='bottom' class='textstar'><a href='http://www.amzer.com/review-order.htm' class='textstar'>SKU added, view cart</a></td></tr></table>";
			imageID1.style.display	=	'block';
			
		}
			
	}
}
function add_shopping_cart(x,y) {
	var load	=	"<table bgcolor='#f7f8f9' cellspacing='0'>";
		load	+=	"<tr><td align='left'>";
		load	+=	"<img src='http://www.amzer.com/images/loading.gif' border='0'></td></tr>";
		load	+=	" </table>";
	if (httpaddtocart) {
		httpaddtocart.open("GET", "http://www.amzer.com/additem_new.php?purchaseSKU="+x+"&purchaseqty=1");
		orderID = document.getElementById(y);
		orderID.innerHTML		=	'';
		orderID.innerHTML		=	load;
		orderID.style.display	=	'block';
		httpaddtocart.onreadystatechange = handleResponse_addtocart;
		httpaddtocart.send(null);
	}
}

function createRequestaddtocart() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

var httpaddtocart = createRequestaddtocart();
var httpsession = createRequestaddtocart();
function calcute_postion() { 
	flashID = document.getElementById("flashalk");
	if ((screen.width>1200) && (screen.height>800)) { 
		flashID.style.left = '185px';
		flashID.style.top = '148px';
		flashID.style.width = '750px';
		flashID.style.height = '250px';;
	}
	else if ((screen.width>1020) && (screen.height>700)) { 
		flashID.style.left = '185px';
		flashID.style.top = '148px';
		flashID.style.width = '750px';
		flashID.style.height = '250px';
	}
	else { 
		flashID.style.left = '185px';
		flashID.style.top = '148px';
		flashID.style.width = '800px';
		flashID.style.height = '240px';
	}
}
function AddToCart(url, type,sku){ 
	var parameters="";
	try {
		req = new XMLHttpRequest(); /* e.g. Firefox */
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP"); /* some versions IE */
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP"); /* some versions IE */ }
			catch (E) {
				req = false;
			}
		}
	}
	req.onreadystatechange = function() { 
	//responseAHAHsort(fname);
	responseAddToCart(sku);
	};
	//alert(url);
	req.open(type,url,true);
	
    req.setRequestHeader("Content-length", parameters.length);
	if(parameters == '') parameters = null;
	req.send(parameters);
	
}

function set_screen_width(x) {
	if (httpsession) {
		httpsession.open("GET", "http://www.amzer.com/set_session.php?screen_w="+x);
		httpsession.onreadystatechange = handleResponse_session;
		httpsession.send(null);
	}
}
function handleResponse_session(aa) {
	if(httpsession.readyState == 4) {
		//alert(aa);	
	}
}
function responseAddToCart(fname) {
	if(req.readyState == 1 ) { //loading
		/*if(document.getElementById('busy-'+fname) != null){ 
			document.getElementById('busy-'+fname).style.display = "block";
			document.getElementById('addbutton-'+fname).style.display = "none";
		}*/
		//document.getElementById('dialog').innerHTML ="<img src='../images/loading.gif'>";
	}
	else if(req.readyState == 4) {
		if(req.status == 200) {
			var response = req.responseText;
			var ship_option = response.split('@@@'); 
			var load1	=	"<table bgcolor='#f7f8f9' cellspacing='0'>";
			load1	+=	"<tr><td align='left'>";
			load1	+=	"<img src='../images/add-to-cart.gif' border='0'></td></tr>";
			load1	+=	" </table>";
			var cartload = "<table width='273' border='0' cellspacing='0' cellpadding='0'>";
				cartload += "<tr><td width='26'><img src='../images/cart-icon-l.jpg' width='26' height='18'></td>";
				cartload += "<td align='left' width='70' bgcolor='#FDFDFF' class='cart-txt'> Item(s)&nbsp; "+ship_option[0]+"</td>";
				cartload += "<td align='right' width='88' bgcolor='#FFFFFF' class='cart-txt2'>Rs."+ship_option[1]+"</td>";
				cartload += "<td width='10'><img src='../images/cart-r.gif' width='10' height='18'></td>";
				cartload += "<td align='center' width='79'><a href='../shopping-detail.php'><img src='../images/view-cart-btn.jpg' width='79' height='18' border='0'></a></td>";
				cartload += "</tr></table>";
			orderID11 = document.getElementById('shopping_cartinfo');
			orderID11.innerHTML		=	'';
			orderID11.innerHTML		=	cartload;
			orderID11.style.display	=	'block';
		}
		else {
			//document.getElementById('info-'+fname).style.display = "none";
			alert("Error occured, Please try again");
			//alert(req.responseText+'=====req.responseText');
		}
	}
}
function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Enter numeric value only.");
        return false;
    }
    return true;
}
function selectQty(theform) {
var noOfRow = document.getElementsByName("purchaseqty[]").length;	
	var fieldchecked=false;
	for(k=0; k< noOfRow; k++)
	{	
		if (document.getElementById("show"+(k))==null)
			{
				s = document.getElementsByName("purchaseqty[]")[k].value;
				var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
			    for (var i = 0; i < s.length; i++) 
			    {
					if (iChars.indexOf(s.charAt(i)) != -1) 
					{
						alert("Please enter valid quantity!");
						document.getElementsByName("purchaseqty[]")[k].value ="";
						document.getElementsByName("purchaseqty[]")[k].focus();
						return(false);
					}	
				}
				if(document.getElementsByName("purchaseqty[]")[k].value != "")
				{
					fieldchecked = true;
					if(isNaN(parseInt(document.getElementsByName("purchaseqty[]")[k].value)) || document.getElementsByName("purchaseqty[]")[k].value<=0)
					{ 
						alert("Please enter valid quantity!");
						document.getElementsByName("purchaseqty[]")[k].value ="";
						document.getElementsByName("purchaseqty[]")[k].focus();
						return(false);
					}
				}	
			}
		else
			{
				s = document.getElementsByName("purchaseqty[]")[k].value;
				if(s.indexOf('.')>=0)
				{	
					alert("Please enter valid quantity!");
					document.getElementsByName("purchaseqty[]")[k].value ="";
					document.getElementsByName("purchaseqty[]")[k].focus();
					return(false);
				}
				if(document.getElementsByName("purchaseqty[]")[k].value != "")
				{
					fieldchecked = true;
					if(isNaN(parseInt(document.getElementsByName("purchaseqty[]")[k].value)) || document.getElementsByName("purchaseqty[]")[k].value<=0)
						{ 
							alert("Please enter valid quantity!");
							document.getElementsByName("purchaseqty[]")[k].value ="";
							document.getElementsByName("purchaseqty[]")[k].focus();
							return(false);
						}
								
				}		
			}
	}
	if (fieldchecked == false){
   		alert('You must enter at least one item');
		document.getElementsByName("purchaseqty[]")[0].focus(); 
		return(false);
	}
}
