// Function to display/Hide 
function toggleDisp(pDispField, pHideField, pFieldsE, pMode)
{
	var dispField = document.getElementById(pDispField);
	var hideField = document.getElementById(pHideField);
	var fieldsE = document.getElementById(pFieldsE);
	var mode = document.getElementById(pMode);

	if(pMode == "toggleModify") {
		var modeDisp = "View";
		var modeHide = "Edit";
	}
	else if (pMode == "toggleShow") {
		var modeDisp = "Hide";
		var modeHide = "Show";
	}
		
	if (dispField.style.display == "none") {
		dispField.style.display = "block";
		hideField.style.display = "none";
		mode.innerHTML = modeDisp;
		
	}
	else if (dispField.style.display == "block")  {
		dispField.style.display = "none";
		hideField.style.display = "block";
		mode.innerHTML = modeHide;
		fieldsE.style.visibility = "hidden";
	}
		
}


// Begin - Timed Layer
function hideElement (pId) {  
	// document.getElementById(pId).style.display = "none";
}
function timedElement (pId) {
  setTimeout("hideElement('" + pId + "')", 10000);
}

// End - Timed layer


// Begin - Display form in Invite to Groups
function displayForm ()
{
	if(document.getElementById("inviteFriends").style.display == "none")
	{
		document.getElementById("invite").style.display = "none";
    	document.getElementById("inviteFriends").style.display = "block";
	}
	else if(document.getElementById("inviteFriends").style.display == "block")
	{
		document.getElementById("invite").style.display = "block";
    	document.getElementById("inviteFriends").style.display = "none";
	}
}
// End - Display form in Invite to Groups


// Begin - Select all check boxes
function check(frm, cName) 
{
	//alert(frm);
	//alert(cName);
	for (i=0,n=frm.elements.length;i<n;i++)
	{
		//alert(frm.elements[i].className);
		if (frm.elements[i].className.indexOf(cName) !=-1)
		{
			if (frm.elements[i].checked == true) 
				frm.elements[i].checked = false;
			else 
				frm.elements[i].checked = true;
		}
	}
}
// End- Select all check boxes


// Being-  Temp Load for Non AJAX Pages
function tLoad()
{
	document.getElementById('load').innerHTML = imgRound;
}
// End-  Temp Load for Non AJAX Pages


// Begin - Display Privilege in Admin User
function showPrivilege()
{  
	document.getElementById("newPrivilege").style.display = "block";
	document.getElementById("editLink").style.display = "none";
    document.getElementById("oldPrivilege").style.display = "none";
}
// End - Display Privilege in Admin User

// Begin - Display Photo Mode in Uploading Photo
function displayUpload(pId)
{
	id = pId;
	if(id == "uploadPhoto")
	{
		document.getElementById("upload").style.display = "block";
		document.getElementById("type").value = "upload";
		document.getElementById("flickr").style.display = "none";
		document.getElementById("url").style.display = "none";
		document.getElementById("flickrDiv").style.display = "none";
		document.getElementById("urlDiv").style.display = "none";
		document.getElementById("linkurl").style.display = "block";
	}
	if(id == "flickrPhoto")
	{
		document.getElementById("upload").style.display = "none";
		document.getElementById("flickr").style.display = "block";
		document.getElementById("type").value = "flickr";
		document.getElementById("url").style.display = "none";
		document.getElementById("uploadDiv").style.display = "none";
		document.getElementById("urlDiv").style.display = "none";
		document.getElementById("linkurl").style.display = "block";
	}
	if(id == "urlPhoto")
	{
		document.getElementById("upload").style.display = "none";
		document.getElementById("flickr").style.display = "none";
		document.getElementById("url").style.display = "block";
		document.getElementById("type").value = "url";
		document.getElementById("uploadDiv").style.display = "none";
		document.getElementById("flickrDiv").style.display = "none";
		document.getElementById("linkurl").style.display = "block";
	}
}
// End - Display Photo Mode in Uploading Photo

// Begin - Disable and enable Photo Mode in Uploading Photo

function toggleAlert(id) {
toggleDisabled(document.getElementById(id));
if(id == "upload1")
{
	toggleEnabled(document.getElementById("upload2"));
	toggleEnabled(document.getElementById("upload3"));
	document.getElementById("type").value = "upload";
}
else if(id == "upload2")
{
	toggleEnabled(document.getElementById("upload1"));
	toggleEnabled(document.getElementById("upload3"));
	document.getElementById("type").value = "flickr";
}
else if(id == "upload3")
{
	toggleEnabled(document.getElementById("upload1"));
	toggleEnabled(document.getElementById("upload2"));
	document.getElementById("type").value = "url";
}
else
{
	toggleEnabled(document.getElementById("upload1"));
	toggleEnabled(document.getElementById("upload1"));
	toggleEnabled(document.getElementById("upload1"));
}
}
function toggleDisabled(el) {
	//alert(el.childNodes.length);
	if(el.disabled == true)
	{
		el.disabled = false;
	}
//el.disabled = el.disabled ? true : false;
if (el.childNodes && el.childNodes.length > 0) 
{
for (var x = 0; x < el.childNodes.length; x++) 
{
toggleDisabled(el.childNodes[x]);
}
}
}
function toggleEnabled(el) {
	//alert(el.childNodes.length);
	if(el.disabled == false)
	{
		el.disabled = true;
	}
//el.disabled = el.disabled ? true : false;
if (el.childNodes && el.childNodes.length > 0) 
{
for (var x = 0; x < el.childNodes.length; x++) 
{
toggleEnabled(el.childNodes[x]);
}
}
}

// End - Disable and enable Photo Mode in Uploading Photo


// Begin - To display photo using Shadow Box

function changeShadow(backgroundId, dialogId, source){
	if(document.getElementById(backgroundId).style.display == "none")
	{
		document.getElementById(backgroundId).style.opacity = 1.0;
		document.getElementById(backgroundId).style.display = "block";
		document.getElementById(dialogId).style.display = "block";
		document.getElementById("image").src = source;
	}
	else
	{
		document.getElementById(backgroundId).style.display = "none";
		document.getElementById(dialogId).style.display = "none";
	}
}

// End - To display photo using Shadow Box


// Begin - Display Single Photo in AlbumpImageFrom, pImageUrl
/*function displayPhoto(pImageFrom, pImageUrl)
{  
	if(pImageFrom == "F" || pImageFrom == "U")
		var imgLink = pImageUrl;
	else if(pImageFrom == "PC")
		imgLink = "../albumPhotos/" + pImageUrl;
	
	var imgTag = '<img src="' + imgLink + '" style="height:auto; width:auto; background-position:center; border:none;" />';
	var closeLink = '<div align="left"><a href="javascript:void(0);" ';
	closeLink = closeLink + 'onclick="document.getElementById(\'viewPhoto\').style.display=\'none\';">Close</a></div>';
	document.getElementById("viewPhoto").innerHTML = closeLink + imgTag;
	document.getElementById("viewPhoto").style.display = "block";
}*/
// End - Display Single Photo in Album

// Begin - Display Add Tag Form for Albums
function displayAddTag(id)
{
	if(document.getElementById("addTagElements"+id).style.display == "none")
	{
		document.getElementById("addTagElements"+id).style.display = "block";
		document.getElementById("addTagText"+id).style.display = "block";
		document.getElementById("addTagLink"+id).style.display = "none";
	}
	else
	{
		document.getElementById("addTagElements"+id).style.display = "none";
		document.getElementById("addTagText"+id).style.display = "none";
		document.getElementById("addTagLink"+id).style.display = "block";
	}
}
// End - Display Add Tag Form for Albums


// Begin - Display Remove Tag Form for Albums
function displayRemove(id)
{
	if(document.getElementById("removeTags"+id).style.display == "none")
	{
		document.getElementById("removeTags"+id).style.display = "block";
		document.getElementById("removeTagLink"+id).style.display = "none";
	}
	else
	{
		document.getElementById("removeTags"+id).style.display = "none";
		document.getElementById("removeTagLink"+id).style.display = "block";
	}
}
// End - Display Remove Tag Form for Albums


// Begin - Display Remove Photo Tag Form
function displayRemovePhotoTag(id)
{
	if(document.getElementById("removePhotoTagElements"+id).style.display == "none")
	{
		document.getElementById("removePhotoTagElements"+id).style.display = "block";
		document.getElementById("removePhotoTagLink"+id).style.display = "none";
	}
	else
	{
		document.getElementById("removePhotoTagElements"+id).style.display = "none";
		document.getElementById("removePhotoTagLink"+id).style.display = "block";
	}
}
// End - Display Remove Photo Tag Form


// Begin - Make Text Box Empty and Display Text 
function toggleText(pId, pValue)
{
	var id = pId;
	var value = pValue;
	if(value == "Search By Tag")
	{
		document.getElementById(id).value = "";
	}
	else if(value == "Search By Name")
	{
		document.getElementById(id).value = "";
	}
	else if(value == 0)
	{
		if(document.getElementById("tagSearch").checked == true)
		{
			document.getElementById(id).value = "Search By Tag";
		}
		else if(document.getElementById("nameSearch")){
			if(document.getElementById("nameSearch").checked == true)
			{
				document.getElementById(id).value = "Search By Name";
			}
		}
		else{
			document.getElementById(id).value = "Search By Name";
		}
	}
}
// End - Make Text Box Empty and Display Text 


// Begin - Make Text Box Empty and Display Text 
function toggleTextSearch(pId, pValue)
{
	var id = pId;
	var value = pValue;
	if(value == "Search By Name")
	{
		document.getElementById(id).value = "";
	}
	else if(value == 0)
	{
		document.getElementById(id).value = "Search By Name";
	}
}
// End - Make Text Box Empty and Display Text 



// Begin - Make Text Box Empty and Display Text  - View Albums Page
function toggleTextAlbum(pId, pValue)
{
	var id = pId;
	var value = pValue;
	if(value == "Search By Tag")
	{
		document.getElementById(id).value = "";
	}
	else if(value == 0)
	{
		document.getElementById(id).value = "Search By Tag";
	}
}
// End - Make Text Box Empty and Display Text - View Albums Page

// Begin - Make Text Box values depend on radio search options
function changeText(pValue)
{
	var value = pValue;
	if(value == "tag")
	{
		if(document.getElementById("searchKey").value == "Search By Name")
		{
			document.getElementById("searchKey").value = "Search By Tag";
			document.getElementById("searchUsing").value = "tag";
		}
	}
	else if(value == "albumName")
	{
		if(document.getElementById("searchKey").value == "Search By Tag")
		{
			document.getElementById("searchKey").value = "Search By Name"
			document.getElementById("searchUsing").value = "albumName";
		}
	}
}
// End - Make Text Box values depend on radio search options


// Begin - Redirect Search For Enter Button
function searchEnter(keyCode, type)
{
	if(keyCode == 13)
	{
		if(type == 'A')
			searchByTag();
		else if(type == 'P')
			searchPhotoTag();
	}
}
// End - Redirect Search For Enter Button


// Begin - Display Add Tag Form for Photos
function displayAddPhotoTag()
{
	if(document.getElementById("addPhotoTagForm").style.visibility == "hidden")
	{
		document.getElementById("addPhotoTagForm").style.visibility = "visible";
		document.getElementById("addPhotoTagLink").style.visibility = "hidden";
	}
	else
	{
		document.getElementById("addPhotoTagForm").style.visibility = "hidden";
		document.getElementById("addPhotoTagLink").style.visibility = "visible";
	}
}
// End - Display Add Tag Form for Photos

