﻿var expvarchar =/[^\w|\s|\!|\=|\&|\$|\'|\?|\.|\/|\_|\)|\(|\[|\]|\:|\-|\%|\;|\`|\@|\#|\^|\*|\{|\}|\+|\,]+/;
var emailexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var msg = '(\",>,<\)';
var strPublishmsg = 'Are you sure to publish / unpublish the selected';
var adminemail = 'xyz@xyz.com'
var expUserID = /([a-zA-Z0-9])+$/;
var expPhone = /[^\d]+/;
function chkMandatory(frmname,obj,name)
{
	strTestObjs = "document."+frmname+"."+obj
	strTestObj = strTestObjs+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=="")
	{
		alert('Please enter the '+name)
		eval(strTestObjs+"."+"focus();");
		return 0
	}
	else
	{
		if(expvarchar.test(strTestObj)==true)
		{
			alert('Special characters like' + msg + ' are not allowed in '+name)
			eval(strTestObjs+"."+"focus();");
			return 0
		}
	}
}
function chkMandatoryUserID(frmname,obj,name)
{
	strTestObjs = "document."+frmname+"."+obj
	strTestObj = strTestObjs+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=="")
	{
		alert('Please enter the '+name)
		return 0
	}
	else
	{	
		/*if(expUserID.test(strTestObj)==false)
		{	
			alert('Only alphanumeric characters are allowed in '+name)
			return 0
		}*/
		for(var iloop =0; iloop <= strTestObj.length -1; iloop++)
		{
			if (expUserID.test(strTestObj.charAt(iloop)) == false)
			{
			 	alert('Only alphanumeric characters are allowed in '+name)
				return 0;
			} 
		}
	}
}
function DropDownListChk(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";	
	strTestObj = eval(strTestObj)	
	if(strTestObj=="")
	{
		alert('Please select the '+name)
		return 0
	}	
}
function chkCatCombo(obj)
{

    strTestObj = document.getElementById(obj);    
	strTestObj = eval(strTestObj)
	//alert(strTestObj.options[strTestObj.selectedIndex].text);
	if(strTestObj.value==0)
	{
		alert('Please select the Category');
		return false;
	}
	//Next level category not present
}
function PhoneNumberChk(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj!='')
	{
		if(expPhone.test(strTestObj)==true)
		{
			alert(name+'can contain only 0-9 digits.');
			return 0
		}
	}
}
function EmailChk(frmname,obj,name)
{
    strTestObjs = "document."+frmname+"."+obj
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=="")
	{
		alert('Please enter the '+name)
		eval(strTestObjs+"."+"focus();");
		return 0
	}
	if (strTestObj != '') 
	{	
		if(emailexp.test(strTestObj)== false)	
		{
			alert('Invalid '+name+' Please re-enter.\n e.g. '+adminemail);
			eval(strTestObjs+"."+"focus();");
			return 0
		}
	}
}
function chkNonMandatory(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj!="")
	{
		if(expvarchar.test(strTestObj)==true)
		{
			alert('Special characters like' +msg+ ' are not allowed in '+name)
			return 0
		}
	}
}
function LimitAttach(form,file,fileext)
{
	 var strExt = new String();
		 strExt = fileext;	 
	   extArray = strExt.split(",")	 
	var allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext  = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++)
	{	
		if (extArray[i] == ext) { allowSubmit = true; break; }
	}			
	if (allowSubmit) 
	{
		return true;
	}					
	else
	{
		alert("Only (" + (extArray.join("  ")) + ") files are allowed to upload," +
		"\nPlease select a new "
		+ "file and upload again.");				
		return false;
	} 
}
function chkMandatoryInteger(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=="")
	{
		alert('Please enter the '+name)
		return 0
	}
	else
	{
		if(isNaN(strTestObj)==true)
		{
			alert(name + ' can contain only numbers')
			return 0
		}
	}
}
function chkNonMandatoryInteger(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj!='')
	{
		if(isNaN(strTestObj)==true)
		{
			alert(name + ' can contain only numbers')
			return 0
		}
	}
}
function chkMandatoryDate(frmname,obj,name)
{
    strTestObjs = "document."+frmname+"."+obj
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=='')
	{		
		alert('Please enter the '+name)
		//eval(strTestObjs+"."+"focus();");
		return 0
	}
}
function CompareDates(frmname,obj1,obj2,name1,name2)
{
	var startdate = "document."+frmname+"."+obj1+".value";
	startdate = eval(startdate);
	enddate = "document."+frmname+"."+obj2+".value";
	enddate = eval(enddate);
	var date1,month1,year1;
	var date2,month2,year2;
	var dtStart,dtEnd;
	if(startdate!=='' && enddate!='')
	{
		month1 = startdate.substring (0, startdate.indexOf ("/"));
		date1 = startdate.substring (startdate.indexOf ("/")+1, startdate.lastIndexOf ("/"));
		year1 = startdate.substring (startdate.lastIndexOf ("/")+1, startdate.length);
		dtStart = new Date(year1,month1-1,date1)
		
		month2 = enddate.substring (0, enddate.indexOf ("/"));
		date2 = enddate.substring (enddate.indexOf ("/")+1, enddate.lastIndexOf ("/"));
		year2 = enddate.substring (enddate.lastIndexOf ("/")+1, enddate.length);					
		dtEnd = new Date(year2,month2-1,date2)
		if (dtStart>dtEnd)
		{
			alert( name2 + ' should be after ' + name1);
			return 0;
		}
	}
}
function checkCharLength(fn,strObj,strName,maxlen)
{
	strTestObj = "document."+fn+"."+strObj 
	if (eval(strTestObj+".value.length")>maxlen)
	{
	  eval(strTestObj+".value="+strTestObj+".value.substring(0,"+maxlen+")");
	  alert(strName+" can only be "+ maxlen +" characters long");
	  return 0
	}
}
function chkNonMandatorySize(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj!="")
	{
		if(expsizevarchar.test(strTestObj)==true)
		{
			alert('Special characters like' +sizemsg+ ' are not allowed in '+name)
			return 0
		}
	}
}
function checkDeleteThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
	try
	{
		for(i=1;i<=objtbl.rows.length;i++)
		{
			var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
			var objChk = document.getElementById(strObjName);
			if((objChk!=null)&&(objChk.type == 'checkbox'))
			if(objChk.checked)
			{
				flg = 1;
			}
		}
	}
	catch(e)
	{
		flg = 0
	}
	if(flg == 0)
	{
		alert(p_strMessage);
		return false;
	}
	else 
	{
		return confirm(GetDeleteMsg("Category(s)"));
	}
}
function checkSameDayThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
//	try
//	{
//		for(i=1;i<=objtbl.rows.length;i++)
//		{
//			var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
//			var objChk = document.getElementById(strObjName);
//			if((objChk!=null)&&(objChk.type == 'checkbox'))
//			if(objChk.checked)
//			{
//				flg = 1;
//			}
//		}
//	}
//	catch(e)
//	{
//		flg = 0
//	}
//	if(flg == 0)
//	{
//		alert(p_strMessage);
//		return false;
//	}
//	else 
//	{
		return confirm("Are you sure you want to make the selected Products(s) Same Day Delivery");
