function GotoPage(Pagename) 
{
	location.href=Pagename;
}
function NextPage()
{
   document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value) + 1;
   document.frmlist.submit();
}
function PrePage()
{
   
	document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value) - 1  ;
	document.frmlist.submit();
}

function NextPageLink(val)
{
    
	document.frmlist.pageNumber.value = eval(val)-1  ;
	document.frmlist.submit();
}
function SubmitForPage(FormName, ControlName, ControlValue, FormAction)
{
	ControlName.value = ControlValue;
	FormName.action = FormAction;
	FormName.submit();
}
function OrderPage(OrderBy)
{
	
	document.frmlist.pageNumber.value = eval(document.frmlist.pageNumber.value);
	
	if(document.frmlist.orderby.value.search(OrderBy)<0)
		document.frmlist.orderby.value = OrderBy;
	else
	{
		if(document.frmlist.orderby.value.search(' desc')<0)
			document.frmlist.orderby.value = OrderBy +' desc';
		else
			document.frmlist.orderby.value = OrderBy;
	}
	document.frmlist.submit();
}
function CheckEmailId(val) {
   if ((val.value.length == 0)) {
      return false;
   }

   if (val.value.length != 0) {
	  var emailformat = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
      if (!emailformat.test(val.value))
	   {
         alert("Please enter valid email.");
		 val.value="";
		 val.focus();
		 return false;
      }
   }
   return true;
}

function OrderFunction(orderstr,type)
{
	//alert(orderstr + type);
    document.frmlist.orderby.value = "order by " + orderstr +" " + type ;
	document.frmlist.submit();
}

function setvalue(tar,con,val)
{
	con.value=val;
	tar.submit();
}
function Trimmer(pVal) { 
    TRs=0; 
    var i;
	for (i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

    TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    return (pVal.substr(TRs, TRe-TRs+1)); 
} 
function TrimObj(theObj) 
{ 
	var pVal = theObj.value;

    var TRs=0; 
    for (var i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

   	var TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    theObj.value = pVal.substr(TRs, TRe-TRs+1); 
} 
function isDate(val) 
{
	var IsValid = 0;
	 if (val.value.length != 0) 
     {
        var longform =  /^[0-9]{2}-[0-1][0-9]-[1-9][0-9]{3}$/;
        if(longform.test(val.value))
		  {
		  		var DateArr = val.value.split("-");
				if(DateArr[0]> 31 || DateArr[1] >12)
					IsValid = 0;
				else
					IsValid = 1;
          }
		
				  if(IsValid == 0)
				  {
				  	
					  val.value='';
					  alert("Please Enter Date in a Valid Format");
					 val.focus();
					 return false;
				  }
   }
   
   return true;
}
function IsAlpha(val) 
{
  if (val.value.length != 0)
   {
       for (i = 0; i < val.value.length; i++)
	   {
		   var ch = val.value.charAt(i);
		   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ") || (ch == ".") || (ch == "&")|| (ch == "/")|| (ch == "|")|| (ch == "\\")) 
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter only character information.");
		    val.focus();
            return false;
           }
      }
  }

   return true;
}

function IsNum(val)
 {
   if (val.value.length != 0) 
    {
      for (i = 0; i < val.value.length; i++) 
	      {
              var ch = val.value.charAt(i);
              if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
		      {
                continue;
              } 
		      else
		      { 
		      val.value='';
              alert("Please enter numeric values.");
			  val.focus();
              return false;
             }
         }
   }
 
}
function IsAlphaNum(val) 
{
  if (val.value.length != 0)
   {
       for (i = 0; i < val.value.length; i++)
	   {
		   var ch = val.value.charAt(i);
		   if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-")|| (ch == "/")|| (ch == "|")|| (ch == "\\"))
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter valid value.");
		    val.focus();
            return false;
           }
      }
  }

   return true;
}

function IsWhiteSpaces(val) 
{
  if (val.value.length != 0)
   {
       for (i = 0; i < val.value.length; i++)
	   {
		   var ch = val.value.charAt(i);
		   if ((ch == " "))
		   {
              val.value='';
            alert("White spaces are not allowed.");
		    val.focus();
            return false;
            } 
		   else
		   {
		    continue;
           }
      }
  }

   return true;
}
function ImposeMaxLength(Object, MaxLen)
 {
    return(Object.value.length<MaxLen);
 }
