<!-- //
	var alert_mes = 'Please select number of pages, writer level and urgency.';
	var non_avail = 'not applicable';
	var pageSelectLimit = new Array();

	
	//var urg=[['7 days','4 days','3 days','48 hours','24 hours'],['30 days','20 days','10 days','7 days','5 days'],[],['7 days','4 days','3 days','48 hours','24 hours']];
	//var urgH=[[1,4,5,6,7],[1,2,3,4,5],[],[1,4,5,6,7]];
	//var lvl=[['Standard Quality','Premium Quality','Specialized: Math/Law/Biology/Finance'],['Standard Quality','Premium Quality','PhD Level'],[],['Standard Quality','Premium Quality','Specialized: Math/Law/Biology/Finance']];
	//var price=[[[11.95,16.95,18.95],[13.95,18.95,20.95],[14.95,20.95,22.95],[17.95,22.95,24.95],[20.95,24.95,26.95]],[[13.95,15.95,17.95],[15.95,17.95,19.95],[17.95,19.95,21.95],[18.95,20.95,23.95],[19.95,22.95,0]],[],[[11.95,16.95,18.95],[13.95,18.95,20.95],[14.95,20.95,22.95],[17.95,22.95,24.95],[20.95,24.95,26.95]]];
	//var minpg=[1,3,1,1];

admissiondoctypes = {
		142: 1,
        143: 1,
        144: 1, 
        145: 1,
        154: 1
        };    

