function check_emailval(obj,cap)
{
	var em=obj.value;
	/*if(obj.value=="")
	{
		alert(cap+" is mandatory");
		obj.focus();
		return false;
	}*/
	if(obj.value!="")
	{
	    atspos=em.indexOf('@') + 1;
	    dtspos=em.lastIndexOf('.');
	    len=em.length-3;
	    if(atspos < 2 || dtspos < 3  ||dtspos <= atspos || len<dtspos)
	    {
		    alert("Enter Valid E-mail Address");
		    obj.focus();
		    return false;
	    }
	}
	return true;
}
function CheckValidEmailSetup(obj,cap)
{
	var em=obj.value;
	if(obj.value!="")
	{
	    atspos=em.indexOf('@') + 1;
	    dtspos=em.lastIndexOf('.');
	    len=em.length-3;
	    if(atspos < 2 || dtspos < 3  ||dtspos <= atspos || len<dtspos)
	    {
		    alert("Enter Valid " + cap);
		    obj.focus();
		    return false;
	    }
	}
	return true;
}
function check_userform(frm)
{
	if(!blankval(frm.elements["name"]))	return false;
	if(!blankval(frm.elements["loginname"]))	return false;
	if(!blankval(frm.elements["password"]))	return false;
	if(!emailval(frm.elements["emailaddress"]))	return false;
	return true;
}
function open_photo(path,width,height)
{	
	/*width = parseInt(width);
	height= parseInt(height);
	scr= "no";
	if(width > 670)
	{
		width = 670;
		scr= "yes";
	}
	if(height > 550 )
	{
		height= 550;
		scr= "yes";
	}*/
	width = parseInt(width);
	height= parseInt(height);
	scr="no,resizable=no"
	if(width > 760)
	{
		width = 760;
		scr= "yes,resizable=yes";
	}
	if(height > 510 )
	{
		height= 510;
		scr= "yes,resizable=yes";
	}
	//window.open(path,"","munubar=0,statusbar=0,resizable=no,scrollbars="+ scr +",width="+(width+25)+",height="+(height+20)+",top=0,left=0");	
	window.open(path,"","munubar=0,statusbar=0,scrollbars="+ scr +",width="+(width+25)+",height="+(height+20)+",top=0,left=0");
}
function open_helppopup(module)
{
	var helpid;
	if(module=='home')
		helpid=1;
	else if(module=='ncr')
		helpid=2;
	else if(module=='cf')
		helpid=3;
	else if(module=='car')
		helpid=4;
	else if(module=='ri')
		helpid=5;
	else if(module=='csp')
		helpid=6;
	else if(module=='nm')
		helpid=7;
	else if(module=='meeting')
		helpid=8;	
	else if(module=='objective')
		helpid=9;
	else if(module=='cm')
		helpid=10;
	else if(module=='vendor')
		helpid=11;
	else if(module=='hr')
		helpid=12;
	else if(module=='sr')
		helpid=13;
	else if(module=='administrator')
		helpid=14;
	else if(module=='sm')
		helpid=15;
    else if(module=='pa')
        helpid=16;
    else if(module=='pmail')
        helpid=17;
    else if(module=='jmm')
        helpid=18;
	else if(module=='helpmanual')
        helpid=19;
	window.open("helpmodule.aspx?helpid="+helpid+"","","munubar=no,statusbar=0,scrollbars=yes,width=750,height=500,top=10,left=10,resizable=yes");
}
function meeting_popup(mid,tid)
{
	//window.open("shomeetings.aspx?mid="+mid+"","","munubar=no,statusbar=0,scrollbars=yes,width=750,height=500,top=10,left=10,resizable=yes");
	open_preview_actions("print_preview.aspx?printlist="+mid+"&templateid="+tid)
}
function open_preview_actions(printlist)
{	
		width = 750;
		height = 500;
		var w = 480, h = 340;
		if (document.all || document.layers)
		{
			w = screen.availWidth;
			h = screen.availHeight;
		}
		var topPos = (h-height)/2, leftPos = (w-width)/2;
		objwnd=window.open(printlist,"objwnd","munubar=0,statusbar=yes,resizable=no,scrollbars=yes,width="+(width)+",height="+(height)+",left="+ leftPos +",top="+ topPos +",screenX="+ leftPos +",screenY="+ topPos);	
		objwnd.focus();
}
function open_js_preview(path,width,height)
{	
	var w = 800, h = 600;
	if (document.all || document.layers)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	var topPos = (h-height)/2, leftPos = (w-width)/2;
	objpreviewwnd=window.open(path,"objpreviewwnd","munubar=0,statusbar=yes,resizable=no,scrollbars=yes,width="+(width+40)+",height="+(height+30)+",left="+ leftPos +",top="+ topPos +",screenX="+ leftPos +",screenY="+ topPos);	
	objpreviewwnd.focus();
}
function open_actionitems(path,height,width)
{	
		width = 750;
		height = 500;
		var w = 480, h = 340;
		if (document.all || document.layers)
		{
			w = screen.availWidth;
			h = screen.availHeight;
		}
		var topPos = (h-height)/2, leftPos = (w-width)/2;
		objwnd=window.open(path,"objwnd","munubar=0,statusbar=yes,resizable=yes,scrollbars=yes,width="+(width)+",height="+(height)+",left="+ leftPos +",top="+ topPos +",screenX="+ leftPos +",screenY="+ topPos);	
		objwnd.focus();
}
function emailval(obj) {
    var str = obj.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;    
    if (!str.match(re))
	{
        alert("Enter Valid E-mail Address");
		obj.focus();
        return false;
    }
	else
	{
		dtspos=str.lastIndexOf('.');
		if(dtspos > 0)
		{
			//alert(str.substring(dtspos).length-1)		
			if(str.substring(dtspos).length > 4)
			{
				alert("Enter Valid E-mail Address");
				obj.focus();
				return false;
			}
		}
        return true;
    }
}
/*
function emailval(obj)
{
	var em=obj.value;
	atspos=em.lastIndexOf('@');
	dtspos=em.indexOf('.',atspos);
	if(atspos < 0 || dtspos < 0)
	{
		alert("Enter Valid E-mail Address");
		obj.focus();
		return false;
	}
	return true;
}*/
function isValidDate(obj,message)
{
	dt=obj.value;
	myDate = new Date(dt);
	arrday=dt.split("/");
//	alert(arrday[1]);
	if(parseInt(myDate.getDate()) != arrday[1])
	{
		alert('Enter Valid '+ message);
		obj.focus();
		return false;
	}
	else
		return true;
}
function valid_dbname(obj)
{
	var tempstr;
	tempstr = obj.value;
	var nreg= /[^0-9]/g;
	nresult = tempstr.charAt(0).match(nreg);
	if(nresult == null)
	{
		obj.focus();
		alert("In Database Name, first char must be alpha char not a number")
		return false;
	}
	
	nresult = tempstr.match(nreg);
	if(nresult == null)
	{
		obj.focus();
		alert("In Database Name, only numbers are not allowed, please use alpha chars with numbers")
		return false;
	}
	else
	{
		var reg = /[^A-Za-z0-9_]/g;
		result = tempstr.match(reg);
		if(result != null)
		{
			obj.focus();	
			alert("Please enter valid Database Name. \n\n Only alpha-numeric,_ characters are allowed.")
			return false;
		}
		else
			return true;
	}
}
function validcost(obj,msg)
{
	if(obj.value == "" || isNaN(obj.value))
	{
		alert("Please enter valid "+msg)
		obj.value="0.00"
		obj.focus()
		return false;
	}
	else
		return true;
}
function validnumeric(obj)
{
	if(obj.value == "" || isNaN(obj.value))
	{
		alert("Only Numeric Value are allowed");
		obj.focus()
		return false;
	}
	else
		return true;
}
function checked_selected(frm,msg,caption)
{
	flg=false;
	chbox = frm.elements['usercheck'];
	if(chbox)
	{
		for(i=0;i<chbox.length;i++)
		{
			flg=chbox[i].checked;
			if(flg)break;		
		}
		if(!chbox.length)
			flg=chbox.checked;
		if(flg)
		{
			//if(confirm("Are you sure! You want to "+msg+" all selected "+caption+"?"))
			//{
				return true;
			//}
		}		
		else
		{
			alert("Please select any "+caption+" to "+msg+".");
			return false;
		}
	}
	else
	{
		alert("Record does not Exist for "+msg+".");
		return false;
	}
	return false;
}
function selectall_checkbox(frm,e,msg)
{
	chbox = frm.elements['usercheck'];
		
	if(chbox)
	{
		if(!chbox.length)	chbox.checked=e.checked;
		for(i=0;i<chbox.length;i++)
			chbox[i].checked=e.checked;
	}
	else
	{
		e.checked=false;
		alert("Record does not Exist for "+msg+".");
	}	
}


