
function showMenu(comId)
{
	x = document.getElementById(comId);
	x.className = 'mItemOver ' + comId +'Over';
	if(comId == 'brandLinkDiv' || comId == 'prdTypeLinkDiv' || comId == 'goalLinkDiv' || comId == 'prdLinkDiv' || comId == 'ordLinkDiv' || comId == 'memLinkDiv' || comId == 'galLinkDiv' || comId == 'newsLinkDiv' || comId == 'artLinkDiv' || comId == 'galLinkDiv')
	{
		chkmouseover(comId);
		var theForm = document.forms[0];
		if(theForm)
		theForm.slOpt.style.display = 'none';
	}
	return true;
}

function hideMenu(comId)
{
	x = document.getElementById(comId);
	x.className = comId;
	if(comId == 'brandLinkDiv' || comId == 'prdTypeLinkDiv' || comId == 'goalLinkDiv' || comId == 'prdLinkDiv' || comId == 'ordLinkDiv' || comId == 'memLinkDiv' || comId == 'galLinkDiv' || comId == 'newsLinkDiv' || comId == 'artLinkDiv' || comId == 'galLinkDiv')
	{
		chkmouseout(comId);
		var theForm = document.forms[0];
		if(theForm)
		theForm.slOpt.style.display = '';
	}
	return true;
}

function chkLogin(frm)
{
	if(!notEmpty(frm.UserName,"User Name"))
	return false;
	if(!notEmpty(frm.Pwd,"Password"))
	return false;
	else
	return true;
}


function chkContactUs(frm)
{
	if(!notEmpty(frm.txtName,"Name"))
	return false;
	if(!notEmpty(frm.txtEmail,"E-mail"))
	return false;
	if(!notEmpty(frm.txtPhone,"Phone"))
	return false;
	else if(!notPhone(frm.txtPhone,"Phone"))
	return false;
	if(!notEmpty(frm.txtSubject,"Subject"))
	return false;
	if(!notEmpty(frm.txtEnquiry,"Enquiry"))
	return false;
	else
	return true;
}

function chkAddGallery(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notEmpty(frm.txtShortDesc,"Short Description"))
	return false;
	if(!isEdit)
	{
	if(!noFileSelected(frm.flImage,"Image"))
	return false;
	}
	if(!notSelected(frm.slCategory,"Category"))
	return false;
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function chkAddBrand(frm)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function chkAddGoal(frm)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function chkAddPrdType(frm)
{
	if(!notEmpty(frm.txtTitle,"Product Type"))
	return false;
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function interFrmSubmit()
{
	frm = document.paypal_form;
	//alert(frm);
	frm.submit();
	return false;
}


function chkAddNews(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notEmpty(frm.txtShortDesc,"Short Description"))
	return false;
	if(!notEmpty(frm.txtDetDesc,"Detail Description"))
	return false;
	if(!isEdit)
	{
	if(!noFileSelected(frm.flImage,"Image"))
	return false;
	}
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function chkAddArticle(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notEmpty(frm.txtShortDesc,"Short Description"))
	return false;
	if(!notEmpty(frm.txtDetDesc,"Detail Description"))
	return false;
	if(!isEdit)
	{
	if(!noFileSelected(frm.flImage,"Image"))
	return false;
	}
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function chkAddProduct(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notSelected(frm.slProductType,"Product Type"))
	return false;
	if(!notSelected(frm.slBrand,"Brand"))
	return false;
	if(!notSelected(frm.txtGoal,"Goal"))
	return false;
	if(!notEmpty(frm.txtPrice,"Price"))
	return false;
	else if(!notCurrency(frm.txtPrice,"Price"))
	return false;
	if(!notEmpty(frm.txtShortDesc,"Short Description"))
	return false;
	//if(!notEmpty(frm.txtDetDesc,"Detail Description"))
	//return false;
	if(!isEdit)
	{
	if(!noFileSelected(frm.flImage,"Image"))
	return false;
	}
	if(frm.slWeeklySpec)
	{
		if(!notSelected(frm.slWeeklySpec,"Monthly Special"))
		return false;
	}
	if(frm.slMemberSpec)
	{
		if(!notSelected(frm.slMemberSpec,"What's HOT"))
		return false;
	}
	if(!notSelected(frm.slStatus,"Status"))
	return false;
	else
	return true;
}