var cookienotdoctypes = {
           
        };

	function chgType(o) {
		var f = o.form;
        var si_;
        if(doctype_view==0) {
            si_=f['doctype'].value;
            //si1=f['doctype'].value;
        } else {
            si_=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
            //si1=f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex;
        }
        toshowTr(o,si_); ///// 
		loadUrgency(si_,o);
        loadLevel(si_,o);
        // reset pages to minpages bu doctype
        
        if(numpages_view!=0) {
            for( k=0; minpg[si_]>0 && k<f['numpages'+getNumeric(o,'numpages')].length; k++){
			    if(f['numpages'+getNumeric(o,'numpages')].options[k].value>=minpg[si_]){ f['numpages'+getNumeric(o,'numpages')].selectedIndex=k; break; }
		    }
        }

        /* ************************************************************* */
        var inter = 0;
        if (f['o_interval'+getNumeric(o,'o_interval')])
        {
            inter = f['o_interval'+getNumeric(o,'o_interval')].options[f['o_interval'+getNumeric(o,'o_interval')].selectedIndex].value;
        }
        var num;
        if(inter == 1) 
        {
            num = 550;
        } 
        else 
        {
            num = 275;
        }
        var pg_s = document.getElementById('numpages'+getNumeric(o,'numpages'));
        var pages_str = ' page(s)';
        var words_str = ' words';
        var delimetr_str = ' / ';
        var k;

        for(k=start_k; k<pg_s.length; k++)
        {
            if ( si_ == 182 )
            {
                if (k+1 <= 50)
                {
                    pg_s.options[k-start_k].text = (k+1);
                }
                else
                {
                    pg_s.options[k-start_k].text = (k+1);
                    pg_s.options[k-start_k].disabled = '"disabled"';
                }
            }
            else
            {
                pg_s.options[k-start_k].text = (k+1) + pages_str + delimetr_str + (k+1)*num + words_str;
            }
            //if (resubmit) pg_s.options[k-start_k].value = (k+1);
        }
        /* ************************************************************* */

		calcTotal(o);
	}

	function loadUrgency(n,o) {
		
        f=o.form;
        if(wrlevel_view==0) {
            si=f['urgency'+getNumeric(o,'urgency')].value;
            f['urgency'+getNumeric(o,'urgency')].value=si;
        } else {
            s=o.form['urgency'+getNumeric(o,'urgency')];
		    si=s.selectedIndex;
            for(i=s.length; i>=0; i--) s.remove(i);
		    for(i=0; i<urg[n].length; i++) {
			    option_= new Option(urg[n][i],urgH[n][i]);
			    s.options[i]=option_;
		    }
		    s.selectedIndex=si;
        }
        if(doctype_view==0) {
            t=f['doctype'+getNumeric(o,'doctype')].value;
        } else {
            t=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
        } 

        if(urgency_view==0) {
            u=urgHH[t][f['urgency'+getNumeric(o,'urgency')].value];
        } else {
            u=urgHH[t][f['urgency'+getNumeric(o,'urgency')].options[f['urgency'+getNumeric(o,'urgency')].selectedIndex].value];
        }
        
        if(urgHours[t][urgH[t][u]]<=48){
        	document.getElementById('tr_allow_night_calls_'+getNumeric(o,'allow_night_calls',true)
        	).style.display='none';
        }else{
        	document.getElementById('tr_allow_night_calls_'+getNumeric(o,'allow_night_calls',true)
        	).style.display='';
        }
	}

	function loadLevel(n,o) {
        f=o.form;
        if(wrlevel_view==0) {
            si=f['wrlevel'+getNumeric(o,'wrlevel')].value;
            f['wrlevel'+getNumeric(o,'wrlevel')].value=si;
        } else {
            s=o.form['wrlevel'+getNumeric(o,'wrlevel')];
		    si=s.selectedIndex;
            for(i=s.length; i>=0; i--) s.remove(i);
		    for(i=0; i<lvl[n].length; i++) {
                lvl_name = lvl[n][i];
                if(typeof(cookielevel)!='undefined')
                {
	                if (cookielevel)
	                {
	                    if ( !cookienotdoctypes[n] && (lvl_name == 'Specialized' || lvl_name == 'Specialized Math/Law/Biology/Finance') )
	                    {
	                        lvl_name = 'Platinum';
	                    }
	                }
                }
			    option_= new Option(lvl_name, lvlHH[n][i]);
			    s.options[i]=option_;
		    }
	    	s.selectedIndex = 0;
		    if (lvl[n].length > si)
		    {
		    	s.selectedIndex=si;
		    }
        }
	}

	function chgUrg(o) {
		f=o.form;
        if(doctype_view==0) {
            t=f['doctype'+getNumeric(o,'doctype')].value;
        } else {
            t=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
        } 

        if(urgency_view==0) {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].value];
        } else {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].options[f['urgency'+getNumeric(o,'urgency')].selectedIndex].value];
        }
        
        if(wrlevel_view==0) {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].value];
        } else {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex];
        }
         
        if(numpages_view==0) {
            pg=f['numpages'+getNumeric(o,'numpages')].value;
        } else {
            pg=f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value;
        }
        g=getPagesGroupId(t, pg);

        if(curr_none==1) {
		    if(!price[t][u][l][g] && urgency_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Urgency \n for given Type of document and Level');
			    for(u=u; u>=0; u--) {
				    if(price[t][u][l][g]>0){f['urgency'+getNumeric(o,'urgency')].selectedIndex=u;break;}
			    }
		    }        
        } else {
		    if(!price[t][currency][u][l][g] && urgency_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Urgency \n for given Type of document and Level');
			    for(u=u; u>=0; u--) {
				    if(price[t][currency][u][l][g]>0){f['urgency'+getNumeric(o,'urgency')].selectedIndex=u;break;}
			    }
		    }
        }
        if(urgHours[t][urgH[t][u]]<=48){
        	document.getElementById('tr_allow_night_calls_'+getNumeric(o,'allow_night_calls',true)
        	).style.display='none';
        }else{
        	document.getElementById('tr_allow_night_calls_'+getNumeric(o,'allow_night_calls',true)
        	).style.display='';
        }
		calcTotal(o);
	}

    function chgLevel(o) {
		f=o.form;
		
        if(doctype_view==0) {
            t=f['doctype'+getNumeric(o,'doctype')].value;
        } else {
            t=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
        } 

        if(urgency_view==0) {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].value];
        } else {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].options[f['urgency'+getNumeric(o,'urgency')].selectedIndex].value];
        }
        
        if(wrlevel_view==0) {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].value];
        } else {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex];
        }
        
        if(numpages_view==0) {
            pg=f['numpages'+getNumeric(o,'numpages')].value;
        } else {
            pg=f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value;
        }
        g=getPagesGroupId(t, pg);

        if(curr_none==1) {
		    if(!price[t][u][l][g] && wrlevel_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Level \n for given Type of document and Urgency');
			    for(l=l; l>=0; l--) {
				    if(price[t][u][l][g]>0){ f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex=l; break; }
			    }
		    }        
        } else {
        	if(pages_groups[t]) l--;
		    if(!price[t][currency][u][l][g] && wrlevel_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Level \n for given Type of document and Urgency');
			    for(l=l; l>=0; l--) {
				    if(price[t][currency][u][l][g]>0){ f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex=l; break; }
			    }
		    }
        }  
        
        calcTotal(o);
	}

    function chgInterval(o, resubmit) {
		f=o.form;
		
        if(doctype_view==0) {
            t=f['doctype'+getNumeric(o,'doctype')].value;
            ty = t;
        } else {
            t=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
            ty = t;
        } 

        if(urgency_view==0) {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].value];
        } else {
            u=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].options[f['urgency'+getNumeric(o,'urgency')].selectedIndex].value];
        }
        
        if(wrlevel_view==0) {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].value];
        } else {
            l=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex];
        }
        
        if(numpages_view==0) {
            pg=f['numpages'+getNumeric(o,'numpages')].value;
        } else {
            pg=f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value;
        }
        g=getPagesGroupId(t, pg);

        if(curr_none==1) {
		    if(!price[t][u][l][g] && wrlevel_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Level \n for given Type of document and Urgency');
			    for(l=l; l>=0; l--) {
				    if(price[t][u][l][g]>0){ f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex=l; break; }
			    }
		    }        
        } else {
		    if((!price[t] || !price[t][currency] || !price[t][currency][u] || !price[t][currency][u][l] || !price[t][currency][u][l][g]) && wrlevel_view!=0){ // no price for this combination!
			    alert('Sorry, we can not guarantee this Level \n for given Type of document and Urgency');
			    for(l=l; l>=0; l--) {
				    if(price[t][currency][u][l][g]>0){ f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex=l; break; }
			    }
		    }
        } 
        
        /////////////////////////////
        inter = 0;
        if((t != 51) && (t != 139) && (t != 235) && (t != 125) && (t != 124) && (t != 234) && (t != 126))
        {
            if (f['o_interval'+getNumeric(o,'o_interval')])
            {
                inter=f['o_interval'+getNumeric(o,'o_interval')].options[f['o_interval'+getNumeric(o,'o_interval')].selectedIndex].value;
            }
            
            pg_s = document.getElementById('numpages'+getNumeric(o,'numpages')); 
            
            //alert(f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value);
            if(inter == 1) {
                num = 550;
                str_o = "(approximately 550 words per page)";
            } else {
                num = 275;
                str_o = "(approximately 275 words per page)";
            }
            //for(k=0; k<pg_s.length; k++) 

            sel_pg = f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value;


            var pages_str = '';
            var words_str = '';
            var delimetr_str = '';

            if (t != 182)
            {
                pages_str = ' page(s)';
                words_str = ' words';
                delimetr_str = ' / ';
            }
            else
            {
                str_o = '';
            }

            for(k=start_k; k<pg_s.length; k++)
            {
                pg_s.options[k-start_k].text = (k+1) + pages_str + delimetr_str + (k+1)*num + words_str;
                if (resubmit) pg_s.options[k-start_k].value = (k+1);
            }
            if (resubmit) f['numpages'+getNumeric(o,'numpages')].selectedIndex = 0;
            
            
            document.getElementById('num_pg_ord').innerHTML = str_o;
            
            
        }
        //////////////////////////////

        //alert(f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value);

		calcTotal(o);
	}    
    
    
	function calcTotal(o) {
		f=o.form;
		t="0.00"; 
        disc = 1;
		f['cost_per_page'+getNumeric(o,'cost_per_page')].value='0.00';
        //alert(i);
        //f.cost_per_page.value='0.00';
        
        //alert('1');

        if(doctype_view==0) {
            ty=f['doctype'+getNumeric(o,'doctype')].value;
        } else {
            ty=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
        } 
        //alert('2 - '+ty+'-'+getNumeric(o,'doctype')+'-'+f['doctype'+getNumeric(o,'doctype')].value);
        inter = 0;
        if((ty != 51) && (ty != 139) && (ty != 235) && (ty != 125) && (ty != 124) && (ty != 234) && (ty != 126))
        {
            if (f['o_interval'+getNumeric(o,'o_interval')])
            {
                inter=f['o_interval'+getNumeric(o,'o_interval')].options[f['o_interval'+getNumeric(o,'o_interval')].selectedIndex].value;
            }
        }
        //alert('3 - '+inter); 
        
		ur_id = f['urgency'+getNumeric(o,'urgency')].value;

        if(urgency_view==0) {
             ur=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].value];
        } else {
             ur=urgHH[ty][f['urgency'+getNumeric(o,'urgency')].options[f['urgency'+getNumeric(o,'urgency')].selectedIndex].value];
        }

		

        if(wrlevel_view==0) {
            le=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].value];
        } else {
            le=lvlHH[ty][f['wrlevel'+getNumeric(o,'wrlevel')].selectedIndex];
            if (pages_groups[ty]) le--;
        }
		if( limitList[ty] && urgHours[ty][ur_id] && o.id != f['numpages'+getNumeric(o,'numpages')].name )
		{
			urg_hours = urgHours[ty][ur_id];
			if( limitList[ty][urg_hours] != null && limitList[ty][urg_hours][le] != null )
				pageLimiter( o, limitList[ty][urg_hours][le], urg_hours );
			else
				pageLimiter( o, -1, 0 );
		}
		else if( o.id == f['numpages'+getNumeric(o,'numpages')].name )
        {
			ativaOptionsDisabled( f['numpages'+getNumeric(o,'numpages')] );
        }

        if(numpages_view==0)
        {
            pg=f['numpages'+getNumeric(o,'numpages')].value;
        } 
        else
        {
            pg=f['numpages'+getNumeric(o,'numpages')].options[f['numpages'+getNumeric(o,'numpages')].selectedIndex].value;
        }

        ///////////////////////////

        /*pg_s = document.getElementById('numpages'+getNumeric(o,'numpages'));

        var pages_str = '';
        var words_str = '';
        var delimetr_str = '';

        if (ty != 182)
        {
            pages_str = ' page(s)';
            words_str = ' words';
            delimetr_str = ' / ';
        }
        else
        {
            str_o = '';
        }

        for(k=start_k; k<pg_s.length; k++)
        {
            pg_s.options[k-start_k].text = (k+1) + pages_str + delimetr_str + (k+1)*num + words_str;
            if (resubmit) pg_s.options[k-start_k].value = (k+1);
        }*/

        ///////////////////////

        if(numpages_view!=0) {
		    if(minpg[ty]>0 && pg<minpg[ty]) {
			    alert('Sorry, Number of pages can not be less than '+minpg[ty]);
			    for( i=0; i<f['numpages'+getNumeric(o,'numpages')].length; i++){
				    if(f['numpages'+getNumeric(o,'numpages')].options[i].value>=minpg[ty]){
					    f['numpages'+getNumeric(o,'numpages')].selectedIndex=i; break;
				    }
			    }
		    }
        }

        g=getPagesGroupId(ty, pg);

        if (g == 0)
        {
            if(admissiondoctypes[ty] == 1) {
                pp = f['numpapers'+getNumeric(o,'numpapers')].value;
                if (pp >= 2 && pp <= 3) { 
	                disc = 0.95;
	                document.getElementById('total_disc').innerHTML = '(5% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else if (pp >= 4 && pp <= 5) { 
	                disc = 0.90;
	                document.getElementById('total_disc').innerHTML = '(10% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else if (pp >= 6) { 
	                disc = 0.85; 
	                document.getElementById('total_disc').innerHTML = '(15% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else {
                    //alert(document.getElementById('total_disc').innerHTML);
	                document.getElementById('total_disc').innerHTML = '';
	                document.getElementById('total_disc').style.display = 'none';
	            }
            } else {
	            if (pg >= 15 && pg <= 50) { 
	                disc = 0.95;
	                document.getElementById('total_disc').innerHTML = '(5% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else if (pg >= 51 && pg <= 100) { 
	                disc = 0.90;
	                document.getElementById('total_disc').innerHTML = '(10% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else if (pg >= 101) { 
	                disc = 0.85; 
	                document.getElementById('total_disc').innerHTML = '(15% discount applied)';
	                document.getElementById('total_disc').style.display = '';
	            } else {
	                document.getElementById('total_disc').innerHTML = '';
	                document.getElementById('total_disc').style.display = 'none';
	            }
            }
		}
		else
		{
	        fg=getPagesGroupId(ty, 1);
	        discount = 0;
			if(curr_none==1)
			{
		        discount = (1 - price[ty][ur][le][g] / price[ty][ur][le][fg]) * 100;
			}
			else
			{
		        discount = (1 - price[ty][currency][ur][le][g] / price[ty][currency][ur][le][fg]) * 100;
		        
			}
	        discount = Math.floor(discount/5) * 5;
	        if (discount)
	        {
	            document.getElementById('total_disc').innerHTML = '('+discount+'% discount applied)';
	            document.getElementById('total_disc').style.display = '';
	        }
	        else
	        {
	            document.getElementById('total_disc').innerHTML = '';
	            document.getElementById('total_disc').style.display = 'none';
	        } 
		}

		if(pg) {   
            if(admissiondoctypes[ty] == 1) {
                pg = pg*pp;    
            }
            if(curr_none==1) {
			    if(ty){  
                    if(inter == 1) { 
				        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=Math.round(2*price[ty][ur][le][g]*100)/100; // cpp
                        // diss total
                        t=Math.round(2*pg*price[ty][ur][le][g]*disc*100)/100;
                    } else {
                        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=price[ty][ur][le][g]; // cpp 
        			    // diss total
                        t=Math.round(pg*price[ty][ur][le][g]*disc*100)/100;
                    }

			    } else {
                    if(inter == 1) {
				        f['cost_per_page'+getNumeric(o,'cost_per_page')].value==Math.round(2*price[ty][ur][le][g]*100)/100; // cpp
				        t=Math.round(2*pg*price[ty][ur][le][g]*disc*100)/100; // essay total                    
                    } else {
				        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=price[ty][ur][le][g]; // cpp
				        t=Math.round(pg*price[ty][ur][le][g]*disc*100)/100; // essay total
                    }
			    }
            } else {
			    if(ty){  
                    if(inter == 1) { 
                        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=Math.round(2*price[ty][currency][ur][le][g]*100)/100; // cpp
				        t=Math.round(2*pg*price[ty][currency][ur][le][g]*disc*100)/100; // diss total
				    } else {
				    	
                        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=price[ty][currency][ur][le][g]; // cpp
				        t=Math.round(pg*price[ty][currency][ur][le][g]*disc*100)/100; // diss total
                    }
			    } else {
                    if(inter == 1) { 
                        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=Math.round(2*price[ty][currency][ur][le][g]*100)/100; // cpp
				        t=Math.round(2*pg*price[ty][currency][ur][le][g]*disc*100)/100; // essay total
                    } else {
                        f['cost_per_page'+getNumeric(o,'cost_per_page')].value=price[ty][currency][ur][le][g]; // cpp
				        t=Math.round(pg*price[ty][currency][ur][le][g]*disc*100)/100; // essay total
                    }
			    }            
            }
		}

        if ( semaphor_fields )
        {
            for (fid in semaphor_fields)
            {
                if ( typeof(f[fid]) != 'undefined' )
                {
                    value = parseFloat(semaphor_fields[fid]);
                    if ( ( f[fid].type == 'checkbox' && f[fid].checked == true ) || ( f[fid].type == 'text' && value > 0 ) )
                    {
                        t = Math.round( (t + value) * 100)/100;
                    }
                }
            }
        }

        f['total'+getNumeric(o,'total')].value=t;
	}




    function chOrderCategoty(o, t, le)
    {
        f=o.form;
        
        if(t == 0 || t == 13 || t == 14 || t == 39 || t == 84 || t == 168 || t == 169 || t == 171)
        {
            //alert(t); 
            if(le == 1 || le == 2) 
            {
                //alert(le);
                var oc = document.getElementById('order_category'+getNumeric(o,'order_category')); // order_category31
                oc.length = 0;
                var num_oc = aoc.length;
                for (i = 0; i < num_oc; i++)
                {
                    if (document.createElement)
                    {
                        var newOCOption = document.createElement("OPTION");
                        newOCOption.text = aoc[i];
                        newOCOption.value = aoc_vals[i];
                        if(aoc_styles[i] == 1) newOCOption.setAttribute("style","color:#5e5cb4;");
                        (oc.options.add) ? oc.options.add(newOCOption) : oc.add(newOCOption, null);
                    }
                    else
                    {
                        // for NN3.x-4.x
                        oc.options[i] = new Option(aoc[i], aoc_vals[i], false, false);
                    }
                }
            } else chOrderCategotyReal(o, t, le);
        }
        else chOrderCategotyReal(o, t, le);
    }
    
    function chOrderCategotyReal(o, t, le)
    {
        f=o.form;
        var oc = document.getElementById('order_category'+getNumeric(o,'order_category')); // order_category31
        oc.length = 0;
        var num_oc = aoc_real.length;
        for (i = 0; i < num_oc; i++)
        {
            if (document.createElement)
            {
                var newOCOption = document.createElement("OPTION");
                newOCOption.text = aoc_real[i];
                newOCOption.value = aoc_vals_real[i];
                if(aoc_styles_real[i] == 1) newOCOption.setAttribute("style","color:#5e5cb4;");
                (oc.options.add) ? oc.options.add(newOCOption) : oc.add(newOCOption, null);
            }
            else
            {
                // for NN3.x-4.x
                oc.options[i] = new Option(aoc_real[i], aoc_vals_real[i], false, false);
            }
        }
    }
    

	function pageLimiter( o, t_on_page, urg_hours )
	{
		var Node = f['numpages'+getNumeric(o,'numpages')];
		if(f['o_interval'+getNumeric(o,'o_interval')])
		{
			inter = f['o_interval'+getNumeric(o,'o_interval')].options[f['o_interval'+getNumeric(o,'o_interval')].selectedIndex].value;
		}
		else
		{
			inter = 0;
		}
		_count_child = urg_hours/t_on_page;

		if ( _count_child && inter == 1 ) {
			_count_child = Math.floor(_count_child / 2);
		}

        for(k=0; k<Node.length; k++) {
			if( _count_child <= k && _count_child )
			{
				Node.options[k].style.display = 'none';
				Node.options[k].disabled = "disabled";
			}
			else
			{
				Node.options[k].disabled = "";
				Node.options[k].style.display = '';
			}

//			Node.options[k].selected = false;
        }

		ativaOptionsDisabled( f['numpages'+getNumeric(o,'numpages')] );		
	}


	function ativaOptionsDisabled( selectObj ){
    var sels = selectObj;
//    alert(1);
		if(sels.options[sels.selectedIndex].disabled){
				var initial_index = sels.selectedIndex
				var found = false
				while (sels.selectedIndex < sels.options.length - 1) {
					sels.selectedIndex++
					if (!sels.options[sels.selectedIndex].disabled) {
						found = true
						break
					}
				}

				if (!found) {
					sels.selectedIndex = initial_index
					while (sels.selectedIndex > 0) {
						sels.selectedIndex--
						if (!sels.options[sels.selectedIndex].disabled) {
							found = true
							break
						}
					}
				}

				if (!found)
					sels.selectedIndex = -1
			}

			for(var j=0; j < sels.options.length; j++){
				if(sels.options[j].disabled){
					sels.options[j].style.color = '#CCC';
				}
				else
					sels.options[j].style.color = '#000';
			}

	}

	function selCurr(o,c,n) {
		f=o.form;
        currency=document.getElementById('currrates'+c).options[document.getElementById('currrates'+c).selectedIndex].value;
        valuta=document.getElementById('currrates'+c).options[document.getElementById('currrates'+c).selectedIndex].text;
              
        if(n!=0) {
          //f['currrates'+n].options[f['currrates'+c].selectedIndex].selected=true;
			document.getElementById('currrates'+n).options[document.getElementById('currrates'+c).selectedIndex].selected=true;
        }  
        if(str_blck==1) {      
            document.getElementById('orderNow').setAttribute('action','account.php?curr='+valuta+'&'+str_local);
        } else {
            document.getElementById('orderNow').setAttribute('action','order.php?curr='+valuta);
        }
		calcTotal(o);
	}  
    
	
	function check_sum() {
		if ( !(document.forms['orderNow'].elements['total'].value > 0)) {
			alert(alert_mes);
			return false;
		}
	}

    function ch_dead(o,id) {
        f=o.form; 
        d=f['todays'].options[f['todays'].selectedIndex].value;
        h=f['tohours'].options[f['tohours'].selectedIndex].value;
        f['tohours'].options[f['tohours'].selectedIndex].selected=true; 
        f['todays'].options[f['todays'].selectedIndex].selected=true; 
        
        dead=deadline;
         
        if(h=='') { h=0; } 
        if(d=='') { d=0; }        
        d=parseFloat(d); h=parseFloat(h);
        
        ff=dead.split(" ");
        ymd=ff[0].split("-");
        
        yn=parseFloat(ymd[0]); 
        mn=parseFloat(ymd[1]);
        dn=parseFloat(ymd[2]);
        his=ff[1].split(":");
        hn=parseFloat(his[0]);
        inn=parseFloat(his[1]);
        sn=parseFloat(his[2]); 
        
        if((hn+h)>24) {
           hn=(hn+h)-24;
           dn+=1;
        } else { hn=hn+h; }
        
        var daysmonth = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

        if((dn+d)>daysmonth[mn-1]) {
           dn=(dn+d)-daysmonth[mn-1];
           mn+=1;
        } else { dn=dn+d; }
        
        if(mn>12) {
           mn=mn-12;
           yn+=1;
        } 
        
        if(mn<10) { mn='0'+mn; } 
        if(dn<10) { dn='0'+dn; } 
        if(hn<10) { hn='0'+hn; } 
        if(inn<10) { inn='0'+inn; }
        if(sn<10) { sn='0'+sn; }
        
        newdate=yn+"-"+mn+"-"+dn+" "+hn+":"+inn+":"+sn;
        
        f[id].value = newdate;
        
       // http://www.exelenz.ru/misc/javascript-date/ !!!!!!!!!!!!!!!!!

    } 