function IsIntVal(obj)
{
	var strVal = obj.value
	if(strVal.indexOf('.')>-1 || isNaN(obj.value) || obj.value=='')
	{
		alert('Only Integer Value are allowed.')
		obj.focus();
		return false;
	}
	return true;
}
function IsIntValWithoutBlank(obj)
{
	var strVal = obj.value
	if(strVal.indexOf('.')>-1 || isNaN(obj.value))
	{
		alert('Only Integer Value are allowed.')
		obj.focus();
		return false;
	}
	return true;
}
function blankval(obj)
{
	if(obj.value=="")
	{
		alert("* indicates required fields");
		obj.focus();
		return false;
	}
	return true;
}
function NotBlank(obj,cap)
{
	
	if(obj.value=="")
	{
		alert(cap + " is mandatory");
		obj.focus();
		return false;
	}
	return true;
}
/*
function displaySnippetIcon(frmobj,fldname,formid)
{
	document.write("&nbsp;<img align=top src='images/snippeticon.ico'  height=25 border=0>");
}*/
function CARRecordLink(carid,backpage,utype)
{
	if(utype==3)
	{
		openrecordinprintmode(carid,3);
	}
	else
	{
		document.Form1.carid.value=carid;
		document.Form1.backpage.value=backpage;
		document.Form1.gocaraddeditpage.value="true";
		document.Form1.__EVENTTARGET.value="LinkButton3";
		document.Form1.submit();
	}
}