// Begin - Display Comments for Photos
function displayComments(id)
{
	if(document.getElementById("viewComments"+id).style.display == "none")
	{
		document.getElementById("viewComments"+id).style.display = "block";
	}
	else
	{
		document.getElementById("viewComments"+id).style.display = "none";
	}
}
// End - Display Comments for Photos

// Begin - Display Add Comments Form for Photos
function displayCommentForm(id)
{
	if(document.getElementById("commentForm"+id).style.display == "none")
	{
		document.getElementById("commentForm"+id).style.display = "block";
	}
	else
	{
		document.getElementById("commentForm"+id).style.display = "none";
	}
}
// End - Display Add Comments Form for Photos


// Begin - Display Edit Tag Form for Photos and albums
function displayEditTagForm(id)
{
	if(document.getElementById("renameTagForm"+id).style.display == "none")
	{
		document.getElementById("editTagLink"+id).style.display = "none"
		document.getElementById("deleteTagLink"+id).style.display = "none"
		document.getElementById("renameTagForm"+id).style.display = "block";
		document.getElementById("tagValue"+id).focus();
	}
	else
	{
		document.getElementById("editTagLink"+id).style.display = "block"
		document.getElementById("deleteTagLink"+id).style.display = "block"
		document.getElementById("renameTagForm"+id).style.display = "none";
	}
}
// End - Display Edit Tag Form for Photos and albums

// Begin - Photo Slide Show
var interval = 2000;
var random_display = 0;
//var imageDir = "../albumPhotos/pradeepFirst";

var imageNum = 0;



function imageItem(image_location) {
		this.image_item = new Image();
		this.image_item.src = image_location;
	}
	function get_ImageItemLocation(imageObj) {
		return(imageObj.image_item.src)
	}
function randNum(x, y) {
		var range = y - x + 1;
		return Math.floor(Math.random() * range) + x;
	}
function getNextImage(url, from, totalImages) {
		if (random_display) {
			imageNum = randNum(0, totalImages-1);
		}
		else {
			imageNum = (imageNum+1) % totalImages;
		}
	if(from[imageNum] == "PC")
	{
		var location = "../albumPhotos/";
		var new_image = location + url[imageNum];
	}
	else
	{
		var new_image = url[imageNum];
	}
	return(new_image);
	}
function getPrevImage(url, from, totalImages) {
		imageNum = (imageNum-1) % totalImages;
		if(from[imageNum] == "PC")
		{
			var location = "../albumPhotos/";
			var new_image = location + url[imageNum];
		}
		else
		{
			var new_image = url[imageNum];
		}
		return(new_image);
	}
function prevImage(place, totalImages, urls, froms) {
		var url = urls.split("#");
		var from = froms.split("@");
		var new_image = getPrevImage(url, from, totalImages);
		document[place].src = new_image;
	}
function switchImage(place, totalImages, urls, froms) {
		var url = urls.split("#");
		var from = froms.split("@");
		var new_image = getNextImage(url, from, totalImages);
		document[place].src = new_image;
		var recur_call = "switchImage('"+place+"','"+totalImages+"','"+urls+"','"+froms+"')";
		timerID = setTimeout(recur_call, interval);
        }
		
//End - Photo Slide Show



// Begin - Display Form to add sub Products
function showaddSubProducts()
{
	if(document.getElementById("productId").value != 0)
	{
		if(document.getElementById("addSubProductsForm").style.display == "none")
		{
			document.getElementById("addSubProductsForm").style.display = "block";
		}
	}
	else
	{
		document.getElementById("addSubProductsForm").style.display = "none";
	}
}
// End - Display Form to add sub Products

// Begin - Display Form to add child Products
function showChildProductForm()
{
	if(document.getElementById("subProductId").value != 0)
	{
		if(document.getElementById("addChildProductForm").style.display == "none")
		{
			document.getElementById("addChildProductForm").style.display = "block";
		}
		else
		{
			document.getElementById("addChildProductForm").style.display = "none";
		}
	}
	else
	{
		document.getElementById("addChildProductForm").style.display = "none";
	}
}
// End - Display Form to add child Products

// Begin - Display Form to add root Products
function showaddRootProductForm()
{
	if(document.getElementById("addRootProductsForm").style.display == "none")
	{
		document.getElementById("addRootProductsForm").style.display = "block";
	}
	else
	{
		document.getElementById("addRootProductsForm").style.display = "none";
	}
}
// End - Display Form to add root Products

 // Being - Sample Test Rich Text Editor
function richText(pInput, pType)
 {
         var startPos = pInput.selectionStart;
         var endPos = pInput.selectionEnd;
         
         var before = pInput.value.substring(0, startPos);
         var selSelection = pInput.value.substring(startPos, endPos);
         var after = pInput.value.substring(endPos, pInput.value.length);
         var sTag, eTag;
         
         if(pType == "b") {
                 sTag = "<b>";
                 eTag = "</b>";
         }
         else if(pType == "i") {
                 sTag = "<i>";
                 eTag = "</i>";
         }
         else if(pType == "u") {
                 sTag = "<u>";
                 eTag = "</u>";
         }
         
         if(document.selection && document.selection.createRange().text.length != 0) {
                 var str = document.selection.createRange().text;
                 var docSelection = document.selection.createRange();
                 
                 //alert(document.selection.createRange().text);
                 docSelection.text = sTag + str + eTag;
                 pInput.focus();
         }
         else if (!document.selection && selSelection.length != 0) {
                 //alert(selSelection);
                 pInput.value = String.concat(before, sTag, selSelection, eTag, after);
                 pInput.focus();
         }
 }
// End - Sample Test Rich Text Editor
 
//Begin - To Update Links for quantity in root products

function updateQuantity(pQuantity, pProductId)
{
	var productId = pProductId;
	var quantity = pQuantity;
	if(quantity != 0)
	{
		//document.getElementById("quantityCart"+productId).value = quantity;
		document.getElementById("quantityBasket"+productId).value = quantity;
	}
}

//End - To Update Links for quantity in root products

//Begin - To display Form to edit for quantity in baskets

function editBasketElement(pRootProductId)
{
	var rootProductId = pRootProductId;
	if(document.getElementById("quantityEdit"+rootProductId).style.display == "none")
	{
		document.getElementById("quantityEdit"+rootProductId).style.display = "block";
		document.getElementById("quantityDisplay"+rootProductId).style.display = "none";
	}
	else
	{
		document.getElementById("quantityEdit"+rootProductId).style.display = "none";
		document.getElementById("quantityDisplay"+rootProductId).style.display = "block";
	}
	if(document.getElementById("quantityEdits"+rootProductId).style.display == "none")
	{
		document.getElementById("quantityEdits"+rootProductId).style.display = "block";
		document.getElementById("quantityDisplays"+rootProductId).style.display = "none";
	}
	else
	{
		document.getElementById("quantityEdits"+rootProductId).style.display = "none";
		document.getElementById("quantityDisplays"+rootProductId).style.display = "block";
	}
	
	
}

//End - To display Form to edit for quantity in baskets


//Begin - To display Form to edit for quantity in cart

function editCartElement(pRootProductId)
{
	var rootProductId = pRootProductId;
	if(document.getElementById("quantityEdit"+rootProductId).style.display == "none")
	{
		document.getElementById("quantityEdit"+rootProductId).style.display = "block";
		document.getElementById("quantityDisplay"+rootProductId).style.display = "none";
	}
	else
	{
		document.getElementById("quantityEdit"+rootProductId).style.display = "none";
		document.getElementById("quantityDisplay"+rootProductId).style.display = "block";
	}
}

//End - To display Form to edit for quantity in cart


//Begin - To copy shipping information onto payment information

function checkBasket () {
  setTimeout("clearBasket()", 500000);
}

//End - To check for expired products in basket


//Begin - To check for expired products in basket

function setPaymentInfo(isChecked)
{
	with (window.document.userDetails) {
		if (isChecked) {
			paymentFirstName.value  = shippingFirstName.value;
			paymentLastName.value   = shippingLastName.value;
			paymentAddress1.value   = shippingAddress1.value;
			paymentAddress2.value   = shippingAddress2.value;
			paymentPhone.value      = shippingPhone.value;
			paymentState.value      = shippingState.value;			
			paymentCity.value       = shippingCity.value;
			paymentPostalCode.value = shippingPostalCode.value;
			
			paymentFirstName.readOnly  = true;
			paymentLastName.readOnly   = true;
			paymentAddress1.readOnly   = true;
			paymentAddress2.readOnly   = true;
			paymentPhone.readOnly      = true;
			paymentState.readOnly      = true;			
			paymentCity.readOnly       = true;
			paymentPostalCode.readOnly = true;			
		} else {
			paymentFirstName.readOnly  = false;
			paymentLastName.readOnly   = false;
			paymentAddress1.readOnly   = false;
			paymentAddress2.readOnly   = false;
			paymentPhone.readOnly      = false;
			paymentState.readOnly      = false;			
			paymentCity.readOnly       = false;
			paymentPostalCode.readOnly = false;			
		}
	}
}

//End - To copy shipping information onto payment information


//Begin - Refresh Chat Window
function refreshChat() {
	//alert("check");
 	//setTimeout("callChatAction()",3000);
	setTimeForChat();
	callChatAction();
	//checkAjax();
	setTimeout("refreshChat()",3000);
	//setTimeout("setTimeForChat()",3000); 
}


//End - Refresh Chat Window


// Begin - Set Javascript time for chat
function setTimeForChat()
{
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
var curSec = curDateTime.getSeconds()
var curDate = curDateTime.getDate()
var curMonth = curDateTime.getMonth() + 1
var curYear = curDateTime.getFullYear()
var curTime = ((curYear < 10) ? "0" : "") + curYear + ":" +
				((curMonth < 10) ? "0" : "") + curMonth + ":"+
				((curDate < 10) ? "0" : "") + curDate + " "+
			   ((curHour < 10) ? "0" : "") + curHour + ":" 
			   + ((curMin < 10) ? "0" : "") + curMin + ":" 
			   + ((curSec < 10) ? "0" : "") + curSec 
document.getElementById("currTime").value = curTime;
}

// End - Set Javascript time for chat

//Begin - Show smileys div
function showImagesDiv()
{
	//alert(document.getElementById("smileyContainer").style.display);
	if(document.getElementById("smileyContainer").style.display == "block")
	{	
		document.getElementById("smileyContainer").style.display = "none";
	}
	else
	{
		document.getElementById("smileyContainer").style.display = "block";
	}
}
//End - Show smileys div

//Begin - Check Image Box Display
function chkImg() {
	//document.getElementById("imgShow").style.visibility="hidden";
	document.getElementById("Smile").style.visibility="Visible";
}
//End - Check Image Box Display

//Begin - Diplay Image
function getImageVal(imVal) {
	document.getElementById("smileyContainer").style.display = "none";
	var textVal=document.getElementById("cText").value;
	//document.getElementById("imgShow").style.visibility="hidden";
	document.getElementById("Smile").style.visibility="Visible";
	document.getElementById("cText").value=textVal+imVal;
	document.getElementById("cText").focus();
}
//End - Diplay Image

