/***************************************************************************/
/*     PROGRAMMER     :  ASW                                               */
/*     SCRIPT NAME    :  js.js                                             */
/*     Java Script Functions For the user area                             */
/***************************************************************************/

/*----------------------------------------------------------------
	Description   :- function to validate an email id
	Programmer    :- ASW
-------------------------------------------------------------------*/


	function isBadEmail(strg) {
		email_array = strg.split('@');
		if (email_array.length != 2) return true;
		if (email_array[1].split(".").length < 2) return true;
		if (email_array[1].split(".")[1].length < 1) return true;
		if (strg.indexOf('@') < 1) return true;
		if (strg.indexOf(' ') != -1) return true;
		if (email_array[1].indexOf('.') < 1) return true;
		if (strg.length < 5) return true;
		return false;
	}

	function OpenWindow(url)
	{
		nw = open(url,'new','height=450,width=450,scrollbars=yes,resizable=1');
		nw.focus();
	}

	function GetFromDate()
	{
		gfPop.fStartPop(document.forPeriod.fromdate,Date);
	}

	function GetToDate()
	{
		gfPop.fStartPop(document.forPeriod.todate,Date);
	}

//statuis updation confirmation
	function updatestatusconfirm(page,name,id,status,mode,type)
	{
		if(confirm("Are you sure to modify the " + status +" status of this " + name + "?"))
		window.location = page + "?name=" + name + "&id=" + id + "&status=" + status +"&mode="+ mode+"&type="+type ;
	}

//deletion confirmation
	 function deleteconfirm(page,name,id,mode,type)
	{ 
		if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
		window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode+"&type="+type;
	}


//merchant personal informations
	function merchant_personal_info(msg1,msg2,msg3,msg4,msg5,msg6,process)
	{
	//Checks the password
		if(CheckPassword(msg1)) {
		//Confirm pasword
			if(ConfirmPassword(msg2,msg3)) {
			//Check & confirm Email Address
				if(ConfirmEmail(msg4,msg5,msg6)) {
					
					var fname = document.frm_mer.txt_fname.value;
					var lname = document.frm_mer.txt_lname.value;
					var uname = document.frm_mer.txt_uname.value;
					var pass = document.frm_mer.txt_password.value;
					var address = document.frm_mer.txt_address.value;
					var city = document.frm_mer.txt_city.value;
					var state = document.frm_mer.sel_state.value;
					var zip = document.frm_mer.txt_zip.value;
					var email = document.frm_mer.txt_email.value;
					var phone = document.frm_mer.txt_phone.value;
					var alt_phone = document.frm_mer.txt_alt_phone.value;
					var mobile = document.frm_mer.txt_mobile.value;
					var fax = document.frm_mer.txt_fax.value;
					var linkId = document.frm_mer.linkId.value;
					var parentId = document.frm_mer.parentId.value;
					var img_code = document.frm_mer.txt_img_verification.value;
					var pass_confirm = document.frm_mer.txt_confirm_password.value;
					var bu_name = document.frm_mer.txt_bu_name.value;
					var mer_country = document.frm_mer.mer_country.value;
					var membership_countryId = document.frm_mer.membership_countryId.value;
					var txt_state = document.frm_mer.txt_state.value;
					
					var url = "merchant_personal.php?fname="+fname+"&lname="+lname+"&uname="+uname+"&pass="+pass+"&address="+address+"&city="+city+"&state="+state+"&zip="+zip+"&email="+email+"&phone="+phone+"&alt_phone="+alt_phone+"&mobile="+mobile+"&fax="+fax+"&linkId="+linkId+"&parentId="+parentId+"&img_code="+img_code+"&pass_confirm="+pass_confirm+"&bu_name="+bu_name+"&mer_country="+mer_country+"&membership_countryId="+membership_countryId+"&txt_state="+txt_state+"&process="+process;
					
					//alert (url);
					ajaxpage(url,'personal');
				}
			}
		}
	}
//merchant business informations
	function merchant_business_info(){  
		var business = document.frm_mer.txt_bu_name.value;
		var uri = document.frm_mer.txt_url.value;
		var pid = document.frm_mer.txt_pid.value;
		var title = document.frm_mer.txt_title.value;
		var tagline = document.frm_mer.txt_tagline.value;
		var plus4 = document.frm_mer.txt_plus4.value;
		var yr_open = document.frm_mer.txt_yr_open.value;
		var hours = document.frm_mer.txt_hrs_operation.value;
		var language = document.frm_mer.txt_language.value;
		var donot = document.frm_mer.txt_donot.value;
		var mer_id = document.frm_mer.id.value; 
		var url = "merchant_business.php?business="+business+"&url="+uri+"&pid="+pid+"&title="+title+"&tagline="+tagline+"&plus4="+plus4+"&yr_open="+yr_open+"&hours="+hours+"&language="+language+"&donot="+donot+"&mer_id="+mer_id;
		//alert('url = '+url);
		
		ajaxpage(url,'personal'); 
	}	

