function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString; var ch = retValue.substring(0, 1);
   while (ch == " ") { retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { retValue = retValue.substring(0, retValue.length-1); ch = retValue.substring(retValue.length-1, retValue.length); }
   while (retValue.indexOf("  ") != -1) { retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); }
   return retValue;
}

function isEmail (s){
	if (isEmpty(s)) 
	if (isEmail.arguments.length == 1){ return false; } else { return (isEmail.arguments[1] == true); }
	if (isWhitespace(s)) { return false; }
	var i = 1; var sLength = s.length;
	while ((i < sLength) && (s.charAt(i) != "@")){ i++; }
	if ((i >= sLength) || (s.charAt(i) != "@")){ return false; } else { i += 2; }
	while ((i < sLength) && (s.charAt(i) != ".")){ i++; }
	if ((i >= sLength - 1) || (s.charAt(i) != ".")){ return false; } else { return true; }
}
var whitespace = " \t\n\r";
function isWhitespace (s){ var i; if (isEmpty(s)) return true; for (i = 0; i < s.length; i++){   var c = s.charAt(i); if (whitespace.indexOf(c) == -1){ return false; } } return true; }
function isEmpty(s){   return ((s == null) || (s.length == 0)); }
function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}

//----------------------------------------------------------------------------------------------------------
// myDate Object
var Months="January,February,March,April,May,June,July,August,September,October,November,December".split(",");
var Days  ="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(",");
var nums  ="01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31".split(",");
var EOM1  = "31,29,31,30,31,30,31,31,30,31,30,31".split(",");
var EOM2  = "31,28,31,30,31,30,31,31,30,31,30,31".split(",");
// Methods for myDate()
function setValues(d){
	this.day=this.d.getDate();
	this.dOW=this.d.getDay();
		this.Day=Days[this.dOW].substr(0,3);
		this.DayName=Days[this.dOW];
	this.month=this.d.getMonth()+1;
		this.Mon=Months[this.month-1].substr(0,3);
		this.Month=Months[this.month-1];
	this.year =this.d.getFullYear();
	this.yearmonth=this.year+nums[this.month-1];
	this.date=this.year+"-"+nums[this.month-1]+"-"+nums[this.day-1];
	this.isLeap=(this.year%4==0)?true:false;
	this.endOfMonth=(this.isLeap)?EOM1[this.month-1]:EOM2[this.month-1];
	d=0; for(i=1; i<this.month; i++){ d=d+eval((this.isLeap)?EOM1[i-1]:EOM2[i-1]); }
	this.dayOfYear=d+this.day;
	this.value=this.year+nums[this.month-1]+nums[this.day];
}
function add(v1, v2){
	switch (v1){
	case "D": this.d = new Date(this.year, this.month-1, eval(this.day+"+"+v2)); break;
	case "W": this.d = new Date(this.year, this.month-1, eval(this.day+"+"+v2+"*7")); break;
	case "M": this.d = new Date(this.year, eval(this.month-1+"+"+v2), this.day); break;
	case "Q": this.add("M", eval(v2+"*3")); break;
	case "H": this.add("M", eval(v2+"*6")); break;
	case "Y": this.add("M", eval(v2+"*12")); break;	} this.setValues();
}
function goStartOf(v1, v2){
	switch (v1){
	case "W": this.add("D", eval("-"+this.dOW+"+1"));	break;
	case "M": this.d = new Date(this.year, this.month-1, 1); break;
	case "Q": this.d = new Date(this.year, this.month-(this.month%3)-1, 1); break;
	case "H": this.d = new Date(this.year, this.month-(this.month%6)-1, 1); break;
	case "Y": this.d = new Date(eval(this.year+"+"+v2), 1-1, 1); break;	} this.setValues();
}
function goEndOf(v1){
//	switch (v1){
//	case "W": this.d = new Date(this.year, this.month-1, eval(this.day+"+"+v2)); break;
//	case "M": this.d = new Date(this.year, this.month-1, (this.isLeap)?EOM1[this.month-1]:EOM2[this.month-1]); break;
//	case "Q": m=(this.month%3==0)?this.month:this.month+(3-this.month%3) this.d = new Date(this.year, m-1, 1); this.setValues(); this.d = new Date(this.year, this.month-1, (this.isLeap)?EOM1[this.month-1]:EOM2[this.month-1]); break;
//	case "H": this.add("M", eval(v2+"*6")); break;
//	case "Y": this.d = new Date(this.year, 12-1, 31); break;	} this.setValues();
}
function getPeriodOf(v1, v2){
	switch (v1){
	case "W": d=this.Mon+" "+this.day+" to "; this.add("D", 5); d=d+this.Mon+" "+this.day+" "+this.year; this.add("D", -5); break;
	case "M": e=(this.isLeap)?EOM1[this.month-1]:EOM2[this.month-1]; d=this.Mon+" 1 to "+this.Mon+" "+e+" "+this.year; break;
	case "Q": d= this.month; if(d>=1  && d<=3) { d="Jan 1 to Mar 31 "; } if(d>=4  && d<=6) { d="Apr 1 to Jun 30 "; } if(d>=7  && d<=9) { d="Jul 1 to Sep 30 "; } if(d>=10 && d<=12){ d="Oct 1 to Dec 31 "; } d +=this.year;
	break;
	case "H": d=(this.month>=1  && this.month<=6)?"January 1 to June 30 ":"July 1 to December 31 "; d +=this.year; break;
	case "Y": d="January 1 to December 31 "+this.year; break; }
	return d;
}
function getEndDate(v1){
	switch (v1){
//	case "W": d=this.Mon+" "+this.day+" to "; this.add("D", 5); d=d+this.Mon+" "+this.day+" "+this.year; this.add("D", -5); break;
	case "M": e=(this.isLeap)?EOM1[this.month-1]:EOM2[this.month-1]; d = this.year+"-"+nums[this.month-1]+"-"+e; break;
	case "Q": e=(this.month%3==0)?this.month:this.month+(3-this.month%3); f=(this.isLeap)?EOM1[e-1]:EOM2[e-1]; d=this.year+"-"+nums[e-1]+"-"+f; break;
	case "H": e=(this.month%6==0)?this.month:this.month+(6-this.month%6); f=(this.isLeap)?EOM1[e-1]:EOM2[e-1]; d=this.year+"-"+nums[e-1]+"-"+f; break;
	case "Y": d = this.year+"-12-31"; break; }
	return d;
}
// myDate object constructor
function myDate(y, m, d){ this.d= new Date(y, m-1, d); this.setValues=setValues; this.setValues(); this.add=add; this.goStartOf=goStartOf; this.goEndOf=goEndOf; this.getPeriodOf=getPeriodOf; this.getEndDate=getEndDate; }
//a= new myDate(2003, 3,1);
//
//-----------------------------------------------------------------------------------------------------
//
// adding day options into dd drop down
function addDays(v1){ for(i=1; i<=31; i++){ v1[i-1]=new Option(nums[i-1], nums[i-1], false, false); } v1[curDate.substr(8,2)-1].selected=true; }
// day and month selection validation
function dateValidate(v1){
	v2 = v1.yyyymm;
	vy=v2.options[v2.selectedIndex].value.substr(0, 4);
	vm=v2.options[v2.selectedIndex].value.substr(5, 2);
	vd=v1.dd.options[v1.dd.selectedIndex].value;
	if(!isDate(vy, vm, vd)) { alert("Selected Day is not valid for selected Month"); return false; }
	if((vy+"a"+vm+"a"+vd).replace(/a/g, "")<minDate.replace(/-/g, "") || (vy+"a"+vm+"a"+vd).replace(/a/g, "")>maxDate.replace(/-/g, "")) { alert("Day is available from "+minDate+" to "+maxDate); return false; }
	document.getit.currDate.value=v2.options[v2.selectedIndex].value+"-"+v1.dd.options[v1.dd.selectedIndex].value;
}
//-------------
function url1(v){ 
	document.getit.currPageType.value="D"; 
	document.getit.currSector.value=document.date.sector.options[document.date.sector.options.selectedIndex].value; 
	document.getit.currExchange.value=document.date.exchange.value;
//	document.getit.currExchange.value=document.date.exchange.options[document.date.exchange.options.selectedIndex].value; 
	document.getit.submit();}
