/*




*/

document.write('<SCRIPT language="JavaScript" src="/js/inc/mbox_rc.js"></'+'SCRIPT>');
//document.write('<SCRIPT language="JavaScript" src="/js/classes/tools/CookiesManager.class.js"></'+'SCRIPT>');

/*





*/




var PP_CONFIG = new function()
{
	//Alex
	var lookup_account_number = (typeof(window['LookupAccount'])!="undefined") ? window['LookupAccount']['number']: "none";
	var lookup_account_userid = (typeof(window['LookupAccount'])!="undefined") ? window['LookupAccount']['userid']: "none";
	var _getMboxSessionId = (typeof(getMboxSessionId)!="undefined") ? getMboxSessionId(): "none";


	//var service  = 'https://qaproweb.dins.ru';
	/*var service  = 'https://service.ringcentral.com';

	var actions =
	{
		trial : '/',
		buy   : '/ordernow/'
	}*/
	var service = location.protocol+'//'+location.host;
	var actions =
	{
		trial : '/s-gate.html',
		buy   : '/s-gate.html'
	}


	var promotion_codes =
	{
		pro   : 56440300372005,
		plus  : 63390500523310,
		power : 54311000536720
	}


	this.pages =
	{
		pp_vista_print_plans :
		{
			init             : true,
			default_callback : true,
			redirect         : '/ordernow/choose-your-freephone-number-vista-print.html?numdef=888',
			need_redirect    : !getSearchVar('uid'),
			trial :
			[
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}

				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}
				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}
				}
			],
			buy :
			[
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						//number      : getSearchVar('number'),
						number      : lookup_account_number,
						uid      	: lookup_account_userid,
						euid		: getSearchVar('uid'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				}
			]
		},

		pp_vista_print :
		{
			init             : true,
			default_callback : true,
			redirect         : '/ordernow/choose-your-freephone-number-vista-print.html?numdef=888',
			need_redirect    : !(getSearchVar('number')&&getSearchVar('formatted_number')),
			trial :
			[
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}

				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}
				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						mboxSession : _getMboxSessionId,
						action		: 'trial30'
					}
				}
			],
			buy :
			[
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						mboxSession : _getMboxSessionId,
						action		: 'buy'
					}
				}
			]
		},

		pp :
		{
			init     : true,
			default_callback : true,
			trial30 :
			[
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			trial :
			[
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			buy :
			[
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}
				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0800-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			]
		},

		pp_0845 :
		{
			init     : true,
			default_callback : true,
            trial30 :
			[
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			trial :
			[
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			buy :
			[
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}
				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/0845-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			]
		},
		pp_local :
		{
			init     : true,
			default_callback : true,
			trial30 :
			[
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			trial :
			[
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			],
			buy :
			[
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro
					}
				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/ordernow/local-number-select.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power
					}
				}
			]
		},
		pp_fax :
		{
			init     : true,
			default_callback : true,
			trial30 :
			[
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3756,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3757,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial30',
						s           : 3710,
						upgradetier : 3758,
						pc          : promotion_codes.power
					}
				}
			],
			trial :
			[
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3756,
						pc          : promotion_codes.pro
					}

				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3757,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'trial',
						s           : 3710,
						upgradetier : 3758,
						pc          : promotion_codes.power
					}
				}
			],
			buy :
			[
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3756,
						pc          : promotion_codes.pro
					}
				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3757,
						pc          : promotion_codes.plus
					}
				},
				{
					host  : '',
					path  : '/fax/ordernow/choose-your-number.html',
					vars :
					{
						action      : 'buy',
						s           : 3710,
						upgradetier : 3758,
						pc          : promotion_codes.power
					}
				}
			]
		},
		pick_plan_800 :
		{
			init             : true,
			default_callback : true,
			redirect         : '/plansandpricing.html',
			need_redirect    : !(getSearchVar('number')&&getSearchVar('formatted_number')),
			trial :
			[
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'trial'
					}

				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'trial'
					}
				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'trial'
					}
				}
			],
			buy :
			[
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'buy'
					}
				}
			]
		},
		pick_plan_0845 :
		{
			init     : true,
			default_callback : true,
			redirect         : '/plansandpricing-0845number.html',
			need_redirect    : !(getSearchVar('number')&&getSearchVar('formatted_number')),
			trial :
			[
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'trial'
					}

				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'trial'
					}
				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'trial'
					}
				}
			],
			buy :
			[
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'buy'
					}
				}
			]
		},
		pick_plan_local :
		{
			init     : true,
			default_callback : true,
			redirect         : '/plansandpricing-localnumber.html',
			need_redirect    : !(getSearchVar('number')&&getSearchVar('formatted_number')&&getSearchVar('state_id')&&getSearchVar('area')&&getSearchVar('city')),
			trial :
			[
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'trial'
					}

				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'trial'
					}
				},
				{
					host  : service,
					path  : getServicePath('trial'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						c           : 'signup',
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'trial'
					}
				}
			],
			buy :
			[
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3716,
						pc          : promotion_codes.pro,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3726,
						pc          : promotion_codes.plus,
						action 		: 'buy'
					}
				},
				{
					host  : service,
					path  : getServicePath('buy'),
					vars :
					{
						number      : getSearchVar('number'),
						state_id    : getSearchVar('state_id'),
						area        : getSearchVar('area'),
						city        : getSearchVar('city'),
						ns          : 1,
						sp          : 'b',
						s           : 3710,
						upgradetier : 3727,
						pc          : promotion_codes.power,
						action 		: 'buy'
					}
				}
			]
		}

	}

	function getServicePath(action)
	{
		return !!actions[action]? actions[action] : actions['trial'];
	}

	function getSearchVar( varName , str){
		var regexS = "[?&]"+varName+"=([^&#]*)";
		var regex = new RegExp( regexS ,'i');
		var tmpURL = str? str : window.location.href;
		var results = regex.exec( tmpURL );
		if( results == null )
		{
			return null;
		}
		else
		{
			return results[1].replace(/%20/g,' ');
		}
	}

	this.getConfig = function(page_name, event, columnId)
	{

		var curPlan = this.pages[page_name][event];
		switch(event)
		{
			case 'trial':
			    curPlan[columnId]['vars']['action'] = CookiesManager.getCookie("trial30")?'trial30':'trial';
				break;
		}
		return curPlan[columnId];
	}

}