//merchant service payment informations
	function merchant_service_plan_info(){ 
	
		var service = document.frm_mer.select_service.value;
		var plan = document.frm_mer.sel_plan.value;
		var plan_interval = document.frm_mer.sel_plan_interval.value;
		var mer_id = document.frm_mer.mer_id.value;
		/*var title = document.frm_mer.txt_title.value;
		var tagline = document.frm_mer.txt_tagline.value;
		var plus4 = document.frm_mer.txt_plus4.value;
		var yr_open = document.frm_mer.txt_yr_open.value;
		var hours = document.frm_mer.txt_hrs_operation.value;
		var language = document.frm_mer.txt_language.value;
		var donot = document.frm_mer.txt_donot.value;*/
		//var logo = document.frm_mer.txt_logo.value;
		//alert(service+'plan'+plan+'interval'+plan_interval);
		
		var url = "merchant_service_plan.php?service="+service+"&plan="+plan+"&plan_interval="+plan_interval+"&mer_id="+mer_id;
		//alert('url = '+url); 
		ajaxpage(url,'personal');
	}	




	function SubmitSearch(frm,url)
	{  
		var title = frm.txt_search.value;	 
		title = leftTrim(title);
		title = rightTrim(title);
		
		var dept = frm.dept.value;	 
		var test = url+"&txt_search="+title+"&dept="+dept;   
		frm.action=test;
		frm.submit();
	}


	function leftTrim(sString)
	{
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		return sString;
	}

	function rightTrim(sString)
	{
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}

	function get_plans(id)
	{
		var val= id.value;
		var url = "get_merchant_plans.php?service_id="+val;
		var url1 = "get_plan_interval.php?service_id="+val;
		var url2 = "get_plan_price.php?service_id="+val;
		ajaxpage(url,'sel_plan'); 
		ajaxpage(url1,'sel_interval');
		ajaxpage(url2,'dis_plan_price'); 
	}
	function get_plan_interval(id,service_id)
	{
		var val= id.value;
		var url = "get_plan_interval.php?plan_id="+val+"&service_id="+service_id;
		var url1 = "get_plan_price.php?plan_id="+val+"&service_id="+service_id;	
		ajaxpage(url,'sel_interval'); 
		ajaxpage(url1,'dis_plan_price');
	}

	function get_plan_price(id)
	{
		var val= id.value;
		var url = "get_plan_price.php?per_id="+val; 
		ajaxpage(url,'dis_plan_price'); 
	}

	function checkusername_exist()
	{	
		var uname1 = document.frm_mer.txt_uname.value;
		uname1 = leftTrim(uname1);
		uname1 = rightTrim(uname1);
		if(uname1 != '') {
			var url = "checkuname_exist.php?uname="+uname1;
			ajaxpage(url,'span_uname'); 
		}
	}
	function checkusername_exist_sub()
	{	
		var uname1 = document.frm_emp_add.txt_uname.value;
		uname1 = leftTrim(uname1);
		uname1 = rightTrim(uname1);
		if(uname1 != '') {
			var url = "checkuname_exist.php?uname="+uname1;
			ajaxpage(url,'span_uname_sub'); 
		}
	}

//Checks if the Password is valid
	function CheckPassword(msg)
	{
		var pass = document.getElementById('txt_password').value;
		if(pass.length < 6) {
			document.getElementById('span_password').innerHTML = msg;	
			document.getElementById('txt_password').focus();
			return false;
		} else {
			document.getElementById('span_password').innerHTML = '';	
		}
		return true;
	}

//Confirms the Passwords
	function ConfirmPassword(msg1, msg2)
	{
		var pass = document.getElementById('txt_password').value;
		var newpass = document.getElementById('txt_confirm_password').value;
		if(pass != newpass) {
			document.getElementById('span_confirm_password').innerHTML = msg1;	
			//document.getElementById('txt_confirm_password').focus();
			//return false;
		} else {
			document.getElementById('span_confirm_password').innerHTML = msg2;	
		}
		return true;
	}

//Confirms the Email
	function ConfirmEmail(msg1, msg2, msg3)
	{  
		var email = document.getElementById('txt_email').value;
		if(isBadEmail(email)) {
		document.getElementById('span_email').innerHTML = msg3;	
		document.getElementById('txt_email').focus();
		return false;
	} else {
		document.getElementById('span_email').innerHTML = '';
	}
		var newemail = document.getElementById('txt_confirm_email').value;
		if(email != newemail) {
			document.getElementById('span_confirm_email').innerHTML = msg1;	
			document.getElementById('txt_confirm_email').focus();
			return false;
		} else {
			document.getElementById('span_confirm_email').innerHTML = msg2;	
			return true;
		}
	}


//Show or hide the tree.  Used in the Service Plan selection
	function ShowOrHideServiceTree(id, imgId)
	{
		if(document.getElementById(id).style.display == 'block')
		{
			document.getElementById(id).style.display = 'none';
			document.getElementById(imgId).src = 'images/arrow.gif';
		}
		else {
			document.getElementById(id).style.display = 'block';
			document.getElementById(imgId).src = 'images/arrow_down.png';
		}
	}