// Begin - Display Form to create chat room
function displayCreateRoom()
{
	if(document.getElementById("createRoom").style.display == "none")
	{
		document.getElementById("createRoom").style.display = "block";
	}
	else
	{
		document.getElementById("createRoom").style.display = "none";
	}
}
// End - Display Form to create chat room

// Begin - Display different rooms 
function displayRooms()
{
	if(document.getElementById("Rooms").style.display == "none")
	{
		document.getElementById("Rooms").style.display = "block";
	}
	else
	{
		document.getElementById("Rooms").style.display = "none";
	}
}
// End - Display different rooms 

// Begin - To close Smileys
function hideSmileys()
{
	if(document.getElementById("imgShow").style.display == "none")
	{
		document.getElementById("imgShow").style.display = "block";
	}
	else
	{
		document.getElementById("imgShow").style.display = "none";
	}
}
// End - To close Smileys

// Begin - Dropdown Div in Products for list by

var slideDownInitHeight = new Array();
	var slidedown_direction = new Array();

	var slidedownActive = false;
	var contentHeight = false;
	var slidedownSpeed = 3; 	// Higher value = faster script
	var slidedownTimer = 7;	// Lower value = faster script
	function slidedown_showHide(boxId)
	{
		if(!slidedown_direction[boxId])slidedown_direction[boxId] = 1;
		if(!slideDownInitHeight[boxId])slideDownInitHeight[boxId] = 0;
		
		if(slideDownInitHeight[boxId]==0)slidedown_direction[boxId]=slidedownSpeed; else slidedown_direction[boxId] = slidedownSpeed*-1;
		
		slidedownContentBox = document.getElementById(boxId);
		var subDivs = slidedownContentBox.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			if(subDivs[no].className=='dropdown_content')slidedownContent = subDivs[no];	
		}

		contentHeight = slidedownContent.offsetHeight;
	
		slidedownContentBox.style.visibility='visible';
		slidedownActive = true;
		slidedown_showHide_start(slidedownContentBox,slidedownContent);
	}
	function slidedown_showHide_start(slidedownContentBox,slidedownContent)
	{

		if(!slidedownActive)return;
		slideDownInitHeight[slidedownContentBox.id] = slideDownInitHeight[slidedownContentBox.id]/1 + slidedown_direction[slidedownContentBox.id];
		if(slideDownInitHeight[slidedownContentBox.id] <= 0){
			slidedownActive = false;	
			slidedownContentBox.style.visibility='hidden';
			slideDownInitHeight[slidedownContentBox.id] = 0;
		}
		if(slideDownInitHeight[slidedownContentBox.id]>contentHeight){
			slidedownActive = false;	
		}
		slidedownContentBox.style.height = slideDownInitHeight[slidedownContentBox.id] + 'px';
		slidedownContent.style.top = slideDownInitHeight[slidedownContentBox.id] - contentHeight + 'px';

		setTimeout('slidedown_showHide_start(document.getElementById("' + slidedownContentBox.id + '"),document.getElementById("' + slidedownContent.id + '"))',slidedownTimer);	// Choose a lower value than 10 to make the script move faster
	}
	
	function setSlideDownSpeed(newSpeed)
	{
		slidedownSpeed = newSpeed;
		
	}
	
// End - Dropdown Div in Products for list by


// Begin - Display number of characters left in textarea


function textCounter(pField, pCountfield, pMaxlimit) 
{
	var dispCount = document.getElementById(pCountfield);
	var msg = document.getElementById(pField);
	
	if (msg.value.length > pMaxlimit)
		msg.value = msg.value.substring(0, pMaxlimit);
	else 
		dispCount.value = pMaxlimit - msg.value.length;
}

// End - Display number of characters left in textarea


// Begin - To scroll the contents inside the div

var ourInterval;
var scrollSpeed = 100;
var scrollHeight = 5;
function scrollStart(direction, divID, elementID){
	ourInterval = setInterval("scroll"+direction+"('"+divID+"')", scrollSpeed);
	//alert(ourInterval);
}
function scrollEnd(which){
clearInterval(ourInterval);
}
function scrollUp(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop - scrollHeight;
}
function scrollDown(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop + scrollHeight;
	//alert(document.getElementById(which).scrollTop);
}

// End - To scroll the contents inside the div

// Begin - To Fade out invite friends form in view groups page

var TimeToFade = 1000.0;

function fade(eid)
{
	//alert(eid);
	var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

// End - To Fade out invite friends form in view groups page

// Begin - To change class in forum topics page

function changeClass(id, subType)
{
	//alert(id);
	document.getElementById(id).className = "subborder forumposted02";
	if(subType == "yes")
	{
		document.getElementById(id+"idSubcategory").className = "subborder forumposted02";	
	}
}
function releaseClass(id, subType)
{
	document.getElementById(id).className = "subborder forumposted02 stripe";
	if(subType == "yes")
	{
		document.getElementById(id+"idSubcategory").className = "subborder forumposted02 stripe";	
	}
}

// End - To change class in forum topics page

// Begin - Function to get confirmation on delete and moving to corresponding page

function confirmDeletePopUp(pMsg,pTargetFunctionName, pParam)
{
	//doLinks(0);
	//alert(pTargetFunctionName);
	//alert(pParam);
	//pParam = pParam.replace(/,/g,"paramSep");
	
	//
	if(pTargetFunctionName == "moveFolder")
	{
		pParam = 'moveFoldernextParam' + pParam;
	}
	else if(pTargetFunctionName == "moveFolderInd")
	{
		pParam = 'moveFolderIndnextParam' + pParam;
	}
	//Checking IE version
	var ua = window.navigator.userAgent
    var msie = ua.indexOf ("MSIE " );
    if ( msie > 0 ){      // If Internet Explorer, return version number
         var clientVersion=parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
	}
	else{
		var clientVersion=0;
	}
	//
	if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) ){
			if(confirm(pMsg)){
				confirmRedirect(pTargetFunctionName, pParam);
			}
			else{
				//doLinks(1);
			}
	}
	else{
		document.getElementById('pop').style.display = "block";
	//newly added 18 - 5 - 2010
		var popInnerHTML;
		popInnerHTML="<div id='msgBox'  style='height:"+document.documentElement.clientHeight+"px;position:fixed;top:0px;left:0px; opacity:0.7;filter:alpha(opacity=70); float:none;width:"+document.documentElement.clientWidth+"px;background-color:#CCC;display:block'>";
		popInnerHTML +='<div style="border:1px solid; margin-top:100px; opacity:100;filter:alpha(opacity=100); margin-left:350px;  float:left; background-color:#9CF; height:200px; width:300px;text-align:center;">';
		//newly added 18 - 5 - 2010
		popInnerHTML += "<br /><br />";
		popInnerHTML += "<br /><b style=\"color:#000000;\">"+ pMsg +"</b><br > &nbsp;";
		popInnerHTML += "<input type=\"button\" name=\"submitYes\" id=\"submitYes\" value=\"Yes\" ";
		popInnerHTML += "style=\"background-color:#6496C3; color:#FFFFFF; width:40px;\"";
		popInnerHTML += "onclick=\"confirmRedirect("+pTargetFunctionName+", '"+pParam+"'); document.getElementById('msgBox').style.display='none';  \"";
		popInnerHTML += "document.getElementById('pop').style.display='none';\" >&nbsp;";
		popInnerHTML += "&nbsp;<input type=\"button\" name=\"submitNo\" id=\"submitNo\" value=\"No\"";
		popInnerHTML += "style=\"background-color:#6496C3; color:#FFFFFF; width:40px\"";
		popInnerHTML += "onclick=\"document.getElementById('pop').style.display='none'; document.getElementById('msgBox').style.display='none'; ";
		popInnerHTML +=  "\" >";
		
		//newly added 18 - 5 - 2010
		popInnerHTML += "</div>";
		popInnerHTML += "</div>";
		//newly added 18 - 5 - 2010
		document.getElementById('pop').innerHTML = popInnerHTML;
	}
	return false;
}
function confirmRedirect(pTargetFunctionName, pParam)
{
	var param = pParam.split("nextParam");
	var len = param.length;
	//Checking IE version
	var ua = window.navigator.userAgent
    var msie = ua.indexOf ("MSIE " );
    if ( msie > 0 ){      // If Internet Explorer, return version number
         var clientVersion=parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
	}
	else{
		var clientVersion=0;
	}
	//
	if(len == 1)
	{
		if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) ){
			window[pTargetFunctionName](pParam);
		}
		else{
			pTargetFunctionName(pParam);
		}
	}
	else if(len == 2)
	{
		if(param[0] == "moveFolder")
		{
			var folderId = document.getElementById("foldersList").value;
			if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
				window[pTargetFunctionName](folderId, param[1]);
			else
				pTargetFunctionName(folderId, param[1]);
		}
		else{
			if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
				window[pTargetFunctionName](param[0],param[1]);
			else
				pTargetFunctionName(param[0],param[1]);
		}
	}
	else if(len == 3)
	{
		if(param[0] == "moveFolderInd")
		{
			var folderId = document.getElementById("folders").value;
			if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
				window[pTargetFunctionName](folderId, param[1],param[2]);
			else
				pTargetFunctionName(folderId, param[1],param[2])
		}
		else{
			if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
				window[pTargetFunctionName](param[0],param[1],param[2]);
			else
				pTargetFunctionName(param[0],param[1],param[2])
		}
	}
	else if(len == 4)
	{
		if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
			window[pTargetFunctionName](param[0],param[1],param[2],param[3]);
		else
			pTargetFunctionName(param[0],param[1],param[2],param[3]);
	}
	else if(len == 5)
	{
		if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
			window[pTargetFunctionName](param[0],param[1],param[2],param[3],param[4]);
		else
			pTargetFunctionName(param[0],param[1],param[2],param[3],param[4])
	}
	else if(len == 6)
	{
		if((navigator.appName=="Microsoft Internet Explorer") && (clientVersion<=6) )
			window[pTargetFunctionName](param[0],param[1],param[2],param[3],param[4],param[5]);
		else
			pTargetFunctionName(param[0],param[1],param[2],param[3],param[4],param[5])
	}
	document.getElementById('pop').style.display='none';
	//doLinks(1);
	//alert(pTargetFunctionName);
}
var linksAction = new Array();
function doLinks(status)
{
	//alert(pTargetFunctionName);
	var inputElements = document.getElementsByTagName('input');
	if(status == 0)
	{
		for(var i=0;i<inputElements.length;i++)
		{
			inputElements[i].disabled=true;
		}
	}
	else if(status == 1)
	{
		for(var i=0;i<inputElements.length;i++)
		{
			inputElements[i].disabled = false;
		}
	}
	for (var pageLinks=document.links, i = pageLinks.length-1; i > -1; --i)
	{
		if (!status)
		{
			linksAction[i] = pageLinks[i].onclick;
			pageLinks[i].onclick=function(){return false;};
		}
		else
		{
			pageLinks[i].onclick=function(){return true;};
			pageLinks[i].onclick = linksAction[i];
		}
	}
}

// End - Function to get confirmation on delete and moving to corresponding page

// Begin - Function to search Products in list of products 

function searchProductsList()
{
	var searchKey = document.getElementById("searchKey").value;
	window.location = "uploadProducts?searchKey="+searchKey+"&search=1";
}

// End - Function to search products in list of products 


// Begin - Functions used in Upload Products


// Begin - Function to select Particular row