function mailOrderNowForm() {
            return true;
}

function getPagesGroupId(doctype, pages) 
{
	result = 0;
	
	if (pages_groups[doctype])
	{
		for (group_id in pages_groups[doctype])
		{
			if ( parseInt(pages_groups[doctype][group_id][0]) <= parseInt(pages) &&
				(parseInt(pages_groups[doctype][group_id][1]) >= pages || parseInt(pages_groups[doctype][group_id][1]) == 0))
			{
				result = group_id; 
			}
		}
	}
	
	return result;
}

/////////////////////////////////////////////////////////

function chgType_pm(o) {
	f=o.form;
    if(doctype_view==0) {
        si_=f['doctype'].value;
    } else {
        si_=f['doctype'+getNumeric(o,'doctype')].options[f['doctype'+getNumeric(o,'doctype')].selectedIndex].value;
    }
    toshowTr(o,si_); ///// 
}    

function popup_notver(dos) {
    info=window.open("","info","toolbar=no,location=no,top=200,left=300,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=250");
    info.document.open();
    if(dos==1) {
        info.document.write("<html><head><title>NOT VERIFIED</title></head><body>")
        info.document.write("<p>Your payment details were incorrectly given/not given. Please provide us with correct payment details to have them verified and your payment will be processed accordingly.</p>");
    }
    
    info.document.write("</body></html>");
    info.document.close();
    return true;
}