//function to check the Cart seelction and to redirect the page to display the cart
	function CheckAddToCart(serviceId,selectPlanMsg,previousOrderId,process)
	{	 
		var prdId = 'radio_'+serviceId; 
		var test = 'document.frm_plans.'+prdId+'.length';		 
		var count = eval(test);
		flag = 0;  
		for(i=0; i<count-1; i++)
		{
			var rd  = 'document.frm_plans.'+prdId+'['+i+'].checked';	 
			var chk = eval(rd); 
			if(chk)
			{
				var rdValue = 'document.frm_plans.'+prdId+'['+i+'].value';
				value = eval(rdValue);   
				flag = 1;
			}
		}

		if(flag == 0)
		{
			alert(selectPlanMsg);
			return false;
		} 
		else if(process == 'outside_plan')
		{
			window.location.href = 'index.php?process=outside_plan&action=purchase&productId='+value;
		}
		else {  
			if(previousOrderId) {
				window.location.href = 'index.php?process=myPlans&action=purchase&productId='+value+'&previousOrderId='+previousOrderId;
			}
			else {
				window.location.href = 'index.php?process=servicePlans&action=purchase&productId='+value;
			}
		}
	}

//check if free employee addition is possible
 	function check_if_free(service_id,no_free_emp,container_id,emp_mer_id)
	{	
		var url = "check_if_free_emp_add.php?service_id="+service_id+"&free_emp="+no_free_emp+"&emp_mer_id="+emp_mer_id;
		ajaxpage(url,container_id); 
	}


//Appends the value of the mode of Renewal with the payment url
	function ProcessPayment(url, id, mode, gateway)
	{  
	
		if(mode == 'annually' && gateway != 'cheque') {
			var prdId = 'renewal_'+id; 
			for(i=0; i<2; i++) {
				var check = "document.cart_pay."+prdId+"["+i+"].checked"; 
				if(eval(check)) {
					var renew = "document.cart_pay."+prdId+"["+i+"].value";
					var renewal = eval(renew); 
					url = url+"&renewal="+renewal;
				}
			}
		}
		window.location.href = url;
	}

	function check_ticket(msg1,msg2)
	{ 
		if ( ( document.sendmail.user.value == "" ) || ( document.sendmail.email.value == "" )
		|| ( document.sendmail.subject.value == "" ) || ( document.sendmail.message.value == "" ) )
		//alert( "Supply Values for all fields" ) ;
		alert(msg1);
		else if(isBadEmail(document.sendmail.email.value)) 
		//alert( "Invalid Email Address" ) ; 
		alert(msg2);
		else
		document.sendmail.submit() ;
	}
	
	function cofirmchatend(page,actions,msg)
	{  
		if(confirm(msg))
		window.location = page + "?" + actions;
	}
	
	function numbersonly(e)
	{
		var key;
		var keychar;
		
		if (window.event)
		key = window.event.keyCode;
		else if (e)
		key = e.which;
		else
		return true;
		
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
		else if ((("0123456789").indexOf(keychar) > -1))
		return true;
		else
		return false;
	}

	function openSendWindow(url)
	{
		nw = open(url,'new','height=200,width=250,scrollbars=no,resizable=1');
		nw.focus();
	}

	function openShareWindow(url)
	{
		nw = open(url,'new','height=200,width=300,scrollbars=yes,resizable=1');
		nw.focus();
	}
	
	//Checks all the checkboxes	
	function CheckAll()
	{
		var count = document.frm_share.count.value;
		for(i=0; i<count; i++)
		{
			var check = 'document.frm_share.subaccount_id_'+i+'.checked=true';
			eval(check);	 
		}
	}
	
//unChecks all the checkboxes	
	function UncheckAll()
	{
		var count = document.frm_share.count.value;
		for(i=0; i<count; i++)
		{
			var check = 'document.frm_share.subaccount_id_'+i+'.checked=false';
			eval(check);	 
		}
	}
	//Toggle the selection of checkboxes
	function ToggleSelection()
	{
		var count = document.frm_share.count.value;
		for(i=0; i<count; i++)
		{	
			var count = document.frm_share.count.value;
			var test = 'document.frm_share.subaccount_id_'+i+'.checked==true';
			var check = 'document.frm_share.subaccount_id_'+i+'.checked=true';
			var uncheck = 'document.frm_share.subaccount_id_'+i+'.checked=false';
			if(eval(test))
			eval(uncheck);	 
			else
			eval(check);	
		}
	}

	function ConfirmChangeRenewal(url,message,id)
	{ 
		for(i=0; i<2; i++) {
			if(eval("document.myplans."+id+"[i].checked==true")){ 
				var renew = eval("document.myplans."+id+"[i].value");  
			}
		}
		url = url+renew; 
		if(confirm(message))
		window.location = url;
		else
		return false;
	}
	
	function togglechecked(){ 
		for (var i = 0; i < document.frm_contact.elements.length; i++) {
				var e = document.frm_contact.elements[i];
			
			if ((e.checked == true) && (e.type == 'checkbox')) {
				e.checked = false;
			}
			else
			{
				e.checked = true;
			}
		}
	}

	function toggleselect2(){ 
		document.frm_contact.chk_import_all.checked = !document.frm_contact.chk_import_all.checked;
		togglechecked();
	}
//for sorting issued card page
	function sortissued(id,sortby,sorting,special){ 
		var url = "issued_list.php?sort="+sorting +"&sortby="+sortby;
		if(special) url +="&page="+special; 
		ajaxpage(url,id);
	}
