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

function showMenu(comId)
{
	x = document.getElementById(comId);
	x.className = 'mItemOver ' + comId +'Over';
	if(comId == 'itemLinkDiv' || comId == 'memLinkDiv' || comId == 'trLinkDiv' || comId == 'catLinkDiv')
	{
		chkmouseover(comId);
		//alert(document.forms.length);
		for(i=0;i<document.forms.length;i++)
		{
			var theForm = document.forms[0];
			//alert(theForm.elements.length);
			for(p=0;p<theForm.elements.length;p++)
			{
				//alert(theForm.elements[p].type);
				if(theForm.elements[p].type == 'select-one')
				theForm.elements[p].style.display = 'none';
			}
		}
	}
	return true;
}

function hideMenu(comId)
{
	x = document.getElementById(comId);
	x.className = comId;
	if(comId == 'itemLinkDiv' || comId == 'memLinkDiv' || comId == 'trLinkDiv' || comId == 'catLinkDiv')
	{
		chkmouseout(comId);
		//alert(document.forms.length);
		for(i=0;i<document.forms.length;i++)
		{
			var theForm = document.forms[0];
			for(p=0;p<theForm.elements.length;p++)
			{
				if(theForm.elements[p].type == 'select-one')
				theForm.elements[p].style.display = '';
			}
		}
	}
	return true;
}

function chkCatDel(noOfItm)
{
	if(noOfItm > 0)
	{
		alert('You cannot really delete this category as it has ' + noOfItm + ' items in it!!!');
		return false;
	}
	else
	{
		return confirm('are you sure you want to delete this category?');
	}
}

function chkForPassword(frm)
{
	if(!notEmpty(frm.txtUserName,"E-mail Address (User Name)"))
	return false;
}