function showHidePromoPrd(frm,disPromoJava)
{
	if(disPromoJava == 1)
	return true;
	if(frm.slTopTen.value == 'Y')
	{
		frm.slPromoProduct.disabled = false;
	}
	else
	{
		frm.slPromoProduct.disabled = true;
	}
	return true;
//slTopTen	
}

function delProductType(noOfPrd)
{
	if(noOfPrd > 0)
	{
		return confirm("There are " + noOfPrd + " products associated with this product type\n\nIf you delete this product type then all these products will also be deleted permanently from the database\n\nAre you sure you want to do this?");
	}
	else
		return confirm('Are you sure you want to delete this product type?');
}

function delUser(noOfOrd)
{
	if(noOfOrd > 0)
	{
		return confirm("This member has made " + noOfOrd + " orders so far.\n\nIf you delete this member then all these orders will also be deleted permanently from the database\n\nAre you sure you want to do this?");
	}
	else
		return confirm('Are you sure you want to delete this member?');
}

function delBrand(noOfPrd)
{
	if(noOfPrd > 0)
	{
		return confirm("There are " + noOfPrd + " products associated with this brand\n\nIf you delete this brand then all these products will also be deleted permanently from the database\n\nAre you sure you want to do this?");
	}
	else
		return confirm('Are you sure you want to delete this brand?');
}

function delBrand(noOfPrd)
{
	if(noOfPrd > 0)
	{
		return confirm("There are " + noOfPrd + " products associated with this brand\n\nIf you delete this brand then all these products will also be deleted permanently from the database\n\nAre you sure you want to do this?");
	}
	else
		return confirm('Are you sure you want to delete this brand?');
}

function delGoal(noOfPrd)
{
	if(noOfPrd)
	{
		return confirm("There are " + noOfPrd + " products associated with this goal\n\nIf you delete this goal then all these products will also be deleted permanently from the database\n\nAre you sure you want to do this?");
	}
	else
		return confirm('Are you sure you want to delete this goal?');
}

function showGalleryDetail(comId)
{
	alert(comId);
	x = document.getElementById("lyrGallery");
	x.style.display = '';
}

function chkPhoneFocus(comId)
{
	document.genEnq.rdContOpt[comId].checked=true;
	return true;
}

function chkUserSignup(frm)
{
	if(!notEmpty(frm.txtName,"Name"))
	return false;
	if(!notEmpty(frm.txtUserName,"User Name"))
	return false;
	if(!notEmpty(frm.txtPassword,"Password"))
	return false;
	if(!notEmpty(frm.txtPasswordConf,"Confirm Password"))
	return false;
	else if(!notCompare(frm.txtPassword,frm.txtPasswordConf,"Password doesn't match"))
	return false;
	if(!notRadioSelected(frm.rdGender,"Gender"))
	return false;
	if(!notEmpty(frm.txtAddress,"Address"))
	return false;
	if(!notEmpty(frm.txtCity,"City"))
	return false;
	if(!notEmpty(frm.txtState,"State"))
	return false;
	if(!notEmpty(frm.txtZipcode,"Zipcode"))
	return false;
	if(!notEmpty(frm.txtContNo,"Contact Number"))
	return false;
	else if(!notPhone(frm.txtContNo,"Contact Number"))
	return false;
	else
	return true;
}

function chkPhoneFocus(comId)
{
	document.genEnq.rdContOpt[comId].checked=true;
	return true;
}

function chkQuickSearchFront(frm)
{
	if(!frm.slBrand.value && !frm.slProductType.value && !frm.slGoal.value)
	{
		alert("Please specify atleast one search criteria");
		frm.slBrand.focus();
		return false;
	}
	else
	return true;
}

function chkQuickSearchTwo(frm)
{
	if(!notSelected(frm.slOpt,"Option"))
		return false;
	if(!notEmpty(frm.keyword,"Search Keyword"))
		return false;
	else
		return true;
}

function notChecked(obj,msg)
{
	var passObj = obj;
	var passMsg = msg;
	if(passObj.checked == false)
	{
		alert(msg);
		passObj.focus();
		return false;
	}
	return true;
}