//for sorting  card page
	function sortcard(id,sortby,sorting,special){
		var url = "card_list.php?sort="+sorting +"&sortby="+sortby;
		if(special) url +="&page="+special; //alert(url);return false;
		ajaxpage(url,id);
	}

	function showmap(address,city,state)
	{
		url = "showmap.php?address="+address+"&city="+city+"&state="+state;
		nw = open(url,'new','height=450,width=450,scrollbars=yes,resizable=1');
	
	}
//function for continue card adding
	function continuecard()
	{
		document.frm_card_details.action="index.php?process=listcontacts&action=addcard";
		document.frm_card_details.submit();
	}
	function deleteconfirm_history(page,name,id,mode,type,action)
	{
		if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
		window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode+"&type="+type+"&action="+action;
	}
//function is used to select client type
	function setclienttype(){
		document.frm_clienttype.action="index.php?process=clients&action=addclient";
		document.frm_clienttype.submit();
	}

/***Combo Menu Load Ajax snippet**/

	function ajaxcombo(url,selectobjID, loadarea,id,selvalue){ 
		if( id != ''){
			uri=url+id+selvalue;
		}else{ 
			var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
			
			//alert(document.getElementById(selectobjID).value);
			
			if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
			
			
			
			//document.getElementById(cat_id).value=selectobj.options[selectobj.selectedIndex].value;
			
			
			uri=url+selectobj.options[selectobj.selectedIndex].value;
		} 
		//
		//return false;
		
		ajaxpage(uri, loadarea)
	
	
	
	}
	
//for edit invoice	
	function editinvoice(url,selectobjID, loadarea,id,selvalue){ 
		if( id != ''){
			var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
			if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
			uri=url+selectobj.options[selectobj.selectedIndex].value;
			uri=url+id+selvalue+"&edit="+1;
			
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divplan.style.display = "block";
			if(divperiod){ 
				divperiod.style.display = "block";
			}
			
		}else{ 
			var selectobj=document.getElementById? document.getElementById(selectobjID) : ""
			if (selectobj!="" && selectobj.options[selectobj.selectedIndex].value!="")
			
			uri=url+selectobj.options[selectobj.selectedIndex].value+"&edit="+1;
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divplan.style.display = "block";
			if(divperiod){
				divperiod.style.display = "block";
			}
		}   //alert(uri);
		ajaxpage(uri, loadarea)
	}

//function for continue adding client
	function continueaddingclient()
	{
		document.frm_clientdetails.action="index.php?process=clients&action=newclient";
		document.frm_clientdetails.submit();
	}
	
//function for changinging display style
	function ChangeView(){
		if(document.frm_sublist.drp_listview.value==1){
			window.location = "index.php?process=employee&listview=1";
		}else{
			window.location = "index.php?process=employee&listview=0";
		}
	}
//Delete confirm for client	
function deleteclientconfirm(name,id,flag,listview)
{
	if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
	window.location = "index.php?process=clients&action=delete&cardid="+id+"&type="+flag;
}

//function for address impoerter
	function opennewwindow(address,sevice){
		//alert(address);	
		//url = "showmap.php?address="+address+"&city="+city+"&state="+state;
		
		url="addressimporter.php?type="+sevice;
		nw = open(url,'new');
		nw.focus();
	}
	
//function to display the service/product div
	function display_div(type){
		if(type == "product"){
			divproduct = document.getElementById('div_product');
			divrecur = document.getElementById('div_recur');
			divonetime = document.getElementById('div_onetime');
			
			divproduct.style.display = "block";
			divrecur.style.display = "none";
			divonetime.style.display = "none";
		}else if(type == "recurring"){
			divrecur = document.getElementById('div_recur');
			divonetime = document.getElementById('div_onetime');
			divproduct = document.getElementById('div_product');
			
			divrecur.style.display = "block";
			divonetime.style.display = "none";
			divproduct.style.display = "none";
		}else if(type == "one-time"){
			divonetime = document.getElementById('div_onetime');
			divproduct = document.getElementById('div_product');
			divrecur = document.getElementById('div_recur');
			
			divonetime.style.display = "block";
			divproduct.style.display = "none";
			divrecur.style.display = "none";
		}
	}