function url2(v){ document.getit.currSector.value=v; document.getit.submit(); }
//-------------
function termValidate(v1){
	document.forms["getit"].currPageType.value=v1.type.options[v1.type.selectedIndex].value;
	document.forms["getit"].currSector.value = v1.sector.options[v1.sector.selectedIndex].value;
	document.forms["getit"].currDate.value=v1.list.options[v1.list.selectedIndex].value;
	document.forms["getit"].submit();
	//url2(document.getit.currSector.value);
}
// year and monthls option for daily data  select object, starting date, ending date
function addyyyymm(v1){
	for(i=maxDate.substr(0,4); i>=minDate.substr(0,4); i--){
	if(minDate.substr(0,4)==i){ st=eval(minDate.substr(5,2)); } else {st=1;}
	if(maxDate.substr(0,4)==i){ ed=eval(maxDate.substr(5,2)); } else {ed=12;}
		for(j=ed; j>=st; j--){ v1.options[v1.options.length] = new Option(i+" "+Months[j-1].substr(0,3), i+"-"+nums[j-1], false, false); }
	} addDays(document.date.dd.options);
	for(i=0; i<v1.options.length; i++){ if(curDate.substr(0,7)==v1.options[i].value){ v1.options[i].selected=true; i=v1.options.length; } }
}
// monthly term comparision options adding (term type "W, etc")
function selectTerm(v){ v=(v=="D")?"M":v; v1=document.term.type.options;
	for(i=0; i<document.term.type.length; i++){ if(v1[i].value==v){ v1[i].selected = true; } else {v1[i].selected = false; } }
}
function termList(v1){ v2 = v1.list.options; for(i=0; i<v2.length; i++){ v2[i] = null; i--; }
	v = v1.type.options[v1.type.selectedIndex].value;
	sD= new myDate(minDate.substr(0,4), minDate.substr(5,2), minDate.substr(8,2));
	eD= new myDate(mxD[v][0], mxD[v][1], mxD[v][2]);
	switch (v) {
	case "Y": while(sD.year<=eD.year         ) { v2[v2.length] = new Option(eD.getPeriodOf("Y"), eD.getEndDate("Y"), false, false); eD.add("Y", -1); } break;
	case "H": while(sD.yearmonth<eD.yearmonth) { v2[v2.length] = new Option(eD.getPeriodOf("H"), eD.getEndDate("H"), false, false); eD.add("H", -1); } break;
	case "Q": while(sD.yearmonth<eD.yearmonth) { v2[v2.length] = new Option(eD.getPeriodOf("Q"), eD.getEndDate("Q"), false, false); eD.add("Q", -1); } break;
	case "M": while(sD.yearmonth<=eD.yearmonth){ v2[v2.length] = new Option(eD.getPeriodOf("M"), eD.getEndDate("M"), false, false); eD.add("M", -1); } break;
	case "W": eD.goStartOf("W", 0); while(sD.value<eD.value){ v2[v2.length] = new Option(eD.getPeriodOf("W"), eD.date, false, false); eD.add("D", -7); } break;
	} selectColor(v2, '#CCCCCC');
}
//--------------------------------------
function selectColor(o, c){ for(i=1; i<o.length; i+=2){ o[i].style.backgroundColor=c; } }
function selectValue(o, v) { for(i=0; i<o.length; i++){ if(o[i].value==v){ o[i].selected=true; i=o.length; } } }
//--------------------------------------
// isDate (STRING year, STRING month, STRING day)
function isDate (y, m, d) {
	var iY = parseInt(y);	var iM = parseInt(m);	var iD = parseInt(d);
	if (iD > EOM1[iM-1]) return false;
	if ((iM == 2) && (iD > dIF(iY))) return false;
	return true;
}
// daysInFebruary (INTEGER year)
function dIF (y){ return (  ((y % 4 == 0) && ( (!(y % 100 == 0)) || (y % 400 == 0) ) ) ? 29 : 28 ); }
//----------------------------------------------
function bgL1(v1, v2){ v1.style.backgroundColor=(v2==1)?"#ffffff":document.body.style.backgroundColor; v1.style.fontWeight=(v2==1)?500:500; }
function trbg(v1, v2){ for(i=0; i<v1.childNodes.length; i++){ v1.childNodes.item(i).style.backgroundColor=(v2==1)?"#ffffff":document.body.style.backgroundColor; } }

