function ShowCursor(show){	var cursor = ( show == true ) ? 'wait' : 'default';	document.body.style.cursor = cursor;	zz = document.getElementsByTagName('SELECT');	for( var i=0; i < zz.length; i++ )		zz[i].style.cursor = cursor;	zz = document.getElementsByTagName('DIV');	for( var i=0; i < zz.length; i++ )		zz[i].style.cursor = cursor;}function ShowDownload(show){	xx = document.getElementById( 'loading' );	if( xx )		xx.style.visibility = ( show == true ) ? 'visible' : 'hidden';	ShowCursor(show);}function getXMLHTTP(){	//fuction to return the xml http object	var xmlhttp=false;	try	{		xmlhttp=new XMLHttpRequest();	}	catch(e)	{		try		{			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");		}		catch(e)		{			try			{				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");			}			catch(e1)			{				xmlhttp=false;			}		}	}	return xmlhttp;}function getState(countryId,stateId,f,h,u,p,n,s){	var x = document.getElementById('select_'+countryId);	var strURL="scripts/findState.php?id="+stateId+"&field="+f+"&h="+h+"&u="+u+"&p="+p+"&n="+n+"&w="+x.style.width+"&m="+x.multiple;	var req = getXMLHTTP();	if (req)	{		req.onreadystatechange = function()		{			if (req.readyState == 4)			{				if( s == 2 || s == 3 )					ShowDownload( false );				// only if "OK"				if (req.status == 200)				{					document.getElementById(countryId).innerHTML=req.responseText;				}				else				{					alert("There was a problem while using XMLHTTP:\n" + req.statusText);				}			}		}		req.open("GET", strURL, true);		req.send(null);		if( s == 1 || s == 3 )			ShowDownload( true );	}}function getStreet(countryId,stateId,f,h,u,p,n,s){	var x = document.getElementById('select_'+countryId);	var strURL="scripts/findCity.php?id="+stateId+"&field="+f+"&h="+h+"&u="+u+"&p="+p+"&n="+n+"&w="+x.style.width+"&m="+x.multiple;	var req = getXMLHTTP();	if (req)	{		req.onreadystatechange = function()		{			if (req.readyState == 4)			{				if( s == 2 || s == 3 )					ShowDownload( false );				// only if "OK"				if (req.status == 200)				{					document.getElementById(countryId).innerHTML=req.responseText;				}				else				{					alert("There was a problem while using XMLHTTP:\n" + req.statusText);				}			}		}		req.open("GET", strURL, true);		req.send(null);		if( s == 1 || s == 3 )			ShowDownload( true );	}}function mySelect(x,f,h,u,p,n){	if( x.name == 'dd_cities' )	{		getState('dd_districts',x.value,f,h,u,p,n,1);		getStreet('dd_streets',0,f,h,u,p,n,2);	}	else	if( x.name == 'dd_districts' )	{		getStreet('dd_streets',x.value,f,h,u,p,n,3);	}}var status_logindiv = false;function opencallpop() {    window.open( 'popup.html', 'pop', "width=540, height=460, left=100, top=50, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no" );}function openlogindiv(e) {    $("#loginopen").show("slow");    status_logindiv = true;    if (!$.browser.msie)        e.stopPropagation();}function closelogindiv(e) {    $("#loginopen").hide("slow");    status_logindiv = false;    if (!$.browser.msie)        e.stopPropagation();}function mySelect2(x) {	return;	//$(x.id).	//load( 'http://127.0.0.1:8888/arajark.com/scripts/submit.php', function() { return false; } );	//if( x.id == '' )	//	return; /*	var MyData = document.getElementById(x.name);	alert(x.id+'['+'0'+']  ->  '+x.name+'['+x.value+']');	alert(MyData.value);*//*	var ajaxRequest;	// The variable that makes Ajax possible!   	try{   		// Opera 8.0+, Firefox, Safari   		ajaxRequest = new XMLHttpRequest();   		}   	catch (e){   		// Internet Explorer Browsers   		try{   			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");   			}   		 catch (e) {   		 	try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");   		 	}   		 catch (e){   		 	// Something went wrong   		 	alert("Your browser broke!");   		 	return false;   		 	}   		 }   	}	// Create a function that will receive data sent from the server   		ajaxRequest.onreadystatechange = function()   		{   			if(ajaxRequest.readyState == 4)   			{   				var ajaxDisplay = document.getElementById('ajaxDiv');   				ajaxDisplay.innerHTML = ajaxRequest.responseText;   			}   		}   		var search_category_id = document.getElementById('search_category_id').value;   		ajaxRequest.open("GET", get.php", true);   		ajaxRequest.send(null);*/};function checkNumber(e){	var keynum;	var keychar;	var numcheck;	var return2;	if( window.event ) // IE	{		keynum = e.keyCode;	}	else	if( e.which ) // Netscape/Firefox/Opera	{		keynum = e.which;	}	else		keynum = e.button;	keychar = String.fromCharCode(keynum);	if(	keynum < 48 || keynum > 57 )	{ // разрешаем только ввод цифр		return2 = false;		if( keynum == 8 )			return2 = true; // разрешаем нажатие клавиши backspace	}	else		return2 = true;	return return2;}function get_search_term() {    var referrer = window.location.href;    var searchParameter = 'search';    var tokens = referrer.substr(referrer.indexOf('?') + 1 ).split('&');    var tokens_num = tokens.length;    for(i = 0; i < tokens_num; i++) {		var parts = tokens[i].split('=');		var param = parts[0];		var value = parts[1];		if(param === searchParameter) return value;    };	return '';};String.prototype.replaceAll = function(stringToFind,stringToReplace){    var temp = this;    var index = temp.indexOf(stringToFind);    while(index != -1) {        temp = temp.replace(stringToFind,stringToReplace);        index = temp.indexOf(stringToFind);    }    return temp;} $(document).ready(function() {    $('#top_menubar').children('ul').addClass('sf-menu sf-navbar');    $("ul.sf-menu").superfish({        autoArrows: true,        pathLevels: 0,        delay: 300    });    $search = get_search_term();    if($search.length > 0) {		$('.para_title').highlight($search);		$('.para_content').highlight($search);    }	var origImg ="";	$(".swapImage").hover (		function () {			$(this).attr("src", $(this).attr("src").replace(/_norm_/, "_on_"));		},		function () {			$(this).attr("src", $(this).attr("src").replace(/_on_/, "_norm_"));		}	);    $("#tabs").tabs();    $('#simple_calc').addClass('calc_title');    $('#mono_calc').addClass('calc_title');    $('#multi_calc').addClass('calc_title');    // This is to add "characters left" functionality//    var max_length = 1024;////    $('textarea').each(function() {//        $(this).limit('1024','#chars_left_' + this.id);////		var error_obj = $(this).closest('span').parent().next();////        if(error_obj.is('.error')) {//            var $width = $(this).width() - error_obj.width();//            error_obj.after("<span id='chars_left_" + this.id + "' class='info_small' align='right' style='text-align: right; float: left; width: " + $width + "px;'>" + max_length + "</span>");//        }//        else {//            var $width = $(this).width();//            $(this).after("<span id='chars_left_" + this.id + "' class='info_small' align='right' style='text-align: right; display: block; padding-top: 5px; width:" + $width + "px;'>" + max_length + "</span>");//        }//    })    // To place focus on the first element with error    parent_obj = $('span.error').parent().find('input', 'textarea');    if(parent_obj.length > 0) {	var parent_id = parent_obj.eq(0).attr('id');	if(!parent_obj.eq(0).hasClass('hasDatepicker')) parent_obj.eq(0).focus();	document.getElementById(parent_id).scrollIntoView(false);    }    // Manages section folding    $('div[id^=section_content_]').not(':eq(0)').hide();    $('span.error').each(function() {        $(this).parent().parent().parent().parent().parent().show();    });    $('span[id^=pointer]').each(function() {        if($(this).parent('div').next('div').is(':visible')) $(this).html('&#9660;');        else $(this).html('&#9658;');    });    $('div[id^=section_title_]').bind('click', function() {        $(this).next('div').toggle();        if($(this).next('div').is(':visible')) {            $(this).children('span').html('&#9660;');        }        else $(this).children('span').html('&#9658;');    });    // Manages subsection folding    $('div[id^=subsection_comment_]').not(':eq(0)').hide();    $('div[id^=subsection_content_]').not(':eq(0)').hide();    $('div[id^=subsection_title_]').not(':eq(0)').addClass('collapsed');    $('span.error').each(function() {        $(this).parent().parent().parent().parent().parent().show();    });    $('div[id^=subsection_title_]').bind('click', function() {        $(this).next('div').toggle();    	$('div[id^=subsection_comment_]').toggle();    	$(this).toggleClass('collapsed');        if($(this).next('div').is(':visible')) {            $(this).children('span[id=pointer]').html('&#9660;');        }        else $(this).children('span[id=pointer]').html('&#9658;');    });    // Manages folding for paragraphs    $('div[id^=foldable_para_content_]').hide();    $('span[id^=pointer]').each(function() {        if($(this).parent('div').next('div').is(':visible')) $(this).html('&#9660;');        else $(this).html('&#9658;');    });    $('div[id^=foldable_para_title_]').bind('click', function() {        $(this).next('div').toggle();        if($(this).next('div').is(':visible')) {            $(this).children('span[id=pointer]').html('&#9660;');        }        else $(this).children('span[id=pointer]').html('&#9658;');		var $id = this.id.replace(/foldable_para_title_/, '');        $('div[id^=foldable_para_content_]').each(function() {            if(this.id != 'foldable_para_content_' + $id) {                $(this).hide();                $(this).prev().children('span[id=pointer]').html('&#9658;');            }        });    });    // Manages folding for right part    $('div[id^=fold_title_]').each(function() {		var content_id = '#fold_content_' + this.id.replace(/fold_title_/, '');        if($.cookie(this.id)) {            if($.cookie(this.id) == 'foldable title_expanded') {                $(this).addClass('foldable title_expanded');                $(content_id).show();            }            else {                $(this).addClass('foldable title_collapsed');                $(content_id).hide();            }        }        else {            $(this).addClass('foldable title_collapsed');            $(content_id).hide();        }		$(this).bind('click', function(){            $(this).toggleClass('title_expanded');            $(this).toggleClass('title_collapsed');            $.cookie(this.id, $(this).attr('class'), {expires: 60});			$(content_id).animate({height: 'toggle', opacity: 'toggle'}, 'fast');		});    });    // add a "rel" attrib if Opera 7+    if(window.opera) {        if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set            $("a.jqbookmark").attr("rel","sidebar");        }    }    $("#jqbookmark").live('click', function(event){        event.preventDefault(); // prevent the anchor tag from sending the user off to the link        var url = this.href;        var title = this.title;        if (window.sidebar) { // Mozilla Firefox Bookmark            window.sidebar.addPanel(title, url,"");        } else if( window.external ) { // IE Favorite            window.external.AddFavorite( url, title);        } else if(window.opera) { // Opera 7+            return false; // do nothing - the rel="sidebar" should do the trick        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)             alert('Unfortunately, this browser does not support the requested action,'             + ' please bookmark this page manually.');        }    });    // Default values ------------------------------------------------------    $('input[id=simple_scenario_number_1]').val('');    $('input[id=simple_repetitions_number_1]').val('');    $('input[id=simple_loss_percent_1]').val('');    $('input[id=simple_sequence_1]').val('');    // Updateability ------------------------------------------------------    $('input[id=simple_scenario_number_1]').attr({readonly: true, disabled: true});    $('input[id=simple_repetitions_number_1]').attr({readonly: true, disabled: true});    $('input[id=simple_loss_percent_1]').attr({readonly: true, disabled: true});    $('input[id=simple_sequence_1]').attr({readonly: true, disabled: true});    $('input[id=mono_scenario_number_1]').attr({readonly: true, disabled: true});    $('input[id=mono_repetitions_number_1]').attr({readonly: true, disabled: true});    $('input[id=mono_sequence_1]').attr({readonly: true, disabled: true});    $('input[id^=multi_scenario_number_]').attr({readonly: true, disabled: true});    $('input[id^=multi_sequence_]').attr({readonly: true, disabled: true});    $('#add_tr').live('click', function() {        $height = parseInt($('.main_content').parent('td').css('height')) + 22 + 'px';        $('.main_content').parent('td').css('height', $height);        $last_row = $('#multi_table tr:last').html();        $old_num = parseInt($('[id^="multi_scenario_number_"]:last').attr('id').replace("multi_scenario_number_", ""));        $new_num = $old_num + 1;        $old_val = parseInt($('[id^="multi_scenario_number_"]:last').val());        if(isNaN($old_val)) $new_val = "";        else $new_val =  $old_val + 1;        $last_row = $last_row.replaceAll("multi_scenario_number_" + $old_num, "multi_scenario_number_" + $new_num);        $last_row = $last_row.replaceAll("multi_repetitions_number_" + $old_num, "multi_repetitions_number_" + $new_num);        $last_row = $last_row.replaceAll("multi_profit_percent_" + $old_num, "multi_profit_percent_" + $new_num);        $last_row = $last_row.replaceAll("multi_loss_percent_" + $old_num, "multi_loss_percent_" + $new_num);        $last_row = $last_row.replaceAll("multi_sequence_" + $old_num, "multi_sequence_" + $new_num);        $('#multi_table > tbody:last').append('<tr>' + $last_row + '</tr>');        $('#multi_scenario_number_' + $new_num).val($new_val);        $('#multi_repetitions_number_' + $new_num).val('');        $('#multi_profit_percent_' + $new_num).val('');        $('#multi_loss_percent_' + $new_num).val('');        $('input[id*=_sequence_]').val('by turns');    });    $('input[id*=_reinvestments_number], input[id*=_repetitions_number_]').live('keypress', function(e) {        var key = e.charCode || e.keyCode || 0;        if(key==8 || key==9 || key==46 || (key>=37 && key<40) || (key>=48 && key<=57)) valid = true;        else valid = false;        if(!valid) e.preventDefault();    });    $('input[id*=_profit_percent_], input[id*=_loss_percent_], input[id$=_starting_sum]').live('keypress', function(e) {        var key = e.charCode || e.keyCode || 0;        if(key==8 || key==9 || key==46 || (key>=37 && key<40) || (key>=48 && key<=57)) valid = true;        else valid = false;        if(!valid) e.preventDefault();    });    $('#mono_chart_button').live('click', function(){        $('#mono_chart').toggle('fast');    });    $('#multi_chart_button').live('click', function(){        $('#multi_chart').toggle('fast');    });    // Validation for calculators    var $calcs = new Array('simple', 'mono', 'multi');    $.each($calcs, function() {        var calc = '#' + this;        var sum = calc + '_starting_sum';        var num = calc + '_reinvestments_number';        $(calc).click(function() {            if($(sum).val().length == 0 || $(sum).val() == 0) {                alert('Field cannot be empty!');                $(sum).focus();                return false;            }            if($(num).val().length == 0 || $(num).val() == 0) {                alert('Field cannot be empty!');                $(num).focus();                return false;            }        })    });    // Uncomment line below to have ajax call every 60 seconds.    //requestPostAjax();    if (!$.browser.msie)    {        $(document).click(function(event){            if(status_logindiv)                closelogindiv(event);        });        $(document).keydown(function(event){            if(status_logindiv && event.keyCode == 27)                closelogindiv(event);        });    }});