function IsUserName(val) 
{
  if(val.value.length != 0)
   {
     if(val.value.length>=5) 
	 { 
	   for(i = 0; i < val.value.length; i++)
	      {
		    var ch = val.value.charAt(i);
		  if((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch >= "0" && ch <= "9")  || (ch == " ") || (ch == ".") || (ch == ",") || (ch == "-"))
		   {
              continue;
            } 
		   else
		   {
		    val.value='';
            alert("Please enter only character information.");
		    val.focus();
            return false;
           }
        }
    }
	else
	  {
	    val.value='';
        alert("Please enter atleast 5 characters for user name.");
		val.focus();
        return false;
	   }
   }
   return true;
}
function Fetch(query,divId)
{
			
		 	var chk;	
			
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			
			if(!xmlhttp && typeof ActiveXObject!="undefined")
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			xmlhttp.open('GET',query,false); 
			xmlhttp.setRequestHeader("Cache-Control","no-cache" );
			
			xmlhttp.onreadystatechange=function()
			{
				if(xmlhttp.readystate==4 && xmlhttp.status==200)
				{
						if(xmlhttp.responseText!="")
			 			{
							var div=document.getElementById(divId);
							div.innerHTML=xmlhttp.responseText;
			 			}
						else
							Chk=0;
				}
			}
			
			xmlhttp.send(null);
}
function AddInvRow()
 {
 	
	//var err=0;
			//alert(itemid);
			document.getElementById('addmoreinvid').style.display='inline';
			TR=mainTable.insertRow();
			//alert(TR.rowIndex);
			TD=TR.insertCell();
			TD.colSpan=6;
		 sHTML=
			  '<table width="100%" border="0" cellspacing="0" cellpadding="0" align=center>'+
					'<tr>'+
					  '<td><div align="center">'+
						  '<input name="stock1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="year1[]" type="text" size="15" maxlength="4">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="make1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="model1[]" type="text" size="15" maxlength="15">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input name="vin1[]" type="text" size="15" maxlength="5">'+
						'</div></td>'+
					  '<td><div align="center">'+
						  '<input type="file" name="invfilepath1[]">'+
						'</div></td>'+
					'</tr>'+
			  '</table>';
			  
		 
		
		TD.insertAdjacentHTML("afterBegin",sHTML);  
	
 }