//function for new product/service 
	function check_service_type(type,flag){
		
		//alert(document.getElementById('sel_method').value); return false;
		method = document.getElementById('sel_method').value; 
		if(flag)
		var producttype  =  type;
		else
		var producttype  =  type.value;
		//alert(producttype);return false;
		if(method == "existing"){
		if(producttype == "recurring"){
			divservice 	= document.getElementById('list_service');
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divallservices 	= document.getElementById('div_services_products');
			divproducts 	= document.getElementById('div_product');
			//divproducts_details 	= document.getElementById('div_product_details');
			
			divservice.style.display = "block";
			divplan.style.display = "block";
			divperiod.style.display = "block";
			divallservices.style.display = "block";
			divproducts.style.display = "none";
			//	divproducts_details.style.display = "none";
			invid	=	document.getElementById('invid').value;
			url = "list_products.php?type="+producttype+"&service="+flag+"&invid="+invid; //alert(url);
			loadarea ='list_service';
			ajaxpage(url, loadarea)
		
		
		}else if(producttype == "one-time"){
			divservice 	= document.getElementById('list_product');
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divproducts 	= document.getElementById('div_product');
			//divproducts_details 	= document.getElementById('div_product_details');
			divservices 	= document.getElementById('list_service');
			divallservices 	= document.getElementById('div_services_products');
			
			divservice.style.display = "block";
			divplan.style.display = "none";
			divperiod.style.display = "none";
			divproducts.style.display = "block";
			//divproducts_details.style.display = "none";
			divservices.style.display = "none";
			divallservices.style.display = "none";
			invid	=	document.getElementById('invid').value;
			url = "list_products.php?type="+producttype+"&service="+flag+"&invid="+invid;//alert(url);return false;
			loadarea ='list_product';		
			ajaxpage(url, loadarea)
			
		}else if(producttype == "product"){
			divservice 	= document.getElementById('list_product');
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divallservices 	= document.getElementById('div_services_products');
			divproducts 	= document.getElementById('div_product');
			//divproducts_details 	= document.getElementById('div_product_details');
			divservices 	= document.getElementById('list_service');
			
			divservice.style.display = "block";
			divplan.style.display = "none";
			divperiod.style.display = "none";
			divallservices.style.display = "none";
			divproducts.style.display = "block";
			//divproducts_details.style.display = "none";
			divservices.style.display = "none";
			invid	=	document.getElementById('invid').value;
			url = "list_products.php?type="+producttype+"&service="+flag+"&invid="+invid; 
			loadarea ='list_product';		
			ajaxpage(url, loadarea)
		
		}
		}else if(method == "new"){
			divservice 	= document.getElementById('list_product');
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divallservices 	= document.getElementById('div_services_products');
			divproducts 	= document.getElementById('div_product');
			//divproducts_details 	= document.getElementById('div_product_details');
			divservices 	= document.getElementById('list_service');
			
			divservice.style.display = "none";
			divplan.style.display = "none";
			divperiod.style.display = "none";
			divallservices.style.display = "none";
			divproducts.style.display = "none";
			divservices.style.display = "none";	
			invid	=	document.getElementById('invid').value;
			window.location = "index.php?process=salesinvoice&action=newservice&type="+producttype+"&method=existing";
		}else if(method == "direct"){ //alert("meth="+method+", typ="+producttype);
			divservice 	= document.getElementById('list_product');
			divplan 	= document.getElementById('list_plan');
			divperiod 	= document.getElementById('list_period');
			divallservices 	= document.getElementById('div_services_products');
			divproducts 	= document.getElementById('div_product');
			//divproducts_details 	= document.getElementById('div_product_details');
			divservices 	= document.getElementById('list_service');
			divnewservices 	= document.getElementById('div_new_product');
			
			divservice.style.display = "none";
			divplan.style.display = "none";
			divperiod.style.display = "none";
			divallservices.style.display = "none";
			divproducts.style.display = "none";
			divservices.style.display = "none";	
			divnewservices.style.display = "block";	
			invid	=	document.getElementById('invid').value;
			url = "new_product.php?type="+producttype+"&invid="+invid; //+"&service="+flag; 
			loadarea ='new_product';		
			ajaxpage(url, loadarea)
		
		}
	}
//for import sales invouce	
	function importsalesinvoice(){
		producttype	=	document.getElementById('sel_type').value;
		//alert(producttype);
		divservice 	= document.getElementById('list_product');
		divplan 	= document.getElementById('list_plan');
		divperiod 	= document.getElementById('list_period');
		divallservices 	= document.getElementById('div_services_products');
		divproducts 	= document.getElementById('div_product');
		//divproducts_details 	= document.getElementById('div_product_details');
		divservices 	= document.getElementById('list_service');
		divnewservices 	= document.getElementById('div_new_Invoice');
		divservice.style.display = "none";
		divplan.style.display = "none";
		divperiod.style.display = "none";
		divallservices.style.display = "none";
		divproducts.style.display = "none";
		divservices.style.display = "none";	
		divnewservices.style.display = "block";	
		url = "create_importinvoice.php?type="+producttype; //+"&service="+flag; 
		loadarea ='new_product';		
		ajaxpage(url, loadarea)
	}
//for display product details
	function display_product_details(producttype,divid,id,value)
	{	
		//alert(divid);
		divproducts 	= document.getElementById(divid);
		divproducts.style.display = "block";
		if(value)
		selectedvalue = value; 
		else
		selectedvalue = id.value;
		
		//to get the id
		div_arr = divid.split("details_");
		if(div_arr.length > 1)
		value = div_arr[1];
		
		url = "product_details.php?type="+producttype+"&id="+selectedvalue;
		if(value) url+="&value="+value;
		/*else url+="&value="+value; alert(url);*/
		loadarea =divid;		
		ajaxpage(url, loadarea)
	}
//function calculate and display total price
	function display_total(quantity,price,shipping,tdid){ 
		//count_id = document.getElementById(quantity);
		/*unit_price_id = document.getElementById(price); 
		shipping_id =  document.getElementById(shipping);alert(quantity+","+price+","+shipping+","+tdid);*/
		product_quantity = quantity.value;
		//alert(product_quantity);
		unit_price = price; 
		total_id =  document.getElementById(tdid);
		//shipping_value	= shipping;
		totalprice = (quantity.value*unit_price)+(shipping*1); 
		//total_id.innerHTML = "$ "+totalprice;
		//total_id.value = totalprice;
	}
	