function notEmpty(obj,msg)
{
	var passObj = obj;
	var passMsg = msg;
	if(!passObj.value)
	{
		alert('Please enter a value for ' + msg + ' Field !!');
		passObj.focus();
		return false;
	}
	return true;
}

function notCurrency(obj,msg)
{
	var passObj = obj.value;
	var passMsg = msg;
	var checkOK = "1234567890.";
	var matched = 0;
	for (p = 0;  p < passObj.length;  p++)
	{
		matched = 0;
		for (j = 0;  j < checkOK.length;  j++)
		{
			if(passObj.charAt(p) == checkOK.charAt(j))
			{
			matched = 1;
			break;
			}
		}
		if(matched==0)
		{
			alert("Please enter a valid " + msg);
			obj.focus();
			return false;
		}
	}
	return true;
}

function notNumber(obj,msg)
{
	var passObj = obj.value;
	var passMsg = msg;
	var checkOK = "1234567890";
	var matched = 0;
	for (p = 0;  p < passObj.length;  p++)
	{
		matched = 0;
		for (j = 0;  j < checkOK.length;  j++)
		{
			if(passObj.charAt(p) == checkOK.charAt(j))
			{
			matched = 1;
			break;
			}
		}
		if(matched==0)
		{
			alert("Please enter a valid " + msg);
			obj.focus();
			return false;
		}
	}
	return true;
}

function notPosNumber(obj,msg)
{
	var passObj = obj.value;
	var passMsg = msg;
	var checkOK = "1234567890";
	var matched = 0;
	for (p = 0;  p < passObj.length;  p++)
	{
		matched = 0;
		for (j = 0;  j < checkOK.length;  j++)
		{
			if(passObj.charAt(p) == checkOK.charAt(j))
			{
			matched = 1;
			break;
			}
		}
		if(matched==0)
		{
			alert("Please enter a valid " + msg);
			obj.focus();
			return false;
		}
	}
	if(passObj <= 0)
	{
			alert("Please enter a valid " + msg);
			obj.focus();
			return false;
	}
	return true;
}

function notPhone(obj,msg)
{
	var passObj = obj.value;
	var passMsg = msg;
	var checkOK = "1234567890-()+ ";
	var matched = 0;
	for (p = 0;  p < passObj.length;  p++)
	{
		matched = 0;
		for (j = 0;  j < checkOK.length;  j++)
		{
			if(passObj.charAt(p) == checkOK.charAt(j))
			{
			matched = 1;
			break;
			}
		}
		if(matched==0)
		{
			alert("Please enter a valid " + msg);
			obj.focus();
			return false;
		}
	}
	return true;
}

function notCompare(obj,secobj,msg)
{
	var passObj = obj;
	var passObjSec = secobj;
	var passMsg = msg;
	if(passObj.value != passObjSec.value)
	{
		alert(msg);
		passObjSec.focus();
		return false;
	}
	return true;
}
function notSelected(obj,msg)
{
	var passObj = obj;
	var passMsg = msg;
	if(!passObj.value)
	{
		alert('Please select a value for ' + msg + ' Field !!');
		passObj.focus();
		return false;
	}
	return true;
}


function noFileSelected(obj,msg)
{
	var passObj = obj;
	var passMsg = msg;
	if(!passObj.value)
	{
		alert('Please select ' + msg + ' !!');
		passObj.focus();
		return false;
	}
	return true;
}

function notRadioSelected(obj,msg)
{
	var passObj = obj;
	var passMsg = msg;
	var noOfEle = obj.length;
	var found = 0;
	
	for(i=0;i<noOfEle;i++)
	{
		if(obj[i].checked == true)
		{
			found = 1;
			break;
		}
	}
	if(found==0)
	{
		alert('Please select an option for ' + msg);
		return false;
	}
	return true;
}

////////////////////////////////////////////////////////////////////
// XML functions and AJAX things
////////////////////////////////////////////////////////////////////
var xmlHttp

function hideGalleryDetail(comId)
{
	x = document.getElementById("lyrGallery");
	x.style.display = 'none';
}