if(typeof page_name == 'string' && PP_CONFIG.pages[page_name] && PP_CONFIG.pages[page_name].init)
{

	if(PP_CONFIG.pages[page_name].redirect && typeof PP_CONFIG.pages[page_name].need_redirect != 'undefined' && PP_CONFIG.pages[page_name].need_redirect)
	{
		window.location = PP_CONFIG.pages[page_name].redirect;
	}
	else
	{
		addEvent(window, 'ondomready', function()
		{
			//var win = window.open();
			//win.document.write(document.body.innerHTML);


			var PlansPriceTable = new PlansPrice({});

			if(PP_CONFIG.pages[page_name].default_callback)
			{
				PlansPriceTable.setCallBack(function(PP_CONFIG, page_name, type, columnId)
				{
						//alert(page_name + "\n"+type + "\n" + columnId);
						var hash = PP_CONFIG.getConfig(page_name, type, columnId);

						if(typeof getMboxSessionId == 'function')
						{
							hash.vars.mboxSession = getMboxSessionId();
						}

						var new_page = LocationManager.buildUrl(hash);
						if(new_page)
						{
							window.location = new_page;
						}
						/*if(!PP_CONFIG.pages || !PP_CONFIG.pages[page_name] ||  !PP_CONFIG.pages[page_name][type])
						{
							return;
						}
						var curPlan = PP_CONFIG.pages[page_name][type][columnId];
						if(curPlan)
						{
							var url_new = LocationManager.buildUrl({
								host : '',
								path : curPlan.next_page,
								vars : curPlan
							});
							if(url_new)
							{
								window.location = url_new;
							}
						}*/
				}.rcBindAsIs(this, PP_CONFIG, page_name));
			}


			PlansPriceTable.init();
		});
	}
}