function deleterecord(tr)
 {
	//alert(tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
	
	tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.deleteRow(tr.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
	   
 }
 function MakeEnable(formname,val)
 {
	 
	 if(val=='S')
	 {
	 	formname.dimension.disabled=true;
		formname.factor.disabled=true
		formname.source.disabled=false;

	 }
	 if(val=='D')
	 {
		formname.source.disabled=true;
		formname.factor.disabled=true;
	 	formname.dimension.disabled=false;
	 }
	 
	 if(val=='F')
	 {
		formname.dimension.disabled=true;
		formname.source.disabled=true;
		formname.factor.disabled=false;
	 }
	 	
 }
function ShowSlider(val,func,vals)
{
	

	var A_TPL = {
		'b_vertical' : false,
		'b_watch': true,
		'n_controlWidth': 120,
		'n_controlHeight': 16,
		'n_sliderWidth': 16,
		'n_sliderHeight': 15,
		'n_pathLeft' : 1,
		'n_pathTop' : 1,
		'n_pathLength' : 103,
		's_imgControl': 'images/blueh_bg.gif',
		's_imgSlider': 'images/blueh_sl.gif',
		's_imgMin': 'images/blueh_bg_min.gif',
		's_imgMax': 'images/blueh_bg_max.gif',
		'n_zIndex': 1
	}

	var A_INIT1 = {
		's_form' : 0,
		's_name': val,
		'n_minValue' : 0,
		'n_maxValue' : 99,
		'n_value' : 20,
		'n_step' : 1
	}
	return new slider(A_INIT1, A_TPL,func,vals);
		
}
function metchPassword(renew,newpass)
{
	if(renew.value!=newpass.value && renew.value!='')
	{
		alert("Re-enterd new password does not match with new password. ");
		
		if(renew.value!='')
		{
			renew.value='';	
			document.updateprofile.renewpass.focus();
		}
		return false;
	}
	return true;
}
function SelectRestrict(obj,countries,str)
{
	
	
	document.getElementById('countriesCount').innerHTML=val+" "+str+" selected";
	document.getElementById('graphCount').innerHTML=parseInt(res)+" Graph";
}
function checkAllData(formObj)
{
	var err=0;
	var mes='';
	if(formObj.analysis[0].checked)
	{
		var len=formObj.source.options.length;
		var sel=0;
		var selec=0;
		for(i=0;i<len;i++)
		{
			
			if(formObj.source.options[i].selected==true)
			{
				
				sel++;	
			}
		}
		
		if(sel==0)
		{
			err=1;
			mes+="Please select atleast one source.\n";
		}
		
	}
	else 
	{
		if((formObj.analysis[1].checked && formObj.dimension.disabled) )
		{
				err=1;
				
				mes+="Please select source.\n";
		}else
		{
			if(formObj.analysis[2].checked && formObj.factor.disabled)
			{
				err=1;
				mes+="Please select source.\n";
			}
		}
				
	}
	var len=formObj.countries.options.length;
	var sel=0;
	var selec=0;
	for(i=0;i<len;i++)
	{
		
		if(formObj.countries.options[i].selected==true)
		{
			
			sel++;	
		}
	}
	
	if(sel==0)
	{
		err=1;
		mes+="Please select atleast one country.\n";
	}
	
	if(!formObj.graphshow.checked && !formObj.graphshow.checked)
	{
		err=1;
		mes+="Please select atleast one medium to show analysis.\n";
	}
	
	if(err==1)
	{
		alert(mes);	
	}
	else
	{
		formObj.graphgeration.value=1;
		formObj.submit();
	}
	
}
function setStep(frmObj,val)
{
		frmObj.gotopage.value=val;
		frmObj.submit();
}
function countSelectedItems(frmObj,obj,name)
{
	
	
	var len=obj.options.length;
	var sel=0;
	var selec=0;
	
	for(i=0;i<len;i++)
	{
		
		if(obj.options[i].selected==true)
		{
			
			sel++;	
		}
	}
	document.getElementById('countriesCount').innerHTML=sel+ " " + name + " selected";
}
function doWithSelectbox(frmObj,obj,name,val)
{
	var sel=0;
	var len=obj.options.length;
	for(i=0;i<len;i++)
	{
		obj.options[i].selected=val;
		sel++
	}
	
	
	if(val)
		document.getElementById('countriesCount').innerHTML=sel+ " " + name + " selected";
	else
		document.getElementById('countriesCount').innerHTML="0  " + name + " selected";
}
function ChangeWeights(val)
{
		if(val==true)
		{
			document.getElementById('weighted1').disabled=false;
			document.getElementById('weighted2').disabled=false;			
			
		}
		else
		{
			document.getElementById('weighted1').disabled=true;
			document.getElementById('weighted2').disabled=true;
			
		}

}
function confirmSubmit()
{
if(!confirm('Do you really want to start from beginning.'))
{
return false;
}
}

function checkGraphsCases(paraName,count,path,type,totalParameteres)
{
	if(paraName!='other')
	{
			var graphError="";
			
			var maxNoParameter=40;
			var maxNoGraphs=30;
			var maxNoCountrisPerGraph=20;
			
			if(totalParameteres>maxNoParameter)
			{
					
				var noOfGraphPerCountry=Math.ceil(totalParameteres/maxNoParameter);
				
				var totalGraphs= count * noOfGraphPerCountry;
				
				if(totalGraphs>maxNoGraphs)
				{
					if(totalParameteres>120)
					{
						var reduceCountries=6;	 //max number of countries that can be selected for selected parameter
					}
					else if (totalParameteres>80)
					{
						var reduceCountries=10;	//max number of countries that can be selected for selected parameter
					}
					else
					{
						var reduceCountries=15;
					}
					
					var reduceParameter= Math.floor (maxNoParameter/Math.ceil(count/maxNoGraphs))  ; //max number of parameter that can be selected for selected countries
						
					graphError="You have selected to analyse " + totalParameteres + " " + paraName + " of " + count + " countries. Due to the limitations of the graphing back-end, we are unable to fulfill your request. Please go back to reset options. You can reduce either number of the countries to " + reduceCountries + " or number of the "+ paraName +" to "+ reduceParameter +".";
				}
			}
			else
			{
				if(totalParameteres<=maxNoParameter && totalParameteres>1)
				{
					var noOfCountryPerGraph=Math.floor(maxNoParameter/totalParameteres);
					var totalGraphs =  Math.ceil(count / noOfCountryPerGraph);
					
					if(totalGraphs>maxNoGraphs)
					{
						
						var reduceCountries=maxNoGraphs * Math.floor(maxNoParameter/totalParameteres);	//max number of countries that can be selected for selected parameter
										
						var reduceParameter= Math.floor (maxNoParameter/Math.ceil(count/maxNoGraphs))  ; //max number of parameter that can be selected for selected countries
						graphError="You have selected to analyse " + totalParameteres + " " + paraName + " of " + count + " countries. Due to the limitations of the graphing back-end, we are unable to fulfill your request. Please go back to reset options. You can reduce either number of the countries to " + reduceCountries + " or number of the "+ paraName +" to "+ reduceParameter +".";
					}
				}
				else
				{	
					var totalGraphs =  Math.ceil(count / maxNoCountrisPerGraph);
					
					if(totalGraphs>maxNoGraphs)
					{
						graphError="Sorry, backend graph generator is enable to show you the graph with selected parameters.";
					}
				}	
			}
			
			if(graphError=="")
			{
				if(type=='graph')
						window.open(path ,'_blank','width=1040,height=1200,status=no,menubar=no,location=no,resizable=no,titlebar=no,scrollbars=yes');	
				else
					location.href=path ;
			}
			else
			{
				alert(graphError);
			}
	}
	else
	{				if(type=='graph')
						window.open(path ,'_blank','width=1040,height=1200,status=no,menubar=no,location=no,resizable=no,titlebar=no,scrollbars=yes');	
					else
						location.href=path ;
	}	
}
function otherRegion(val)
{
	if(val=='other')
	{
		document.getElementById('regionName').disabled=false;		
	}
	else
	{
		document.getElementById('regionName').disabled=true;				
	}
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
{
	obj.value=obj.value.substring(0,mlength);
	alert("you can not enter more then "+ mlength +" characters");
}
}
function addSrcToCountryList(allC) 
{
	
	destList1 = window.document.forms[0].countries;
	srcList = window.document.forms[0].allcountries;
	
	if(allC==true)
		allSelect(srcList);
	
	var len = destList1.length;
	var length=srcList.length;
	for(var i = (length-1); i >=0 ; i--)
	{
		if ((srcList.options[i] != null) && (srcList.options[i].selected))
		{
			//Check if this value already exist in the destList or not
			//if not then add it otherwise do not add it.
			
			destList1.options[destList1.length] = new Option(srcList.options[i].text);
			destList1.options[(destList1.length-1)].value=srcList.options[i].value;
			destList1.options[(destList1.length-1)].ondblclick = deleteFromCountryList;
			srcList.options[i]=null;
			len++;
		}
	}
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Country(s) selected';
}
function deleteFromCountryList(allC)
{
	
	var destList1 = window.document.forms[0].countries;
	srcList = window.document.forms[0].allcountries;
	if(allC==true)
		allSelect(destList1);
	var len = destList1.options.length;
	for(var i = (len-1); i >= 0; i--)
	{
		if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) 
		{
			srcList.options[srcList.length] = new Option(destList1.options[i].text);
			srcList.options[(srcList.length-1)].ondblclick = addSrcToCountryList;
			srcList.options[(srcList.length-1)].value = destList1.options[i].value;
			destList1.options[i] = null;
		}
	}
	sortlist(srcList)
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Country(s) selected';
}
function addSrcToSourceList(allC) 
{
	
	destList1 = window.document.forms[0].sources;
	srcList = window.document.forms[0].allsources;
	
	if(allC==true)
		allSelect(srcList);
	
	var len = destList1.length;
	var length=srcList.length;
	for(var i = (length-1); i >=0 ; i--)
	{
		if ((srcList.options[i] != null) && (srcList.options[i].selected))
		{
			
			destList1.options[destList1.length] = new Option(srcList.options[i].text);
			destList1.options[(destList1.length-1)].value=srcList.options[i].value;
			destList1.options[(destList1.length-1)].ondblclick = deleteFromSourceList;
			srcList.options[i]=null;
			len++;
		}
	}
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Source(s) selected';
}
function deleteFromSourceList(allC)
{
	
	var destList1 = window.document.forms[0].sources;
	srcList = window.document.forms[0].allsources;
	if(allC==true)
		allSelect(destList1);
	var len = destList1.options.length;
	for(var i = (len-1); i >= 0; i--)
	{
		if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) 
		{
			srcList.options[srcList.length] = new Option(destList1.options[i].text);
			srcList.options[(srcList.length-1)].ondblclick = addSrcToSourceList;
			srcList.options[(srcList.length-1)].value = destList1.options[i].value;
			destList1.options[i] = null;
		}
	}
	sortlist(srcList)
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Source(s) selected';
}
function addSrcToDimensionList(allC) 
{
	
	destList1 = window.document.forms[0].dimension;
	srcList = window.document.forms[0].alldimension;
	
	if(allC==true)
		allSelect(srcList);
	
	var len = destList1.length;
	var length=srcList.length;
	for(var i = (length-1); i >=0 ; i--)
	{
		if ((srcList.options[i] != null) && (srcList.options[i].selected))
		{
			destList1.options[destList1.length] = new Option(srcList.options[i].text);
			destList1.options[(destList1.length-1)].value=srcList.options[i].value;
			destList1.options[(destList1.length-1)].ondblclick = deleteFromDimensionList;
			srcList.options[i]=null;
			len++;
		}
	}
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Dimension(s) selected';
}
function deleteFromDimensionList(allC)
{
	
	var destList1 = window.document.forms[0].dimension;
	srcList = window.document.forms[0].alldimension;
	if(allC==true)
		allSelect(destList1);
	var len = destList1.options.length;
	for(var i = (len-1); i >= 0; i--)
	{
		if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) 
		{
			srcList.options[srcList.length] = new Option(destList1.options[i].text);
			srcList.options[(srcList.length-1)].ondblclick = addSrcToDimensionList;
			srcList.options[(srcList.length-1)].value = destList1.options[i].value;
			destList1.options[i] = null;
		}
	}
	sortlist(srcList)
	document.getElementById('countriesCount').innerHTML=destList1.length + ' Dimension(s) selected';
}
function sortlist(lb)
{

	arrTexts = new Array();
	arrValues = new Array();
	arrOldTexts = new Array();
	
	for(i=0; i<lb.length; i++)
	{
		arrTexts[i] = lb.options[i].text;
		arrValues[i] = lb.options[i].value;
		
		arrOldTexts[i] = lb.options[i].text;
	}
	
	arrTexts.sort();
	
	for(i=0; i<lb.length; i++)
	{
		lb.options[i].text = arrTexts[i];
		for(j=0; j<lb.length; j++)
		{
			if (arrTexts[i] == arrOldTexts[j])
			{
				lb.options[i].value = arrValues[j];
				j = lb.length;
			}
		}
	}
}
function allSelect(List)
{

	
	if (List.length && List.options[0].value == 'temp') return;
	for (var i=0;i<List.length;i++)
	{
		List.options[i].selected = true;
	}
}
function testFun(countryID)
{
	
	testExplode(this,'explode2');
	var dis=document.getElementById('explode2');
	
	dis.style.left = event.clientX + document.body.scrollLeft
  	dis.style.top =  event.clientY +document.body.scrollTop
	//dis.scrollLeft=document.body.scrollLeft;
	
	xajax_BandingChart(countryID);
	
}
function createToolTipSta(val,value)
{
			
		new Tip(val, value ,{  offset: {x:6, y:6} });
		
		
}