function openrecordinprintmode(id,flag)
{	
	if(id != "")
	{
		width = 750;
		height = 500;
		var w = 480, h = 340;
		if (document.all || document.layers)
		{
			w = screen.availWidth;
			h = screen.availHeight;
		}
		var topPos = (h-height)/2, leftPos = (w-width)/2;
		objwnd=window.open("review_records.aspx?printlist="+id+"&templateflag="+flag,"objwnd","munubar=0,statusbar=yes,resizable=no,scrollbars=yes,width="+(width)+",height="+(height)+",left="+ leftPos +",top="+ topPos +",screenX="+ leftPos +",screenY="+ topPos);	
		objwnd.focus();
	}
	else
	{
		alert("Please select at least one record to print.");
	}
}
function CARGridLinks(tablename,primaryid,utype)
{
	if(utype==3)
	{
		switch(tablename)
		{
			case "ncr":
				openrecordinprintmode(primaryid,1);
				break;
			case "customercomplaint":
				openrecordinprintmode(primaryid,2);
				break;
			case "nm":
				openrecordinprintmode(primaryid,11);
				break;
		}
	}
	else
	{
		document.Form1.primaryid.value=primaryid;
		document.Form1.action.value="edit";
		document.Form1.comesfromcar.value="true";
		switch(tablename)
		{
			case "ncr":
				document.Form1.__EVENTTARGET.value="LinkButton1";
				break;
			case "customercomplaint":
				document.Form1.__EVENTTARGET.value="LinkButton2";
				break;
			case "nm":
				document.Form1.__EVENTTARGET.value="LinkButton11";
				break;
		}
		document.Form1.submit();
	}
}
function submit_onncr(primaryid,backpage)
{
	eventTarget="ncr1:ncr_LinkButton2";
	frm=document.Form1;	
	frm.__EVENTTARGET.value=eventTarget.split("$").join(":");
	frm.subtab__EVENTTARGET.value="ncr1:ncr_LinkButton2";
	frm.maintab__EVENTTARGET.value="LinkButton1";
	frm.ncrid.value=primaryid;
	//frm.primaryid.value=primaryid;
	frm.fromdamagegrid.value="1";
	document.Form1.submit();
    //alert('Under Construction');
}
function submit_onworkorder(primaryid,backpage)
{
	eventTarget="proc1:wo1:wo_LinkButton2";
	
	frm=document.Form1;	
	frm.backpage.value=backpage;
	frm.__EVENTTARGET.value=eventTarget.split("$").join(":");
	frm.subtab__EVENTTARGET.value="proc1:home_LinkButton6";
	frm.maintab__EVENTTARGET.value="LinkButton7";
	frm.primaryid.value=primaryid;
	frm.action.value="editwo";
	document.Form1.submit();
}
function submit_oninspection(primaryid,backpage)
{
	eventTarget="damage1:dm_LinkButton2";
	frm=document.Form1;	
	frm.backpage.value=backpage;
	frm.__EVENTTARGET.value=eventTarget.split("$").join(":");
	frm.subtab__EVENTTARGET.value="damage1:dm_LinkButton2";
	frm.maintab__EVENTTARGET.value="LinkButton4";
	frm.primaryid.value=primaryid;
	frm.action.value="fromncr";
	document.Form1.submit();
}
function WOGridLinks(tablename,primaryid)
{
	document.Form1.primaryid.value=primaryid;
	document.Form1.action.value="edit";
	document.Form1.comesfromwo.value=tablename;
	switch(tablename)
	{
		case "ncr":
			document.Form1.__EVENTTARGET.value="LinkButton1";
			break;
		case "cc":
			document.Form1.__EVENTTARGET.value="LinkButton2";
			break;
		case "car":
			document.Form1.__EVENTTARGET.value="LinkButton3";
			document.Form1.carid.value=primaryid;
			break;
		case "nm":
			document.Form1.__EVENTTARGET.value="LinkButton11";
			break;
		case "clb":
			document.Form1.__EVENTTARGET.value="manage1:calibration1:cal_LinkButton2";
			document.Form1.maintab__EVENTTARGET.value="LinkButton5";
			document.Form1.subtab__EVENTTARGET.value="manage1:mg_LinkButton4";
			break;
	}
	
	document.Form1.submit();
}
function Close_FormView()
    {
        if($get("Div_productFormView"))
            $get("Div_productFormView").style.display="none";
        if($get("Div_productGridView"))
            $get("Div_productGridView").style.display="block";
    }