//for subaccount login
	function subaccountlogin(empid){
		url = "index.php?process=personal&treeviewempid="+empid;
		nw = open(url,'new');
	}
	
//function for verifying tn number
	function verifycard(name,id){
		window.location = "index.php?process=tnnumber&action=verify&cardid="+id;
	}
	
//for multiple product
function display_products(type,id){

	//document.getElementById('product_form').style.display = "block"; 
	number = id.value;
	url = "additional_product.php?total="+number+"&type="+type; 
	loadarea ='div_product_list';		//alert(url);
	ajaxpage(url, loadarea)
	

}

/*function display_additional_products(id)
{	
var left_index = id.value;
if(left_index >= 0)
{
hideAllDivs();
var val = frm.options[left_index].value;//return false;
id = "div_additional"; 
document.getElementById('div_additional').style.display="block";alert(document.getElementById('div_additional').style.display);
//}
}
function hideAllDivs()
{
//var allDiv = document.frm_plan.hdn_exists_div.value;
//div_arr = allDiv.split(",")
for(j=1; j<=5; j++)
{
div_id = "product_form_"+j;
document.getElementById(div_id).style.display="none";
}
}*/

//function to check the business or personal client selection

	function check_personal(){
		document.getElementById('sel_personal').selectedIndex="";
		//alert(document.getElementById('sel_business').selectedIndex);
		if(document.getElementById('sel_business').selectedIndex == 1){
		type = document.getElementById('sel_business').value;
		window.location = "index.php?process=clients&action=addclient&type="+type+"&from="+type;
	}

}

function check_business(){
	document.getElementById('sel_business').selectedIndex="";
	if(document.getElementById('sel_personal').selectedIndex == 1){
		type = document.getElementById('sel_personal').value;
		window.location = "index.php?process=clients&action=addclient&type="+type+"&from="+type;
	}
}
//check for alphabets
	function alphaonly(e)
	{
		var key;
		var keychar;
		
		if (window.event)
		key = window.event.keyCode;
		else if (e)
		key = e.which;
		else
		return true;
		
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
		else if ((("abcdefghijklmnopqrstuvwxyz").indexOf(keychar) > -1))
		return true;
		else
		return false;
	}
//function set invoice number per page
	function formsubmit(){ 
		document.frm_record.submit();
	}

//Used in the Mechant Signup & Contact Info Edit 
	function CheckCountry_old()
	{	 
		var country = document.frm_mer.mer_country.value; 
		if(country == '223') {  
			document.getElementById('sel_state').style.display = 'block';
			document.getElementById('txt_state').style.display = 'none';
		} else if(country == '38'){
			document.getElementById('sel_state').style.display = 'block';
			document.getElementById('txt_state').style.display = 'none';
		} else { 
			document.getElementById('sel_state').style.display = 'none';
			document.getElementById('txt_state').style.display = 'block';
		}
	}
//checking countries
	function CheckCountry()
	{
		var country = document.frm_mer.mer_country.value; 
		var merchantId = document.frm_mer.merchantId.value; 
		//	alert(merchantId);
		ajaxpage('contact_state.php?country='+country+'&merchantId='+merchantId, 'TD_State');
	}
//check countries 
	function CheckCountry_tylooner()
	{ 
		// alert('in    ='+tystate);
		var country 	= document.frm_mer.mer_country.value;  
		var merchantId 	= document.frm_mer.merchantId.value; 
		//var txt_state 	= document.getElementById('txt_state').value;
		//var state 		= document.getElementById('sel_state').value;
		//var txt_state = document.frm_mer.txt_state.value;
		//var state = document.frm_mer.sel_state.value;
		//var state = document.frm_tyloonersignup.sel_state.value;
		//alert('state'+state);
		//alert(tystate+country);+"&js_txt_state="+txt_state+'&js_state='+state
		//alert(txt_state+state);
		//ajaxpage('tylooner_state.php?country='+country+'&merchantId='+merchantId+'&js_state='+state+'&js_txt_state='+txt_state, 'TD_State');
		url="tylooner_state.php?country="+country+"&merchantId="+merchantId;
		ajaxpage(url, 'TD_State');
	}	

//function for pdf creation
	function createpdf(){
		window.location = "create_pdf.php?download=1";
	}
	
//function for html creation
function createhtml(){
	window.location = "htmldownload.php";
}
//function for text file creation 
	function createtextfile(){
		window.location = "create_textfile.php";
	}