function selectRow(pRowNumber)
{
	var rownumber, checkVal = 0;
	rowNumber = pRowNumber;
	if(document.getElementById("productType"+rowNumber).value == 0)
	{
		checkVal = 0;
	}
	else
	{
		checkVal++;
	}
	if(document.getElementById("color"+rowNumber).value == 0)
	{
		checkVal = 0;
	}
	else
	{
		checkVal++;
	}
	if(document.getElementById("stock"+rowNumber).value == "")
	{
		checkVal = 0;
	}
	else
	{
		checkVal++;
	}
	//alert(document.getElementById("stock"+rowNumber).value);
	if(checkVal >= 3)
	{
		if(document.getElementById("productType"+rowNumber).style.backgroundColor == "blue")
		{
			document.getElementById("rootProductMainImage"+rowNumber).style.backgroundColor = "white";
			document.getElementById("productType"+rowNumber).style.backgroundColor = "white";
			document.getElementById("color"+rowNumber).style.backgroundColor = "white";
			document.getElementById("colortab1"+rowNumber).style.backgroundColor = "white";
			document.getElementById("colortab2"+rowNumber).style.backgroundColor = "white";
			document.getElementById("colortab3"+rowNumber).style.backgroundColor = "white";
			document.getElementById("L"+rowNumber).style.backgroundColor = "white";
			document.getElementById("a"+rowNumber).style.backgroundColor = "white";
			document.getElementById("b"+rowNumber).style.backgroundColor = "white";
			document.getElementById("h"+rowNumber).style.backgroundColor = "white";
			document.getElementById("c"+rowNumber).style.backgroundColor = "white";
			document.getElementById("hex"+rowNumber).style.backgroundColor = "white";
			document.getElementById("stock"+rowNumber).style.backgroundColor = "white";
			document.getElementById("availStock"+rowNumber).style.backgroundColor = "white";
			//document.getElementById("makeup"+rowNumber).style.backgroundColor = "white";
			//document.getElementById("price"+rowNumber).style.backgroundColor = "white";
			//document.getElementById("stock"+rowNumber).style.backgroundColor = "white";
			//document.getElementById("length"+rowNumber).style.backgroundColor = "white";
			//document.getElementById("weight"+rowNumber).style.backgroundColor = "white";
			document.getElementById("copyLink"+rowNumber).style.display = "none";
		}
		else
		{
			//document.getElementById("rootProductName"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("rootProductDesc"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("rootProductMainImage"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("rootProductThumb"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("productType"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("color"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("colortab1"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("colortab2"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("colortab3"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("L"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("a"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("b"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("h"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("c"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("hex"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("stock"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("availStock"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("makeup"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("price"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("stock"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("length"+rowNumber).style.backgroundColor = "blue";
			//document.getElementById("weight"+rowNumber).style.backgroundColor = "blue";
			document.getElementById("copyLink"+rowNumber).style.display = "block";
		}
	}
	else
	{
		alert("Mandatory Fields should not be empty to select.");
	}
}

// End - Function to select Particular row

// Begin - Function to copy Particular row

function copyRow(pRowNumber)
{
	var rowNumber = pRowNumber;
	//var tempName = document.getElementById("rootProductName"+rowNumber).value;
	//var tempDesc = document.getElementById("rootProductDesc"+rowNumber).value;
	var tempMainImage = document.getElementById("rootProductMainImage"+rowNumber).value;
	//var tempThumb = document.getElementById("rootProductThumb"+rowNumber).value;
	var tempProductType = document.getElementById("productType"+rowNumber).value;
	var tempColor = document.getElementById("color"+rowNumber).value;
	var tempColortab1 = document.getElementById("colortab1"+rowNumber).value;
	var tempColortab2 = document.getElementById("colortab2"+rowNumber).value;
	var tempColortab3 = document.getElementById("colortab3"+rowNumber).value;
	var tempL = document.getElementById("L"+rowNumber).value;
	var tempa = document.getElementById("a"+rowNumber).value;
	var tempb = document.getElementById("b"+rowNumber).value;
	var temph = document.getElementById("h"+rowNumber).value;
	var tempc = document.getElementById("c"+rowNumber).value;
	var temphex = document.getElementById("hex"+rowNumber).value;
	//var tempMakeup = document.getElementById("makeup"+rowNumber).value;
	//var tempPrice = document.getElementById("price"+rowNumber).value;
	var tempStock = document.getElementById("stock"+rowNumber).value;
	var tempAvailStock = document.getElementById("availStock"+rowNumber).value;
	//var tempLength = document.getElementById("length"+rowNumber).value;
	//var tempWeight = document.getElementById("weight"+rowNumber).value;
	//document.getElementById("tempRootProductName").value = tempName;
	//document.getElementById("tempRootProductDesc").value = tempDesc;
	document.getElementById("tempMainImage").value = tempMainImage;
	//document.getElementById("tempThumb").value = tempThumb;
	document.getElementById("tempProductType").value = tempProductType;
	document.getElementById("tempColor").value = tempColor;
	document.getElementById("tempColorTab1").value = tempColortab1;
	document.getElementById("tempColorTab2").value = tempColortab2;
	document.getElementById("tempColorTab3").value = tempColortab3;
	document.getElementById("tempL").value = tempL;
	document.getElementById("tempa").value = tempa;
	document.getElementById("tempb").value = tempb;
	document.getElementById("temph").value = temph;
	document.getElementById("tempc").value = tempc;
	document.getElementById("temphex").value = temphex;
	//document.getElementById("tempMakeup").value = tempMakeup;
	//document.getElementById("tempPrice").value = tempPrice;
	document.getElementById("tempStock").value = tempStock;
	document.getElementById("tempAvailStock").value = tempAvailStock;
	//document.getElementById("tempLength").value = tempLength;
	//document.getElementById("tempWeight").value = tempWeight;
	var numOfRowsPaste = prompt("Enter the number of rows to be pasted", "Number of Rows");
	paste(numOfRowsPaste,rowNumber);
}

// End - Function to copy Particular row

// Begin - Function to paste copied items in number of rows

function paste(pNumOfRowsPaste,pOrigRow)
{
	var numRows = pNumOfRowsPaste;
	var origRow = pOrigRow + 1;
	//var tempName = document.getElementById("tempRootProductName").value;
	//var tempDesc = document.getElementById("tempRootProductDesc").value;
	var tempMainImage = document.getElementById("tempMainImage").value;
	//var tempThumb = document.getElementById("tempThumb").value;
	var tempProductType = document.getElementById("tempProductType").value;
	var tempColor = document.getElementById("tempColor").value;
	var tempColortab1 = document.getElementById("tempColorTab1").value;
	var tempColortab2 = document.getElementById("tempColorTab2").value;
	var tempColortab3 = document.getElementById("tempColorTab3").value;
	var tempL = document.getElementById("tempL").value;
	var tempa = document.getElementById("tempa").value;
	var tempb = document.getElementById("tempb").value;
	var temph = document.getElementById("temph").value;
	var tempc = document.getElementById("tempc").value;
	var temphex = document.getElementById("temphex").value;
	//var tempMakeup = document.getElementById("tempMakeup").value;
	//var tempPrice = document.getElementById("tempPrice").value;
	var tempStock = document.getElementById("tempStock").value;
	var tempAvailStock = document.getElementById("tempAvailStock").value;
	//var tempLength = document.getElementById("tempLength").value;
	//var tempWeight = document.getElementById("tempWeight").value;
	for (var i = 1; i <= numRows; i++, origRow++)
	{
		//alert(origRow);
		//document.getElementById("rootProductName"+origRow).value = tempName;
		//document.getElementById("rootProductDesc"+origRow).value = tempDesc;
		document.getElementById("rootProductMainImage"+origRow).value = tempMainImage;
		//document.getElementById("rootProductThumb"+origRow).value = tempThumb;
		document.getElementById("productType"+origRow).value = tempProductType;
		document.getElementById("color"+origRow).value = tempColor;
		document.getElementById("colortab1"+origRow).value = tempColortab1;
		document.getElementById("colortab2"+origRow).value = tempColortab2;
		document.getElementById("colortab3"+origRow).value = tempColortab3;
		document.getElementById("L"+origRow).value = tempL;
		document.getElementById("a"+origRow).value = tempa;
		document.getElementById("b"+origRow).value = tempb;
		document.getElementById("h"+origRow).value = temph;
		document.getElementById("c"+origRow).value = tempc;
		document.getElementById("hex"+origRow).value = temphex;
		//document.getElementById("makeup"+origRow).value = tempMakeup;
		//document.getElementById("price"+origRow).value = tempPrice;
		document.getElementById("stock"+origRow).value = tempStock;
		document.getElementById("availStock"+origRow).value  = tempAvailStock;
		//document.getElementById("length"+origRow).value = tempLength;
		//document.getElementById("weight"+origRow).value = tempWeight;
	}
	selectRow(pOrigRow);
	document.getElementById("copyLink"+rowNumber).style.display = "none";
}

// End - Function to paste copied items in number of rows

// Begin - Function to insert number of rows

function insertRow()
{
	var existRows = parseInt(document.getElementById("numRowsPresent").value);
	var remainRows = 40 - existRows;
	if(remainRows > 0)
	{
		var promptText = "Enter the number of rows to be added (Maximum ";
		//alert(existRows);
		promptText = promptText + remainRows + ")";
		//alert(promptText);
		var numOfRowsInsert = prompt(promptText , "Number of Rows");
		if(numOfRowsInsert > remainRows)
		{
			alert("You can insert only " + remainRows + " rows now");
		}
		else
		{
			if(isNaN(numOfRowsInsert) != 1)
			{
				var rowstoBeInserted = existRows + parseInt(numOfRowsInsert);
				existRows++;
				for(var i = existRows; i <= rowstoBeInserted; i++)
				{
					document.getElementById("extraRows"+i).style.display = "block";
				}
				if(isNaN(rowstoBeInserted) != 1)
					document.getElementById("numRowsPresent").value = rowstoBeInserted;
			}
		}
	}
	else
	{
		alert("40 rows is maximum limit. Upload Current Products and try again.");
	}
}

// End - Function to insert number of rows

// Begin - Function to validate and count number of items entered

function validateUpload()
{
	var numItemsExist = document.getElementById("numRowsPresent").value;
	var valuesExist = numValuesExist(numItemsExist);
	var len = valuesExist.length;
	document.getElementById("numRowsPresent").value = numItemsExist;
	//alert(len);
	/*for(var k = 0; k < len; k++)
	{
		alert(valuesExist[k]);
	}
	return false;*/
	if(len == 0)
	{
		alert("Enter the required values");
		return false;
	}
	var existRowText = "";
	for(var i = 0; i < len; i++)
	{
		if(existRowText == "")
			existRowText = valuesExist[i];
		else
			existRowText = existRowText + "," + valuesExist[i];
		
		var stock = document.getElementById("stock"+valuesExist[i]).value;
		//var price = document.getElementById("price"+valuesExist[i]).value;
		//var length = document.getElementById("length"+valuesExist[i]).value;
		//var weight = document.getElementById("weight"+valuesExist[i]).value;
		if(isNaN(stock) == 1)
		{
			alert("Only Numeric values are allowed for stock, price, length and weight");
			return false;
		}
		/*else if(isNaN(length) == 1)
		{
			alert("Only Numeric values are allowed for stock, price, length and weight");
			return false;
		}
		else if(isNaN(weight) == 1)
		{
			alert("Only Numeric values are allowed for stock, price, length and weight");
			return false;
		}
		else if(price == 0)
		{
			alert("Price value should be higher");
			return false;
		}
		else if(isNaN(price) == 1)
		{
			alert("Only Numeric values are allowed for stock, price, length and weight");
			return false;
		}*/
	}
	document.getElementById("valueExistRows").value = existRowText;
	return true;
}