//function NewByNiteen(){ alert(this.name) ;f_sliderMouseDown( this.name ,'min'); document.write=""; }
function slider (a_init, a_tpl,func,vals) {

	this.f_setValue  = f_sliderSetValue;
	this.f_getPos    = f_sliderGetPos;
	
	var first=false;		
	// register in the global collection	
	if (!window.A_SLIDERS)
	{
		window.A_SLIDERS = [];
		var first=true;
	}
	this.n_id = window.A_SLIDERS.length;
	window.A_SLIDERS[this.n_id] = this;
	window.A_SLIDERS[this.n_id + 'callingFunc'] = func ;
		window.A_SLIDERS[this.n_id + 'callingFuncValues'] = vals ;

	/*if(first)
	{
		document.getElementById("onsources").name= this.n_id;
		document.getElementById("onsources").onmousedown=NewByNiteen;
	}*/
	// save config parameters in the slider object
	var s_key;
	if (a_tpl)
		for (s_key in a_tpl)
			this[s_key] = a_tpl[s_key];
	for (s_key in a_init)
		this[s_key] = a_init[s_key];

	this.n_pix2value = this.n_pathLength / (this.n_maxValue - this.n_minValue);
	if (this.n_value == null)
		this.n_value = this.n_minValue;

	document.write(
		'<table><tr><td><img src="' + this.s_imgMin + '" border="0" onmousedown="return f_sliderMouseDown(' + this.n_id + ',\'min\')" /></td><td><div  style="width:' + this.n_controlWidth + 'px;height:' + this.n_controlHeight + 'px;border:0; background-image:url(' + this.s_imgControl + ')" id="sl' + this.n_id + 'base">' +
		'<img src="' + this.s_imgSlider + '" width="' + this.n_sliderWidth + '"l height="' + this.n_sliderHeight + '" border="0" style="position:relative;left:' + this.n_pathLeft + 'px;top:' + this.n_pathTop + 'px;z-index:' + this.n_zIndex + ';cursor:hand;visibility:hidden;" name="sl' + this.n_id + 'slider" id="sl' + this.n_id + 'slider" onmousedown="return f_sliderMouseDown(' + this.n_id + ',\'nill\')"/>'+
		'</div></td><td><img src="' + this.s_imgMax + '" border="0" onmousedown="return f_sliderMouseDown(' + this.n_id + ',\'max\')" /></td></tr></table>'
	);
	
	
	this.e_base   = get_element('sl' + this.n_id + 'base');
	this.e_slider = get_element('sl' + this.n_id + 'slider');
	
	if (document.onmousemove != f_sliderMouseMove) {
		window.f_savedMouseMove = document.onmousemove;
		document.onmousemove = f_sliderMouseMove;
		
	}
	if (document.onmouseup != f_sliderMouseUp) {
		window.f_savedMouseUp = document.onmouseup;
		document.onmouseup = f_sliderMouseUp;
			
	}
	var e_input = this.s_form == null
		? get_element(this.s_name)
		: document.forms[this.s_form]
			? document.forms[this.s_form].elements[this.s_name]
			: null;
	this.f_setValue(e_input && e_input.value != '' ? e_input.value : null, 1);
	this.e_slider.style.visibility = 'visible';
}