function wrpm_popdef(dos){
    info=window.open("","info","toolbar=no,location=no,top=200,left=300,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=250");
    info.document.open();
    if(dos==1) {
        info.document.write("<html><head><title>PayPal info</title></head><body>")
        info.document.write("<p>Your e-mail registered with <a href='http://www.paypal.com' class='small' target='_blank'>PayPal.com</a></p>");
    }
    
    if(dos==2) {
        info.document.write("<html><head><title>E-Gold info</title></head><body>")
        info.document.write("<p>Your <a href='http://www.e-gold.com' class='small' target='_blank'>e-gold.com</a> account number<br/>Maximum 10 digits</p>");
    }
    
    if(dos==3) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p>8 digits OR 11 digits</p>");
    }
    
    if(dos==4) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p>Maximum 20 digits</p>");
    }
    
    if(dos==5) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p>9 digits only</p>");
    }
    
    if(dos==6) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p>8 digits OR 11 digits</p>");
    }
    
    if(dos==7) {
        info.document.write("<html><head><title>ACH info</title></head><body>")
        info.document.write("<p>9 digits only</p>");
    }
    
    if(dos==8) {
        info.document.write("<html><head><title>ACH info</title></head><body>")
        info.document.write("<p>Maximum 20 digits</p>");
    }
    
    if(dos==9) {
        info.document.write("<html><head><title>xoom.com info</title></head><body>")
        info.document.write("<p>4 digits only</p>");
    }
    
    if(dos==10) {
        info.document.write("<html><head><title>xoom.com info</title></head><body>")
        info.document.write("<p>6 digits only</p>");
    }
    if(dos==11) {
        info.document.write("<html><head><title>ACH info</title></head><body>")
        info.document.write("<p>Full name of account holder.</p>");
    }
    if(dos==12) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p><b>Beneficiary</b> - legal recipient of money. <p><b>Beneficiary name</b> - Full name of account holder.</p>");
    }
    
    if(dos==13) {
        info.document.write("<html><head><title>Wire Transfer info</title></head><body>")
        info.document.write("<p>Postal code, city, street and house/flat number where beneficiary lives.</p>");
    }
    
    if(dos==14) {
        info.document.write("<html><head><title>FirePay</title></head><body>")
        info.document.write("<p>FirePay Account E-mail</p>");
    }
    
    if(dos==15) {
        info.document.write("<html><head><title>FirePay</title></head><body>")
        info.document.write("<p>16 digits only</p>");
    }
    
    info.document.write("</body></html>");
    info.document.close();
    return true;
}

