// JavaScript Document
/// show hide edit field

function popup_billto()
{
	 showPopWin('Insurance Company','_show_insurance_company_list.php', 950, 500, null);
}
function popup_shipto()
{
	 showPopWin('Client Address','_show_ship_to_list.php', 950, 500, null);
}


function termspopup()
{
	 showPopWin('Terms Of Services','_popupterms.php', 900, 500, null);
}


function privacypopup()
{
	 showPopWin('Privacy','_popupprivacy.php', 900, 500, null);
}

function orderingpolicypopup()
{
	 showPopWin('Privacy','_popuporderingpolicy.php', 900, 500, null);
}


/////


function createCookie(c_name,value,expiredays) {
		var expiredays=1;
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function add_main_links()
{
	window.location='_add_mainpage_link.php';
}

function add_sub_links(mainid)
{
	
	window.location='_add_mainpage_link.php?mainid='+mainid;
}
function you_need_login()
{
	showPopWin(' ','_you_need_to_login.php', 655, 220, null,true);
}

function add_new_insurance_company_popup()
{
	showPopWin('Add new insurance company','add_insurancecompany.php', 655, 470, null,true);
}


function add_new_client_popup()
{
	showPopWin('Add new client','add_clientaddressbook.php', 655, 540, null,true);
}



function edit_insurance_company_popup(i)
{
	showPopWin('Edit insurance company','edit_insurancecompany.php?id='+i, 655, 470, null,true);
}

function edit_client_popup(i)
{
	showPopWin('Edit client','edit_clientaddressbook.php?id='+i, 655, 520, null,true);
}

function edit_shipp_address()
{
	

	abhurlwindow('','_ship_chk_edit.php',600,530,0);	
}
function edit_bill_address()
{
	
	abhurlwindow('','_bill_chk_edit.php',650,530,0);	

}
function set_id_value(sourceid,str)
{
document.getElementById(sourceid).value=str;	
}
function copy_content(sourceid,targetid)
{
document.getElementById(targetid).value=document.getElementById(sourceid).value;
}
// remove blank space from value
function remove_space_all(str)
{
	var str=str;
	return (str.replace(/ /g, ""));
}
function remove_space_all(str)
{

var str=str;
return (str.replace(/ /g, ""));
}

function divblock(id,show)
{
	if(show==1)
	{
		document.getElementById(id).style.display="";	
	}
	if(show==0)
	{
		document.getElementById(id).style.display="none";	
	}

	
}
function showhide(id,show)
{
	if(show==1)
	{
		document.getElementById(id).style.display="block";	
	}
	if(show==0)
	{
		document.getElementById(id).style.display="none";	
	}

	
}
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 roundNumber(pnumber,decimals){
	if (isNaN(pnumber)) { return 0};
	if (pnumber=='') { return 0};
	
	var snum = new String(pnumber);
	var sec = snum.split('.');
	var whole = parseFloat(sec[0]);
	var result = '';
	
	if(sec.length > 1){
		var dec = new String(sec[1]);
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
		var dot = dec.indexOf('.');
		if(dot == -1){
			dec += '.'; 
			dot = dec.indexOf('.');
		}
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	} else{
		var dot;
		var dec = new String(whole);
		dec += '.';
		dot = dec.indexOf('.');		
		while(dec.length <= dot + decimals) { dec += '0'; }
		result = dec;
	}	
	return result;
}


function roundNumber_old(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)
}

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

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


/// 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;
		}
    }
	
///////// 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 GetRadioButtonValue(id)

        {

            var radio = document.getElementsByName(id);

            for (var ii = 0; ii < radio.length; ii++)

            {

                if (radio[ii].checked)

                    return radio[ii].value;

            }

			return '';
        }
		
		
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)
}


function attri_listbox(id,attriname)
{
		// for listbox
		var selected_index = document.getElementById(id).selectedIndex;
		
		var my_attri_val = document.getElementById(id).options[selected_index].getAttribute(attriname);
		if( my_attri_val)
		{
		  return my_attri_val;
		}
		else
		{
		  return "";
		}

}

function attri(id,attriname)
{
		// for text box, label, textarea
		var my_attri_val= document.getElementById(id).getAttribute(attriname);
		
		
		if( my_attri_val)
		{
		  return my_attri_val;
		}
		else
		{
		  return "";
		}

}