function f_sliderSetValue (n_value, b_noInputCheck) {
	if(window.actionDone)
	{
		if(window.actionDone=='max')
			n_value= this.n_maxValue;
		if(window.actionDone=='min')
			n_value=this.n_minValue;	
	}
		
	if (n_value == null)
		n_value = this.n_value == null ? this.n_minValue : this.n_value;
	if (isNaN(n_value))
		return false;
	if (this.n_step)
		n_value = Math.round((n_value - this.n_minValue) / this.n_step) * this.n_step + this.n_minValue;
	if (n_value % 1)
		n_value = Math.round(n_value * 1e5) / 1e5;

	if (n_value < this.n_minValue)
		n_value = this.n_minValue;
	if (n_value > this.n_maxValue)
		n_value = this.n_maxValue;

	this.n_value = n_value;

	if (this.b_vertical)
		this.e_slider.style.top  = (this.n_pathTop + this.n_pathLength - Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';
	else
		this.e_slider.style.left = (this.n_pathLeft + Math.round((n_value - this.n_minValue) * this.n_pix2value)) + 'px';

	var e_input;
	if (this.s_form == null) {
		e_input = get_element(this.s_name);
		if (!e_input)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the input with ID='" + this.s_name + "'.");
	}
	else {
		var e_form = document.forms[this.s_form];
		if (!e_form)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the form with NAME='" + this.s_form + "'.");
		e_input = e_form.elements[this.s_name];
		if (!e_input)
			return b_noInputCheck ? null : f_sliderError(this.n_id, "Can not find the input with NAME='" + this.s_name + "'.");
	}
	
	e_input.value = n_value;
}



function f_sliderGetPos (b_vertical, b_base) {
	var n_pos = 0,
		s_coord = (b_vertical ? 'Top' : 'Left');
	var o_elem = o_elem2 = b_base ? this.e_base : this.e_slider;
	
	while (o_elem) {
		n_pos += o_elem["offset" + s_coord];
		o_elem = o_elem.offsetParent;
	}
	o_elem = o_elem2;

	var n_offset;
	while (o_elem.tagName != "BODY") {
		n_offset = o_elem["scroll" + s_coord];
		if (n_offset)
			n_pos -= o_elem["scroll" + s_coord];
		o_elem = o_elem.parentNode;
	}
	return n_pos;
}

function f_sliderMouseDown (n_id,val) {
	window.n_activeSliderId = n_id;
	window.actionDone= val;
	return false;
}

function f_sliderMouseUp (e_event, b_watching) {
	
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];
		o_slider.f_setValue(o_slider.n_minValue + (o_slider.b_vertical
			? (o_slider.n_pathLength - parseInt(o_slider.e_slider.style.top) + o_slider.n_pathTop)
			: (parseInt(o_slider.e_slider.style.left) - o_slider.n_pathLeft)) / o_slider.n_pix2value);
		if (b_watching)	return;
		
	
		window.eval(window.A_SLIDERS[window.n_activeSliderId + 'callingFunc'] + '(' + window.A_SLIDERS[window.n_activeSliderId + 'callingFuncValues'] + ')');
		 
		
		//window.eval(window.A_SLIDERS[window.n_activeSliderId + 'callingFunc'] + '(' + window.A_SLIDERS[window.n_activeSliderId + 'callingFuncValues'] + ')');*/
		
		window.n_activeSliderId = null;
	}
	if (window.f_savedMouseUp)
	{
			
		return window.f_savedMouseUp(e_event);
	}
}