function wr_alike(str_val) {
    info=window.open("","info","toolbar=no,location=no,top=200,left=300,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=400,height=250");
    info.document.open();

    info.document.write("<html><head><title>Keywords</title></head><body>")
    info.document.write("<p>" + str_val + "</p>");

    info.document.write("</body></html>");
    info.document.close();
    return true;
}

function onblur_digits(id) {
    var txtint=document.getElementById(id);
    values = txtint.value;
    len = values.length;

    var pattern=new RegExp("\\s");
    if (isNaN(txtint.value) == true || pattern.test(txtint.value)) {
        alert("digits only");  
        txtint.focus();
        txtint.select();
    }
    
    if(len==8 || len==11) {
    } else {
       alert("8 digits OR 11 digits only");  
       txtint.focus();
       txtint.select();
    }
    
} 
 
function onblur_digits2(id) {
    var txtint=document.getElementById(id);
    values = txtint.value;
    len = values.length;

    var pattern=new RegExp("\\s");
    if (isNaN(txtint.value) == true || pattern.test(txtint.value)) {
        alert("digits only");  
        txtint.focus();
        txtint.select();
    }
    
    if(len==9) {
    } else {
       alert("9 digits only");  
       txtint.focus();
       txtint.select();
    }
    
}  

function onblur_digits3(id) {
    var txtint=document.getElementById(id);
    values = txtint.value;
    len = values.length;

    var pattern=new RegExp("\\s");
    if (isNaN(txtint.value) == true || pattern.test(txtint.value)) {
        alert("digits only");  
        txtint.focus();
        txtint.select();
    }
}