// End - Function to validate and count number of items entered

// Begin - Function to count number of items entered

function numValuesExist(pNumItemsExist)
{
	var numItemsExist = pNumItemsExist;
	var itemsExist = new Array();
	var arrCount = 0, rowCount;
	for(var j = 1; j <= numItemsExist; j++)
	{
		rowCount = 0;
		if(document.getElementById("color"+j).value != 0)
		{
			//alert(document.getElementById("rootProductName"+j).value);
			rowCount = rowCount + 1;
		}
		/*if(document.getElementById("price"+j).value != 0)
		{
			//alert(document.getElementById("price"+j).value);
			rowCount = rowCount + 1;
		}*/
		if(document.getElementById("productType"+j).value != 0)
		{
			rowCount = rowCount + 1;
		}
		if(document.getElementById("stock"+j).value !="")
		{
			rowCount = rowCount + 1;
		}
		if(document.getElementById("hex"+j).value !="")
		{
			rowCount = rowCount + 1;
		}
		/*if(document.getElementById("length"+j).value != 0)
		{
			rowCount = rowCount + 1;
		}
		if(document.getElementById("weight"+j).value != 0)
		{
			rowCount = rowCount + 1;
		}*/
		//alert(rowCount);
		if(rowCount >= 4)
		{
			//alert(j);
			itemsExist[arrCount] = j;
			arrCount++;
		}
	}
	return itemsExist;
}

// End - Function to count number of items entered

// End - Functions used in Upload Products

// Begin - Function to display edit form in list Products Page - Admin Page

