// Change Password FORM VALIDATION START
function checkPassform()
{
	if(document.frmchkpwd.oldPassword.value == "")
	{
		alert("Please Enter Old password");
		document.frmchkpwd.oldPassword.focus();
		return false;
	}
	else if(document.frmchkpwd.newPassword.value == "")
	{
		alert("Please Enter New password");
		document.frmchkpwd.newPassword.focus();
		return false;
	}	
	else if(document.frmchkpwd.retypePassword.value == "")
	{
		alert("Please Enter Retype password");
		document.frmchkpwd.retypePassword.focus();
		return false;
	}	
	else if(document.frmchkpwd.retypePassword.value != document.frmchkpwd.newPassword.value)
	{
		alert("Retype password should be match with New password");
		document.frmchkpwd.retypePassword.value = '';
		document.frmchkpwd.retypePassword.focus();
		return false;
	}
	return true;
}
 function checkUncheckAll(flag)
{
	if(flag == null)
	{
		for(var i=0; i<document.getElementById('count').value; i++)
		{
			if(document.getElementById('checkUncheckAllId').checked)
			{
				document.getElementById('cb1_'+i).checked = true;
			}
			else
			{
				document.getElementById('cb1_'+i).checked = false;
			}
		}
	}
	else
	{
		var checkFlag = 0;
		for(var i=0; i<document.getElementById('count').value; i++)
		{
			if(document.getElementById('cb1_'+i).checked)
			{
				checkFlag = 1;
			}
			else
			{
				checkFlag = 0;
				break;
			}
		}
		if(checkFlag == 0)
		{
			document.getElementById('checkUncheckAllId').checked = false;
		}
		else
		{
			document.getElementById('checkUncheckAllId').checked = true;
		}
	}
}
 

// LOGIN FORM VALIDATION START
function validate_loginfrm(){
	if(trim(document.loginfrm.empcode.value)=='') {
		alert('Please Enter Employee Code');
		document.loginfrm.empcode.focus();
		return false;
	}
	if(trim(document.loginfrm.password.value)=='') {
		alert('Please Enter Password');
		document.loginfrm.password.focus();
		return false;
	}
	return true;
}
function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
// CHECK ALL & UNCHECK ALL FUNCTION Start
function chkvalidatation(b)
{
  	for (var c=0,d=0,e; e=b[d]; d++)
	{
  		if (e.type=='checkbox' && e.name.match(/^(cb1_[0-9]*)$/) && e.checked) 
			c++;
 	}
 	if(c==0)
	{
		alert("Select at least One checkbox");
		return false;
	}
	else
	{
 		if(!confirm('Are you sure you want to delete selected Record(s)?'))
 	 	  return false;
	}
	return true;
}
function chkSingle(singleChk)
{
	b = document.form1;
	for (var c=0,d=0,e; e=b[d]; d++)
	{
		//alert(e.name);
		if (e.type=='checkbox' && e.name.match(/^(cb1_[0-9]*)$/) && e.checked == false) c++;
	}
	
	if(c != 0)
	{
		document.form1.allornone1.checked = false;
	}
}
// CHECK ALL & UNCHECK ALL FUNCTION End

//  Start function for pageingnation 
function setPageNumber(e,path,pageNo,first,last)
{
	 var unicode=e.charCode? e.charCode : e.keyCode
	 
	 if(unicode == 13)
	 {
		  if(eval(pageNo) > eval(last)) 
		  { 
		 	 window.location.href= path+'/page/'+last;
		  }
		  else if(eval(pageNo) < eval(first))
		  { 
			  window.location.href= path+'/page/'+first;
		  }
		  else
		  {
			  window.location.href= path+'/page/'+pageNo;
		  }
	  }
	 
	 if ((unicode<48||unicode>57) && unicode!=8 && unicode!=9 && unicode!=35 && unicode!=36 && unicode!=37 && unicode!=39)
	 {
		  return false //disable key press
	 }
 
}

function formSub(val, path, formName)
{	
	document.frmProdcutListing.action = site_url + path+"/page/"+val;	
	document.frmProdcutListing.submit();
}

function formSubAdmin(val, path, formName)
{	
	document.frmSearch.action = site_url + path + "/page/" + val;	
	document.frmSearch.submit();
}