function f_sliderMouseMove (e_event) {

	if (!e_event && window.event) e_event = window.event;
	if (e_event) {
		window.n_mouseX = e_event.clientX + f_scrollLeft();
		window.n_mouseY = e_event.clientY + f_scrollTop();
	}
	if (window.n_activeSliderId != null) {
		var o_slider = window.A_SLIDERS[window.n_activeSliderId];

		var n_pxOffset;
		if (o_slider.b_vertical) {
			var n_sliderTop = window.n_mouseY - o_slider.n_sliderHeight / 2 - o_slider.f_getPos(1, 1) - 3;
			// limit the slider movement
			if (n_sliderTop < o_slider.n_pathTop)
				n_sliderTop = o_slider.n_pathTop;
			var n_pxMax = o_slider.n_pathTop + o_slider.n_pathLength;
			if (n_sliderTop > n_pxMax)
				n_sliderTop = n_pxMax;
			o_slider.e_slider.style.top = n_sliderTop + 'px';
			n_pxOffset = o_slider.n_pathLength - n_sliderTop + o_slider.n_pathTop;
		}
		else {
			var n_sliderLeft = window.n_mouseX - o_slider.n_sliderWidth / 2 - o_slider.f_getPos(0, 1) - 3;
			// limit the slider movement
			if (n_sliderLeft < o_slider.n_pathLeft)
				n_sliderLeft = o_slider.n_pathLeft;
			var n_pxMax = o_slider.n_pathLeft + o_slider.n_pathLength;
			if (n_sliderLeft > n_pxMax)
				n_sliderLeft = n_pxMax;
			o_slider.e_slider.style.left = n_sliderLeft + 'px';
			n_pxOffset = n_sliderLeft - o_slider.n_pathLeft;
		}
		if (o_slider.b_watch)
			 f_sliderMouseUp(e_event, 1);

		return false;
	}
	
	if (window.f_savedMouseMove)
		return window.f_savedMouseMove(e_event);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_sliderError (n_id, s_message) {
	alert("Slider #" + n_id + " Error:\n" + s_message);
	window.n_activeSliderId = null;
}

get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };


//function that checks whether a number is non-negative
function isNotNegNum(s) {
   return (parseFloat(s) >= 0);
}
function weight_check(item, min, max, num, type, val) {
   var returnVal = false;
   var weightNum = num + 1;
   var alertString;
   if (!isNotNegNum(item.value)) {
      alertString =  "Please enter a non-negative weight for " + type + weightNum;
      alert(alertString);
      item.value = val;
   }
   else if (parseFloat(item.value) < min) {
      alertString = "Please enter a weight greater than " + min + " for " + type + weightNum;
      alert(alertString);
      item.value = val;
   }
   else if (parseFloat(item.value) > max) {
      alertString = "Please enter a weight less than or equal to " + max + " for " + type + weightNum;
      alert(alertString);
      item.value = val;
   }
   else {
      returnVal = true;
   }
   return returnVal;
}
function getElementName(n){
  var numResult = n.match(/\d+/);
  var nameResult = n.match(/\D+/);
  var userNum = parseInt(numResult) + 1;
  var userName = nameResult[0] + userNum;
  return userName;
}
function checkUpdateWeight(e, min, max, currentValue, anchor, admin){
  var changedWeight = "";
  var error = "";
  var alertString = "";
  if(e.type == "text"){
    if ((e.value == null) || (e.value == "")){
      error = "Please enter a non-negative weight for " +  getElementName(e.name)  + ".\n";
    }
    else if (!isFinite(e.value)){
       error = "Please enter a non-negative weight for " +  getElementName(e.name)  + ".\n";
    }
    else if (!isNotNegNum(e.value)) {
      error = "Please enter a non-negative weight for " +  getElementName(e.name)  + ".\n";
    }
    else if (parseFloat(e.value) < min) {
      error = "Please enter a weight greater than " + min + " for " + getElementName(e.name) + ".\n"; //type + weightNum;
    }
    else if (parseFloat(e.value) > max) {
      error = "Please enter a weight less than or equal to " + max + " for " + getElementName(e.name) + ".\n"; //type + weightNum;
    }
    else{
      changedWeight = "&" + e.name + "=" + e.value;
    }
   
   if(!error) {
    if(admin == 0){
      window.open('selectWeights.php?weightChanged=1' + changedWeight + anchor,'_self');
    }
    else{
      window.open('setDefaultWeights.php?weightChanged=1' + changedWeight + anchor,'_self');
    }
    return true;
   }
   else{
     alert(error);
     e.value = currentValue;
     e.focus();
     return false;
   }
 }
 else{

  alertString += 'checkUpdateWeight: this script can only be attached to a text input.';
  alertString += e.name + ' is a ' + e.type;
  alert(alertString);
 }
}
function checkWeightsSetNameForm(f){
  var illegalChars = /\W/;
  
  if (f.weightsSetName.value == "") {
    alert("Please enter a name for the custom weights set\n");
    f.weightsSetName.focus();
    return false;
  }

  else if (illegalChars.test(f.weightsSetName.value)) {
      alert("Please enter a name for the custom weights that only consists of letters, numbers and underscores\n");
      f.weightsSetName.value = "";
      f.weightsSetName.focus();
      return false;
    }
  else{
   return true;
  }
}
function filterApply(val)
{
	var formname=document.filterForm;
	
	if(val=='sources')
	{
		formname.sourcesOpr.disabled=false;
		formname.sources.disabled=false;
		formname.masterIndexOpr.disabled=true;
		formname.masterIndex.disabled=true;
		formname.ranking.disabled=true;
		formname.rankingOpr.disabled=true;
		formname.countries.disabled=true;
	}
	else
	{
			
		if(val=='ranking')
		{
				formname.sourcesOpr.disabled=true;
				formname.sources.disabled=true;
				formname.masterIndexOpr.disabled=true;
				formname.masterIndex.disabled=true;
				formname.ranking.disabled=false;
				formname.rankingOpr.disabled=false;
				formname.countries.disabled=true;
		}
		else
		{
			if(val=='masterIndex')
			{
				formname.sourcesOpr.disabled=true;
				formname.sources.disabled=true;
				formname.masterIndexOpr.disabled=false;
				formname.masterIndex.disabled=false;
				formname.ranking.disabled=true;
				formname.rankingOpr.disabled=true;
				formname.countries.disabled=true;
			}
			else
			{
				formname.sourcesOpr.disabled=true;
				formname.sources.disabled=true;
				formname.masterIndexOpr.disabled=true;
				formname.masterIndex.disabled=true;
				formname.ranking.disabled=true;
				formname.rankingOpr.disabled=true;
				formname.countries.disabled=false;
			}
		}	
	}
}


