function setPagingAJAX(form,divId,currPage,numberOfRecordsPerPage){
   if(document.getElementById('taskName').value == 'searchProductAjax') {
		divId = 'productSpace';
	}
	else {
		divId = 'hotProdTable';
	}		
   document.getElementById('resetPaging').value='N';
   document.getElementById('currPage').value=currPage;
   document.getElementById('numberOfRecordsPerPage').value=numberOfRecordsPerPage;
   asynchronousProcessByPost(form, divId); 
}
function setRecordsAJAX(form,divId,value) {
	//alert(form+"-"+divId+"-"+value);
   document.getElementById('resetPaging').value='N';
   document.getElementById('numberOfRecordsPerPage').value=value;
   document.getElementById('filterPaging').value='Y';
   if(document.getElementById('selected').value) {
   	document.getElementById('selected').value = 'Y';
   		if(document.getElementById('taskName').value == 'searchProductAjax') {
   			divId = 'productSpace';
   		}
   		else {
   			divId = 'hotProdTable';
   		}
   }
   asynchronousProcessByPost(form, divId);
}

function setPagingGroupAJAX(form,divId,currPageGroup,numberOfRecordsPerPage){
   document.getElementById('resetPaging').value='N';
   document.getElementById('currPageGroup').value=currPageGroup;
   document.getElementById('currPage').value=(currPageGroup-1)*10+1;
   document.getElementById('numberOfRecordsPerPage').value=numberOfRecordsPerPage;
   asynchronousProcessByPost(form, divId);
}

function ajaxCall(form, divId, taskValue)
{
	if(taskValue != '') {
		form.task.value = taskValue;
		form.module.value='user';
	}
	asynchronousProcessByPost(form,divId);
	//if(displayMessage) {
		//setTimeout('setDisplayMessage()', 5000);
	//}
}

function submitAjaxForm(form, taskValue, divId){
	if (form.task.length>1) {
		for (i=0; i<form.task.length; i++) {
			form.task[i].value = taskValue;
		}
	}
	else {
		form.task.value = taskValue;
	}
	asynchronousProcessByPost(form,divId);
}
//function to check integer values
function checkInt(text){

		var chk= "0123456789";
		var lent,flag= false;
		 lent = text;
		var ans;
		for(i=0;i<lent.length;i++){
			
			for(j=0;j<chk.length;j++){
			
				if(lent.charAt(i) == chk.charAt(j)){
					if(ans == 1){
						break;
					}
					flag=true;
					ans = 0;				
					break;

				}
				else{
				
					if(j == chk.length - 1){
						ans = 1;
						break;
					}
				}
					
				
			}
			
		}
	
		if(ans == 0){
			return true;
		}else{
			
			return false;
		}
		
}
//function to check valid email address
function isValidEmail(strEmail)
{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) 
	{
		return false;	
	}
	return true; 
}

function ltrim(argvalue) 
{
	while (1)
	{
		if (argvalue.substring(0, 1) != " ")
		break;
		argvalue = argvalue.substring(1, argvalue.length);
	}	
	return argvalue;
}

function rtrim(argvalue) 
{

	while (1) 
	{
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	
	return argvalue;
}

function trim(argvalue)
{
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

function isURL(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@\,\!\-\/]))?/
	//var regexp = /(ftp|http|https):\/\/(\w{0,2}\w*)?(\S+)([0-9]+)?(.)?(S+)/
	/*//var regexp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}[0-9A-Za-z\.\-]*\.[0-9A-Za-z\.\-]*$/
	//var regexp = /^(ftp|https?):\/\/+(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/
	var regexp = (((http?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i*/
	return regexp.test(s);
}
function validateName(name,fieldname)
{
	var iChars = "`~!@#$%^&*()+=-[]\\\';,/{}|\":<>?";
	for (var i = 0; i < name.length; i++) 
	{
		if (iChars.indexOf(name.charAt(i)) != -1) 
		{
			alert ("special characters are not allowed in " + fieldname + ".");
			return false;
		}
	}
	return true;
}