function editProductsAdmin(pProductId)
{
	var productId = pProductId;
	if(document.getElementById("productNameDisplay"+productId).style.display == "block")
	{
		document.getElementById("productEditOption"+productId).style.display = "none";
		document.getElementById("productUpdateOption"+productId).style.display = "block";
		document.getElementById("productNameEdit"+productId).style.display = "block";
		document.getElementById("productName"+productId).style.backgroundColor = "#15A9C8";
		//document.getElementById("productNameEdit"+productId).bgColor = "#B1E3E9";
		document.getElementById("productNameDisplay"+productId).style.display = "none";
		document.getElementById("productImageEdit"+productId).style.display = "block";
		document.getElementById("productImage"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productImageDisplay"+productId).style.display = "none";
		document.getElementById("productDescEdit"+productId).style.display = "block";
		document.getElementById("productDesc"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productDescDisplay"+productId).style.display = "none";
		document.getElementById("productPriceEdit"+productId).style.display = "block";
		document.getElementById("productPrice"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productPriceDisplay"+productId).style.display = "none";
		document.getElementById("productStockEdit"+productId).style.display = "block";
		document.getElementById("productStock"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productStockDisplay"+productId).style.display = "none";
		document.getElementById("productLengthEdit"+productId).style.display = "block";
		document.getElementById("productLength"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productLengthDisplay"+productId).style.display = "none";
		document.getElementById("productWeightEdit"+productId).style.display = "block";
		document.getElementById("productWeight"+productId).style.backgroundColor = "#15A9C8";
		document.getElementById("productWeightDisplay"+productId).style.display = "none";
	}
	else if(document.getElementById("productNameDisplay"+productId).style.display == "none")
	{
		document.getElementById("productEditOption"+productId).style.display = "block";
		document.getElementById("productUpdateOption"+productId).style.display = "none";
		document.getElementById("productNameEdit"+productId).style.display = "none";
		document.getElementById("productNameDisplay"+productId).style.display = "block";
		document.getElementById("productImageEdit"+productId).style.display = "none";
		document.getElementById("productImageDisplay"+productId).style.display = "block";
		document.getElementById("productDescEdit"+productId).style.display = "none";
		document.getElementById("productDescDisplay"+productId).style.display = "block";
		document.getElementById("productPriceEdit"+productId).style.display = "none";
		document.getElementById("productPriceDisplay"+productId).style.display = "block";
		document.getElementById("productStockEdit"+productId).style.display = "none";
		document.getElementById("productStockDisplay"+productId).style.display = "block";
		document.getElementById("productLengthEdit"+productId).style.display = "none";
		document.getElementById("productLengthDisplay"+productId).style.display = "block";
		document.getElementById("productWeightEdit"+productId).style.display = "none";
		document.getElementById("productWeightDisplay"+productId).style.display = "block";
	}
}

// End - Function to display edit form in list Products Page - Admin Page

// Begin - Update Products - Admin Page

function updateProductsAdmin(pProductId)
{
	var productId = pProductId;
	document.forms["productsEditForm"+productId].submit();
	//document.getElementById("post").value = 0;
	//alert(document.getElementById("post").value);
}

// End - Update Products - Admin Page

// Begin - Change Background of a row in list of products - Admin Page

function changeBackGround(pProductId)
{
	var productId = pProductId;
	var productCategories = ["productName","productImage","productDesc","productPrice","productStock","productLength","productWeight","productType","productImage","productThumb","productManu","productColor","productColorTab1","productColorTab2","productColorTab3","productL","producta","productb","producth","productc","producthex","productMakeup","productAvailStock","productBasketStock","productStock","productLength","productWeight","productPrice","productInSite1","productInSite2","productInSite3","productExSite1","productExSite2","productExSite3"];
	//alert(document.getElementById("productRow" + productId).bgColor);
	if((document.getElementById("productRow" + productId).bgColor == "#B1E3E9") || (document.getElementById("productRow" + productId).bgColor == "#b1e3e9"))
	{
		document.getElementById("productRow" + productId).bgColor = "#FFFFFF";
		for(var i = 0; i < productCategories.length; i++)
		{
			document.getElementById(productCategories[i]+productId).style.backgroundColor = "#FFFFFF";
		}
	}
	else 
	{
		document.getElementById("productRow" + productId).bgColor = "#B1E3E9";
		for(var i = 0; i < productCategories.length; i++)
		{
			document.getElementById(productCategories[i]+productId).style.backgroundColor = "#B1E3E9";
		}
	}
}

// End - Change Background of a row in list of products - Admin Page

// Begin - Deselect row in a list of products - Admin Page

function changeProductType(pNewType)
{
	var newType = pNewType;
	//alert(newType);
	var checkBoxes = document.getElementsByClassName("check");
	var selected = "";
	for(var checkLoop = 0; checkLoop < checkBoxes.length; checkLoop++)
	{
		if(checkBoxes[checkLoop].checked == true)
		{
			var productIds = checkBoxes[checkLoop].name.split("productEditCheck");
			selected = selected + productIds[1] + ",";
		}
	}
	//alert(selected);
	updateProductType(selected,newType);
}

// Begin - Deselect row in a list of products - Admin Page

// Begin - Deselect row in a list of products - Admin Page

function deselectValues(pProductId)
{
	var productId = pProductId;
	//alert(document.getElementById("productName" + productId).style.backgroundColor);
	//if((document.getElementById("productName" + productId).style.backgroundColor == "#15A9C8") || (document.getElementById("productName" + productId).style.backgroundColor == "#15a9c8"))
	//{
		document.getElementById("productName" + productId).style.backgroundColor = "white";
		document.getElementById("productImage"+productId).style.backgroundColor = "white";
		document.getElementById("productDesc"+productId).style.backgroundColor = "white";
		document.getElementById("productPrice"+productId).style.backgroundColor = "white";
		document.getElementById("productStock"+productId).style.backgroundColor = "white";
		document.getElementById("productLength"+productId).style.backgroundColor = "white";
		document.getElementById("productWeight"+productId).style.backgroundColor = "white";
	//}
}

// End - Deselect row in a list of products - Admin Page

// Begin - Get Elements by class name

var getElementsByClassName = function (className, tag, elm){
    if (document.getElementsByClassName) {
        getElementsByClassName = function (className, tag, elm) {
            elm = elm || document;
            var elements = elm.getElementsByClassName(className),
                nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                returnElements = [],
                current;
            for(var i=0, il=elements.length; i<il; i+=1){
                current = elements[i];
                if(!nodeName || nodeName.test(current.nodeName)) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    else if (document.evaluate) {
        getElementsByClassName = function (className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = "",
                xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
                returnElements = [],
                elements,
                node;
            for(var j=0, jl=classes.length; j<jl; j+=1){
                classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
            }
            try    {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
            }
            catch (e) {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
            }
            while ((node = elements.iterateNext())) {
                returnElements.push(node);
            }
            return returnElements;
        };
    }
    else {
        getElementsByClassName = function (className, tag, elm) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = [],
                elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
                current,
                returnElements = [],
                match;
            for(var k=0, kl=classes.length; k<kl; k+=1){
                classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
            }
            for(var l=0, ll=elements.length; l<ll; l+=1){
                current = elements[l];
                match = false;
                for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
                    match = classesToCheck[m].test(current.className);
                    if (!match) {
                        break;
                    }
                }
                if (match) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    return getElementsByClassName(className, tag, elm);
};
   
// End - Get Elements by class name

// Begin - Select Check box if the product edited in a list of products - Admin Page
var selectedProductsValue = "";
function selectCheckBox(pProductId)
{
	var productId = pProductId;
	var selectedProducts = document.getElementById("checkedProducts").value;
	var values = selectedProducts.split(",");
	var arrayCheck = 0;
	for(var i=0; i< selectedProducts.length;i++)
	{
		if(values[i] == productId)
			arrayCheck++;
	}
	document.getElementById("productEditCheck" + productId).checked = "true";
	//
	selectedProductsValue += document.getElementById("productEditCheck" + productId).value +",";
	//
	if(arrayCheck == 0)
	{
		if(selectedProducts != "")
			document.getElementById("checkedProducts").value = selectedProducts + productId + "," ;
		else
			document.getElementById("checkedProducts").value = productId + ",";
	}
	if(document.getElementById("updateOptionsDiv").style.display == "none")
		document.getElementById("updateOptionsDiv").style.display = "block";
		
}

// End - Select Check box if the product edited in a list of products - Admin Page

// Begin - Display Edit and delete options div - Admin Page

function displayUpdateOptions(pProductId)
{
	if(document.getElementById("updateOptionsDiv").style.display == "none")
	{
		document.getElementById("updateOptionsDiv").style.display = "block";
	}
	var productId = pProductId;
	var selectedProducts = document.getElementById("checkedProducts").value;
	var values = selectedProducts.split(",");
	var arrayCheck = 0;
	for(var i=0; i< selectedProducts.length;i++)
	{
		if(values[i] == productId)
			arrayCheck++;
	}
	if(arrayCheck == 0)
	{
		if(selectedProducts != "")
			document.getElementById("checkedProducts").value = selectedProducts + productId + "," ;
		else
			document.getElementById("checkedProducts").value = productId + ",";
	}
}

// End - Display Edit and delete options div - Admin Page

// Begin - Form submit of update Products - Admin Page

function submitForm(pUpdateType)
{
	var updateType = pUpdateType;
	var Err =0;
	document.getElementById("updateType").value = updateType;

	tempProductsValue = selectedProductsValue.substring(0,selectedProductsValue.length-1);
	var temp = tempProductsValue.split(",");
	for(var i=0;i<temp.length;i++){
		//alert(document.getElementById("productStock" + temp[i] ).value);
		//var productColor = document.getElementById("productColor" + temp[i] ).value;
		//var productType = document.getElementById("productType" + temp[i]).value;
		//var productStock = document.getElementById("productStock" + temp[i]).value;
		//if(productColor.length == 0) Err++;
		//if(productType == 0) Err++;
		//if(productStock.length == 0) Err++;
		
	}
	if(Err)
		alert("Require field should not be empty");
	else
		document.forms["productsEditForm"].submit();

	//document.forms["productsEditForm"].submit();
	//document.getElementById("post").value = 0;
	//alert(document.getElementById("post").value);
}

// End - Form submit of update Products - Admin Page

// Begin - Display Search products div - Admin Page

function displaySearch()
{
	if(document.getElementById("searchForProducts").style.display == "none")
	{
		document.getElementById("searchForProducts").style.display = "block";
		document.getElementById("searchLink").style.display = "none"
	}
	else
	{
		document.getElementById("searchForProducts").style.display = "none";
		document.getElementById("searchLink").style.display = "block"
	}
}

// End - Display Search products div - Admin Page


// Begin - Display text in cost per kg - Admin Page

function displayCostPerKg()
{
	if(document.getElementById("costPer").value == "kg")
	{
		document.getElementById("costPer").value = "";
	}
	else if(document.getElementById("costPer").value == 0)
	{
		document.getElementById("costPer").value = "kg";
	}
}

// End - Display text in cost per kg - Admin Page


// Begin - Custom search for products - Products Page

function removeFilter(pFilterType, pRemoveColor)
{
	var orderBy = document.sortProducts.orderBy.value;
	var searchKey = document.sortProducts.searchKey.value;
	var searchOption = document.sortProducts.searchOption.value;
	var view = document.sortProducts.view.value;
	var dateFilter = document.sortProducts.dateFilter.value;
	var filterDate = "";
	if(dateFilter != 0)
	{
		var startDate = document.getElementById("startDate").value;
		var endDate = document.getElementById("endDate").value;
		filterDate = dateFilter + "$" + startDate + "$" + endDate;
	}
	else
		filterDate = 0;
	var filterElements = document.sortProducts.filterElements.value;
	var filterOptions = document.sortProducts.filterOptions.value;
	var filterType = pFilterType;
	var removeColor = pRemoveColor ;
	if(filterType == "productType")
	{
		filterOptions = "";
		filterElements = "";
		var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
		var lengthOptions = oldFilterOptions.length;
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0){
				var str = new RegExp("[@]?"+pRemoveColor+"");
				$temp = document.getElementById('productType').value.replace(str,"");
				if($temp){
					filterOptions = "1";
				}
				else
					filterOptions = "0";
			}
			else
				filterOptions = filterOptions + "@" + oldFilterOptions[loop];
		}
		var oldFilterElements = document.sortProducts.filterElements.value.split(",");
		var lengthElements = oldFilterElements.length;
		for(var loop = 0; loop < lengthElements; loop++)
		{
			if(loop == 0){
				var str = new RegExp("[@]?"+pRemoveColor+"");
				filterElements = document.getElementById('productType').value.replace(str,"");
				//filterElements = "";
			}
			else
				filterElements = filterElements + "," + oldFilterElements[loop];
		}
	}
	else if(filterType == "manufacturer")
	{
		filterOptions = "";
		filterElements = "";
		var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
		var lengthOptions = oldFilterOptions.length;
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0)
			{
				filterOptions = oldFilterOptions[loop];
			}
			else
			{
				if(loop == 1){
					var str = new RegExp("[@]?"+pRemoveColor+"");
					temp = document.getElementById('manufacturer').value.replace(str,"");
					if(temp){
						filterOptions = filterOptions + "@1";
					}
					else{
						filterOptions = filterOptions + "@0";
					}
				}
				else
					filterOptions = filterOptions + "@" + oldFilterOptions[loop];
			}
		}
		var oldFilterElements = document.sortProducts.filterElements.value.split(",");
		var lengthElements = oldFilterElements.length;
		for(var loop = 0; loop < lengthElements; loop++)
		{
			if(loop == 0)
			{
				filterElements = oldFilterElements[loop];
			}
			else
			{
				if(loop == 1){
					var str = new RegExp("[@]?"+pRemoveColor+"");
					//filterElements = filterElements + ",";
					filterElements += document.getElementById('manufacturer').value.replace(str,"") + ",";
				}
				else
					filterElements = filterElements + "," + oldFilterElements[loop];
			}
			//alert(filterElements);
		}
	}
	else if(filterType == "yarnCountName")
	{
		filterOptions = "";
		filterElements = "";
		var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
		var lengthOptions = oldFilterOptions.length;
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0)
			{
				filterOptions = oldFilterOptions[loop];
			}
			else
			{
				if(loop == 2)
					filterOptions = filterOptions + "@0";
				else
					filterOptions = filterOptions + "@" + oldFilterOptions[loop];
			}
		}
		var oldFilterElements = document.sortProducts.filterElements.value.split(",");
		var lengthElements = oldFilterElements.length;
		for(var loop = 0; loop < lengthElements; loop++)
		{
			if(loop == 0)
			{
				filterElements = oldFilterElements[loop];
			}
			else
			{
				if(loop == 2)
					filterElements = filterElements + ",";
				else
					filterElements = filterElements + "," + oldFilterElements[loop];
			}
		}
	}
	else if(filterType == "totalYarnCount")
	{
		filterOptions = "";
		filterElements = "";
		var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
		var lengthOptions = oldFilterOptions.length;
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0)
			{
				filterOptions = oldFilterOptions[loop];
			}
			else
			{
				if(loop == 3){
					var str = new RegExp("[@]?"+pRemoveColor);
					temp = document.getElementById('totalYarnCount').value.replace(str,"");
					if(temp){
						filterOptions = filterOptions + "@1";
					}
					else{
						filterOptions = filterOptions + "@0";
					}
				}
				else
					filterOptions = filterOptions + "@" + oldFilterOptions[loop];
			}
		}
		var oldFilterElements = document.sortProducts.filterElements.value.split(",");
		var lengthElements = oldFilterElements.length;
		for(var loop = 0; loop < lengthElements; loop++)
		{
			if(loop == 0)
			{
				filterElements = oldFilterElements[loop];
			}
			else
			{
				if(loop == 3){
					var str = new RegExp("[@]?"+pRemoveColor);
					filterElements = filterElements + ",";
					filterElements += document.getElementById('totalYarnCount').value.replace(str,"") ;
					//filterElements = filterElements + ",";
				}
				else
					filterElements = filterElements + "," + oldFilterElements[loop];
			}
		}
	}
	else if(filterType == "fibre")
	{
		filterOptions = "";
		filterElements = "";
		//
		var oldFiberElements = document.sortProducts.filterElements.value.split(",");
		var tempFiberElements = oldFiberElements[4];
		var oldFiberElements = oldFiberElements[4].split("@");
		var oldFiberElementsLength =  oldFiberElements.length;
		//alert(oldFiberElementsLength);
		if(oldFiberElementsLength > 1 ){
			if(pRemoveColor != 0){
				var str = new RegExp("[@]?"+pRemoveColor);
				//var temp =  "@" + oldFiberElements[pRemoveColor];
				//tempFiberElements = tempFiberElements.replace(temp,'');
				tempFiberElements = tempFiberElements.replace(str,'');
			}
			else{
				var str = new RegExp("[@]?"+pRemoveColor);
				//var temp =  oldFiberElements[pRemoveColor] + "@";
				//tempFiberElements = tempFiberElements.replace(temp,'');
				tempFiberElements = tempFiberElements.replace(str,'');
			}
			//
			var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
			var lengthOptions = oldFilterOptions.length;
			for(var loop = 0; loop < lengthOptions; loop++)
			{
				if(loop == 0)
				{
					filterOptions = oldFilterOptions[loop];
				}
				else
				{
					if(loop == 4){
						if(tempFiberElements)
							filterOptions = filterOptions + "@" + oldFilterOptions[loop];
						else
							filterOptions = filterOptions + "@0";
					}
					else
						filterOptions = filterOptions + "@" + oldFilterOptions[loop];
				}
			}
			//
			var oldFilterElements = document.sortProducts.filterElements.value.split(",");
			var lengthElements = oldFilterElements.length;
			for(var loop = 0; loop < lengthElements; loop++)
			{
				if(loop == 0)
				{
					filterElements = oldFilterElements[loop];
				}
				else
				{
					if(loop == 4)
						filterElements = filterElements + "," + tempFiberElements;
					else
						filterElements = filterElements + "," + oldFilterElements[loop];
				}
			}
			//
		}
		else{
		//
			var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
			var lengthOptions = oldFilterOptions.length;
			for(var loop = 0; loop < lengthOptions; loop++)
			{
				if(loop == 0)
				{
					filterOptions = oldFilterOptions[loop];
				}
				else
				{
					
					if(loop == 4){
						filterOptions = filterOptions + "@0";
					}
					else
						filterOptions = filterOptions + "@" + oldFilterOptions[loop];
				}
			}
			var oldFilterElements = document.sortProducts.filterElements.value.split(",");
			var lengthElements = oldFilterElements.length;
			for(var loop = 0; loop < lengthElements; loop++)
			{
				if(loop == 0)
				{
					filterElements = oldFilterElements[loop];
				}
				else
				{
					if(loop == 4)
						filterElements = filterElements + ",";
					else
						filterElements = filterElements + "," + oldFilterElements[loop];
				}
			}
		}
	}
	else if(filterType == "color")
	{
		filterOptions = "";
		filterElements = "";
		var oldFilterElements = document.sortProducts.filterElements.value.split(",");
		var lengthElements = oldFilterElements.length;
		for(var loop = 0; loop < lengthElements; loop++)
		{
			if(loop == 0)
			{
				filterElements = oldFilterElements[loop];
			}
			else
			{
				if(loop == 5)
				{
					var newColor = "";
					var color = oldFilterElements[loop].split("nextCol");
					var lenColor = color.length;
					if(lenColor > 1)
					{
						for(var i = 0; i < lenColor; i++)
						{
							if(removeColor != color[i])
							{
								if(i == 0)
									newColor = color[i];	
								else
									newColor = newColor + "nextCol" + color[i];
							}
						}
					}
					else
						newColor = "";
					filterElements = filterElements + "," + newColor;
				}
				else
					filterElements = filterElements + "," + oldFilterElements[loop];
			}
		}
		//alert(lenColor);
		var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
		var lengthOptions = oldFilterOptions.length;
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0)
			{
				filterOptions = oldFilterOptions[loop];
			}
			else
			{
				if(loop == 5)
				{
					if(newColor == "") 
						filterOptions = filterOptions + "@0";
					else
						filterOptions = filterOptions + "@1";
				}
				else
					filterOptions = filterOptions + "@" + oldFilterOptions[loop];
			}
		}
	}
	else if(filterType == "date")
	{
		filterDate = 0;
	}
	else if(filterType == "search")
	{
		searchOption = 0;
		searchKey = "";
	}
	//alert(filterOptions);
	//alert(filterElements);
	window.location = 'rootProducts?orderBy='+ orderBy +'&searchKey='+ searchKey +'&searchOption='+searchOption+'&view='+view+'&filterElements='+filterElements+'&filterOptions='+filterOptions+'&dateFilter='+filterDate;
}