function onblur_digits61(id) {
    var txtint=document.getElementById(id);
    values = txtint.value;
    len = values.length;

    var pattern=new RegExp("\\s");
    if (isNaN(txtint.value) == true || pattern.test(txtint.value)) {
        alert("digits only");  
        txtint.focus();
        txtint.select();
    }
    
    if(len==16) {
    } else {
       alert("16 digits only");  
       txtint.focus();
       txtint.select();
    }
    
}


function check_ph_name(ff, ll, id) {
    var str_ff=document.getElementById(ff).value;
    var str_ll=document.getElementById(ll).value;

    document.getElementById(id).value=str_ff+' '+str_ll;
} 

//onChange="check_fields('pm_options_xoom36','xoom_first_name24','xoom_last_name25','xoom_ph_bank_name37','xoom_ph_acc_holder_name38','xoom_ph_bb_acc_number39');"  

function check_fields(val, id, ff, ll, id1, id2, id3, curr_id) {
    var str_ff=document.getElementById(ff).value;
    var str_ll=document.getElementById(ll).value;
    
    document.getElementById(id2).value=str_ff+' '+str_ll;
    
    si=document.getElementById(id).selectedIndex;
    vi = document.getElementById(id);
    
    //alert(vi.options[si].value);
    
    val_r = vi.options[si].value;
    if(val_r==val) {
        document.getElementById('save_pid').style.display='none';
        
        str1 = document.getElementById(id1).value;
        if(str1.length=='' || str1=='Not empty') {
            str_id1=document.getElementById(id1);
            //alert("Not empty"); 
            str_id1.value = 'Not empty'   
            str_id1.focus();
            str_id1.select();
        } else {
            str1 = document.getElementById(id3).value; 
            if(str1.length=='' || str1=='Not empty') {
                str_id3=document.getElementById(id3);
                //alert("Not empty"); 
                str_id3.value = 'Not empty'   
                str_id3.focus();
                str_id3.select();
            } else {
                document.getElementById('save_pid').style.display='';
            }
        }
        document.getElementById(curr_id).selectedIndex=1; 
    }  else {
        //alert(document.getElementById(curr_id).selectedIndex);
        document.getElementById('save_pid').style.display=''; 
        document.getElementById(curr_id).selectedIndex=0; 
        document.getElementById(id1).value='';
        document.getElementById(id2).value='';
        document.getElementById(id3).value='';
    }
} 

function not_empty(val_main, id_main, id, id1) {
    si=document.getElementById(id_main).selectedIndex;
    vi = document.getElementById(id_main);
    val_r = vi.options[si].value;
    
    if(val_r==val_main) {
        str = document.getElementById(id).value; 
        if(str.length=='' || str=='Not empty') {
            str_id=document.getElementById(id);
            //alert("Not empty"); 
            str_id.value = 'Not empty' 
            str_id.focus();
            str_id.select();
        } else {
            str = document.getElementById(id1).value; 
            if(str.length=='' || str=='Not empty') {
                str_id=document.getElementById(id1);
                //alert("Not empty"); 
                str_id.value = 'Not empty'  
                str_id.focus();
                str_id.select();
            } else {
                document.getElementById('save_pid').style.display='';
            }
        }
    }
} 


function check_fields2(val_main, id_main, ff, ll, id0, id1, id2, id3, id4, id5) {
    var str_ff=document.getElementById(ff).value;
    var str_ll=document.getElementById(ll).value;
    
    
    document.getElementById(id0).value=str_ff+' '+str_ll;
    
    si=document.getElementById(id_main).selectedIndex;
    vi = document.getElementById(id_main);
    
    //alert(vi.options[si].value);
    
    val_r = vi.options[si].value;
    if(val_r==val_main) {
        document.getElementById('save_pid').style.display='none';
    
        str1 = document.getElementById(id1).value;
        if(str1.length=='' || str1=='Not empty') {
            str_id1=document.getElementById(id1);
            //alert("Not empty"); 
            str_id1.value = 'Not empty' 
            str_id1.focus();
            str_id1.select();
        }  else {
            if(id2!=0) {
                str = document.getElementById(id2).value;
                if(str.length=='' || str=='Not empty') { 
                    str_id=document.getElementById(id2);
                    //alert("Not empty");
                    document.getElementById(id2).value = 'Not empty';    
                    str_id.focus();
                    str_id.select();
                } else if(id3!=0) {
                    str = document.getElementById(id3).value;
                    if(str.length=='' || str=='Not empty') { 
                        str_id=document.getElementById(id3);
                        document.getElementById(id3).value = 'Not empty';
                        //alert("Not empty");  
                        str_id.focus();
                        str_id.select();
                    } else if(id4!=0) {
                        str = document.getElementById(id4).value;
                        if(str.length=='' || str=='Not empty') { 
                            str_id=document.getElementById(id4);
                            document.getElementById(id4).value = 'Not empty';  
                            //alert("Not empty");  
                            str_id.focus();
                            str_id.select();
                        } else if(id5!=0) {
                            str = document.getElementById(id5).value;
                            if(str.length=='' || str=='Not empty') { 
                                str_id=document.getElementById(id5);
                                document.getElementById(id5).value = 'Not empty';  
                                //alert("Not empty");  
                                str_id.focus();
                                str_id.select();
                            } else {
                                document.getElementById('save_pid').style.display='';
                            }
                        }
                    }         
                }             
            }
        }

    }  else {
        //alert(document.getElementById(curr_id).selectedIndex);
        document.getElementById('save_pid').style.display='';
        document.getElementById(id0).value=''; 
        document.getElementById(id1).value='';
        document.getElementById(id2).value='';
        document.getElementById(id3).value='';
        document.getElementById(id4).value='';
        document.getElementById(id5).value=''; 
    }
}

