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) {
		var response = httpaddtocart.responseText;
		var ship_option = response.split('@@@'); 
		var divid = "devimage"+ship_option[2];
		var divadded = "productinfo"+ship_option[2];
		var load1	=	"<img src='../images/cart-icon.gif' border='0'>";
		
		var cartload = "<table width='110' border='0' align='right' cellpadding='0' cellspacing='0'>";
            cartload += "<tr><td valign='bottom'><table width='100%' border='0' cellpadding='0'><tr>";
			cartload += "<td class='cart-items'>"+ship_option[0]+"&nbsp;Item(s)</td>";
			cartload += "</tr><tr>";
			cartload += "<td class='cart-total'>$"+ship_option[1]+"</td>";
			cartload += "</tr></table></td><td width='30' align='right' valign='bottom'><a href='../shopping-detail.php'><img src='../images/go_btn.gif' width='30' height='26'/></a></td>";
			cartload += "</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' width=100%><tr><td align='center' valign='bottom'><a href='../shopping-detail.php' class='footer-txt' id=green><b>SKU ADDED, VEIW CART</b></a></td></tr></table>";
			imageID1.style.display	=	'block';
			
	}
}
function add_shopping_cart(x,y) {
	//alert(x)
	var load	=	"<table cellspacing='0'>";
		load	+=	"<tr><td align='left'>";
		load	+=	"<img src='http://www.fommy.com/images/loading.gif' border='0'></td></tr>";
		load	+=	" </table>";
	if (httpaddtocart) {
		httpaddtocart.open("GET", "../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();

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 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 a Positive Integer Value!!");
						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 a Positive Integer Value!!");
						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 a Positive Integer Value!!");
					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 a Positive Integer Value!!");
							document.getElementsByName("purchaseqty[]")[k].value ="";
							document.getElementsByName("purchaseqty[]")[k].focus();
							return(false);
						}
					if(document.getElementsByName("showmodel[]")[k].value=="")
						{
							alert("Please Select Your Phone Model!!");
							document.getElementsByName("showmodel[]")[k].focus();
							return(false);
						}				
				}		
			}
	}
	if (fieldchecked == false){
   		alert('You must enter at least one item');
		document.getElementsByName("purchaseqty[]")[0].focus(); 
		return(false);
	}
}
function splitvalue(index)
{
	if(document.getElementsByName("showmodel[]")[index].value)
	{
		var arrdata =  document.getElementsByName("showmodel[]")[index].value.split("#");
		document.getElementsByName("ProductID[]")[index].value=arrdata[0];
		document.getElementsByName("purchaseModel[]")[index].value=arrdata[1];
		document.getElementsByName("model_type[]")[index].value=arrdata[2];
		document.getElementsByName("freeProduct[]")[index].value=arrdata[3];
		document.getElementsByName("freeQty[]")[index].value=arrdata[4];
		document.getElementsByName("HoldQty[]")[index].value=arrdata[5];		
		if (arrdata[3] != "" && arrdata[4] != "" && arrdata[5] != "")
		{
			document.getElementById("freeproduct"+(index)).innerHTML = "<strong id='maroon'>Buy "+arrdata[5]+" Get"+arrdata[4]+"<a href='javascript:freeshow("+arrdata[6]+");' class='subheading-link' id='blue'>"+arrdata[7]+"</a><font size='3'>Free</font></strong>";
		}		
		else if(document.getElementById("freeproduct"+(index)))
		{
			document.getElementById("freeproduct"+(index)).innerHTML ="";
		}
	}
}
function sp_value(index)
{
	var arrdata =  document.getElementsByName("showmodel[]")[index].value.split("#");
	document.getElementsByName("ProductID[]")[index].value=arrdata[0];
	document.getElementsByName("purchaseModel[]")[index].value=arrdata[1];
	document.getElementsByName("model_type[]")[index].value=arrdata[2];
	document.getElementsByName("freeProduct[]")[index].value=arrdata[3];
	document.getElementsByName("freeQty[]")[index].value=arrdata[4];
	document.getElementsByName("HoldQty[]")[index].value=arrdata[5];
	if (arrdata[3] != "" && arrdata[4] != "" && arrdata[5] != "")
	{
		document.getElementById("freeproduct"+(index)).innerHTML = "<strong id='maroon'>Buy "+arrdata[5]+" Get"+arrdata[4]+"<a href='javascript:freeshow("+arrdata[6]+");' class='subheading-link' id='blue'>"+arrdata[7]+"</a><font size='3'>Free</font></strong>";
	}		
	else
	{
		document.getElementById("freeproduct"+(index)).innerHTML ="";
	}
}
function splitRelatedvalue(index)
{
	var arrdata =  document.getElementsByName("showmodel[]")[index].value.split("#");
	document.getElementsByName("ProductID[]")[index].value=arrdata[0];
	document.getElementsByName("purchaseModel[]")[index].value=arrdata[1];
	document.getElementsByName("model_type[]")[index].value=arrdata[2];

}
function  freeshow(sku)
{
	var shwppage= "freeproduct.asp?skuno="+sku;
	window.open(shwppage,'Demo','scrollbars=yes,resizable=no,width=650,height=490,left=300,top=200');
}

function UpdateCart()
{
	var noOfproduct = document.getElementsByName("modi_qty[]").length;
	var total = 0;
	var totalqty = 0;
	for (ii=0; ii< noOfproduct; ii++)
	{	
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		q = document.getElementsByName("modi_qty[]")[ii].value;
	    for (var i = 0; i < q.length; i++) 
		{
			if (iChars.indexOf(q.charAt(i)) != -1) 
			{	
				alert("Please enter a Positive Integer Value!!");
				document.getElementsByName("modi_qty[]")[ii].value ="";
				document.getElementsByName("modi_qty[]")[ii].focus();
				return(false);
			}
		}
		if(q == "")
			{
				alert("Please Enter Quantity");
				document.getElementsByName("modi_qty[]")[ii].focus();
				return(false);
			}
		
		if (!(isNaN(parseInt(document.getElementsByName("modi_qty[]")[ii].value))) && parseInt(document.getElementsByName("modi_qty[]")[ii].value) > 0)
		{
			var amount = CurrencyFormatted(parseFloat(document.getElementsByName("updateprice[]")[ii].value)*parseFloat(document.getElementsByName("modi_qty[]")[ii].value));
			document.getElementById("total"+ii).innerHTML="<strong>$"+amount+"</strong>";			
			total = parseFloat(total)+parseFloat(amount);
			totalqty = parseInt(totalqty) + parseInt(document.getElementsByName("modi_qty[]")[ii].value);			
		}
		else
		{
			alert("Please Enter a Positive Number");
			document.getElementsByName("modi_qty[]")[ii].focus();
			return(false);
		}			
	}
	if (document.getElementById("tqty"))
		{
			document.getElementById("tqty").innerHTML= "<strong id='orange'>"+totalqty+"</strong>";
		}	
	if (document.getElementById("nettotal"))
		{
			document.getElementById("nettotal").innerHTML= "<strong class='searchtxt' id='orange'>$"+CurrencyFormatted(total)+"</strong>";
		}
	document.checkout_frm.action = "";
	document.checkout_frm.Submit.value="Update My Cart";
	document.checkout_frm.update.value="YES";
}
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;
}