// End - Custom search for products - Products Page

// Begin - Change Search Option value - Products Page

function changeSearchOption()
{
	//document.getElementById("searchOption").value = "1";
	document.getElementById("searchOption").value = "1";
	if(document.getElementById("choice1").checked)
		document.getElementById("searchOption").value = "1";
	if(document.getElementById("choice2").checked)
		document.getElementById("searchOption").value = "2";
	if(document.getElementById("choice3").checked)
		document.getElementById("searchOption").value = "3";
}

// End - Change Search Option value - Products Page

// Begin - Functions to show and hide div in add search contents - Admin page

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var imageName = document.getElementById("image"+numericId).src.split("/");
	imageName.reverse();
	//alert(imageName[0]);
	if(imageName[0] == "minusContents.png")
	{
		document.getElementById("image"+numericId).src = "../images/addContents.png";
	}
	else
	{
		document.getElementById("image"+numericId).src = "../images/minusContents.png";
	}
	//alert(numericId);
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}
//window.onload = initShowHideDivs;
// End - Functions to show and hide div in add search contents - Admin page

// Begin - Function to show and hide color palettes div

function showColorPalettesDiv()
{
	if(document.getElementById("popUpColor").style.display == "block")
	{
		document.getElementById("popUpColor").style.display = "none";
	}
	else
	{
		document.getElementById("popUpColor").style.display = "block";
	}
}

// End - Function to show and hide color palettes div


// Begin - Color search for products - Products Page

function colorSearchProducts(pColor)
{
	var orderBy = document.getElementById("orderBy").value;
	var searchKey = document.getElementById("searchKey").value;
	var searchOption = document.getElementById("searchOption").value;
	var view = document.getElementById("view").value;
	var dateFilter = "0";
	var filterDate = "";
	if(dateFilter != 0)
	{
		var startDate = document.getElementById("startDate").value;
		var endDate = document.getElementById("endDate").value;
		filterDate = dateFilter + "$" + startDate + "$" + endDate;
	}
	else
		filterDate = 0;
	var filterElements = document.sortProducts.filterElements.value;
	var filterOptions = document.sortProducts.filterOptions.value;
	var color = pColor;
	filterOptions = "";
	filterElements = "";
	var oldFilterOptions = document.sortProducts.filterOptions.value.split("@");
	var lengthOptions = oldFilterOptions.length;
	if(oldFilterOptions[5] != 1)
	{
		for(var loop = 0; loop < lengthOptions; loop++)
		{
			if(loop == 0)
			{
				filterOptions = oldFilterOptions[loop];
			}
			else
			{
				if(loop == 5)
					filterOptions = filterOptions + "@1";
				else
					filterOptions = filterOptions + "@" + oldFilterOptions[loop];
			}
		}
	}
	else
		filterOptions = document.sortProducts.filterOptions.value;
	var oldFilterElements = document.sortProducts.filterElements.value.split(",");
	var lengthElements = oldFilterElements.length;
	for(var loop = 0; loop < lengthElements; loop++)
	{
		if(loop == 0)
		{
			filterElements = oldFilterElements[loop];
		}
		else
		{
			if(loop == 5)
			{
				if(oldFilterOptions[5] != 1)
					filterElements = filterElements + "," + color;
				else
				{
					color =  oldFilterElements[5] + "nextCol" + color;
					filterElements = filterElements + "," + color;
				}
			}
			else
				filterElements = filterElements + "," + oldFilterElements[loop];
		}
	}
	//
	if(trim(document.getElementById('searchName').value).length != 0 ){
		searchName = "&searchName=" + document.getElementById('searchName').value;
	}
	if(trim(document.getElementById('editSearch').value).length != 0 ){
		editSearch = "&editSearch=" + document.getElementById('editSearch').value;
	}
	//
	//alert(filterElements);
	//alert(filterOptions);
	window.location = 'rootProducts?orderBy='+ orderBy +'&searchKey='+ searchKey +'&searchOption='+searchOption+'&view='+view+'&filterElements='+filterElements+'&filterOptions='+filterOptions+'&dateFilter='+filterDate + searchName + editSearch;
}

// End - Custom search for products - Products Page

// Begin - Color search for products - Products Page

function filterDate()
{
	if((document.getElementById("startDate").value == 0) && (document.getElementById("endDate").value == 0))
	{
		alert("Enter both start and end date to filter.");
	}
	else
	{
	var orderBy = document.sortProducts.orderBy.value;
	var searchKey = document.sortProducts.searchKey.value;
	var searchOption = document.sortProducts.searchOption.value;
	var view = document.sortProducts.view.value;
	var filterElements = document.sortProducts.filterElements.value;
	var filterOptions = document.sortProducts.filterOptions.value;
	var startDate = document.getElementById("startDate").value.split("-");
	var endDate = document.getElementById("endDate").value.split("-");
	var newStartDate = startDate[2] + "-" + startDate[1] + "-" + startDate[0];
	var newEndDate = endDate[2] + "-" + endDate[1] + "-" + endDate[0];
	var filterDate = "1" + "$" + newStartDate + "$" + newEndDate;
	//alert(filterElements);
	//alert(filterOptions);
	window.location = 'rootProducts?filterByDate&orderBy='+ orderBy +'&searchKey='+ searchKey +'&searchOption='+searchOption+'&view='+view+'&filterElements='+filterElements+'&filterOptions='+filterOptions+'&dateFilter='+filterDate;
	}
}

// End - Custom search for products - Products Page

// Begin - Function to display Options in Check out page

function displayPlies(pType, pId)
{
	var type = pType;
	var id = pId;
	if(document.getElementById(type+"Yes"+id).checked == true)
		document.getElementById(type+"PliesSpan"+id).style.visibility = "visible";
	else
		document.getElementById(type+"PliesSpan"+id).style.visibility = "hidden";
}

// End - Function to display Options in Check out page

// Begin - Print different type of orders - Admin Page  - XMLHttpRequest

function printOptions(pStatus)
{
	if(pStatus != 0)
	{
		var status = pStatus;
		var url = "printOrders.php";
		url = url + "?ordersPrint&status="+status;
		//window.location = url;
		window.open(url,"","width=800,height=700,status=yes,toolbar=no,menubar=no")
		document.getElementById("printingOptions").selectedIndex = 0;
		//alert(url);
	}
}

// End - Print different type of orders - Admin Page  - XMLHttpRequest


// Begin - Print different type of orders - Admin Page  - XMLHttpRequest

function printConeOptions(pStatus)
{
	if(pStatus != 0)
	{
		var status = pStatus;
		var url = "conePrintOutMultiple.php";
		url = url + "?printCone&status="+status;
		//window.location = url;
		window.open(url,'','width=800,height=700,status=1,toolbar=0,menubar=0,scrollbars=1')
		document.getElementById("printingCone").selectedIndex = 0;
		//alert(url);
	}
}

// End - Print different type of orders - Admin Page  - XMLHttpRequest

// Begin - Function to display Options in Check out page

function showPurchasesStatusList(pOrderId)
{
	var orderId = pOrderId;
	if(document.getElementById("statusChangeDiv"+orderId).style.display == "none")
	{
		document.getElementById("statusChangeDiv"+orderId).style.display = "block";
		document.getElementById("showPurchaseStatus"+orderId).style.display = "none";
	}
	else
	{
		document.getElementById("statusChangeDiv"+orderId).style.display = "none";
		document.getElementById("showPurchaseStatus"+orderId).style.display = "block";
	}
}

// End - Function to display Options in Check out page

// Begin - Function to take print out product Type

function printProductType()
{
	var productType = document.getElementById("productType").value;
	var numberPrint = document.getElementById("numberPrint").value;
	if(productType != 0 && numberPrint != 0)
	{
		//window.location='productTypePrintOut.php?productTypeId='+productType+'&numberPrint='+numberPrint;
		window.open('productTypePrintOut.php?productTypeId='+productType+'&numberPrint='+numberPrint,"","width=800,height=700,status=yes,toolbar=no,menubar=no");
	}
	else
	{
		if(productType == 0)
			alert("Select Product type to Proceed");
		else if(numberPrint == 0)
			alert("Select Number of Prints to Proceed");
		
	}
		
}

// End - Function to take print out product Type

// Begin - Function to take print out Cone Labels

function coneLabelPrint(pOrderId)
{
	var orderId = pOrderId;
	//window.location = 'coneLabelPrint?orderId='+orderId;
	window.open('conePrintOutInd?orderId='+orderId,"","width=800,height=700,status=1,toolbar=0,menubar=0,scrollbars=1");
}

// End - Function to take print out Cone Labels

// Begin - Function to dislay form to add new shipping address

function addShippingAddr(pType)
{
	var type = pType;
	var numExistAddress = document.getElementById("numExistAddr").value;
	for(var i = 1; i<=numExistAddress; i++)
	{
		document.getElementById("existShippingAddress"+i).style.display = "none";
	}
	if(numExistAddress > 0)
		document.getElementById("existAddrLink").style.display = "block";
	if(type == "new")
	{
		document.getElementById("shippingAdrress").style.display = "none";
		document.getElementById("addLink").style.display = "none";
		document.getElementById("defaultLink").style.display = "block";
		document.getElementById("newShippingAddress").style.display = "block";
		document.getElementById("shippingAddressChange").value = 1;
	}
	else if(type == "default")
	{
		document.getElementById("shippingAdrress").style.display = "block";
		document.getElementById("newShippingAddress").style.display = "none";
		document.getElementById("addLink").style.display = "block";
		document.getElementById("defaultLink").style.display = "none";
		document.getElementById("shippingAddressChange").value = 1;
	}
}

// End - Function to dislay form to add new shipping address


// Begin - Function to dislay already existing shipping address

function showExistShippingAddr(pNumAddress, pType)
{
	var numAddress = pNumAddress;
	var type = pType;
	document.getElementById("newShippingAddress").style.display = "none";
	if(type == "exist")
	{
		for(var i = 1; i<=numAddress; i++)
		{
			document.getElementById("existShippingAddress"+i).style.display = "block";
		}
		document.getElementById("existAddrLink").style.display = "none";
		document.getElementById("shippingAdrress").style.display = "none";
		document.getElementById("addLink").style.display = "block";
		document.getElementById("defaultLink").style.display = "block";
		document.getElementById("shippingAddressChange").value = 2;
		var initialAddressId = document.getElementById("initialAddressId").value;
		document.getElementById("addressId").value = initialAddressId;
	}
	/*else
	{
		document.getElementById("shippingAdrress").style.display = "block";
		document.getElementById("addLink").style.display = "none";
		document.getElementById("defaultLink").style.display = "block";
		for(var i = 1; i<=numAddress; i++)
		{
			document.getElementById("existShippingAddress"+i).style.display = "none";
		}
		document.getElementById("shippingAddressChange").value = 0;
		document.getElementById("existAddrLink").style.display = "block";
	}*/
}

// End - Function to dislay already existing shipping address


// Begin - Function to put selected address Id

function selectedAddress(pAddressId)
{
	var addressId = pAddressId;
	document.getElementById("addressId").value = addressId;
}

// End - Function to put selected address Id



// Begin - Hide/View search criteria

