// JavaScript Document
/// show hide edit field

function my_pop_up(i)
{

   var kkk;
   kkk=window.open("_show_detail_requirement.php?i="+i, "Window_name","resizable=0,HEIGHT=500,WIDTH=660,left=200,top=100,replace,scrollbars"); 
   kkk.focus();
}

function firstlistbox(listboxid)
{
	var objSelect = document.getElementById(listboxid);
	objSelect.options[0].selected = true;
}
function checkimage(mid)
{

	if(ISBLANK(document.getElementById(mid).value))
	{
	    // do nothing //
	}
	else
	{
		if (IsValidimage(document.getElementById(mid).value)==false)
	    {
		  return false;
		}
    }	
}
function settextbox(textboxid,textboxvalue)
{	
	document.getElementById(textboxid).value=textboxvalue;
}
	// Isvalidexcel .xls
function Isvalidexcel(xx) 
	{   
	    var str=xx;
		
		var dotpos=str.lastIndexOf('.');
		var rr=(str.charAt(dotpos+1)+str.charAt(dotpos+2)+str.charAt(dotpos+3)+str.charAt(dotpos+4));
		
		if (rr.toLowerCase()=="xls" )
		{
			return true;
		}
		else
		{
			return false;
		}
    }

function show_edit(rowid)
{
var x;
var rowid=rowid;
// table-row or none
if(document.getElementById(rowid).style.display=="none")
{
   try
   {
   document.getElementById(rowid).style.display="table-row";
   }
   catch(e)
   {
      document.getElementById(rowid).style.display="block";
   }
}
else
{
document.getElementById(rowid).style.display="none";
}
}
// 
function show_divid_upon_value(val,id)
{
var x;
var eleid=id;
// table-row or none

if(val==1)
{
      document.getElementById(eleid).style.display="block";
}
else
{
	document.getElementById(eleid).style.display="none";
}
}

function show_divid(id)
{
var x;
var eleid=id;
// table-row or none
if(document.getElementById(eleid).style.display=="none")
{
      document.getElementById(eleid).style.display="block";
}
else
{
	document.getElementById(eleid).style.display="none";
}
}

//
function loginstatus()
{
 var go = confirm("Are you sure to change login status ?");
 if (go == true) {
   return true;
 }
 else {
  return false;
 }	
}
/// delete confir
function create() {
 var go = confirm("Are you sure to DELETE this record?");
 if (go == true) {
   return true;
 }
 else {
  return false;
 }
}

function popmsg(str) {
 var go = confirm(str);
 if (go == true) {
   return true;
 }
 else {
  return false;
 }
}

function msgunvoid() {
 var go = confirm("Are you sure to Un-void this record?");
 if (go == true) {
   return true;
 }
 else {
  return false;
 }
}

function msgvoid() {
 var go = confirm("Are you sure to void this record?");
 if (go == true) {
   return true;
 }
 else {
  return false;
 }
}

function msgdeletefile()
{
 var go = confirm("Are you sure to delete this file ?");
 if (go == true) {
   return true;
 }
 else {
  return false;
 }	
}
function roundNumber(number,decimal_points) 
{
//
	if(!decimal_points) return Math.round(number);
	if(number == 0) {
		var decimals = "";
		for(var i=0;i<decimal_points;i++) decimals += "0";
		return "0."+decimals;
	}

	var exponent = Math.pow(10,decimal_points);
	var num = Math.round((number * exponent)).toString();
	return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
}
/// check is it blank
function ISBLANK(xx)
{ 
        var cc=0,tt;
		for(tt=0; tt<xx.length; tt++)
		{
		     if (xx.charAt(tt)==' ')
			 {
			 	cc=cc+1; // count blank character
			 }
		}
		if (cc==xx.length)
		{
			return true;  //// means it is BLANK
		}
	     return false;	//// means it is NOT BLANK
}

// is valid image file jpg/jpeg/gif
function IsValidimage(xx) 
	{   
	    var str=xx;
		
		var dotpos=str.lastIndexOf('.');
		var rr=(str.charAt(dotpos+1)+str.charAt(dotpos+2)+str.charAt(dotpos+3)+str.charAt(dotpos+4));
		
		if (rr.toLowerCase()=="jpg" || rr.toLowerCase()=="gif" || rr.toLowerCase()=="jpeg" || rr.toLowerCase()=="png")
		{
			return true;
		}
		else
		{
			return false;
		}
    }
function Isvalid_video_file(xx) 
	{   
	    var str=xx;
		
		var dotpos=str.lastIndexOf('.');
		var rr=(str.charAt(dotpos+1)+str.charAt(dotpos+2)+str.charAt(dotpos+3)+str.charAt(dotpos+4));
		
		if (rr.toLowerCase()=="avi" || rr.toLowerCase()=="mpg" || rr.toLowerCase()=="flv" )
		{
			return true;
		}
		else
		{
			return false;
		}
    }	
///////// RADIO BUTTON VALIDATION ////////

/*
/// how to call in main function
function CheckAll(x)
{
if(!is_radio_button_selected(x.radiobutton_name))
{
  alert ("Please select radio button !!");
  return false;
}
}
*///

function is_radio_button_selected(fieldnm)
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < fieldnm.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (fieldnm[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
return (false); /// means not selected
}
return (true); /// means selected
}

///
function is_checkbox_button_selected(fieldnm)
{
// set var radio_choice to false
var radio_choice = false;

// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < fieldnm.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (fieldnm[counter].checked)
radio_choice = true; 
}

if (!radio_choice)
{
return (false); /// means not selected
}
return (true); /// means selected
}

///

function checkemail(myemail)
{
var str=myemail;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
{
testresults=true
}
else
{
testresults=false
}
return (testresults)
}