function HideShowBlock(divid)
{
	if(divid!="")
	{
		objdiv=document.getElementById(divid);
		if(objdiv)
		{
			objkeydiv=eval("document.getElementById('key_" + divid + "')");
			if(objkeydiv.src.indexOf("plus") == -1 )
			{
				objdiv.style.display="none";
				objkeydiv.src="images/plus_a.gif";
			}
			else
			{
				objdiv.style.display="block";
				objkeydiv.src="images/minus_a.gif";
			}
		}
	}
}
function UsDateFormat(DateValue)
{
    //alert("DateValue - " + DateValue);
    d = new Date(DateValue);            //Create Date object.
    //alert("ParseDateValue - " + d);
    var dd ;
    var s = (d.getMonth() + 1); //+ "/";   //Get month
    if(s < 10)
        s="0" + s + "/";
    else s= s + "/";
     if(d.getDate() < 10)
       dd = "0" + d.getDate();   
        else
    dd = d.getDate();   
    //s += d.getDate() + "/";              //Get day
    s += dd + "/";              //Get day
    s += d.getFullYear();
   
    return s;
}
function View_Record(id)
{
    open_dialogbox('view_mprocess.aspx?id='+id,700,600,'yes','yes','','1');
}
function open_dialogbox(path,width,height,resize,scroll,status,samewindow)
{	
	var w = 480, h = 340;
	
	if(!width)
		width="700";
	if(!height)
		height="500";
	if(!resize)
		resize="yes";
	if(!scroll)
		scroll="no";
	if(!samewindow)
		samewindow="objwnd";
	if(!status)
		status="no";
	
		
	if (document.all || document.layers)
	{
		w = screen.availWidth;
		h = screen.availHeight;
	}
	var topPos = (h-height)/2, leftPos = (w-width)/2;
	objwnd=window.open(path,samewindow,"munubar=no,titlebar=no,status="+status+",resizable="+resize+",scrollbars="+scroll+",width="+(width)+",height="+(height)+",left="+ leftPos +",top="+ topPos +",screenX="+ leftPos +",screenY="+ topPos);	
	objwnd.focus();
}
function DivHideShow(mainid,divid)
{
    objdiv=document.getElementById(divid);
    if(mainid.checked==true)
    {  objdiv.style.display="block";}

    else
    {  objdiv.style.display="none";}
}
function setonScroll(divObj,DgID)  
{
    var datagrid = document.getElementById(DgID);
	var HeaderCells;
	if(datagrid!=null)
	    HeaderCells = datagrid.getElementsByTagName('td');

    var HeaderRow;
    if(HeaderCells == null || HeaderCells.length == 0)
    {
		if(datagrid!=null)
		{
        	var AllRows = datagrid.getElementsByTagName('tr');
        	HeaderRow = AllRows[0];  
		}
		else
		{
			currentobj=divObj.getElementsByTagName('tr');
			HeaderRow=currentobj[0];
		}
    }
    else
    {
        
		HeaderRow = HeaderCells[0].parentNode;
    }
    var DivsTopPosition = parseInt(divObj.scrollTop);
    if(DivsTopPosition>0)
    {
        HeaderRow.style.position = 'absolute';
        HeaderRow.style.top = (parseInt(DivsTopPosition)).toString() + 'px';
        HeaderRow.style.zIndex='1000';
    }
    else
    {
        divObj.scrollTop = 0;
        HeaderRow.style.position = 'relative';
        HeaderRow.style.top = '0';
        HeaderRow.style.bottom='0';
        HeaderRow.style.zIndex='0';                
    }
	//HeaderRow.setAttribute("style","border:1px solid red");
	//HeaderRow.className="title_bar";
	
	
	//document.getElementById("testtable1").cellSpacing="1";
	//document.getElementById("testtable1").cellPadding="4";
	if(HeaderCells!=null)
	{
		for(i=0;i<HeaderCells.length;i++)
		{
			//HeaderCells[i].style.background="url(images/bar_background.gif)";
		}
	}
}
function HideShowDivByCompactMode(objcompactmode)
{
	if(objcompactmode.checked==true)
	{
	    document.getElementById("div_scrollable").style.display="none";
	    document.getElementById("div_scrollable1").style.display="block";
	}
	else
	{
	    document.getElementById("div_scrollable").style.display="block";
	    document.getElementById("div_scrollable1").style.display="none";
	}
}
function ReplaceUnneededChars(searchstr)
{
    searchstr=searchstr.replace(/</g,"").replace(/>/g,"");
    return searchstr;
}
function CheckForDecimalValue(Obj, event) {
    if (event.which) // mozilla
        var key = event.which;
    else // ie
        var key = event.keyCode;

    //alert(key);
    if (Obj.value.length == 10 && key != 8)
        return false;
    if (key == 46 && Obj.value.indexOf(".") > -1)
        return false;

    if ((key >= 48 && key <= 57) || key == 8 || key == 46)
        return true;

    return false;
}
