/***************************************************************************/
/*     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,invflag,pagen)
	{
		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+"&action="+mode+"&mode="+mode+"&type="+type+"&search="+type+"&pagen="+pagen+"&invflag="+invflag;
		}
	}
//delete subaccount confirm	
	function deleteconfirm_sub(page,name,id,mode,type,msg1,msg2,msg3)
	{
		if(confirm(msg1 + name + msg2 + name + msg3))
		{
			window.location = "index.php?process=subaccount_delete&page="+page+"&id="+id+"&name="+name+"&mode="+mode+"&type"+type;
		}
	}	
	
	// Added by xianwei 2008-08-14
	// 为实现确认信息的多语言，所以将组织好的提示语句传入函数
	function deleteconfirm_2(confirmmsg, page, name, id, mode, type) {
	    if (confirm(confirmmsg)) {
	        window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode+"&type="+type;
	    }
	}

//cage 2008.7.29 translate value for login
	function merchant_login_submit() {
	
		var uname = document.getElementById('txt_uname').value;
		var pwd = document.getElementById('txt_pwd').value;
	//	alert(uname);
		var url = 'index.php?process=login&txt_uname='+uname+'&txt_pwd='+pwd;
		document.frm_login.action = url;
		document.frm_login.method = 'post';
		document.frm_login.submit();
	}

	function setIfAgree(msg) {
		document.getElementById('ifHasAgreed').value = msg;
//		alert(document.getElementById('ifHasAgreed').value);
	}
	
	function checkIfAgree(msg) {
		var result = document.getElementById('ifHasAgreed').value;
		if(result == 'yes') {
			document.getElementById('agreeWord').innerHTML = '';
			return true;
		}	
		else {
			document.getElementById('txta_note').focus();
			document.getElementById('agreeWord').innerHTML = msg;
			return false;
		}
	}	
	function merchant_agree_info(msg) {
		if(checkIfAgree(msg)) {
			document.frm_mer.submit();
		}
	}	
//merchant personal informations
	function merchant_personal_info(msg1,msg2,msg3,msg4,msg5,msg6,process,msg7)
	{
		if(checkIfAgree(msg7)) {
		//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 txt_state = document.frm_mer.txt_state.value;
						var business_profile = document.frm_mer.txt_business_profile.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_no="+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+"&txt_state="+txt_state+"&business_profile="+business_profile+"&process="+process;
	
						 //alert (url);
						 //exit();
						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');
	}

//cage 2008.7.24
	function username_check_format()
	{
		var uname = document.frm_mer.txt_uname.value;
		var url = "checkuname_format.php?uname="+uname;
		ajaxpage(url, 'span_uname');
	}

//cage 2008.7.30
	function keydown_login(e) {
		var keynum;
		if(window.event) {	//IE
			keynum = e.keyCode;
		} else if(e.which) {	//Netscape/Firefox/Opera
			keynum = e.which;
		}
		if(keynum==13) {
	//		alert(keynum);
			merchant_login_submit();
		}
	}

//cage 2008.7.24
	function CheckUsername(msg1, msg2) {
		var uname = document.getElementById('txt_uname').value;
		//alert(uname);
		if(uname.length<2) {
			document.getElementById('span_uname').innerHTML = msg1;
			return false;
		}
		else {
			var Expression = /^[a-zA-Z0-9_]{2,30}$/;
			var objExp = new RegExp(Expression);
			if(objExp.test(uname)==false) {
				document.getElementById('span_uname').innerHTML = msg2;
				return false;
			}
			else {
				document.getElementById('span_uname').innerHTML = '';
				return true;
			}
		}
	}

//cage 2008.7.29
	function CheckEmail(msg1, msg2) {
		var email = document.getElementById('txt_email').value;

		if(isBadEmail(email)) {
			document.getElementById('span_email').innerHTML = msg1;
		}
		else
			document.getElementById('span_email').innerHTML = msg2;
	}


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

	function checkusername_exist_msg(msg1, msg2)
	{
		var uname1 = document.frm_mer.txt_uname.value;
//		alert(uname1);
		uname1 = leftTrim(uname1);
		uname1 = rightTrim(uname1);
		var Expression = /^[a-zA-Z0-9_]{2,30}$/;
		var objExp = new RegExp(Expression);		
		if(uname1.length < 2) {
			document.getElementById('span_uname').innerHTML = msg1;
		}
		else if(objExp.test(uname1)==false) {
			document.getElementById('span_uname').innerHTML = msg2;
		}
		else {
			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');
		}
	}
	//subaccount add 
	function checkusername_exist_sub_msg(msg1, msg2)
	{
		var uname1 = document.frm_emp_add.txt_uname.value;
		uname1 = leftTrim(uname1);
		uname1 = rightTrim(uname1);
		if(uname1.length < 2) {
			document.getElementById('span_uname').innerHTML = msg1;
			document.getElementById('span_uname_sub').innerHTML = '';
		}
		else {	
			var url = "checkuname_exist.php?uname="+uname1;
			ajaxpage(url,'span_uname_sub');
		}
	}
	//cage 2008.7.31
	function CheckPasswordMore(msg1, msg2) {
		var pass = document.getElementById('txt_password').value;
//		alert(pass);
		if(pass.length < 6) {
			document.getElementById('span_password').innerHTML = msg1;
			document.getElementById('txt_password').focus();
			return false;
		} else {
			var Expression = /[a-zA-Z0-9]{2,30}/;
			var objExp = new RegExp(Expression);
			if(objExp.testpass(pass)==false) {
				document.getElementById('span_password').innerHTML = msg2;
				return false;
			}
			else
				document.getElementById('span_password').innerHTML = '';
		}
		return true;
	}

//Checks if the Password is valid
	function CheckPassword(msg)
	{
		var pass = document.getElementById('txt_password').value;
//		alert(pass);
		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;
		if(typeof count != "undefined")
			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;
				}
			}
		else{
			var rd  = 'document.frm_plans.'+prdId+'.checked';
			var chk = eval(rd);
			if(chk)
			{
				var rdValue = 'document.frm_plans.'+prdId+'.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;
//		alert(country);
		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');
     }
function appAdminMail(j){
	success = false;
	$.get("?process=wizards&action=sendMail2Admin",function(b){
		if(/success/.test(b)){
			alert(j.success);
		}else if(/fail/.test(b)){
			alert(j.fail);
		}else{
			alert("error: "+b);
		}
	});
	return ;
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/**
* object getCurrentStyle(object)
* 返回当前对象样式信息
* by longerface 11/11/2008
*/
function getCurrentStyle(obj){
	b = (window.navigator.userAgent).toLowerCase();
	if(/msie|opera/.test(b)){
		s = obj.currentStyle;
	}else if(/gecko/.test(b)){
		s = document.defaultView.getComputedStyle(obj, null);
	}
	return s;
}
/**
*    string Request(string)
*    取得 get 传过来参数的值。
*	 longerface 2008-7-22
*/
function Request(name) {
	var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
	if (reg.test(location.href))
	return unescape(RegExp.$2.replace(/\+/g, " "));
	return "";
}
/**
*    Array/string getQueryString(int 0/1,string str)
*    取得 get 传过来的值。
*    by longerface 2008-7-22
*    s 传值：
*    当传入0时候返回变量与值的二维数组，array[N][0] 变量名，array[N][1] 变量值，(默认)；
*        query = getQueryString(0);
*        if(query!=null)
*            for(i=0;i<query.length;i++)
*                alert(query[i][0] + "=" + query[i][1]);
*
*    当传入1时候返回一个可定义的字符串，用eval()来定义。
*        str = "var a=1;var b=2;...."
*        alert(getQueryString(1));
*        eval(getQueryString(1));
*
*    传入 str 为字串地址。默认空时取 window.location.href
*/
function getQueryString(s,str){
	var vhref="";
	if(str)
		vhref = str;
	else
		vhref = window.location.href;
	var temp,tempquery,queryString,varstr="";
    var query = new Array();
    if(vhref.length<1) return null;
    if(vhref.search(/\?/)==-1) return null;
    temp = vhref.split(/\?/);
    if(temp.length<2) return null;
    queryString = temp[1];
    if(queryString.length<1) return null;
    if(queryString.search(/=/)==-1) return queryString;
    temp = queryString.split(/&/);
    for(var i=0;i<temp.length;i++){
        if(temp[i].search(/=/)!=-1){
            tempquery = temp[i].split(/=/);
            if(tempquery.length<2) tempquery[1]="";
            varstr += "var "+tempquery[0]+"=\""+tempquery[1]+"\";";
            query[i] = new Array(tempquery[0],tempquery[1]);
        }
    }
    if(arguments.length<1)
        {return query;}
    if(s==1){
        return varstr;
    }else{
        return query;
    }
}