function setFocusOnKeyPress(e,id)
{
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode == 38)
	{
		tabIndex = parseInt(document.getElementById(id).tabIndex) - 1;
		getElementByTabIndex(tabIndex).focus();
	}
	else if(unicode == 40)
	{
		tabIndex = parseInt(document.getElementById(id).tabIndex) + 1;
		getElementByTabIndex(tabIndex).focus();
	}
}
function numbersonly(e)
{
	
	var unicode=e.charCode? e.charCode : e.keyCode
	//if (unicode!=8 && unicode!=9 && unicode!=37 && unicode!=39 && unicode!=45 && unicode!=47 && unicode!=46)
	if (unicode!=8 && unicode!=9 && unicode!=37 && unicode!=39 && unicode!=45 && unicode!=47)
	{ //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
		return false //disable key press
	}
}
function setCaretPosition(elemId, caretPos) 
{
    var elem = document.getElementById(elemId);
    if(elem != null) 
	{
        if(elem.createTextRange) 
		{
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else 
		{
            if(elem.selectionStart)
			{
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
			{
                elem.focus();
			}
        }
    }
}
function checkValidDateFormat(id,dateFormat)
{
 	var dateArray = new Array();
	dateArray = dateFormat;
	for(var i=0; i<dateArray.length; i++)
	{
		if((dateArray[i] != 'd' && dateArray[i] != 'm' && dateArray[i] != 'y') && (dateArray[i] != 'D' && dateArray[i] != 'M' && dateArray[i] != 'Y'))
		{
			seperator = dateArray[i];
			break;
		}
	}
	currentDate 		= document.getElementById(id).value;
	currentDateArray 	= currentDate.split(seperator);
	currentFormatArray 	= dateFormat.split(seperator);
	
	if(trim(document.getElementById(id).value) == '')
	{
		alert("Please Select Date"); //updated Gautam
		document.getElementById(id).focus();
		return false;
	}
	else
	{
		if(currentDate.indexOf(seperator) == -1)
		{
			alert("Please Enter Valid Date as per '"+dateFormat+"' Format");
			return false;
		}
		else
		{
			var flag = 0;
			for(j=0; j<currentFormatArray.length; j++)
			{
				if(currentFormatArray[j] == 'dd' || currentFormatArray[j] == 'DD')
				{
					if(trim(currentDateArray[j]) == '' || currentDateArray[j].length != 2)
					{
						flag = 1;
					}
					else
					{
						if(trim(currentDateArray[j]) < 1 || trim(currentDateArray[j]) > 31)
						{
							flag = 1;
						}
					}
					day = trim(currentDateArray[j]);
				}
				else if(currentFormatArray[j] == 'mm' || currentFormatArray[j] == 'MM')
				{
					if(trim(currentDateArray[j]) == '' || currentDateArray[j].length != 2)
					{
						flag = 1;
					}
					else
					{
						if(trim(currentDateArray[j]) < 1 || trim(currentDateArray[j]) > 12)
						{
							flag = 1;
						}
					}
					month = trim(currentDateArray[j]);
				}
				else if(currentFormatArray[j] == 'yyyy' || currentFormatArray[j] == 'YYYY')
				{
					if(trim(currentDateArray[j]) == '' || currentDateArray[j].length != 4)
					{
						flag = 1;
					}
					currentYear = trim(currentDateArray[j]);
				}
				
				if(flag == 1)
				{
					alert("Please Enter Valid Date as per '"+dateFormat+"' Format");
					break;
					return false;
				}
			}
		}
	}
	
	if(flag == 0)
	{
		var monthName 	= 	new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var weekDay 	= 	new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var wd 			= 	new Date(monthName[month-1] + ' ' + day + ', ' + currentYear);
		selectedDayName	=	weekDay[wd.getDay()];
		if(document.getElementById("weekDayName_"+id))
		{
			if(selectedDayName == 'Sunday')
			{
				document.getElementById("weekDayName_"+id).style.color = '#EE0000';
			}
			else
			{
				document.getElementById("weekDayName_"+id).style.color = '#000000';
			}
 			document.getElementById("weekDayName_"+id).innerHTML = selectedDayName;
 		}
	}
}
//rtrim function
function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }

  return argvalue;
}

//trim function
function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}
function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}
function showMessageOnFocus(fieldName, elementType)
{
	msg = 'Please ';
	if(elementType == 'text')
	{
		txt = 'Enter ';
	}
	else if(elementType == 'radio' || elementType == 'checkbox' || elementType == 'combobox')
	{
		txt = 'Select ';
	}
	msg = msg + txt + fieldName;
	if(document.getElementById('statusBarMessage'))
	{
		document.getElementById('statusBarMessage').innerHTML = '<div class="statusbarmessage">' + msg + '</div>';
	}
} 
function createRequestObject()
{
	var request_;
	
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer")
	{
		 request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		 request_ = new XMLHttpRequest();
	}
	return request_;
}

/*For Decimal Fields*/
function validateDecimal(e)
{
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode!=13)
	{
		keychar = String.fromCharCode(key);
		reg = /[\d\.]/;
		return reg.test(keychar);
	}
}