function companyData(v2){
	while(sD.yearmonth<eD.yearmonth){ v2[v2.length] = new Option(eD.getPeriodOf("M"), eD.date, false, false); eD.add("M", -1); }
	for(i=0; i<v2.length; i++){ if(v2[i].text==cDate.getPeriodOf('M')){ v2.selectedIndex = i; } }
}

function callit(obj){
	o =this.toString();
	var r = "";	for (var i in obj) { r += o + i + " = " + obj[i] + "\n" ; }
	document.test.text.value=r;
	r="";
	v=document.body;
	for(i=0; v.length; i++){
		r=r+v[0]
	}
	alert(document.body['dd1']);
}

function showDays(v){
};

function appendBodyChild(id,style,html){
	var ni=document.getElementsByTagName("body")[0];
	var mainDiv = document.createElement('div');
  	mainDiv.setAttribute('id',id);
	mainDiv.setAttribute('style',style);
	mainDiv.innerHTML=html;
	mainDiv.style.display="block";
	mainDiv.style.visibility="visible";
	ni.appendChild(mainDiv);
}
function appendBodyScript(url){
	var ni=document.getElementsByTagName("body")[0];
	var obj = document.createElement('script');
  	obj.setAttribute('src',url);
	ni.appendChild(obj);
}

function owc(u){
	PopupWarning.init(u,700,440);
}
function closePop(pName){
	var p= document.getElementById(pName);
	p.innerHTML="";
	p.style.display="none;";
	p.style.visibility="hidden";
	var parent = document.getElementsByTagName("body")[0];
	parent.removeChild(p);
}