//function to check the method and type for displaying the invoice form
	function check_method(){
		if(document.getElementById('sel_type').selectedIndex > 0){
			producttype = document.getElementById('sel_type').value;
			method = document.getElementById('sel_method').value;
			if(method == "existing"){
				if(producttype == "recurring"){
					divservice 	= document.getElementById('list_service');
					divplan 	= document.getElementById('list_plan');
					divperiod 	= document.getElementById('list_period');
					divallservices 	= document.getElementById('div_services_products');
					divproducts 	= document.getElementById('div_product');
					//divproducts_details 	= document.getElementById('div_product_details');
					divnewservices 	= document.getElementById('div_new_product');
					
					divservice.style.display = "block";
					divplan.style.display = "block";
					divperiod.style.display = "block";
					divallservices.style.display = "block";
					divproducts.style.display = "none";
					divnewservices.style.display = "none";
					
					url = "list_products.php?type="+producttype //alert(url);+"&service="+flag;
					loadarea ='list_service';
					ajaxpage(url, loadarea)
					
				
				}else if(producttype == "one-time"){
					divservice 	= document.getElementById('list_product');
					divplan 	= document.getElementById('list_plan');
					divperiod 	= document.getElementById('list_period');
					divproducts 	= document.getElementById('div_product');
					//divproducts_details 	= document.getElementById('div_product_details');
					divservices 	= document.getElementById('list_service');
					divallservices 	= document.getElementById('div_services_products');
					divnewservices 	= document.getElementById('div_new_product');
					
					divservice.style.display = "block";
					divplan.style.display = "none";
					divperiod.style.display = "none";
					divproducts.style.display = "block";
					//divproducts_details.style.display = "none";
					divservices.style.display = "none";
					divallservices.style.display = "none";
					divnewservices.style.display = "none";
					
					url = "list_products.php?type="+producttype;//alert(url);return false;+"&service="+flag
					loadarea ='list_product';		
					ajaxpage(url, loadarea)
				
				}else if(producttype == "product"){
					divservice 	= document.getElementById('list_product');
					divplan 	= document.getElementById('list_plan');
					divperiod 	= document.getElementById('list_period');
					divallservices 	= document.getElementById('div_services_products');
					divproducts 	= document.getElementById('div_product');
					//divproducts_details 	= document.getElementById('div_product_details');
					divservices 	= document.getElementById('list_service');
					divnewservices 	= document.getElementById('div_new_product');
					
					divservice.style.display = "block";
					divplan.style.display = "none";
					divperiod.style.display = "none";
					divallservices.style.display = "none";
					divproducts.style.display = "block";
					//divproducts_details.style.display = "none";
					divservices.style.display = "none";
					divnewservices.style.display = "none";
					
					url = "list_products.php?type="+producttype; //+"&service="+flag; 
					loadarea ='list_product';		
					ajaxpage(url, loadarea)
					
				}
			}else if(method == "new"){
				divservice 	= document.getElementById('list_product');
				divplan 	= document.getElementById('list_plan');
				divperiod 	= document.getElementById('list_period');
				divallservices 	= document.getElementById('div_services_products');
				divproducts 	= document.getElementById('div_product');
				//divproducts_details 	= document.getElementById('div_product_details');
				divservices 	= document.getElementById('list_service');
				divnewservices 	= document.getElementById('div_new_product');
				
				divservice.style.display = "none";
				divplan.style.display = "none";
				divperiod.style.display = "none";
				divallservices.style.display = "none";
				divproducts.style.display = "none";
				divservices.style.display = "none";	
				divnewservices.style.display = "none";	
				window.location = "index.php?process=salesinvoice&action=newservice&type="+producttype+"&method=existing";
			}else if(method == "direct"){ 
				divservice 	= document.getElementById('list_product');
				divplan 	= document.getElementById('list_plan');
				divperiod 	= document.getElementById('list_period');
				divallservices 	= document.getElementById('div_services_products');
				divproducts 	= document.getElementById('div_product');
				//divproducts_details 	= document.getElementById('div_product_details');
				divservices 	= document.getElementById('list_service');
				divnewservices 	= document.getElementById('div_new_product');
				
				divservice.style.display = "none";
				divplan.style.display = "none";
				divperiod.style.display = "none";
				divallservices.style.display = "none";
				divproducts.style.display = "none";
				divservices.style.display = "none";	
				divnewservices.style.display = "block";	
				url = "new_products.php?type="+producttype; //+"&service="+flag; 
				loadarea ='new_product';		
				ajaxpage(url, loadarea)
			
			}
		}
		
	}



//***********************************************************
//FUNCTIONS FOR CHOOSE LANGUAGE
//***********************************************************


	var aCookie;
	var nLanguages=4;
	function SetCookie(sName, sValue)
	{
		var date = new Date();
		date.setTime(date.getTime()+(1000*24*60*60*1000));
		document.cookie = sName + "=" + escape(sValue) 
		+ "; expires="+date.toGMTString();
	}

	function GetCookie(sName)
	{  
		if(!aCookie)
		aCookie=document.cookie.split("; ");
		// cookies are separated by semicolons
		for (var i=0; i < aCookie.length; i++)
		{
			// a name/value pair (a crumb) is separated by an equal sign
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0]) 
			return unescape(aCrumb[1]);
		}
		return '0';
	}

	function processForm()
	{
		for(var i=1;i<=nLanguages;i++)
		SetCookie("lang_"+i,document.getElementById("lang_"+i).checked);
	}
	
	function hideUnwanted()
	{
		for(var i=1;i<=nLanguages;i++)
		{
			var t=GetCookie("lang_"+i);
			if(t=='0') continue;
			if(t=='true') continue;
			document.getElementById("lang_"+i).style.display="none";
			document.getElementById("lang_"+i).style.visibility="hidden";
		}
	}

	function disable()
	{
		for(var i=1;i<=nLanguages;i++)
		document.getElementById("lang_"+i).checked=GetCookie("lang_"+i)=="true"?true:false;
	}	
//***********************************************************
//END FUNCTIONS FOR CHOOSE LANGUAGE
//***********************************************************

	function checkinvoice(){
		window.location = "index.php?process=manageinvoice&action=checkinvoice";
	}