var eethreg=new RegExp(",","g");
var eedecreg=new RegExp("[.]","g");
var eedec=".";
var eeth="";
function eeinsertThousand(whole){if(whole==""||whole.indexOf("e")>=0){return whole;}else{var minus_sign="";if(whole.charAt(0)=="-"){minus_sign="-";whole=whole.substring(1);};var res="";var str_length=whole.length-1;for(var ii=0;ii<=str_length;ii++){if(ii>0&&ii%3==0){res=eeth+res;};res=whole.charAt(str_length-ii)+res;};return minus_sign+res;}};
function round(n,nd){if(isFinite(n)&&isFinite(nd)){var sign_n=(n<0)?-1:1;var abs_n=Math.abs(n);var factor=Math.pow(10,nd);return sign_n*Math.round(abs_n*factor)/factor;}else{return NaN;}};
function myIsNaN(x){return(isNaN(x)||(typeof x=='number'&&!isFinite(x)));};
function eeparseFloatTh(str){str=String(str).replace(eethreg,"");str=String(str).replace(eedecreg,".");var res=parseFloat(str);if(isNaN(res)){return 0;}else{return res;}};
function eeparseFloatThV(str){if(str=="")return str;str=String(str).replace(eethreg,"");str=String(str).replace(eedecreg,".");if(!eeparseFloatThVreg.test(str)){return str;};var res=parseFloat(str);if(isNaN(res)){return str;}else{return res;}};
function eedisplayFloatNDTh(x,nd){if(myIsNaN(x)){return Number.NaN;}else{var res=round(x,nd);if(nd>0){var str=String(res);if(str.indexOf('e')!=-1)return str;if(str.indexOf('E')!=-1)return str;var parts=str.split('.');var res2=eeinsertThousand(parts[0].toString());if(parts.length<2){var decimals=('00000000000000').substring(0,nd);return(res2+eedec+decimals);}else{var decimals=((parts[1]).toString()+'00000000000000').substring(0,nd);return(res2+eedec+decimals);}}else{return(eeinsertThousand(res.toString()));}}};
function eedisplayInt(x){if(x != ''){return x;}else{return 0;}};

function hideDecimalValueOnFocus(id)
{
	if(document.getElementById(id).value == 0)
	{
		document.getElementById(id).value = '';
		return;
	}
}

//function to check email validation
function validateEmail(email) 
{//passing controlas a argument
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) 
	{
	//alert("Error");
	//email.focus();
	//email.select();
		return false;
	}
	return true;
}

function makePOSTRequest(url, parameters, type) 
{
  
  http_request[curDateTime].open('POST', url, true);
  http_request[curDateTime].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request[curDateTime].setRequestHeader("Content-length", parameters.length);
  http_request[curDateTime].setRequestHeader("Connection", "close");
  http_request[curDateTime].send(parameters);
  
  if(type=='contactGroup')
  {
  	http_request[curDateTime].onreadystatechange = alertContents;  
  }
}

function selectedLabel1(frameName,formName,Labelurl)
{
	if(document.getElementsByName("checkbox[]").length == null || document.getElementsByName("checkbox[]").length == '0')
	 {
		 alert("no any Record");
		 return false;
	 }
	 var allchk = 0;
	  for (var i=0;i<document.getElementsByName("checkbox[]").length;i++) 
	  {
			if(document.getElementsByName("checkbox[]")[i].checked == false)
			{
				allchk=allchk+1;
			}
	  }
	  if(allchk==document.getElementsByName("checkbox[]").length)
	  {
		 alert("Please Select Record");
		 return false; 
	  }
	  else 
	  {
		  document.forms[formName].action=Labelurl;
		  document.forms[formName].submit();
	  }
}

function selectedLabel(frameName,formName,Labelurl,totalrecord)
{
 	if(totalrecord == 0)
	{
		alert("No any Record");
		return false;	
	}
	 
	b = document.contactList;
	for (var c=0,d=0,e; e=b[d]; d++)
	{
		if (e.type=='checkbox' && e.name.match(/^(cb1_[0-9]*)$/) && e.checked) 
			c++;
	}	
	if(c==0)
	{
		alert("Select at least One checkbox");
		return false;
	}
	else
	{
		document.forms[formName].action=Labelurl;
		document.forms[formName].submit();
	}
}



/////////////Added by Parimal Jariwala 14/07/2009////////////////////////
function changeImageOnMouseOver(id)
{
	var imagePath, oldImageName, newImageName, temp, newImagePath, src;
	src = document.getElementById(id).src;
	imagePath = src.split('/');
	oldImageName = imagePath[parseInt(imagePath.length)-1];
	temp = oldImageName.split('.');
	newImageName = temp[0]+'Hover.'+temp[1];
	newImagePath = src.replace(oldImageName,newImageName);
	document.getElementById(id).src = newImagePath;
}
function changeImageOnMouseOut(id)
{
	var imagePath, oldImageName, newImageName, temp, newImagePath, src;
	src = document.getElementById(id).src;
	imagePath = src.split('/');
	oldImageName = imagePath[parseInt(imagePath.length)-1];
	temp = oldImageName.split('.');
	temp[0] = temp[0].replace('Hover','');
	newImageName = temp[0]+'.'+temp[1];
	newImagePath = src.replace(oldImageName,newImageName);
	document.getElementById(id).src = newImagePath;
}
/////////////////////////////////////////////////////////////////////////
//Function for searching
function searchThis()
{
	document.frmSearch.submit();
}

function searchThis1()
{
	document.frmSearch1.submit();
}

function popupImage(imageFile)
{	
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer")
	{
		myLightWindow.activateWindow({
										href: imageFile, 									
										width:350,
										height:454,
										left: 300,
										top:200										
									});
	}
	else
	{
		myLightWindow.activateWindow({
										href: imageFile, 									
										width:350,
										height:454,
										left: 300										
									});
	}
}   