function dispSearchCriteria()
{
	var dispSearchCriteria = document.getElementById('dispSearchCriteria');
	
	if(dispSearchCriteria.style.display == 'none')
		dispSearchCriteria.style.display = 'block';
	else
		dispSearchCriteria.style.display = 'none';
}

// End - Hide/View search criteria
var queryString = '';
//
var orderBy='';
var	userView='';
var productTypeList ='';
var manufacturerList = '';
var yarnCountNameList = '';
var totalYarnCount = '';
var fibre = '';
var i=0;
var filterOptions = Array("0","0","0","0","0","0");
var filterElements = Array("","","","","","");
var filterOptionsStr ='';
var filterElmentsStr ='';
var locationSearch = '';
var searchChange = '';
var manufacturerName = '';
var searchOption = 0;
var searchKey = "";
var searchName = "";
var editSearch = "";

var gotoPage = "";
var lastPage = 0;
var incMin = 0 ; 
var incMax = 0 ;

//
function storeSearch(pName,pVal)
{
	//alert("kan");
	if(pName== "gotoPage"){
		lastPage = document.getElementById('lastPage').value;
		if(!isNaN(pVal)){
			if(pVal > lastPage){
				for(i=1;i<=lastPage;i+=3){
					if(i==pVal){
						incMax = i + 3 ;
						incMin = i - 3 ;
						gotoPage = "&pagenum="+ pVal +"&incMax=" + incMax + "&incMin=" + incMin + "&f=" + pVal  ;
						break;
					}
					if(pVal < i){
						incMax = parseInt(pVal) + (parseInt(i) - parseInt(pVal))  ;
						incMin = parseInt(pVal) - (parseInt(i) - parseInt(pVal)) ;
						gotoPage = "&pagenum="+ pVal +"&incMax=" + incMax + "&incMin=" + incMin   ;
						break;
					}
				}
				
			}
			if(pVal == 1){
						incMax = pVal + 4  ;
						incMin = 0;
						gotoPage = "&pagenum="+ pVal +"&incMax=" + incMax + "&incMin=" + incMin + "&f=" + pVal ;
			}
			if(pVal == lastPage){
						incMax =  pVal ;
						incMin = 0;
						gotoPage = "&pagenum="+ pVal +"&incMax=" + pVal + "&incMin=" + incMin + "&f=" + pVal ;
			}	
			if(pVal == lastPage-1){
						incMax =  lastPage ;
						incMin = lastPage - 2;
						gotoPage = "&pagenum="+ pVal +"&incMax=" + pVal + "&incMin=" + incMin ;
			}	
		}
		else{
			alert("Please enter numbers only");
			return false;
		}
	}
	if(pName=="orderBy"){
		orderBy = "&orderBy=" + pVal;
		i++;
	}
	else{
		orderBy = "&orderBy=" + document.getElementById('orderBy').value;
	}
	if(pName=="pageLimits"){
		pageLimits = "&pageLimits=" + pVal;
		i++;
	}
	else{
		pageLimits =  "&pageLimits="+document.getElementById('pageLimits').value;
	}
	if(pName=="userView"){
		userView = "&view=" + pVal;
		i++;
	}
	if(pName=="productTypeList"){
		tProduct = trim(document.getElementById('productType').value);
		if(tProduct.length != 0 ){
			pVal = pVal+ "@" + tProduct ;
		}
		productTypeList = "&productType=" + pVal;
		searchChange = searchChange + "&changeProductType";
		i++;
	}
	if(pName=="manufacturerList"){
		//
		tManufacturer = trim(document.getElementById('manufacturer').value);
		if(tManufacturer.length != 0 ){
			pVal = pVal+ "@" + tManufacturer ;
		}
		//
		manufacturerList = '&manufacturer=' + pVal;
		searchChange = searchChange + '&changeManufacturer';
		filterOptions[1] = "1";filterElements[1] = "1";
		manufacturerName = pVal;
		i++;
	}
	if(pName=="yarnCountNameList"){
		yarnCountNameList = "&yarnCountName=" + pVal;
		searchChange = searchChange + "&changeYarnCountName";
		filterOptions[1] = "1";filterElements[1] = "1";
		i++;
	}
	if(pName=="totalYarnCount"){
		//
		tTotalYarnCount = trim(document.getElementById('totalYarnCount').value);
		if(tTotalYarnCount.length != 0 ){
			pVal = pVal+ "@" + tTotalYarnCount ;
		}
		//
		totalYarnCount = "&totalYarnCount=" + pVal;
		searchChange = searchChange + "&changeTotalYarnCount" ;
		filterOptions[3] = "1";filterElements[3] = "1";
		i++;
	}
	if(pName=="fibre"){
		/*var selFibre = '';
		for(var x = 0; x < pVal.length ; x++){
			if(pVal[x].selected){
				selFibre = selFibre + String(pVal[x].value) + "@" ;
			}
		}*/
		/*selFibre = selFibre.substr(0,selFibre.length-1);*/
		
		//fibre = "&fibre=" + selFibre;
		//
		tFibreName = trim(document.getElementById('fibreName').value);
		if(tFibreName.length != 0 ){
			pVal = pVal+ "@" + tFibreName ;
		}
		//
		fibre = "&fibre=" + pVal;
		searchChange = searchChange + "&changeFibre" ;
		filterOptions[4] = "1";filterElements[4] = "1";
		i++;
	} 
	if(document.getElementById('searchKey').value.length != 0){
			searchOption = "1";
		if(document.getElementById("choice2").checked)
			searchOption = "2";
		if(document.getElementById("choice3").checked)
			searchOption = "3";
	}
	//
	if(trim(document.getElementById('searchName').value).length != 0 ){
		searchName = "&searchName=" + document.getElementById('searchName').value;
	}
	if(trim(document.getElementById('editSearch').value).length != 0 ){
		editSearch = "&editSearch=" + document.getElementById('editSearch').value;
	}
	//
	if(document.getElementById('filterOptions').value=="0@0@0@0@0@0"){
		filterOptionsStr =  filterOptions[0] + "@" + filterOptions[1] + "@" + filterOptions[2] + "@" + filterOptions[3] + "@" + filterOptions[4] + "@" + filterOptions[5] ;
	}
	else{
		filterOptionsStr = document.getElementById('filterOptions').value;
	}
	if(document.getElementById('filterElements').value==",,,,,"){
		filterElmentsStr = filterElements[0] + "," + filterElements[1] + "," + filterElements[2] + "," + filterElements[3] + "," + filterElements[4] + "," + filterElements[5] ;
	}
	else{
		filterElmentsStr = document.getElementById('filterElements').value;
	}
		if(i==0){
			locationSearch = "rootProducts?sortProducts&orderBy=" + document.sortProducts.orderBy.value + "&searchOption="+searchOption + "&searchKey="+document.getElementById("searchKey").value + "&view="+document.sortProducts.view.value +"&filterOptions=" + filterOptionsStr + "&filterElements="+filterElmentsStr + searchName + editSearch ;
		}
		else{
			queryString =  orderBy +  userView +  productTypeList + manufacturerList + yarnCountNameList + totalYarnCount + fibre + searchChange;
			locationSearch = "rootProducts?searchOption="+searchOption+"&sortProducts" + "&searchKey="+ document.getElementById("searchKey").value + "&view=" + document.sortProducts.view.value + "&filterOptions="+ filterOptionsStr + "&filterElements=" + filterElmentsStr + queryString + pageLimits + searchName + editSearch ;
		}
		
	if(pName=='gotoPage'){	
		window.location = locationSearch + gotoPage ;	
	}
	if(pName=='submit'|| pName=='orderBy' || pName=='userView' || pName == 'productTypeList' || pName == 'manufacturerList' || pName == 'fibre' || pName == 'totalYarnCount'  || pName == 'pageLimits' ||  pName == 'searchKey'  ){
		window.location = locationSearch;
	}
	
}
function changeColor(str)
{
	var i = parseInt(str);
	for(c=1;c<=i;c++){
		document.getElementById(c).style.backgroundColor = "#096";
	}
	document.getElementById('displayProgress').innerHTML = i * 10 + "%";
}
function changeColor1(str)
{
	var i = parseInt(str);
	for(c=1;c<=i;c++){
		document.getElementById(c).style.backgroundColor = "#999999";
	}
	document.getElementById('displayProgress').innerHTML = i * 10 + "%";
}
function defaultColor()
{
	var i = parseInt(document.getElementById('progressVal').value);
	for(c=1;c<=i;c++){
		document.getElementById(c).style.backgroundColor = "#096";
	}
	document.getElementById('displayProgress').innerHTML = i * 10 + "%";
}
function setProgress(str)
{
	document.getElementById('progressVal').value=parseInt(str);
	projectId = document.getElementById('projectId').value;
	xmlHttp = GetXmlHttpObject();
	var result = parseInt(str) * 10;
	url = "jsMyColourmart.php";
	url = url + "?ChangeProjectProgress&result=" + result +"&projectId="+ projectId  ;
	xmlHttp.onreadystatechange = deletePostSC;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function validProjectComment(){
	var comments = trim(document.getElementById('comments').value);
	errField("off", document.getElementById('comments'));
	if(comments.length==0){
		document.getElementById('comments').value = "";
		document.getElementById('comments').focus();
		errField("on", document.getElementById('comments'));
		return false;	
	}
	else
		return true;
}
function checkPhoto()
{
	var check = document.getElementById('selectall').checked;
	if(check){
		for(i=0;i<document.getElementsByName('photo[]').length;i++){
			document.getElementsByName('photo[]').item(i).checked = true;
		}
	}
	else{
		for(i=0;i<document.getElementsByName('photo[]').length;i++){
			document.getElementsByName('photo[]').item(i).checked = false;
		}
	}
}
function validDeletePhoto()
{
	c=0;
	for(i=0;i<document.getElementsByName('photo[]').length;i++){
		if(document.getElementsByName('photo[]').item(i).checked)
			c++;
	}
	if(c>0)
		return true;
	else 
		return false;
}
function validCartCheck(frm, cName)
{
	c=0;
	for (i=0,n=frm.elements.length;i<n;i++)
	{
		if (frm.elements[i].className.indexOf(cName) !=-1)
		{
			if (frm.elements[i].checked == true) 
				c++;
		}
	}
	if(c>0)
		return true;
	else {
		alert("Please select any one of products");
		return false;
	}
}
function validSearchName()
{
	var newSearchName = trim(document.getElementById('newSearchName').value);
	if(newSearchName.length == 0)
	{
		document.getElementById('Err').innerHTML = '<table align="center"><tbody><tr><td valign="top"><img src="../images/errorMsg.gif"></td><td>Please enter the search name</td></tr></tbody></table>';
		document.getElementById('newSearchName').focus();
		return false;
	}
	else
		return true;
}
function trim(str)
{
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function toggle(id)
{
	if(document.getElementById(id).style.display=='block')
		document.getElementById(id).style.display = 'none';
	else
		document.getElementById(id).style.display = 'block';
}

function checkAllBox(Id,checkboxVal)
{
	var check = document.getElementById(Id).checked;
	if(check){
		for(i=0;i<document.getElementsByName(checkboxVal).length;i++){
			document.getElementsByName(checkboxVal).item(i).checked = true;
		}
	}
	else{
		for(i=0;i<document.getElementsByName(checkboxVal).length;i++){
			document.getElementsByName(checkboxVal).item(i).checked = false;
		}
	}
}