//	}
}
function checkPublicThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
//	try
//	{
//		for(i=1;i<=objtbl.rows.length;i++)
//		{
//			var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
//			var objChk = document.getElementById(strObjName);
//			if((objChk!=null)&&(objChk.type == 'checkbox'))
//			if(objChk.checked)
//			{
//				flg = 1;
//			}
//		}
//	}
//	catch(e)
//	{
//		flg = 0
//	}
//	if(flg == 0)
//	{
//		alert(p_strMessage);
//		return false;
//	}
//	else 
//	{
		return confirm("Are you sure you want to Publish / UnPublish the selected Article(s)");
//	}
}
function GetDeleteMsg(name)
{
	var strDeleteMsg = "All the information related with this "+name+" will be Deleted from the WebSite. \n Are you sure you want to delete the selected "+name+"?";
	return strDeleteMsg;
}
function chkSpace( strValue )
{
	var objRegExp
	objRegExp = new RegExp(/\s+/g)
	if(!objRegExp.test(strValue))
	return true;
	return false;
}
function checkAddresBook(p_strTableName, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strTableName);
	var RowID = objtbl.rows.length;
	try
	{
		for(i=0;i<=4;i++)
		{
			var strObjName = p_strTableName + "_"+i;
			var objChk = document.getElementById(strObjName);
			if((objChk!=null)&&(objChk.type == 'checkbox'))
			if(objChk.checked)
			{
				flg = 1;
			}
		}
	}
	catch(e)
	{
		flg = 0
	}
	if(flg == 0)
	{
		alert(p_strMessage);
		return false;
	}
	else 
	{
		//return confirm(GetDeleteMsg("Article(s)"));
		return true;
	}
}
function chkQtndecimal(arg)
{
	if(arg!='')
	{
		if (arg.indexOf(".") >= 0)
		{
			return 0;
		}
	}
}
function checkShoppingCart()
{
    var isQnt = 1;
    var isTrue = 0;
	var frm=document.getElementById("aspnetForm");   
       var flg = 0;
       for (i=0; i<frm.length; i++)
       { 
           if (frm.elements[i].name.indexOf("txtQnt") !=-1)
	        {	          
		        if(frm.elements[i].value=='')
		        {	
			         alert('Please enter the Quantity .');
                     frm.elements[i].value = "1";
                     frm.elements[i].focus();
                     isQnt = 0;
                     return false;
		        }
		    }
		    else
	        {
	            if(isQnt == 1)
	            {
	                if (frm.elements[i].name.indexOf("chkDelete") !=-1)
                    {
	                    if(frm.elements[i].checked)
	                    {
                             isTrue = 1;
                             break;
	                    }
                    }
                }
	        }        
        }
        if(isTrue == 1)
        {
            return confirm("By removing the main Item, all associated Items will also be removed.\nPress 'Ok' to continue");
        }
        else
        {
            return true;
        }
}
function checkvalue(objQty)
{
    objQty.value=objQty.value.replace(/[^\d]*/gi,"");
    if(objQty.value=='0')
    {
        objQty.value=1;
    }
}
function PhoneNumberChkChkOut(frmname,obj,name)
{
	strTestObj = "document."+frmname+"."+obj+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=='')
	{
		alert('Please enter the '+name);
		return 0
	}
	if(strTestObj!='')
	{
		if(expPhone.test(strTestObj)==true)
		{
			alert(name+'can contain only 0-9 digits.');
			return 0
		}
	}
}
function checkProdDeleteThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
	try
	{	
		//for(i=1;i<=objtbl.rows.length;i++)
		for(i=1;i<=objtbl.rows.length;i++)
		{
		    var strObjName = '';
		    if(i<=9)
			    strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
			else
			    strObjName = p_strDatagridId + '_ctl' + i + '_' + p_strCheckBoxName;
			
			var objChk = document.getElementById(strObjName);
			
			if((objChk!=null)&&(objChk.type == 'checkbox'))
			{
			    if(objChk.checked)
			    {
				    flg = 1;
			    }
			}
		}
	}
	catch(e)
	{
		flg = 0
	}
	if(flg == 0)
	{
		alert(p_strMessage);
		return false;
	}
	else 
	{
		return confirm(GetDeleteMsg("Products(s)"));
	}
}
function checkMidNightThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
//	try
//	{
//		for(i=1;i<=objtbl.rows.length;i++)
//		{
//			var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
//			var objChk = document.getElementById(strObjName);
//			if((objChk!=null)&&(objChk.type == 'checkbox'))
//			if(objChk.checked)
//			{
//				flg = 1;
//			}
//		}
//	}
//	catch(e)
//	{
//		flg = 0
//	}
//	if(flg == 0)
//	{
//		alert(p_strMessage);
//		return false;
//	}
//	else 
//	{
		return confirm("Are you sure you want to make the selected Products(s) Mid Night");