//function to display additional rows
	function display_more(type){ 
		total_row = document.getElementById('total_row').value; 
		document.getElementById('total_row').value = (total_row*1)+1;
		total_rows = (total_row*1)+1;
		
		var tbl=document.getElementById('additional');	
		var dv =document.createElement('div');
		dv.id='additional_'+total_rows;
		tbl.appendChild(dv);
		url = "addmore.php?type="+type+"&rows="+total_rows;
		loadarea ='additional';		
		ajaxpage(url, 'additional_'+total_rows)
		
	}

//function for adding additional products
	function add_more(){ 
		var type	=document.getElementById('type').value;
		var totalrow=document.getElementById('totalrow').value;
		window.location = "new_product.php?type="+type+"&totalrow="+totalrow;
	}

//function for sorting invoice fields
	function sortinvoice(id,sortby,sorting,special,flag,searchstr){ 
		var url = "paidinvoice_list.php?sort="+sorting +"&sortby="+sortby+"&flag="+flag;
		if(special) url += "&page="+special+"&search="+searchstr; 
		ajaxpage(url,id);
	}
//fuction is for sorting sales invoice fields
	function sortsalesinvoice(id,sortby,sorting,special,flag,searchstr){
		if(flag){
			var url = "sort_salesinvoice.php?action=paid&sort="+sorting +"&sortby="+sortby+"&flag="+flag+"&searchstr="+searchstr;
		}else{
			var url = "sort_salesinvoice.php?sort="+sorting +"&sortby="+sortby+"&flag="+flag+"&searchstr="+searchstr;
		}
		if(special) url += "&page="+special; 
			ajaxpage(url,id);
		}
//for display paid purchase invoice		
	function showpaidinvoice(id,sortby,sorting,page,flag){
			var url = "paidinvoice_list.php?sort="+sorting +"&sortby="+sortby+"&flag="+flag;
			if(special) url += "&page="+special; 
			ajaxpage(url,id);
		//window.location = "paidinvoice_list.php?sort="+sorting +"&sortby="+sortby+"&flag="+flag+"&page="+page;
	}

//confirm paybypaypal
	function confirmpaybypayapl(name,order){ 
		if(confirm("Are you sure you want to pay the invoice using " + name + " method?\nIf 'OK' ,you can't undo this process"))
		window.location = "index.php?process=purchaseinvoice&action=paypal&order="+order;
	
	}
//confirm pay the invoice using authrozie.net	
	function confirmpaybyauthorize(name,order){ 
		if(confirm("Are you sure you want to pay the invoice using " + name + " method?\nIf 'OK' ,you can't undo this process"))
		window.location = "index.php?process=purchaseinvoice&action=authrozie&order="+order;
	
	}
//confirm paybycheck
	function confirmpaybycheck(name,order){
		if(confirm("Are you sure you want to pay the invoice using  " + name +  " method?\nIf 'OK' ,you can't undo this process"))		
		window.location = "index.php?process=purchaseinvoice&action=paid&order="+order;
	}
	
//confirm markasrecieved
	function confirmmarkasrecieved(name,order){
		if(confirm("Are you sure you want to modify the invoice as  " + name +  "?\nIf 'OK' ,you can't undo this process"))		
		window.location = "index.php?process=manageinvoice&action=received&order="+order;
	}
	
//function for check  
	function checkmerchant(type){ 
	 
		window.location = "index.php?process=checkinvoice&type="+type;
	}
	
//function to update status
	function confirmStatusUpdate_business(page,name,id,mode,msg)
	{
	//alert('business');
		if(confirm(msg+ name + "?"))
		window.location = page + "?" +mode;
	
	}

//function to redirect for invoice export
	function export_invoice(year,month){
		window.location = "index.php?process=paidinvoice&action=export&year="+year+"&month="+month;
	}

	function display_div_associate(id)
	{	
		var type = document.frm_assoc.sel_pay_option.value;
		hideAllDivs(id);
		if(type == "paypal")
		document.getElementById(id).style.display="block";
		else if(type == "direct deposit")
		document.getElementById('pay_opt_2').style.display="block";
	}
	
//hide div
	function hideAllDivs(id)
	{	
		div_id = id;
		document.getElementById(div_id).style.display="none";
		document.getElementById('pay_opt_2').style.display="none";
	}
	
//merchant business informations
	function tylooner_personal_info()
	{ 
	
		var mer_country=document.frm_mer.mer_country.value;
		if(mer_country == 223 ||  mer_country =='' || mer_country == 38 ){
			var tystate = document.getElementById('sel_state').value;
		}else{
			var tystate	=document.getElementById('txt_state').value;
		}
		document.frm_mer.action="index.php?process=tylooner&action=submit&tystate="+tystate;
		document.frm_mer.submit();
	}
//for Department sections
	function CheckNumeric(e)
	{
		var key;
		var keychar;
		
		if (window.event)
		key = window.event.keyCode;
		else if (e)
		key = e.which;
		else
		return true;
		
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
		else if ((("0123456789").indexOf(keychar) > -1))
		return true;
		else
		return false;
	
	}
     function Popup(url)
     {
        window.open(url,'remote','menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,dependent,width=440,height=100,left=300,top=300,modal=no');
     }