var LocationManager = {
	is_var : function( varName ){
		var regexS = "[?&]"+varName+"=([^&#]*)";
		var regex = new RegExp( regexS ,'i');
		var tmpURL = window.location.href;
		var results = regex.exec( tmpURL );
		if( results == null ){
			return null;
		}else{
			return results[1].replace(/%20/g,' ');
		}
	},
	get_hash: function( varName , str){
		var regexS = "[#&]"+varName+"=([^&]*)";
		var regex = new RegExp( regexS ,'i');
		var tmpURL = str? str : window.location.hash;
		var results = regex.exec( tmpURL );
		if( results == null ){
			return null;
		}else{
			return results[1].replace(/%20/g,' ');
		}
	}, 
	get_var : function( varName , str){
		var regexS = "[?&]"+varName+"=([^&#]*)";
		var regex = new RegExp( regexS ,'i');
		var tmpURL = str? str : window.location.href;
		var results = regex.exec( tmpURL );
		if( results == null ){
			return null;
		}else{
			return results[1].replace(/%20/g,' ');
		}
	},
	get_refer : function()
	{
		return document.referrer;
	},
	get_hostname : function(str)
	{
		if(typeof str == 'undefined')
		{	
			return window.location.hostName;
		}
		else
		{	
			// exemple
			//http://www.google.com.ua/?asa=df&PID=GG_080919RC&aaa
			var res = null;
			
			if(res = str.match(/^http(s|):\/\/(www\.|)(.+?)\//))
			{
				return res[3];
			}
			
			return null; 
		}	
	},
	get_pathname : function(str)
	{
		// exemple
		//str = 'http://devorigin.ringcentral.com/features/local-numbers/overview.html';
		var res = null;
		if(typeof str == 'undefined')
		{
			return window.location.pathname
		}
		else
		{
		if(res = str.match(/^http(s|):\/\/(www\.|)(.+?)(\/.*)/))
			{
				return res[4];
			}
		}
	},
	is_hash : function(varName){
		var hash  = window.location.hash.replace(/^#/,'');
		var aHash = hash.split('&');
		return in_array(varName,aHash);
	},
	buildUrl : function(hash){
		var fullUrl = '';
		// 	hash
		// 	Array {
		//		host
		//		path
		//		vars : Array{
		//			varName1 : varNameValue1,
		//			varName2 : varNameValue2,
		//		}
		//	}
		if(hash){
		//if(hash && hash.host){
			fullUrl += hash.host;
			if(hash.path ){
				fullUrl += hash.path;
			}
			if(hash.vars){
				var vars = Array();
				for(var key in hash.vars){
					if(hash.vars[key] != hash.path && hash.vars[key] != null)
					{
						vars.push(key + '=' + hash.vars[key]);
					}
				}
				if(!empty(vars)){
					fullUrl += '?' + vars.join('&');
				}
			}
		}else{
			return false;
		}
		return fullUrl;
	},
	getLocationState : function()
	{
		var pathname = window.location.pathname;
		if(res = pathname.match(/([a-z]{2})(|\-n|\-s)\.html$/))
		{
			return res[1].toUpperCase();
		}
		return null;
	},
	getLocationCode : function()
	{
		var pathname = window.location.pathname;
		if(res = pathname.match(/area\-code\-(\d+)\.html$/))
		{
			return res[1];
		}
		return null;
	}
}




function $_(id){
	return document.getElementById(id);
}
if(!$_('showControl'))
{
	document.write('<span id="showControl" ondblclick ="this.innerHTML = \'\'" style="background-color:white;position:absolute;left:0px;top:0px;z-Index:10000"></span>')
}


if(!/msie 6/i.test(navigator.userAgent))
{
	if(!$_('showStopper'))
	{
		document.write('<iframe id="showStopper" style="display: none"></iframe>');
	}
}


function showStopper(time)
{
	var param = time? 'param[sleep]=' + time : '';
	if($_('showStopper'))
	{
		$_('showStopper').src = '/api/index.php?cmd=showStopper&api=collector&' + param;
	}
}


function hash_to_string(hash)
{
	arr = [];
	for(key in hash){
		try{
			arr.push(key+':'+ hash[key]);
		}catch(e){}
	}
	return arr.join(',');
}

function show(obj,cmd){
	str = '';
	for(key in obj){
		try{
			str += '&nbsp;&nbsp;&nbsp;&nbsp;<b>'+key+'</b>='+(obj[key]&&obj[key][cmd] ? obj[key][cmd]:obj[key])+'<br>';
		}catch(e){}
	}
	switch(cmd){
		case 'inTail':
			$_('showControl').innerHTML += str!=''? str:'<b>EMPTY</b>';
			break;
		default:
			$_('showControl').innerHTML = str!=''? str:'<b>EMPTY</b>';
			break;
	}
}
function printArray(arr){
	$_('showControl').innerHTML = '<pre>' + print_r(arr, true);
}
function print_r( array, return_val ) {
	var output = "", pad_char = " ", pad_val = 4;
	var formatArray = function (obj, cur_depth, pad_val, pad_char) {
		if (cur_depth > 0) {
			cur_depth++;
		}
		var base_pad = repeat_char(pad_val*cur_depth, pad_char);
		var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
		var str = "";
		if (obj instanceof Array || obj instanceof Object) {
			str += "Array\n" + base_pad + "(\n";
			for (var key in obj) {
				//if (obj[key] instanceof Array) {
					str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char) + '<br>';
				//} else {
				//	str += thick_pad + "["+key+"] => " + obj[key] + "\n";
				//}
			}
			str += base_pad + ")\n";
		} else {
			if(obj && obj.toString){
				str = obj.toString();
			}
		}
		return str;
	};
	var repeat_char = function (len, pad_char) {
		var str = "";
		for(var i=0; i < len; i++) {
			str += pad_char;
		};
		return str;
	};
	output = formatArray(array, 0, pad_val, pad_char);
	if (return_val !== true) {
		document.write("<pre>" + output + "</pre>");
		return true;
	} else {
		return output;
	}
}
Function.prototype.bind = function(obj) {
    var method = this;
    var arg = Array();
    for(var i = 0; i < arguments.length; i++){
    	if(i){
    		arg.push(arguments[i])
    	}
    }
    return function(E) {
    	var arg_ = Array();
	    for(var i = 0; i < arguments.length; i++){
	    	if(arguments[i] instanceof Array || arguments[i] instanceof Object){
	    		arg_.push(arguments[i]);
	    	}
	    }
    	if(arg_.length){
    		arg = arg_.concat(arg);

    	}
    	returnVal = method.apply(obj, arg);
    	window.addEvent( window, 'onunload', function(){method = null; arg = null; obj = null;})
		return returnVal;
    }
}

Function.prototype.rcBind = function(obj)
{
	var m = this;
	var a = arguments.length>1 ? arguments[1] : {};
	return function(e)
	{
		if(arguments.length)
		{
			if(arguments[0].srcElement || arguments[0].target)
			{
				a['oEvent'] = arguments[0];
			}
			else
			{
				for(var key in arguments[0])
				{
					a[key] = arguments[0][key];
				}
			}

		}
		return m.call(obj, a);
	}
}

Function.prototype.rcBindAsIs = function(obj)
{
	var method = this;
	var arg = [];
	for(var i = 1; i < arguments.length; i++)
	{
		arg.push(arguments[i]);
	}
	return function()
	{
		if(arguments.length)
		{
			for(var i = 0; i < arguments.length; i ++)
			{
				arg.push(arguments[i]);
			}
		}
		//var res = null;
		//try
		//{
			res = method.apply(obj, arg);
		//}
		//catch(e){}
		if(arguments.length)
		{
			for(var i = 0; i < arguments.length; i ++)
			{
				arg.pop();
			}
		}
		return res;
	}
}


function addEvent(obj, ev, func){
	if(ev == 'ondomready')
	{
		onDomReady(func);
		return;
	}
	if(ev != 'onunload'){
		window.addEvent( window, 'onunload', function(){window.removeEvent(obj, ev, func); func = null;})
	}
	if (window.addEventListener){
		obj.addEventListener(ev.replace(/^on/i,''), func, false);
	}
	if (window.attachEvent){
		obj.attachEvent(ev,func);
	}
	
	
	
}


function onDomReady(callback)
	{	
		var _timer;
		
		
		
		var onDomReadyCallBack = function()
		{		
			if (arguments.callee.done) return;		
			arguments.callee.done = true;
			if (_timer)
			{
				clearInterval(_timer);
				_timer = null;
			}
			
			
			callback();		
			
		};	
		
		
		
		if (document.addEventListener)
		{
			document.addEventListener("DOMContentLoaded", onDomReadyCallBack, false);
		}
		
		if(document.attachEvent && !$_('__ie_onload'))
		{
			/*document.write("<script id='__ie_onload' defer src='" + (location.protocol == "https:" ?  "https://javascript:void(0)" : "javascript:void(0)") + "'><\/script>");
			var script = document.getElementById("__ie_onload");
			if(script)
			{
				script.onreadystatechange = function()
				{
					if (this.readyState == "complete")
					{
						onDomReadyCallBack(); 
					}
				};
			}*/			
		}
		
		if (document.attachEvent && document.documentElement.doScroll && window == window.top)
		{
			(
				function()
				{
					try
					{
						document.documentElement.doScroll("left");
					}
					catch(error)
					{
						setTimeout( arguments.callee, 0 );
						return;
					}
					onDomReadyCallBack();
				}
			)();
		}
		
		if (document.attachEvent)
		{
			/*document.onreadystatechange = function()
			{
				alert(document.readyState);
				if(document.readyState == "interactive")
				{
					alert(11);
					onDomReadyCallBack();
				}
			}*/
		}
		
		
	
		if (/WebKit/i.test(navigator.userAgent))
		{ 
			_timer = setInterval(function()
			{
				if (/loaded|complete/.test(document.readyState))
				{
					onDomReadyCallBack(); 
				}
			}, 10);
		}	
	
		addEvent(window, 'onload', onDomReadyCallBack);
	
	}




function removeEvent(obj, ev, func){
	if (window.addEventListener){
		obj.removeEventListener(ev.replace(/^on/i,''), func, false);
	}
	if (window.detachEvent){
		obj.detachEvent(ev, func);
	}
}
function in_array(needle, haystack, strict) {
    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}
function count( mixed_var, mode ) {
   var key, cnt = 0;

    if( mode == 'COUNT_RECURSIVE' ) mode = 1;
    if( mode != 1 ) mode = 0;

    for (key in mixed_var){
        cnt++;
        if( mode==1 && mixed_var[key] && (mixed_var[key].constructor === Array || mixed_var[key].constructor === Object) ){
            cnt += count(mixed_var[key], 1);
        }
    }

    return cnt;
}
function is_string( mixed_var ){
    return (typeof( mixed_var ) == 'string');
}
function is_numeric( mixed_var ) {
    return !isNaN( mixed_var );
}

function is_dom(obj){
	return obj && obj.style;
}

function is_oObj(obj){
	return obj && obj.getView && obj.getView();
}
is_vObj = is_oObj;

function is_array(mixed_var) {
    return ( mixed_var instanceof Array );
}


function is_object( mixed_var ){
     if(mixed_var instanceof Array) {
        return false;
    } else {
        return (mixed_var !== null) && (typeof( mixed_var ) == 'object');
    }
}

function is_numeric(mixed_var) {
    return !isNaN( mixed_var );
}

function empty(mixed_var) {
	var is_object_empty = false;
	if(is_object(mixed_var)){
		for(key in mixed_var){
			return is_object_empty;
		}
		is_object_empty = true;
	}
    return ( mixed_var === "" || mixed_var === 0   || mixed_var === "0" || mixed_var === null  || mixed_var === false  ||  ( is_array(mixed_var) && mixed_var.length === 0 ) || is_object_empty );
}

function is_obj(obj){
	return obj && typeof(obj);
}
/*function in_array(arr,str){
	for(var i=0;i<arr.length;i++)
		if(arr[i] == str)
			return true;
	return false;
}*/
function getChilds(obj, nodeName, attr, style, arr){
	if(!arr){
		arr = Array();
	}
	if(obj.hasChildNodes()){
		for(var i=0; i < obj.childNodes.length; i++){
			if(obj.childNodes[i].nodeName == '#text'){
				continue;
			}
			if(!nodeName || obj.childNodes[i].nodeName == nodeName){
				if(!attr){
					if(!style){
						arr.push(obj.childNodes[i]);
					}else{
						if(obj.childNodes[i].style){
							var flg = false;
							for(key in style){
								var re = new RegExp(style[key])
								if(obj.childNodes[i].style[key].match(re)){
									flg = true;
								}else{
									flg = false;
									break;
								}
							}
							if(flg){
								arr.push(obj.childNodes[i]);
							}
						}
					}
				}else{
					var flg = false;
					for(key in attr){
						if(obj.childNodes[i].getAttribute(key) == attr[key]){
							flg = true;
						}else{
							flg = false;
							break;
						}
					}
					if(flg){
						if(!style){
							arr.push(obj.childNodes[i]);
						}else{
							if(obj.childNodes[i].style){
								var flg = false;
								for(key in style){
									if(obj.childNodes[i].style[key] == style[key]){
										flg = true;
									}else{
										flg = false;
										break;
									}
								}
								if(flg){
									arr.push(obj.childNodes[i]);
								}
							}
						}
					}
				}
			}
			getChilds(obj.childNodes[i], nodeName, attr, style, arr);
		}
	}
	return arr;
}
function errorMsg( method, msg){
	alert("Error:\r\r\n\n    " + method + "                        \r\n    " + msg);
}
function noticeMsg( method, msg){
	alert('Notice!!!:\r\r    ' + method + '                        \r    ' + msg + '!');
}

// зарезервирования ретурн ложь , нужна для что бы потом можно было снять событие с обьекта
function returnFalse(event){
	event.cancelBubble = true;
	return false;
}

// нахрена?
function getNextBrother(obj){
	if(!is_dom(obj)){
		errorMsg('tools.js -> Window :: getNextBrother','Object in not DOM element');
		return;
	}
}


/*function parseXML(xml){
	var arr = Array();
	if(xml){
		var root=xml.getElementsByTagName('result')[0];
		if( root != null ){
			for( var i = 0; i < root.childNodes.length; i++ ){
				item_=root.childNodes[i];
				if( item_.nodeName != '#text'){
					var index = arr.length;
					arr[index] = Array();
					arr[index]['nodeName'] = item_.nodeName;
					arr[index]['textContent'] = item_.text||item_.textContent;
					for( var k = 0; k < item_.attributes.length; k++){
						var attr = item_.attributes[k];
						arr[index][attr.name] = attr.value;
					}
				}
			}
		}
	}
	return arr;
}*/

/*function parseXML(xml, arr){
	if(!arr){
		arr = Array();
	}
	if(xml.nodeName == '#document'){
		var root = xml.firstChild;
	}else{
		var root = xml;
	}
	if(root){
		if(root.hasChildNodes()){
			for( var i = 0; i < root.childNodes.length; i++ ){
				var item_    = root.childNodes[i];
				var nodeName = item_.nodeName;
				if( nodeName != '#text'){
					if(!arr[root.nodeName]){
						arr[root.nodeName] = Array();
					}
					if(!arr[root.nodeName][item_.nodeName]){
						arr[root.nodeName][item_.nodeName] = Array();
					}
					var val = parseXML(item_);
					if(is_array(val)){
						arr[root.nodeName][item_.nodeName].push(val);
					}else{
						arr[root.nodeName][item_.nodeName] = val;
					}
				}
			}

		}else{
			var textContent = root.text||root.textContent;
			var attributes  = getAttributes(xml);
			if(attributes){
				attributes['textContent'] = textContent;
				return attributes;
			}
			return textContent;
		}
	}else{
		return '';
	}
	return arr;
}*/

function parseXML(xml){
	var arr = Array();
	if(!xml || !xml.firstChild){
		return '';
	}

	var root = xml.nodeName=='#document'? xml.firstChild : xml;
	if(root.nodeName == '#text'){
		root = root.nextSibling;
	}
	if(root.nodeName == 'xml'){
		root = root.nextSibling;
	}
	if(root){
		for( var i = 0; i < root.childNodes.length; i++ ){
			var item    = root.childNodes[i];
			var nodeName = item.nodeName;
			var attributes = getAttributes(item);
			if(nodeName != '#text'){
				if(nodeName != "#comment" ){
					switch(nodeName){
						case 'length':case 'push':
							nodeName = '_' + nodeName;
							break;
					}
					var val = parseXML(item);
					if(!arr[nodeName]){
						if(attributes){
							var temp = Array();
							temp['attrs']  = attributes;
							temp['textContent'] = val;
							arr[nodeName] = temp;
						}else{
							arr[nodeName] = val;
						}
					}else{
						if(!is_array(arr[nodeName])){
							var temp = arr[nodeName];
							arr[nodeName] = Array(temp);
						}
						if(arr[nodeName].length == 0){
							var temp = arr[nodeName];
							arr[nodeName] = Array(temp);
						}
						if(attributes){
							var temp = Array();
							temp['attrs']  = attributes;
							temp['textContent'] = val;
							arr[nodeName].push(temp);
						}else{
							arr[nodeName].push(val);
						}
					}
				}
			}
		}
		var flg = false;
		for(key in arr){
			flg = true;
			break;
		}
		
		
		
		//return flg? arr : (root.text||root.textContent||(root.firstChild? root.firstChild.nodeValue : undefined));
		return flg? arr : (root.text||root.textContent);
	}
	return null;
}

function getAttributes(node){
	var arr = Array();
	if(node && node.attributes && node.attributes.length > 0){
		for( var i = 0; i < node.attributes.length; i++){
			var attr = node.attributes[i];
			arr[attr.name] = attr.value;
		}
		return arr;
	}
	return null;
}

function formatPhoneNumber(number){
	return number.substring(0,1)+' ('+number.substring(1,4)+') '+number.substring(4,7)+'-'+number.substring(7,11);
}

function templater(str, hash)
{

	var leftQ  = '<%';
	var rightQ = '%>';
	var re1 = new RegExp("((^|"+ rightQ +")[^\t]*)'",'g');
	var re2 = new RegExp("\t=(.*?)\\" + rightQ,'g');
	var my_str = "var a=[];with(hash){a.push('" + str
					.replace(/[\t\r\n]/g, " ")
					.split(leftQ)
					.join("\t")
					.replace(re1, "$1\r")
					.replace(re2, "',$1,'")
					.split("\t")
					.join("');")
					.split(rightQ)
					.join("a.push('")
					.split("\r")
					.join("\\'")+ "');} return a.join('');";
	
	my_str = 'try{' + my_str + '}catch(e){throw e;}';

	return new Function("hash", my_str)(hash);

}

function getCssClassNamevalue(o, className)
{
	var sClasses = o.className.replace(/\n|\r|\t/g,' ');
	var aClasses = sClasses.split(' ');
	
	
	var re       = new RegExp('^' + className + '(\-|)([^\-]+|)','') ;
	for(var i = 0; i < aClasses.length; i++)
	{
		var class_ = aClasses[i];
		if(res = class_.match(re))
		{
			return res[2];
		}
	}
	return null;
}
getCssClassNameValue = getCssClassNamevalue

function setCssClassName(o, className, value)
			{
				
				if(getCssClassNameValue(o, className) == value)
				{
					return;
				}
				
				if(typeof value == 'undefined')
				{
					o.className = className;
				}
				else
				{
					var sClasses = o.className.replace(/\n|\r|\t/g,' ');
					var aClasses = sClasses.split(' ');
					var re       = new RegExp('^' + className + '\-[^\-]+','') ;
					for(var i = 0; i < aClasses.length; i++)
					{
						var class_ = aClasses[i];
						if(class_.match(re))
						{
							aClasses.splice(i,1);
						}
					}

					if(value == '' && value != 0)
					{
						aClasses.push(className);
					}
					else
					{
						aClasses.push(className + '-' + value);
					}
					o.className = aClasses.join(' ');
					if(o.firstChild && o.firstChild.tagName == 'B')
					{
						o.firstChild.innerHTML = o.className;
					}
				}
				//alert(o.className)
			}

			function addClassName(o, className)
			{
				var aClasses = o.className.replace(/\n|\r|\t/g,' ').split(' ');
				for(var i = 0; i < aClasses.length; i++)
				{
					if(aClasses[i] == className)
					{
						return;
					}
				}
				o.className += ' ' + className;
			}

function initCss(rules)
{
	if(!rules || typeof rules != 'string')
	{
		return false;
	}
	try
	{
		var oStyle = document.createElement('DIV');
		oStyle.innerHTML = '*<style>' + rules + '</style>*';
		document.getElementsByTagName('HEAD')[0].appendChild(oStyle);
	}
	catch(e)
	{
		var oStyle = document.createElement('STYLE');
		oStyle.innerHTML = rules;
		document.body.appendChild(oStyle);
	}
	return true;
}

function getElementsByClassName(classNameVal, parent, tag)
{
	var res =[];
	parent = parent||document;
	var nodes = parent.getElementsByTagName(tag || '*');
	var l = nodes.length; 
	if(l) 
	{
		var re = new RegExp("(^|\\s)" + classNameVal + "(\\s|$)");
		  
		for(var i = 0; i < l; i++)
			if (re.test(nodes[i].className) ) res.push(nodes[i]);
	}
	return res;
}

/*
 function getElementsByClassName(classNameVal, parent)
 {
 	var res =[];
 	parent = parent||document;
 	var nodes = parent.getElementsByTagName('*');
 	var l = nodes.length;
 	if(l)
 	{
 		for(var i = 0; i < l; i++)
 		{
 			var node = nodes[i];
 			var aClasses = node.className.replace(/\n|\r|\t/g,'').split(' ');
 			if(inArray (aClasses, classNameVal) != -1)
 			{
 				res.push(node);
 			}
 		}
 	}
 	return res;
 }
 */

function each(obj, callBack, space)
{
	if(!obj)
	{
		throw new Error('Each\nObject is undefined')	;
	}
	if(typeof callBack != 'function')
	{
		throw new Error('Each\nCallBack undefined or not a function')	;
	}

	space = space || obj;

	if(obj.length)
	{
		for (var i = 0, l = obj.length; i < l; i++) {
			if (callBack.call(space, obj[i], parseInt(i), obj) === false)
					return false;
		}
	}
	else
	{
		for (var key in obj) {
			if (obj.hasOwnProperty(key)) {
				if (callBack.call(space, obj[key], key, obj) === false)
					return false;
			}
		}
	}
	return true;
}

function getCurrentStyle(o, name)
{
	if( window.getComputedStyle )
	{
	   return window.getComputedStyle(o,null)[name];
	} else if( o.currentStyle )
	{
	    return o.currentStyle[name];
	}
	return  null;
}

function each_r(obj, callBack, space)
{
	if(!obj)
	{
		throw new Error('Each\nObject is undefined')	;
	}
	if(typeof callBack != 'function')
	{
		throw new Error('Each\nCallBack undefined or not a function')	;
	}

	space = space || obj;

	var res = [];

	if(obj.length)
	{
		for (var i = 0, l = obj.length; i < l; i++) {
			var ret_val = callBack.call(space, obj[i], i, obj);
			if(ret_val)
			{
				res.push(ret_val);
			}
		}
	}
	else
	{
		for (var key in obj) {
			if (obj.hasOwnProperty(key)) {
				var ret_val = callBack.call(space, obj[key], key, obj);
				if(ret_val)
				{
					res.push(ret_val);
				}
			}
		}
	}
	return res.length? res : null;
}

function getCssPropValueBySelectorAndProp(selector, prop)
	{
		var css = window.document.styleSheets;
		if(css.length)
		{
			var res =
			each_r(css,
				(
					function(selector, prop, cssGroup)
					{
						try
						{
							var fullRules = cssGroup.cssRules || cssGroup.rules
							if(fullRules)
							{
								var res =
								each_r(fullRules,
									(
										function(selector, prop, rule)
										{
											if(rule.selectorText == selector)
											{
												return rule.style[prop];
											}
											return null;
										}
									).rcBindAsIs(this, selector, prop)
								);
								return res? res : null;
	
							}
						}catch(e){}
					}
				).rcBindAsIs(this, selector, prop)
			);
			return res? res[0] : null;
		}
	}

function inArray (arr, val)
{
	if(arr)
	{
		for(var i = 0, l = arr.length; i < l; i++)
		{
			if(arr[i] == val)
			{
				return i;
			}
		}
	}
	return -1;
}



function opacity(id, opacStart, opacEnd, millisec) {
	
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	}
	
	
	function changeOpac(opacity, id) {
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
	
function getParentByTagsName(arr, node)
	{
		while(inArray(arr, node.nodeName) == -1)
		{	
			if(node.nodeName == 'BODY')
			{
				return null;
			}		
			node = node.parentNode;
		}
		return node;
		
	}
	
	
	
function fireEvent(el, ev)
{
	if (document.createEventObject)
	{
	    var E = document.createEventObject();
	    el.fireEvent(ev, E);
	    return true;
	}
	else if(document.createEvent)
	{
	    var E = document.createEvent("MouseEvents");
	    E.initEvent(ev.replace(/^on/,''), true, false);
	    el.dispatchEvent(E);
	    
	     var E = document.createEvent("HTMLEvents");
	    E.initEvent(ev.replace(/^on/,''), true, false);
	    el.dispatchEvent(E);
	    
	    return true;
	}
	else
	{
	    return false;
	}
}

function rand( min, max ) {
    var argc = arguments.length;
    if (argc == 0) {
        min = 0;
        max = 2147483647;
    } else if (argc == 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function concatHash()
{
	var r = {};
	for(var i = 0; i < arguments.length; i++)
	{
		var parent = arguments[i];
		for(var key in parent)
		{
			r[key] = parent[key];
		}
	}
	return r;
}


/*







*/




function PlansPrice(hash)
{

	Subscriber.call(this);

	this._columnSwitchCmd   = null;
	this._ColumnsMgrNode    = null;
	this._TablePriceNode    = null;
	this._event             = null;
	this._ColumnNodeName    = null;
	this._MarkerColumnIdCmd = null;
	this._trialClassName    = null;
	this._buyClassName      = null;
	this._optionId          = null;
	this._callBack          = null;

	this.__construct(hash);



}
PlansPrice.prototype =
{
	__construct : function(hash)
	{
		this._columnSwitchCmd   = hash.columnSwitchCmd   ? hash.columnSwitchCmd   : 'activeColumn';
		this._ColumnsMgrNode    = hash.ColumnsMgrNode    ? hash.ColumnsMgrNode    : $_('columns_mgr_node');
		this._TablePriceNode    = hash.TablePriceNode    ? hash.TablePriceNode    : $_('table_price');
		this._event             = hash.event             ? hash.event             : 'onclick';
		this._ColumnsNodeName   = hash.ColumnsNodeName   ? hash.ColumnsNodeName   : ['TD'];
		this._MarkerColumnIdCmd = hash.MarkerColumnIdCmd ? hash.MarkerColumnIdCmd : 'MarkerColumnId';


		this._trialBuyNodeName  = hash.trialBuyNodeName  ? hash.trialBuyNodeName  : ['A'];
		this._trialClassName    = hash.trialClassName    ? hash.trialClassName    : 'trial';
		this._buyClassName      = hash.buyClassName      ? hash.buyClassName      : 'buy';
	},

	setCallBack : function(callBack)
	{
		this._callBack = callBack;
	},

	init : function()
	{

		if(this._TablePriceNode)
		{

			window.addEvent(this._TablePriceNode, this._event, function(E)
			{

				var TargetNode = E.target?  E.target : E.srcElement;
				var TdNode = getParentByTagsName(this._ColumnsNodeName, TargetNode);


				if(TdNode)
					{
						var columnId = getCssClassNameValue(TdNode, this._MarkerColumnIdCmd);
						if(typeof columnId == 'string')
						{

							window.setCssClassName(this._ColumnsMgrNode, this._columnSwitchCmd, columnId);


							var AnhNode = getParentByTagsName(this._trialBuyNodeName, TargetNode);
							if(AnhNode)
							{

								var is_trial = getCssClassNameValue(AnhNode, this._trialClassName) == ''? true : false;
								var is_buy   = getCssClassNameValue(AnhNode, this._buyClassName)   == ''? true : false;

								if((is_trial || is_buy) && AnhNode.nodeName == 'A')
								{
									AnhNode.removeAttribute('href');
								}
								if(is_trial)
								{
								    var trial = "trial";
								    if(/action=trial30/.test(window.location.toString())) {
								        trial = "trial30";
								    }
									this._fireEvent(trial, columnId);
									if(this._callBack)
									{
										this._callBack(trial, columnId);
									}
								}
								if(is_buy)
								{
									this._fireEvent('buy', columnId);
									if(this._callBack)
									{
										this._callBack('buy' ,columnId);
									}
								}

							}
						}
					}


			}.rcBindAsIs(this));
		}
	}


}







var CookiesManager = {
	setCookie : function (name, value, expires, path, domain, secure) {
		name = name.toLowerCase();
		if(!path){
			path = '/';
		}
		if(typeof expires != 'number'){
			expires = '';
		}else{
			var expires_date = new Date( (new Date()).getTime() + (expires*24*60*60*1000) );
			expires = ' expires=' + expires_date.toGMTString() + ';';
		}

		var d = (domain) ? ';domain=' + domain : '';
		var s = ( secure ) ? ";secure" : "";
		document.cookie = name + "=" + value + ";" + expires + " Path=" + path + d + s;
	},
	getCookie : function (name){
		var c = document.cookie;
		var matches = c.match(new RegExp("(?:^|; )" + name + "=([^;]*)", "i"));
		return (matches ? decodeURIComponent(matches[1]) : null);
	},
	attachCookie : function(cookieName, str){
		var value = CookiesManager.getCookie(cookieName);
		var re = new RegExp("(&|\\\?)"+cookieName+"=");
		if(value && !str.match(re)){
			str += '&' + cookieName + '=' + value;
		}
		return str;
	},
	delCookie : function( name, path, domain ) {
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	},

	delAlienCookies : function(cookies, write) {

		var src = window.location.protocol + '//' + window.location.host +'/inc/php/clearc.php?' + cookies.join('&');
		cookies.push((new Date())*1);
		if ( write && write == true ) {
			document.write('<iframe style="display:none;" src="'+ src + '"></iframe>');
		} else {
			var ifr = document.createElement('iframe');
			ifr.style.display = 'none';
			ifr.src = src;
			document.body.appendChild(ifr);
		}
	}
}

/*




*/

function Subscriber(){
	EventsPack.call(this);
	this._observers = Array();
	
	this.setObserver = function(eventName, callBack, obj){
		if(obj == undefined){
			obj = this._view;
		}
		if(obj){
			if(!this[eventName]){
				window.addEvent(obj, eventName, callBack);
			}else{
				if(!this._observers[eventName]){
					this._observers[eventName] = Array();
				}
				this._observers[eventName].push(callBack);
			}
		}else{
			if(!this._observers[eventName]){
				this._observers[eventName] = Array();
			}
			this._observers[eventName].push(callBack);
		}
	}
	
	
	this.on = this.setObserver;
	
	
	
	this.removeObserver = function(eventName, callBack, obj){
		if(!this[eventName]){
			if(obj == undefined){
				obj = this._view;
			}
			window.removeEvent(obj,eventName,callBack);	
		}else{
			if(this._observers[eventName]){
				var len = this._observers[eventName].length;
				for(var i = 0; i < len; i++){
					if(this._observers[eventName][i] == callBack){
						this._observers[eventName][i] = undefined;
						return;
					}
				}
			}
		}
	}
				
	this._informObservers = function(eventName){
		
		var arg = [];
		for(var i = 1; i < arguments.length; i++)
		{
			arg.push(arguments[i]);
		}
		if(this._observers[eventName]){
			for( var i = 0; i < this._observers[eventName].length; i++){
				if(this._observers[eventName][i]){
					if(arg.length)
					{
						this._observers[eventName][i].apply(this, arg);
					}
					else
					{
						this._observers[eventName][i]();
					}
				}
			}
		}
	}
	
	this._fireEvent = this._informObservers;
	this.fireEvent = this._informObservers;
	
}

function EventsPack(){
	this.onselection = function(){
		this._informObservers('onselection');
	}
	this._attachEvent = function(eventName,obj){
		if(!this[eventName]){
			this[eventName] = function(arg, e){
				this._informObservers(eventName, e);
			}
		}
	}
}