function chkAddCategory(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Category Name"))
	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 chkAddPhoto(frm,isEdit)
{
	var noOfPhotos = frm.hidAllPhotos.value;
	var isSel = 0;
	for(i=0;i<noOfPhotos;i++)
	{
		comObj = eval("frm.flImage_" + i);
		if(comObj.value)
		{
			isSel = 1;
		}
	}
	if(!isSel && !isEdit)
	{
		alert("Please specify atleast one photo!");
		frm.flImage_0.focus();
		return false;
	}
	else
	return true;
}

function chkAddProduct(frm,isEdit)
{
	if(!notEmpty(frm.txtTitle,"Title"))
	return false;
	if(!notSelected(frm.slCategory,"Category"))
	return false;
	if(!notRadioSelected(frm.rdUniqueBidType,"Unique Bid Type"))
	return false;
	if(!notEmpty(frm.txtPrice,"Retail Price"))
	return false;
	else if(!notCurrency(frm.txtPrice,"Retail Price"))
	return false;
	if(!notEmpty(frm.txtMinBids,"Minimum Bids"))
	return false;
	else if(!notCurrency(frm.txtMinBids,"Minimum Bids"))
	return false;
	if(!notEmpty(frm.txtMaxBids,"Maximum Bids"))
	return false;
	else if(!notCurrency(frm.txtMaxBids,"Maximum Bids"))
	return false;
	
	var diff = 0;
	
	if(Number(frm.txtMinBids.value) >= Number(frm.txtMaxBids.value))
	{
		alert("Maximum bids should be greater than Minimum bids!");
		frm.txtMaxBids.focus();
		return false;
	}
	
	if(!notEmpty(frm.txtReqBids,"Required Bids"))
	return false;
	else if(!notPosNumber(frm.txtReqBids,"Required Bids"))
	return false;
	if(!notEmpty(frm.txtAdminFee,"Admin Fee"))
	return false;
	else if(!notCurrency(frm.txtAdminFee,"Admin Fee"))
	return false;
	if(!notEmpty(frm.txtBidIncrement,"Bid Increment"))
	return false;
	else if(!notCurrency(frm.txtBidIncrement,"Bid Increment"))
	return false;
	
	var firstInc = 0;
	firstInc = Number(frm.txtMinBids.value) + Number(frm.txtBidIncrement.value);
	if(firstInc > frm.txtMaxBids.value)
	{
		alert("The increment value that you have set doesn't fit with the minimum and maximum range that you have set!\n\nThere is no single value fits because of the increment value that you have specified between the bids range\n\nPlease enter some lower value as increment value!");
		frm.txtBidIncrement.focus();
		return false;
	}
	if(!notEmpty(frm.txtShortDesc,"Short Description"))
	return false;
	if(!notInLimit(frm.txtShortDesc,"Short Description",200))
	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 showGalleryDetail(comId)
{
	alert(comId);
	x = document.getElementById("lyrGallery");
	x.style.display = '';
}

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

function chkChangePass(frm)
{
	if(!notEmpty(frm.txtOldPassword,"Old Password"))
	return false;
	if(!notEmpty(frm.txtPassword,"New Password"))
	return false;
	if(!notEmpty(frm.txtPasswordConf,"Confirm New Password"))
	return false;
	else if(!notCompare(frm.txtPassword,frm.txtPasswordConf,"Password doesn't match"))
	return false;
}

function chkBidding(frm,minbid,maxbid,bidinc)
{
	if(!notEmpty(frm.txtBidAmount,"Bidding Amount"))
	return false;
	if(!notCurrency(frm.txtBidAmount,"Bidding Amount"))
	return false;
	if(!notTwoDecimalCurrency(frm.txtBidAmount,"Bidding Amount"))
	return false;
	if(Number(frm.txtBidAmount.value) < Number(minbid))
	{
		alert("Bidding amount is too low !!!");
		frm.txtBidAmount.focus();
		return false;
	}
	if(Number(frm.txtBidAmount.value) > Number(maxbid))
	{
		alert("Bidding amount is too high !!!");
		frm.txtBidAmount.focus();
		return false;
	}
/*	alert(minbid);
	alert(maxbid);
	alert(bidinc);	*/
	
	var fl = true;
	var cnt = 0;
	var minbid = parseFloat(minbid);
	var maxbid = parseFloat(maxbid);
	var bidinc = parseFloat(bidinc);
	var nextInc = parseFloat(minbid);
	
	if(maxbid == frm.txtBidAmount.value)
	{
		return true;
	}

	for(i=minbid;i<=maxbid;i = i + bidinc)
	{
		j = i.toFixed(2);
		if(j == frm.txtBidAmount.value)
		{
			return true;
		}
	}
	
	/*for(i=minbid;i<maxbid;i = i + bidinc)
	{
		if(i == frm.txtBidAmount.value)
		return true;
	}*/
	alert("Bidding amount doesn't fit with Bid increment");
	frm.txtBidAmount.focus();
	return false;
}

function chkReferFriend(frm)
{
	if(!notEmpty(frm.txtName,"Name"))
	return false;
	if(!notEmpty(frm.txtEmail,"E-mail"))
	return false;
}

function chkUserSignup(frm,isupdate)
{
	if(!notEmpty(frm.txtName,"Name"))
	return false;

	if(!isupdate)
	{
		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.slBrand.value && !frm.slBrand.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 notInLimit(obj,msg,limit)
{
	var passObj = obj;
	var passMsg = msg;
	if((passObj.value.length) > limit)
	{
		alert('Length should not be more than ' + limit + ' characters for ' + msg + '!!');
		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 notTwoDecimalCurrency(obj,msg)
{
	var passObj = obj.value;
	var passMsg = msg;
	var checkOK = "1234567890.";
	var matched = 0;
	var afterDot = 0;
	for (p = 0;  p < passObj.length;  p++)
	{
		matched = 0;
		if(passObj.charAt(p) == '.')
		{
			afterDot = (passObj.length - p) - 1;
			if(afterDot > 0 && afterDot < 3)
			return true
			else if(afterDot == 0)
			{
				alert("Invalid . (dot) in price !!!");
				obj.focus();
				return false;
			}
			else if(afterDot > 2)
			{
				alert("There has to be only 2 decimal places !!!");
				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 GetXmlHttpObject()
{ 
	var objXMLHttp=null;
	if(window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

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

////////////////////////////////////////////////////////////////////
// menu functions
////////////////////////////////////////////////////////////////////

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;
}


////////////////////////////////////////////////////////////////////
// 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 clItemTemp()
{
	x = document.getElementById("itemTableTr");
	var curmode = x.style.display;
	if(curmode=='none')
		x.style.display = '';
	else
		x.style.display = 'none';

}

function chkBidConfirm()
{
	return confirm("Are you sure you want to deduct amount from winner's membership account?\n\nAs soon as you click on 'OK' button, information will be updated in the database and won't be able to reset back\n\nAre you sure you want to do this?");
}

function showGallery()
{
	x = document.getElementById("itmgallery");
	//alert(screenWidth());
	x.style.left = (screenWidth() / 2) - 250;
	
	x.style.top = (screenHeight() / 2) - 225;

	if(x.style.display == 'none')
	x.style.display = '';
	else
	x.style.display = 'none';
}

function showImage(comid)
{
	x = document.getElementById("itmgalimage");
	x.src = eval("document.tmpform." + comid + ".value");
	return true;
}

function screenWidth()
{
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return frameWidth;
}

function screenHeight()
{
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return frameHeight;
}