//	}
}
function checkIntThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
//	try
//	{
//		for(i=1;i<=objtbl.rows.length;i++)
//		{
//			var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
//			var objChk = document.getElementById(strObjName);
//			if((objChk!=null)&&(objChk.type == 'checkbox'))
//			if(objChk.checked)
//			{
//				flg = 1;
//			}
//		}
//	}
//	catch(e)
//	{
//		flg = 0
//	}
//	if(flg == 0)
//	{
//		alert(p_strMessage);
//		return false;
//	}
//	else 
//	{
		return confirm("Are you sure you want to make the selected Products(s) International");
//	}
}
function chkMandatoryPrice(frmname,obj,name)
{
	strTestObjs = "document."+frmname+"."+obj
	strTestObj = strTestObjs+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj=="")
	{
		alert('Please enter the '+name)
		eval(strTestObjs+"."+"focus();");
		return 0;
	}
	else
	{
		    if(isNaN(strTestObj)==true)
			{
				alert('Please enter the numeric value in ' + name);
				eval(strTestObjs+"."+"focus();");
				return 0;
			}			
			//(+)ve
			if((strTestObj==0)&&(strTestObj!=''))
			{
				alert("Please enter the "+ name +" greater than 0 ");
				eval(strTestObjs+"."+"focus();");
				return 0;
			}
			if(isNaN(strTestObj)==false)
	        {
		        if (strTestObj.indexOf(".") >= 0)
		        {
			        var price1;
			        price1 = strTestObj.substring(strTestObj.indexOf(".")+1, strTestObj.length);
			        if(price1.length>2)
			        {
				        alert("Only two digits are allowed after decimal");
				        return 0;
			        }
		        }
	        }
	}	
}
function checkProdHomePageThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
	var flg = 0;
	var objtbl = document.getElementById(p_strDatagridId);	
	var RowID = objtbl.rows.length;					
	try
	{
		for(i=1;i<=objtbl.rows.length;i++)
		{
		    var strObjName = '';
		    if(i<=9)
			    strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
			else
			    strObjName = p_strDatagridId + '_ctl' + i + '_' + p_strCheckBoxName;
			    
			//var strObjName = p_strDatagridId + '_ctl' + 0+i + '_' + p_strCheckBoxName;
			var objChk = document.getElementById(strObjName);
			if((objChk!=null)&&(objChk.type == 'checkbox'))
			if(objChk.checked)
			{
				flg = 1;
			}
		}
	}
	catch(e)
	{
		flg = 0
	}
	if(flg == 0)
	{
		alert(p_strMessage);
		return false;
	}
	else 
	{
		return confirm("Are you sure you want to make the selected Products(s) Home Page Product(s)");
	}
}
function chkNonMandatoryPrice(frmname,obj,name)
{
	strTestObjs = "document."+frmname+"."+obj
	strTestObj = strTestObjs+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	if(strTestObj!="")
	{
		    if(isNaN(strTestObj)==true)
			{
				alert('Please enter the numeric value in ' + name);
				eval(strTestObjs+"."+"focus();");
				return 0;
			}
			//(+)ve
			if((strTestObj==0)&&(strTestObj!=''))
			{
				alert("Please enter the "+ name +" greater than 0 ");
				eval(strTestObjs+"."+"focus();");
				return 0;
			}
			if(isNaN(strTestObj)==false)
	        {
		        if (strTestObj.indexOf(".") >= 0)
		        {
			        var price1;
			        price1 = strTestObj.substring(strTestObj.indexOf(".")+1, strTestObj.length);
			        if(price1.length>2)
			        {
				        alert("Only two digits are allowed after decimal");
				        eval(strTestObjs+"."+"focus();");
				        return 0;
			        }
		        }
	        }
	}	
}
function chkViceVersaPrice(frmname,obj,obj1,name)
{
	strTestObjs = "document."+frmname+"."+obj
	strTestObj = strTestObjs+".value";
	strTestObj = strTestObj+'.replace(/ /g,"")'
	strTestObj = eval(strTestObj)
	
	
	strTestObjs1 = "document."+frmname+"."+obj1
	strTestObj1 = strTestObjs1+".value";
	strTestObj1 = strTestObj1+'.replace(/ /g,"")'
	strTestObj1 = eval(strTestObj1)	
	if((strTestObj!="")&&(strTestObj1==""))
	{
		alert('Please enter the Prices in both INR and USD');		
		eval(strTestObjs1+"."+"focus();");
		return 0;
	}
	if((strTestObj=="")&&(strTestObj1!=""))
	{
		alert('Please enter the Prices in both INR and USD');		
		eval(strTestObjs+"."+"focus();");
		return 0;
	}	
}
function AdminCngPasswordvalidate()
{
	var OldPassword=document.aspnetForm.ctl00$CPHolder$txtOldPassword.value.replace(/ /g,"");
	if(OldPassword=="")
	{
		alert("Please enter Old Password");
		document.aspnetForm.ctl00$CPHolder$txtOldPassword.focus();
		return false;
	}
	else
	{
		if(expvarchar.test(OldPassword)==true)
		{
			alert('Special characters like '+msg+' are not allowed in enter Old Password.');
			document.aspnetForm.ctl00$CPHolder$txtOldPassword.focus();
			return false;
		}
	}	
	
	var NewPassword=document.aspnetForm.ctl00$CPHolder$txtNewPassword.value.replace(/ /g,"")
	if(NewPassword=="")
	{
		alert("Please enter New Password");
		document.aspnetForm.ctl00$CPHolder$txtNewPassword.focus();
		return false;
	}
	else
	{
		if(expvarchar.test(NewPassword)==true)
		{
			alert('Special characters like '+msg+' are not allowed in enter New Password.');
			document.aspnetForm.ctl00$CPHolder$txtNewPassword.focus();
			return false;
		}
	}
	
	var ConfirmNewPassword=document.aspnetForm.ctl00$CPHolder$txtConfirmPassword.value.replace(/ /g,"")
	if(ConfirmNewPassword=="")
	{
		alert("Please Retype New Password");
		document.aspnetForm.ctl00$CPHolder$txtConfirmPassword.focus();
		return false;
	}
	else
	{
		if(expvarchar.test(ConfirmNewPassword)==true)
		{
			alert('Special characters like '+msg+' are not allowed in Retype New Password.');
			document.aspnetForm.ctl00$CPHolder$txtConfirmPassword.focus();
			return false;
		}
	}
	
	if(NewPassword!=ConfirmNewPassword)
	{
		alert("Your New Password and Retype New Password do not match")
		document.aspnetForm.ctl00$CPHolder$txtConfirmPassword.value="";
		document.aspnetForm.ctl00$CPHolder$txtNewPassword.value="";
		document.aspnetForm.ctl00$CPHolder$txtNewPassword.focus();
		return false;
	}	
	
}
function checkManCharLength(fn,strObj,strName,maxlen)
{
	strTestObj = "document."+fn+"."+strObj
	
	if(eval(strTestObj+".value")=='')
	{
		alert('Please enter the '+strName)		
		return 0
	}
	if (eval(strTestObj+".value.length")>maxlen)
	{
	  eval(strTestObj+".value="+strTestObj+".value.substring(0,"+maxlen+")");
	  alert(strName+" can only be "+ maxlen +" characters long");
	  return 0
	}
}
function checkUpdateThis(p_strDatagridId, p_strCheckBoxName, p_strMessage)
{
    if(DropDownListChk("aspnetForm","ctl00$CPHolder$cmbStatus","Status") == 0)
    {
        return false;
    }
    else
    {
	    var flg = 0;
	    var objtbl = document.getElementById(p_strDatagridId);
	    var RowID = objtbl.rows.length;					
	    try
	    {
		    for(i=0;i<objtbl.rows.length;i++)
		    {
			    var strObjName = 'ctl00_CPHolder_rptOrder_ctl' +0+i + '_' + p_strCheckBoxName;			
			    var objChk = document.getElementById(strObjName);			
			    if((objChk!=null)&&(objChk.type == 'checkbox'))
			    {
			        if(objChk.checked)
			        {
				        flg = 1;
			        }
			    }
		    }
	    }
	    catch(e)
	    {
		    flg = 0
	    }
	    if(flg == 0)
	    {
		    alert(p_strMessage);
		    return false;
	    }
	    else 
	    {
		    return confirm("Are you sure you want to update the selected Orders(s)");
	    }
	}
}