function not_empty2(val_main, id_main, id1, id2, id3, id4, id5) {
    si=document.getElementById(id_main).selectedIndex;
    vi = document.getElementById(id_main);
    val_r = vi.options[si].value; 
    if(val_main==val_r) {
        if(id1!=0) {
            str = document.getElementById(id1).value;
            if(str.length=='' || str=='Not empty') { 
                str_id=document.getElementById(id1);
                document.getElementById(id1).value = 'Not empty';  
                //alert("Not empty");  
                str_id.focus();
                str_id.select();
            } else if(id2!=0) {
                str = document.getElementById(id2).value;
                if(str.length=='' || str=='Not empty') { 
                    str_id=document.getElementById(id2);
                    //alert("Not empty");
                    document.getElementById(id2).value = 'Not empty';    
                    str_id.focus();
                    str_id.select();
                } else if(id3!=0) {
                    str = document.getElementById(id3).value;
                    if(str.length=='' || str=='Not empty') { 
                        str_id=document.getElementById(id3);
                        document.getElementById(id3).value = 'Not empty';
                        //alert("Not empty");  
                        str_id.focus();
                        str_id.select();
                    } else if(id4!=0) {
                        str = document.getElementById(id4).value;
                        if(str.length=='' || str=='Not empty') { 
                            str_id=document.getElementById(id4);
                            document.getElementById(id4).value = 'Not empty';  
                            //alert("Not empty");  
                            str_id.focus();
                            str_id.select();
                        } else if(id5!=0) {
                            str = document.getElementById(id5).value;
                            if(str.length=='' || str=='Not empty') { 
                                str_id=document.getElementById(id5);
                                document.getElementById(id5).value = 'Not empty';  
                                //alert("Not empty");  
                                str_id.focus();
                                str_id.select();
                            } else {
                                document.getElementById('save_pid').style.display='';
                            } 
                        }
                    }         
                }             
            }
        }
    }
}


function check_fields3(val_main, id_main, ff, ll, curr_id, id0, id2, id3, id4) {
    var str_ff=document.getElementById(ff).value;
    var str_ll=document.getElementById(ll).value;
    
    document.getElementById(id0).value=str_ff+' '+str_ll;
    
    si=document.getElementById(id_main).selectedIndex;
    vi = document.getElementById(id_main);
    
    //alert(vi.options[si].value);
    
    val_r = vi.options[si].value;
    if(val_r==val_main) {
        document.getElementById('save_pid').style.display='none';
    
        str1 = document.getElementById(id3).value;
        if(str1.length=='' || str1=='Not empty') {
            str_id1=document.getElementById(id3);
            //alert("Not empty"); 
            str_id1.value = 'Not empty' 
            str_id1.focus();
            str_id1.select();
        }  else {
            document.getElementById('save_pid').style.display='';
        }
        document.getElementById(curr_id).selectedIndex=1; 
    }  else {
        document.getElementById(curr_id).selectedIndex=0; 
    
        document.getElementById('save_pid').style.display='';
        document.getElementById(id0).value=''; 
        document.getElementById(id2).value='';
        document.getElementById(id3).value='';
        document.getElementById(id4).value='';
    }
}

function not_empty3(val_main, id_main, id1) {
    si=document.getElementById(id_main).selectedIndex;
    vi = document.getElementById(id_main);
    val_r = vi.options[si].value; 
    if(val_main==val_r) {
        if(id1!=0) {
            str = document.getElementById(id1).value;
            if(str.length=='' || str=='Not empty') { 
                str_id=document.getElementById(id1);
                document.getElementById(id1).value = 'Not empty';  
                //alert("Not empty");  
                str_id.focus();
                str_id.select();
            } else {
                document.getElementById('save_pid').style.display='';
            } 
        }
    }
}
  
function chgDoctypeGroup(t)
{
	f=document.forms["orderNow"];

	var field1 = f["doctype"+getNumeric(f,"doctype")];
	var field2 = f["doctype"+getNumeric(f,"doctype")+"_hidden"];
	
	field1.sort;
	
	var n = field2.length;
	var doct_list = doct_groups[t.value];
	var tmp = new Array();
	
	for(i=0;i<n;i++){
		for(j=0;j<doct_groups[t.value].length;j++){
		
			if(field2[i].value==doct_list[j]) 
			{
				tmp[tmp.length] = {"value": field2[i].value,
				"text": field2[i].text};
			}
		}
	}
	
	field1.length=tmp.length;
	for(i=0;i<tmp.length;i++)
	{
		field1[i].value=tmp[i]["value"];
		if(field2.value==field1[i].value){ field1[i].selected=true;field1.value=field2.value}
		field1[i].text=tmp[i]["text"];
	}
	chgType(field1);
}

/////////////////////////////////////////////////////////


var maxnum = 10;
 
function add_preff_id(name,num){
	var num = document.getElementById('hidden_num').value*1;
	var last = document.getElementById('last').value*1;
	var div = document.getElementById('preff_container');
	var newDiv = document.createElement('div');
	
	if (num == maxnum-1){
		document.getElementById('add_preff_wr').style.display = 'none';
		//return;
	}
	newDiv.setAttribute('id', 'div' + (last + 1));
	
	newDiv.innerHTML = '<div name="preff_'+(last+1)+'" class="preff_input">'+
		'<div style="float:left;">'+
			'<input type="text" style="width: 120px; display: inline;" name="'+name+'[]" id="'+name+'[]">'+
		'</div>'+
		'<div style="position:relative;margin-left:125px;">'+
			'<a class="preff_delete" href="javascript:delete_preff_id('+(last+1)+');" title="Delete ID">&nbsp;</a>'+
		'</div>'+
	'</div>';
	div.appendChild(newDiv);
	//last++;
	document.getElementById('hidden_num').value++;
	document.getElementById('last').value++;
}

function delete_preff_id(number){
	if (number <= 1){
		return;
	}
	if (confirm('Are you sure you want to delete this writer?')){
		var divParent = document.getElementById('preff_container');
		var div = document.getElementById('div' + number);
		divParent.removeChild(div);
		document.getElementById('hidden_num').value--;
		document.getElementById('add_preff_wr').style.display = 'block';
		//number--;
	}
}

function show_writers(){
	for(var i=0;i<max_writers;i++){
		document.getElementById('writer_'+i).style.display = '';
	}
}


function hide_writers(){
	for(var i=0;i<max_writers;i++){
		document.getElementById('writer_'+i).style.display = 'none';
	}
}

/*
function wr_search(flag){
	var url = '/wr_search.php';
	var str = '';
	if(flag) str += '?favor=1';
    search = window.open(url+str,'wr_search',"copyhistory=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes,width=700,height=400");
    search.focus();
}*/

var newwindow = '';