function ldGalleryDetails(glrId)
{
	x = document.getElementById("lyrGallery");
	x.style.display = '';

	xmlHttp = GetXmlHttpObject()
	if(xmlHttp==null)
	{
		alert("Browser does not support HTTP Request");
		return false;
	}
	var urlPass = "gallerydetail.php";
	urlPass = urlPass + "?GI=" + glrId;
	urlPass = urlPass + "&sid="+Math.random();
	//alert(urlPass);
	xmlHttp.onreadystatechange = fillGalleryDetails;
	urlPass = new String(urlPass);
	xmlHttp.open("GET",urlPass);
	xmlHttp.send(null);
	return true;
}

function ldHomeContent(conId)
{
	xmlHttp = GetXmlHttpObject()
	if(xmlHttp==null)
	{
		alert("Browser does not support HTTP Request");
		return false;
	}
	
	var urlPass = "fetchHomeContent.php";
	urlPass = urlPass + "?CI=" + conId;
	urlPass = urlPass + "&sid="+Math.random();
	//alert(urlPass);
	xmlHttp.onreadystatechange = fillHomePages;
	urlPass = new String(urlPass);
	xmlHttp.open("GET",urlPass);
	xmlHttp.send(null);
	return true;
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if(window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

var glId;
function changeDivs(comStr,comId)
{
	var comStr = comStr;
	var slices = comStr.split(",");
	var noOfPiece = Number(slices.length);

	for (p = 0;  p < noOfPiece;  p++)
	{
		//alert(slices[p]);
		j = p + 1;
		if(slices[p] == comId)
		{
			if(j != noOfPiece)
			glId = slices[p+1];
			else
			glId = slices[0];
		}
	}
		//alert(comId);

	if(!comId && noOfPiece > 0)
	{
		comId = slices[0];
		if(noOfPiece > 1)
		{
		glId = slices[1];
		}
		else
		{
			glId = comId;
		}
	}
	else if(!comId)
	{
		comId = slices[0];
		glId = comId;
	}
	//alert(comId);
	//alert(glId);
	ldHomeContent(comId);
	
	setTimeout("changeDivs('" + comStr + "'," + glId + ");",20000);
	
	return true;
}

function fillGalleryDetails() 
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("lyrGallery").innerHTML = xmlHttp.responseText;
	}
} 

function fillHomePages() 
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("home_page").innerHTML = xmlHttp.responseText;
	}
} 

////////////////////////////////////////////////////////////////////
// SHOPPING CART function
////////////////////////////////////////////////////////////////////

function addToCart(prdId)
{
	frmobj = document.frmshoppingcart;
	document.frmshoppingcart.prdid.value = prdId;
	document.frmshoppingcart.action.value = "Add";
	document.frmshoppingcart.submit();
	return true;
}

function removeProduct(prdId)
{
	document.frmshoppingcart.prdid.value = prdId;
	document.frmshoppingcart.action.value = "Remove";
	document.frmshoppingcart.submit();
}

function chkCartUpdate(frm)
{
	//alert(frm);
	var noOfProducts;
	var comObj;
	noOfProducts = frm.hidProducts.value;
	for(i=1;i<=noOfProducts;i++)
	{
		comObj = eval("frm.txtqty_" + i);
		if(!notEmpty(comObj,"Quantity"))
		return false;
		else if(!notPosNumber(comObj,"Quantity"))
		return false;
	}
	return true;
}

function chkCartDelete(frm)
{
	//alert(frm);
	var noOfProducts;
	var comObj;
	var noOfChecked = 0;
	noOfProducts = frm.hidProducts.value;
	for(i=1;i<=noOfProducts;i++)
	{
		comObj = eval("frm.chkPrd_" + i);
		if(comObj.checked == true)
		{
			noOfChecked = noOfChecked + 1;
		}
	}
	if(noOfChecked==0)
	{
		alert("Please select atleast one product to delete!!");
		return false;
	}
	else
		return confirm("Are you sure you want to remove selected "+ noOfChecked +" product(s)");
}

function chkmouseover(passobj)
{
	x = document.getElementById(passobj);
	curX = findPosX(x);
	curY = findPosY(x);

	y = document.getElementById('menu' + passobj);

	y.style.display = '';

	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		y.style.top = curY + 21;
		y.style.left = curX - 1;
	}
	else
	{
		y.style.top = curY + 25;
		y.style.left = curX + 0;
	}
}

function chkmouseout(passobj)
{
	y = document.getElementById('menu' + passobj);

	y.style.display = 'none';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}