var PopupWarning = {
	go_url: "", width: 618, height:420,
	init : function(url,w,h)
	{
		this.width=w;
		this.height=h;
		this.go_url = url;
		this.load_popup();
	},
	load_popup: function(){
		var pop_name = 'popup_pop';
		s="<iframe name='"+pop_name+"frame' src='"+this.go_url+"' width='"+(this.width-20)+"' height='"+(this.height-20)+"'></iframe>";
		document.getElementById('pop_container').innerHTML=s;
		this.animate(pop_name);
		this.moveable(pop_name);
	},
	animate:function(popName){
		(function(){gk_popup(popName,PopupWarning.width,PopupWarning.height);}).delay(500);
	},
	moveable:function(popName){
		var dObj = DragHandler.attach(document.getElementById(popName));
	}
};

var DragHandler = {
    _oElem : null,
    attach : function(oElem) {
        oElem.onmousedown = DragHandler._dragBegin;
        oElem.dragBegin = new Function();
        oElem.drag = new Function();
        oElem.dragEnd = new Function();
        return oElem;
    },
    _dragBegin : function(e) {
        var oElem = DragHandler._oElem = this;
        if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
        if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }
        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);
        e = e ? e : window.event;
        oElem.mouseX = e.clientX;
        oElem.mouseY = e.clientY;
        oElem.dragBegin(oElem, x, y);
        document.onmousemove = DragHandler._drag;
        document.onmouseup = DragHandler._dragEnd;
        return false;
    },
    _drag : function(e) {
        var oElem = DragHandler._oElem;
        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);
        e = e ? e : window.event;
        oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
        oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
        oElem.mouseX = e.clientX;
        oElem.mouseY = e.clientY;
        oElem.drag(oElem, x, y);
        return false;
    },
    _dragEnd : function() {
        var oElem = DragHandler._oElem;
        var x = parseInt(oElem.style.left);
        var y = parseInt(oElem.style.top);
        oElem.dragEnd(oElem, x, y);
        document.onmousemove = null;
        document.onmouseup = null;
        DragHandler._oElem = null;
    }
}