// Password Validator
function isPass(pass1,pass2)	
{
	if ((pass1 == "") || (pass1.length < 6))
	{
		alert("\nThe password field is either empty or less than 6 chars.\n\nPlease enter your password.")
		return false;
	}
	if (pass1 != pass2)
	{
		alert("Passwords typed do not match, please re-enter your passwords.\n\n");
		return false;
	}
	return true;
}

function isDate(mm,dd,yyyy) 
{
	var d = new Date(mm + "/" + dd + "/" + yyyy);
	return d.getMonth() + 1 == mm && d.getDate() == dd && d.getFullYear() == yyyy;
}


function in_array(needle, haystack) 
{
	var n = haystack.length;
	for(var i=0; i<n; i++) 
	{
		if (haystack[i]==needle.toLowerCase()) 
		{
			return true;
		}
	}
	return false;
}

function goToURL()
{
	var loopInitialValue = 0;
	var url = "index.php?";
	if (arguments[0] == 0)
	{
		url += "module="+arguments[1]+"&task="+arguments[2];
	}
	else if (arguments[0] == 1)
	{
		url += "module="+arguments[1]+"&task="+arguments[2]+"&";
		loopInitialValue = 3;
		for(var i=loopInitialValue; i<arguments.length; i+=2)
		{
			url += arguments[i]+"="+arguments[i+1]+"&";
		}
		url = url.substring(0, url.length-1);
	}
	window.location.href = url;
}

function showPopUp()
{
	var url = "index.php?";
        if (arguments[0] == 0)
        {
                url += "module="+arguments[1]+"&task="+arguments[2];
        }
        else if (arguments[0] == 1)
        {
                url += "module="+arguments[1]+"&task="+arguments[2]+"&";
                loopInitialValue = 3;
                for(var i=loopInitialValue; i<arguments.length; i+=2)
                {
                        url += arguments[i]+"="+arguments[i+1]+"&";
                }
                url = url.substring(0, url.length-1);
        }
	window.open(url,'',"width=700,height=500,left=200,top=200");
}

var count = 2;

function getDetailsByAjax(module,task,param,Id,divId,r,tableName)
{
	//alert(document.getElementById(divId));
	//alert(module);
	if(module == 'admin') {
		var currIndex = r.parentNode.parentNode.rowIndex;
		var deleteIndex = currIndex+1;
		if(task != 'listSubCategory' && task != 'listSubCategoryForPrice') {
			for(var i=currIndex; i < (count+1); i++) {
				if(chkElement("subCat"+(i+1))) {
					deleteRow(deleteIndex,tableName);
				}
			}
			divId = divId+count;
			insRow(tableName);
		}
		if(task == 'listSubCategory') {
			if(chkElement("subCat2")) {
				for(var i=currIndex; i < (count+1); i++) {
					if(chkElement("subCat"+(i+1))) {
						deleteRow(deleteIndex+1, tableName);
					}
				}
			}
		}
	}
	ajaxManager("start_up","index.php?module="+module+"&task="+task+"&"+param+"="+Id,divId,0,1);
	if(task == 'getHotProduct') {
		globalId = 'hotProdTable';
	}
	else {
		globalId = 'productSpace';
	}
}

function setUpdatedParamBeforeAjax(type,url,div,param,id,form) {
	prodQty = document.getElementById(param+id).value;
	url = url+"&"+param+"="+prodQty;
	ajaxManager(type,url,div);
}

function showPhoto(imageName)
{
	objWindow = window.open('../userdata/userImage/'+imageName, '', 'menubar=no,resizeable=yes,scrollbar=yes,status=no,titlebar=no');
}


function insRow(tblName) {
	//alert(count);
	var x=document.getElementById(tblName).insertRow(count);
	var a=x.insertCell(0);
	var b=x.insertCell(1);
	
	a.align = "right";
	if(count == 1) {
		a.innerHTML="SubCategory: ";
		x.id="cat";
	}
	else {
		a.innerHTML="Child Category: ";
		x.id="subCat"+count;
	}
	b.id="subCategory"+count;
	b.innerHTML="<select name=\"subCategoryId[]\" class=\"textBox\" style=\"width:125px\"><option value=\"\">Select</option></select>";
	//alert("inserted: subCat"+count);
	count++;
	//alert("Count: "+count);
}