function openwindow(url){
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name',"copyhistory=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes,width=700,height=400");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function wr_search(flag) {
	var url = '/wr_search.php';
	var str = '';
	if(flag) str += '?favor=1';
	
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url+str;
	}
	else {
		newwindow=window.open(url+str,'name',"copyhistory=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes,width=700,height=400");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
/*
function func_ch(o){
    f=o.form;
    name=f['sel_ind'].options[f['sel_ind'].selectedIndex].text;
    if(name.indexOf('-')!=-1) {
        var names=name.split('-');
        name=names[0];
    }
    val=f['sel_ind'].options[f['sel_ind'].selectedIndex].value;
    opener.document.getElementById('writer_id').value=val; 
    wr_name=opener.document.getElementById('wr_names');
    oldname=wr_name.firstChild;
    wr_name.removeChild(oldname);
    newtxt=opener.document.createTextNode(name);
    wr_name.appendChild(newtxt); 
    window.close();
}
*/
function removeButton(wrid,wrstr){
	if (opener) var flag = 1;
	if(flag){
		var add_to_order = document.getElementById('add_to_order_'+wrid);
	}
	else{
		var add_to_order = document.getElementById('add_to_order_'+wrid);
	}
		add_to_order.innerHTML =
		'<td align="center">'+
		'<div class="wr_button2_inactive" onclick="javascript:remove_from_order(\''+wrid+'\',\''+wrstr+'\');" style="width: 96px; cursor: pointer;">Remove</div>'+
		'</td>';
}
function addButton(wrid,wrstr){
	document.getElementById('add_to_order_'+wrid).innerHTML =
	'<td align="center">'+
	'<div class="wr_button2" onclick="javascript:add_to_order(\''+wrid+'\',\''+wrstr+'\');" style="width: 96px; cursor: pointer;">Place order</div>'+
	'</td>';
}


function add_to_order(wrid,wrstr){
	if (opener) var flag = 1;
	
	if(flag=='1'){
		var added_wr = opener.document.getElementById('added_wr');
	}
	else{
		var added_wr = document.getElementById('added_wr');
	}

	added_wr.innerHTML +=
	'<div id="added_wr_'+wrid+'" style="padding-top:10px;"><div style="width:150px;float:left;">'+ 
	wrstr+
	'<input type="hidden" name="preff_wr_id54[]" value="'+wrid+'" /></div><div>'+
	' <a href="javascript:remove_from_order(\''+wrid+'\',\''+wrstr+'\');">'+
	'<img src="/images/buttons/delete.gif" border="0" />'+
	'</a></div></div>';

	removeButton(wrid,wrstr);
	
	if(flag=='1'){
		alert('Writer was added');
		//opener.focus();
		//window.close();
	}
}

function remove_from_order(wrid,wrstr){
	if (opener) var flag = 1;
	if(flag=='1'){
		var added_wr = opener.document.getElementById('added_wr');
		var added_wr_id = opener.document.getElementById("added_wr_"+wrid);
	}
	else{
		var added_wr = document.getElementById('added_wr');
		var added_wr_id = document.getElementById("added_wr_"+wrid);
	}
	
	added_wr.removeChild(added_wr_id);

	addButton(wrid,wrstr);
	
	if(flag=='1'){
		alert('Writer was removed');
		//opener.focus();
		//window.close();
	}
}

function contact_wr(wrid){
	openwindow('contact_wr.php?wid='+wrid);
}

function add_to_favorite(wrid){
	//openwindow('add_to_favorite.php?wrid='+wrid);
	window.location = 'add_to_favorite.php?wrid='+wrid;
}

function delete_assigned_wr(wrid,curr,numpages){

	var deleted_wr = document.getElementById('deleted_wr').innerHTML;
	deleted_wr = deleted_wr.split(" ");
	var flag_not_del = true;
	for(j in deleted_wr){
		if(deleted_wr[j]==wrid){
			var flag_not_del = false;
			break;
		}
	}
	if(flag_not_del){
		deleted_wr.push(wrid);
	}

	var preferred_wr = document.getElementById('preferred_wr').innerHTML;
	preferred_wr = preferred_wr.split(" ");
	
	var cpp_max = 0;
	var flag = true;
	var writers = new Array();
	
	for(i in preferred_wr){
		for(j in deleted_wr){
			if(preferred_wr[i]==deleted_wr[j]){
				flag = false;
			}
		}

		if(flag)
			writers.push(preferred_wr[i]);
		flag=true;
	}
	for(i in writers){
		cpp_max = Math.round(Math.max(cpp_max,writers_prices[writers[i]])*100)/100;
	}
	if(cpp_max>0 && flag_not_del){
		if(document.getElementById('deleted_wr').innerHTML=='')
			document.getElementById('deleted_wr').innerHTML += wrid;
		else document.getElementById('deleted_wr').innerHTML += ' '+wrid;
		var preff_wr_to_del=document.getElementById('preff_wr_to_del_'+wrid)
		preff_wr_to_del.style.display = 'none';
		while (preff_wr_to_del.firstChild)
   			preff_wr_to_del.removeChild(preff_wr_to_del.firstChild);

		alert('Writer '+wrid+' was removed');
	}

	if(cpp_max>0){
		document.getElementById('writers_cost_per_page').firstChild.innerHTML = curr + cpp_max;
		document.getElementById('writers_total').firstChild.innerHTML = curr + cpp_max*numpages;
	}else{
		alert('This writer can\'t be removed!');
	}
}

function clear_first_preff(){
	document.getElementById("in_preff_1").innerHTML = '<input type="text" id="preff_wr_id54[]" name="preff_wr_id54[]" style="width: 120px; display: inline;"/>';
}

function Showsubtext(e, id, v) 
{
     var mousX=e.screenX;
     var mousY=e.screenY;
     var vScroll = document.body.scrollTop;
     var perMinus = 120;
     var perPlus = 10;
     if(site_id == 4 || site_id == 8 || site_id == 16 || site_id == 17)
     {
         var vScroll = document.documentElement.scrollTop;
         if(site_id == 17) perPlus = -120;
     }

     if(id == 2)
     {
         f = document.getElementById('orderNow');
         if(doctype_view == 0) si_=f['doctype'].value;
         else si_ = f['doctype' + getNumeric(o, 'doctype')].options[f['doctype' + getNumeric(o, 'doctype')].selectedIndex].value;

         if(si_ == 3) id = 1;
     }

     //elem = document.getElementById('elem'+id);
     elem = document.getElementById('elements_def');
     if(v==0)
     {
       if(id == 5) elem.style.width = '450px';
       //elem.style.top=mousY+vScroll-120;
       elem.style.top=(mousY+vScroll-perMinus)+'px';
       elem.style.left=(mousX+perPlus)+'px';
       elem.innerHTML = array_popdef[id];
       elem.style.display = 'block';
     }
     else
     {
       elem.style.width = '300px';
       elem.style.top=-10+'px';
       elem.style.left=-100+'px';
       elem.style.display = 'none';
     }
}

// -->