function ExpandCollepsParameters(parameter,id,len,sourceCount)
{
	if(parameter=='dimension')
	{
		
		
		for(var i=0;i<len;i++)
		{
			var val='';
			if(document.getElementById('dimension'+id+i).style.display=='')
			{
				document.getElementById('dimension'+id+i).style.display='none';					
				val='none';
			}
			else
			{
				document.getElementById('dimension'+id+i).style.display='';	
			}
			
		}
		
		if(val=='none')
			{
				for(var j=0;j<sourceCount;j++)
				{
					if(document.getElementById('source'+id+j))
					{
						document.getElementById('source'+id+j).style.display=val;		
					}
				}
			}
	}
	else
	{
		if(parameter=='source')
		{
			for(var i=sourceCount;i<(len+sourceCount);i++)
			{
				if(document.getElementById('source'+id+i).style.display=='')
				{
					document.getElementById('source'+id+i).style.display='none';					
				}
				else
				{
					document.getElementById('source'+id+i).style.display='';	
				}
			}
		}
	}
}

function expandCollapsAllFacDimSour(val)
{
	var factor=0;
	var factNum=Array();
	for(var i=1; i<arguments.length; i++)
    {
        
		factNum[i]=arguments[i];
		factor++;
    }
	
	
	for(var i=1 ; i <=factor ; i++)
	{
		for(var j=0;  ; j++)
		{
				
				
				if(document.getElementById('dimension'+factNum[i]+j))
				{
						document.getElementById('dimension'+factNum[i]+j).style.display=val;		
				}
				else
				{
					break;	
				}
		}		
	}
	
	for(var i=1 ; i <=factor ; i++)
	{
		for(var k=0; ; k++)
		{
			if(document.getElementById('source'+factNum[i]+k))
			{
				document.getElementById('source'+factNum[i]+k).style.display=val;		
			}
			else
			{
				break;	
			}
		}
	}
}


function setOrderField(action,title)
{
	
	document.frmfieldOrder.actionType.value=action;
	document.frmfieldOrder.actionOn.value=title;
	document.frmfieldOrder.submit();
}