function deleteRow(r,tblName) {
	//alert(tblName);
	document.getElementById(tblName).deleteRow(r);
	//alert("deleted: subCat"+(r));
	count--;
	//alert("Count: "+count);
}

function chkElement(theVal) {
	//alert("checking"+theVal);
	if (document.getElementById(theVal) != null) {
		return true;
	} 
	else {
		return false;
	}
}

function submitForm_task(taskName) {
	//alert(taskName);
	document.getElementById('taskName').value = taskName;
}

function validateSearchBox(frmName, f) {
	//alert(overlay);
	if(overlay == 'yes') {
		overlay = 'yes';
	}
	else {
		overlay = f;
	}
	overlay = 'no';
	//alert(overlay);
	if(overlay == 'no') {
		//alert(document.getElementById('name').value);
		if((document.getElementById('name').value == '') || (document.getElementById('name').value == 'Search for')) {
			/*alert('Please enter your search text');
			document.getElementById('name').focus();
			document.getElementById('name').value="";
			return false;*/
			document.getElementById('name').value = '';
		}
		else {
			//alert(overlay);
			submitForm_task(frmName);
			document.forms[0].submit();
			return true;
		}
		submitForm_task(frmName);
		document.forms[0].submit();
		return true;
	}
	else {
		return false;
	}
}

/*function showNextCat(dec, e) {
	if(dec == 'show') {
		for(k=13; k < e; k=k+4) {
			document.getElementById('nextCat'+k).style.display = 'block';
		}
		document.getElementById('nextCatDecision').innerHTML = "";
		document.getElementById('nextCatDecision').innerHTML = "<a href=\"#\" onclick=\"javascript:showNextCat('hide', "+e+");\" >Hide this..</a>";
	}
	else {
		for(k=13; k < e; k=k+4) {
			document.getElementById('nextCat'+k).style.display = 'none';
		}
		document.getElementById('nextCatDecision').innerHTML = "";
		document.getElementById('nextCatDecision').innerHTML = "<a href=\"#\" onclick=\"javascript:showNextCat('show', "+e+");\" >Show this..</a>";
	}
}*/

function showNextCat(dec) {
	if(dec == 'show') {
		document.getElementById('nextCat').style.display = 'block';
		document.getElementById('nextCatDecision').innerHTML = "";
		document.getElementById('nextCatDecision').innerHTML = "<a href=\"#\" onclick=\"javascript:showNextCat('hide');\" >Hide this..</a>";
	}
	else {
		document.getElementById('nextCat').style.display = 'none';
		document.getElementById('nextCatDecision').innerHTML = "";
		document.getElementById('nextCatDecision').innerHTML = "<a href=\"#\" onclick=\"javascript:showNextCat('show');\" >Show more..</a>";
	}
}



function controlTsrBody(tsrBodyDivId,status)
{
var body="";
var bodyClose="";
var bodyOpen="";
if(document.getElementById)
{
    body=document.getElementById(tsrBodyDivId);
    bodyOpen=document.getElementById(tsrBodyDivId+'_open_ctrl');
    bodyClose=document.getElementById(tsrBodyDivId+'_close_ctrl');
}
else if(document.all)
{
    body=document.all[tsrBodyDivId];
    bodyOpen=document.all[tsrBodyDivId+'_open_ctrl'];
    bodyClose=document.all[tsrBodyDivId+'_close_ctrl'];
}
if(body==null||bodyOpen==null||bodyClose==null)
{
    return;
}
if(status=="open")
{
    body.style.display="block";
    bodyClose.style.display="block";
    bodyOpen.style.display="none";
}
else if(status=="close")
{
    body.style.display="none";
    bodyClose.style.display="none";
    bodyOpen.style.display="block";
}
}