function getBodyMaxHeight(){  // by longerface
	var h = 0;
	var childMaxHeight = 0;
	if(document.body.scrollHeight) 
		h = document.body.scrollHeight > h ? document.body.scrollHeight : h;
	if(document.documentElement.clientHeight) 
		h = document.documentElement.clientHeight > h ? document.documentElement.clientHeight : h;
	if(document.body.clientHeight) 
		h = document.body.clientHeight > h ? document.body.clientHeight : h;
	if(document.body.offsetHeight) 
		h = document.body.offsetHeight > h ? document.body.offsetHeight : h;
	if(window.screen.height) 
		h = window.screen.height > h ? window.screen.height : h;
	if(document.body.offsetHeight)
		h = document.body.offsetHeight > h ? document.body.offsetHeight : h;
	if(document.all){
		var da = document.all;
		for(i=0;i<da.length;i++){
			if(da[i].offsetHeight!="" && da[i].offsetTop!="" && typeof da[i].offsetHeight!="undefined" && typeof da[i].offsetTop!="undefined"){
				childMaxHeight = Math.max(parseInt(da[i].offsetHeight) + parseInt(da[i].offsetTop), childMaxHeight);
			}
		}
	}
	h = childMaxHeight > h ? childMaxHeight : h;
	return h;
}
function getBodyMaxWidth(){  // by longerface
	var w = 0;
	var childMaxWidth = 0;
	if(document.body.scrollWidth) 
		w = document.body.scrollWidth > w ? document.body.scrollWidth : w;
	if(document.documentElement.clientWidth) 
		w = document.documentElement.clientWidth > w ? document.documentElement.clientWidth : w;
	if(document.body.clientWidth) 
		w = document.body.clientWidth > w ? document.body.clientWidth : w;
	if(document.body.offsetWidth) 
		w = document.body.offsetWidth > w ? document.body.offsetWidth : w;
	if(window.screen.width) 
		w = window.screen.width > w ? window.screen.width : w;
	if(document.body.offsetWidth)
		w = document.body.offsetWidth > w ? document.body.offsetWidth : w;
	if(document.all){
		var da = document.all;
		for(i=0;i<da.length;i++){
			if(da[i].offsetWidth!="" && da[i].offsetLeft!="" && typeof da[i].offsetWidth!="undefined" && typeof da[i].offsetLeft!="undefined"){
				childMaxWidth = Math.max(parseInt(da[i].offsetWidth) + parseInt(da[i].offsetLeft), childMaxWidth);
			}
		}
	}
	w = childMaxWidth  > w ? childMaxWidth  : w;
	return w;
}
function setDivMaxHeight(id){  // by longerface
	h = getBodyMaxHeight();
	h = h == 0 ? "100%" : h += "px" ;
	document.getElementById(id).style.height = h;
}
function setDivMaxWidth(id){  // by longerface
	w = getBodyMaxWidth();
	w = w == 0 ? "100%" : w += "px" ;
	document.getElementById(id).style.width = w;
}
function addBgWall(id, zindex, color, opacity){  ////在页面中加入半透明背景墙。 by longerface
	if(typeof zindex == "undefined" || zindex == "")
		var zindex = "2";
	if(typeof color == "undefined" || color == "")
		var color = "#000000";
	if(typeof opacity == "undefined" || opacity == "")
		var opacity = 40;
/*
alert(document.compatMode);
*/
	h = "0px";
	w = "0px";
	var bw = document.createElement("DIV");
		style = "border:0px;display:none;position:absolute;z-index:"+zindex+";top:0px;left:0px;height:"+h+";width:"+w+";filter:alpha(opacity="+opacity+");-moz-opacity:0."+opacity+";opacity: 0."+opacity+"!important;";
		bw.setAttribute("ID", id);
		bw.setAttribute("STYLE", style);
		bw.id = id;
		bw.style.cssText = style;
		var bw_div = document.createElement("DIV");
			style = "border:0px;position:absolute;z-index:1;top:0px;left:0px;height:100%;width:100%;background-color:"+color+";";
			bw_div.setAttribute("STYLE", style);
			bw_div.style.cssText = style;
		var bw_iframe = document.createElement("IFRAME");
			style = "position:absolute;visibility:inherit;border:0px;top:0px;left:0px;width:100%;height:100%;z-index:-1;";
			src = "";
			bw_iframe.setAttribute("SRC", src);
			bw_iframe.setAttribute("STYLE", style);
			bw_iframe.src = src;
			bw_iframe.style.cssText = style;
	bw.appendChild(bw_div);
	bw.appendChild(bw_iframe);
	
	if(document.getElementById(id)){
		alert("Named failed for bg wall '" + id + "'.");
		return ;
	}
//	var str = "<div id=\""+id+"\" style=\"display:none;position:absolute;z-index:"+zindex+";top:0px;left:0px;height:"+h+";width:"+w+";filter:alpha(opacity="+opacity+");-moz-opacity:0."+opacity+";opacity: 0."+opacity+"!important;\"><div style=\"position:absolute;z-index:1;top:0px;left:0px;height:100%;width:100%;background-color:"+color+";\"></div><iframe src=\"\" style=\"position:absolute;visibility:inherit;border:0px;top:0px;left:0px;width:100%;height:100%;z-index:-1;\"></iframe></div>";
//	document.body.innerHTML = document.body.innerHTML + str;
	if(document.all){
		document.body.insertBefore(bw, document.body.firstChild);
	}else{
		document.body.appendChild(bw);
	}
}
function showBgWall(id){  ////控制背景墙为显示状态 by longerface
    window.scroll(0,0);
    document.body.scroll = 'no';
    setDivMaxHeight(id);
    setDivMaxWidth(id);
    document.getElementById(id).style.display='block';
	/* 隐藏 z-index 小于层的 select 
	var zind = document.getElementById(id).style.zIndex;
	if(document.body.all)
		for(i in document.body.all){
			var obj = document.body.all[i];
			if(obj.style!=null && obj.style.zIndex!=null && obj.type=="select-one" && obj.style.zIndex<zind)
				obj.style.display = 'none';
		}
	*/
}
function shutBgWall(id){  ////控制背景墙为隐藏状态 by longerface
	/* 显示 z-index 小于层的 select 
	var zind = document.getElementById(id).style.zIndex;
	if(document.body.all)
		for(i in document.body.all){
			var obj = document.body.all[i];
			if(obj.style!=null && obj.style.zIndex!=null && obj.type=="select-one" && obj.style.zIndex<zind)
				obj.style.display = '';
		}
	*/
	document.body.scroll = 'yes';
    document.getElementById(id).style.display='none';
}
/**
*  by longerface
*  图层拖拽方法使用说明：
*	一、使用方法：
*	  在鼠标焦点拖动的位置写入 onMouseDown 事件：
*	  onmousedown="_$m.moveDivId='DivId';_$m.moveDivDown(event);"
*	  分析：onMouseDown 事件内有两句语句分别为：
*		  _$m.moveDivId='DivId'  为全局变量赋值，值为你要拖动的 div 层的 id 名。注：position:absolute;
*		  _$m.moveDivDown(event);  运行点下鼠标事件，并传入些事件(无需改动)
*	二、图层拖动各属性方法说明：
*		属性：
*		moveDivId                          要拖动的图层 id
*		moveDivLeft                        图层原始居左距离
*		moveDivTop                         图层原始居上距离
*		onMouseDownState                   鼠标是否按下，按下为 true ，抬起为 false
*		方法：
*		void moveDivDown(event ev)         鼠标按下后的初始化
*		void moveDivUp()                   鼠标抬起后还原变量
*		void moveDiv(event ev)             鼠标移动控制图层位置
*		object getMousePosition(event ev)  返回当前鼠标x,y位置 this.x 为 left 距离， this.y 为 top 距离
*/
var _$m = {
	moveDivId: null,
	moveDivLeft: 0,
	moveDivTop: 0,
	onMouseDownState: false,
	moveDivDown: function(ev){
		var ID = document.getElementById(this.moveDivId);
		this.onMouseDownState = true;
		ev = ev || window.event;
		var mouse = this.getMousePosition(ev);
		if(typeof ID.style.left=="undefined" || ID.style.left==null || ID.style.left==""){
			if(ID.offsetLeft=="undefined" || ID.offsetLeft==null){
				ID.style.left = "0px;";
			}else{
				ID.style.left = ID.offsetLeft + "px";
			}
		}
		if(typeof ID.style.top=="undefined" || ID.style.top==null || ID.style.top==""){
			if(ID.offsetTop=="undefined" || ID.offsetTop==null){
				ID.style.top = "0px;";
			}else{
				ID.style.top = ID.offsetTop + "px";
			}
		}
		this.moveDivLeft = mouse.x - parseInt(ID.style.left);
		this.moveDivTop  = mouse.y - parseInt(ID.style.top);
		mouse = null;
		if(document.addEventListener){
			document.addEventListener('mousemove', this.moveDiv,true);
			document.addEventListener('mouseup', this.moveDivUp,true);
		}else if(document.attachEvent){
			document.attachEvent('onmousemove', this.moveDiv);
			document.attachEvent('onmouseup', this.moveDivUp);
		}
	},
	moveDivUp: function(){
		var m = _$m || window;
		m.onMouseDownState = false;
		m.moveDivLeft = null;
		m.moveDivTop = null;
		m.moveDivId = "";
	},
	moveDiv: function(ev)
	{
		var m = _$m || window;
		if(typeof m.onMouseDownState!="undefined" && m.onMouseDownState)
		{
			var ID = document.getElementById(m.moveDivId);
			ev = ev || window.event;
			var mouse = m.getMousePosition(ev);
			if((mouse.y - m.moveDivTop)>0 && (mouse.x - m.moveDivLeft)>0 && (mouse.x - m.moveDivLeft)<(document.body.offsetWidth-ID.offsetWidth) && (mouse.y - m.moveDivTop)<(document.body.offsetHeight-ID.offsetHeight)){
				ID.style.left = (mouse.x - m.moveDivLeft) + "px";
				ID.style.top =  (mouse.y - m.moveDivTop) + "px";
			}
			mouse = null;
		}
	},
	getMousePosition: function(ev){
		if(ev.pageX || ev.pageY){
			return {
				x:ev.pageX,
				y:ev.pageY
			};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
}

/**	
*	  by longerface
*     string getFormStr(object obj)
*     此函数用于取得某 form 里每个控件的名称和值。
*     e.g:  getFormStr(form对象)
*           返回 get 型上传字串，aaa=11&bbb=2&ccc=333。此处中文用 escape 函数转成URL编码。
*/
function getFormStr(obj){
    var FormStr = "1=1";
    for(j=0;j<obj.length;j++){
	    if(obj[j].type=="checkbox"){  //多选框
	        var mychk = document.getElementsByName(obj[j].name);
	        for(ck=0;ck<mychk.length;ck++){
		        if(mychk[ck].checked){
			        FormStr += ("&" + obj[j].name + "=" + escape(mychk[ck].value));
		        }
	        }
	    }else if(obj[j].type=="select-one"){  //下拉框(下拉框选中value=""的项返回)
		    for(op=0;op<obj[j].options.length;op++){
			    if(obj[j].options[op].selected){
				    FormStr += ("&" + obj[j].name + "=" + escape(obj[j].options[op].value));
			    }
		    }
	    }else if(obj[j].type=="radio"){  //单选框
	        var mychk = document.getElementsByName(obj[j].name);
            for(ck=0;ck<mychk.length;ck++){
		        if(mychk[ck].checked){
			        FormStr += ("&" + obj[j].name + "=" + escape(mychk[ck].value));
		        }
	        }
	    }else if(obj[j].type=="hidden"){  //隐藏框
		    FormStr += ("&" + obj[j].name + "=" + escape(obj[j].value));
	    }else {  //文本框,输入框,密码框,文件浏览框
		    FormStr += ("&" + obj[j].name + "=" + escape(obj[j].value));
        };
    }
    return FormStr
}

/**
*   void setUpMenu
*   用 jquery 设置 menu 菜单样式
*   by longerface 2008.7.22
*/
function setUpMenu(){
	$("#_menu_div dl").find("dt").each(function(i){
		if($(this).attr("class")!="nav_dtx")
			$(this).click(function(e){
				if(!$(this).next(".nav_dtx").is(':visible')){
					$(this).next(".nav_dtx").find("li a").hide();
					$(this).next(".nav_dtx").slideDown("fast");
					$(this).next(".nav_dtx").find("li a").fadeIn("slow");
				}else
					$(this).next(".nav_dtx").slideUp("fast");
			});
		else{
			$(this).hide();
			$(this).find("a").each(function(i){
				vhref = $(this).attr("href");
				queryArr = getQueryString(0,vhref);
				if(queryArr!=null)
					for(j=0;j<queryArr.length;j++)
						if(queryArr[j][0].toLowerCase()=="process" && queryArr[j][1].toLowerCase()==Request("process").toLowerCase())
							$(this).parent().parent().parent().show();
			});
		}
	});
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
var set_up_Menu = function(){
    $("#tr_sch_1").hide();
    $("#tr_sch_2").hide();
    $("#tr_sch_3").hide();
    $("#tr_tch_1").hide();
    $("#tr_tch_2").hide();
    $("#tr_tch_3").hide();
    $("#tr_sp_1").hide();
    $("#tr_sp_2").hide();
    $("#tr_sp_3").hide();
    $("#menu_sch").click(function(){
    	if(!$("#tr_sch_1").is(":visible")){
    		$("#tr_en_1").hide();
    		$("#tr_en_2").hide();
    		$("#tr_en_3").hide();
	    	$("#tr_tch_1").hide();
	    	$("#tr_tch_2").hide();
	    	$("#tr_tch_3").hide();
	    	$("#tr_sp_1").hide();
	    	$("#tr_sp_2").hide();
	    	$("#tr_sp_3").hide();
	        $("#tr_sch_1").toggle();
	        $("#tr_sch_2").toggle();
	        $("#tr_sch_3").toggle();
    	}
    });
    $("#menu_tch").click(function(){
    	if(!$("#tr_tch_1").is(':visible')){
    		$("#tr_en_1").hide();
	    	$("#tr_en_2").hide();
	    	$("#tr_en_3").hide();
	    	$("#tr_sch_1").hide();
	    	$("#tr_sch_2").hide();
	    	$("#tr_sch_3").hide();
	    	$("#tr_sp_1").hide();
	    	$("#tr_sp_2").hide();
	    	$("#tr_sp_3").hide();
	        $("#tr_tch_1").toggle();
	        $("#tr_tch_2").toggle();
			$("#tr_tch_3").toggle();
    	}
    });
    $("#menu_sp").click(function(){
    	if(!$("#tr_sp_1").is(':visible')){
    		$("#tr_en_1").hide();
	    	$("#tr_en_2").hide();
	    	$("#tr_en_3").hide();
	    	$("#tr_tch_1").hide();
	    	$("#tr_tch_2").hide();
	    	$("#tr_tch_3").hide();
	    	$("#tr_sth_1").hide();
	    	$("#tr_sth_2").hide();
	    	$("#tr_sth_3").hide();
	        $("#tr_sp_1").toggle();
	        $("#tr_sp_2").toggle();
			$("#tr_sp_3").toggle();
    	}
    });
    $("#menu_en").click(function(){
    	if(!$("#tr_en_1").is(':visible')){
    		$("#tr_en_1").hide();
	    	$("#tr_en_2").hide();
	    	$("#tr_en_3").hide();
	    	$("#tr_tch_1").hide();
	    	$("#tr_tch_2").hide();
	    	$("#tr_tch_3").hide();
	    	$("#tr_sch_1").hide();
	    	$("#tr_sch_2").hide();
	    	$("#tr_sch_3").hide();
	    	$("#tr_sp_1").hide();
	    	$("#tr_sp_2").hide();
	    	$("#tr_sp_3").hide();
	        $("#tr_en_1").toggle();
	        $("#tr_en_2").toggle();
	        $("#tr_en_3").toggle();
    	}
    });
}
/**
*  string ltrim(string str,char ABC)
*    去掉字符左边空格或左右的字符默认空格
*  string rtrim(string str,char ABC)
*    去掉字符右边空格或左右的字符默认空格
*  string trim(string str,char ABC)
*    去掉字符左右两边边空格或左右的字符默认空格
*/
function ltrim(str,ABC) 
{
    if(typeof(ABC)=="undefined" || ABC==null || ABC=="") ABC = " \t\n\r"
	var whitespace = new String(ABC);
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}
function rtrim(str,ABC)
{
    if(typeof(ABC)=="undefined" || ABC==null || ABC=="") ABC = " \t\n\r"
    var whitespace = new String(ABC);
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}
function trim(str,ABC)
{
    if(typeof(ABC)=="undefined" || ABC==null || ABC=="") ABC = " \t\n\r"
    return rtrim(ltrim(str,ABC),ABC);
}