
var toShow=true; var toHide = false; var margins; margins = Array(0,0,20,120,165,220);
function showTopMenuItem(ch,e){
	document.getElementById("tmfldiv").style.display = 'block'; 
	for(i=2; i<=5;i++) { document.getElementById("tmfld"+i).style.display = 'none';	document.getElementById("tmlink"+i).className = ''; }
	document.getElementById("tmfdbox").style.marginLeft = margins[ch]+"px";
	document.getElementById("tmfld"+ch).style.display = 'block';
	Nifty("div#tmfld"+ch,"normal transparent");
	document.getElementById("tmlink"+ch).className = 'thover';
	toHide = false;
	hideTopMenuItem();
}
function hideTopMenuItem() {
	if(toHide==true)
	{
		document.getElementById("tmfldiv").style.display = 'none';
		for(i=2; i<=5;i++) { document.getElementById("tmfld"+i).style.display = 'none';	document.getElementById("tmlink"+i).className = ''; } return;		
	}
	else setTimeout("hideTopMenuItem()",500);
}
function holdTopMenu(){ toHide = false; }
function leaveTopMenu(){ toHide = true; }
function logMeIn(){
	hideSelectBoxes();
	document.getElementById("loginflier").style.visibility = "visible";document.getElementById("lftable").style.visibility = "visible";
	document.getElementById("logsgmid").value = ""; document.getElementById("logsgmpwd").value = ""; 
	document.getElementById("idicon").innerHTML = ""; document.getElementById("pwdicon").innerHTML = "";
	document.getElementById("idmsg").innerHTML = ""; document.getElementById("pwdmsg").innerHTML = "";
	document.body.style.overflow = "hidden";document.getElementById("logsgmid").focus();
}
function closeMe(){
	showSelectBoxes();
	document.getElementById("loginflier").style.visibility = "hidden";document.getElementById("lftable").style.visibility = "hidden";
	document.body.style.overflow = "visible";	
}
function catchKey(event,dual){ if (event.keyCode == 13) validateLogin(dual); }
function validateLogin(dual){
	document.getElementById("idicon").innerHTML = ""; document.getElementById("pwdicon").innerHTML = "";
	document.getElementById("idmsg").innerHTML = ""; document.getElementById("pwdmsg").innerHTML = "";
	
	if(document.getElementById("logsgmid").value=="")
	{
		document.getElementById("idicon").innerHTML = '<img src="'+document.getElementById("logroot").value+'/resources/images/icons/alert.gif" alt="Invalid Data" title="Invalid Data" />';		
		document.getElementById("idmsg").innerHTML = "<font class=\"error\">Enter&nbsp;Login-Id</font>";
		document.getElementById("logsgmid").focus();return false;
	}
	if(document.getElementById("logsgmpwd").value=="")
	{
		document.getElementById("pwdicon").innerHTML = '<img src="'+document.getElementById("logroot").value+'/resources/images/icons/alert.gif" alt="Invalid Data" title="Invalid Data" />';	
		document.getElementById("pwdmsg").innerHTML =" <font class=\"error\">Enter&nbsp;Password</font>";
		document.getElementById("logsgmpwd").focus();return false;
	} // validation
	
	document.body.style.cursor='wait';
	// Create an instance of the XML HTTP Request object
	document.getElementById("idicon").innerHTML = '<img src="'+document.getElementById("logroot").value+'/resources/images/icons/timer-circle-small-1.gif" alt="Please wait..." title="Please Wait..." />';		
	document.getElementById("idmsg").innerHTML =  "<font class=\"link1\">Please&nbsp;wait...</font>";
	var oXMLHTTP;
	if (window.XMLHttpRequest) // Mozilla, Safari, ...
		var oXMLHTTP = new XMLHttpRequest();
	else if (window.ActiveXObject) // IE
		var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	var sURL = document.getElementById("logroot").value+"ajax/logme.php?s=" + document.getElementById("logsgmid").value + "&p=" + document.getElementById("logsgmpwd").value+"&dual="+dual;
	oXMLHTTP.open( "POST", sURL, false );
	oXMLHTTP.send(sURL); // ajax
	if(oXMLHTTP.responseText=="tweety") // login ok
	{
		var sURL = document.getElementById("logroot").value+"ajax/cpanel.php";
		oXMLHTTP.open( "POST", sURL, false );
		oXMLHTTP.send(sURL);	
		document.getElementById("cpaneltd").innerHTML = oXMLHTTP.responseText;
		var str = oXMLHTTP.responseText; var re = /<script\b.*?>(.*?)<\//ig; var match;
		while (match = re.exec(str)) { eval(match[1]); }
		closeMe(); afterMath();
	}
	else if(oXMLHTTP.responseText == "00") // activation required for member
	{
		parent.location = document.getElementById("logroot").value+'/members/';	
	}
	else if(oXMLHTTP.responseText == "0000") // activation required for client
	{
		parent.location = document.getElementById("logroot").value+'/clients/';	
	}
	else if(oXMLHTTP.responseText == "1") // user id doesn't exist
	{
		document.getElementById("idicon").innerHTML = '<img src="'+document.getElementById("logroot").value+'/resources/images/icons/alert.gif" alt="Id doesn\'t exist" title="Id doesn\'t exist" />';		
		document.getElementById("idmsg").innerHTML =  "<font class=\"error\">Login&nbsp;doesn't&nbsp;exist</font>";	
		document.getElementById("logsgmpwd").value="";
		document.getElementById("logsgmid").focus();
	}
	else if(oXMLHTTP.responseText == "2") // password incorrect
	{
		document.getElementById("pwdicon").innerHTML = '<img src="'+document.getElementById("logroot").value+'/resources/images/icons/alert.gif" alt="Password is incorrect" title="Password is incorrect" />';		
		document.getElementById("pwdmsg").innerHTML =  "<font class=\"error\">Password&nbsp;is&nbsp;incorrect</font>";
		document.getElementById("logsgmpwd").value="";
		document.getElementById("logsgmpwd").focus();
		
		document.getElementById("idicon").innerHTML = ""; document.getElementById("idmsg").innerHTML = ""; 
	}
	document.body.style.cursor='default';
}
function showSelectBoxes() {
	for(i=0;i<document.forms.length;i++)
		for(j=0;j<document.forms[i].elements.length;j++)
			if(document.forms[i].elements[j].type == "select-one")
				document.forms[i].elements[j].style.visibility = "visible";	
}
function hideSelectBoxes() {
	for(i=0;i<document.forms.length;i++)
		for(j=0;j<document.forms[i].elements.length;j++)
			if(document.forms[i].elements[j].type == "select-one")
				document.forms[i].elements[j].style.visibility = "hidden";
				
	var divs = document.getElementsByTagName("table"); var len = divs.length; var thisDiv, thisDivID;
	for (var i = 0; i < len; i++)
	{ thisDiv = divs[i]; if (thisDiv.className == 'flier') { thisDivID = thisDiv.id; } }
	document.getElementById(thisDivID).style.height = getBodyHeight()+"px";
}
function getBodyHeight()
{
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	return this.pageY;
}
function badJack(str){
     /* var reTag = /<(?:.|\s)*?>/g;
	 var reBadWords = /fuck|dick|sex|shit|boob|vagina|penis|/gi;
     if(str.search(reBadWords)!=-1)
	 	return 0;
	else
        return str.replace(reTag, " "); */
	return str;
}
function isBadJack(str){
	 /*//var sTag=/<([A-Z][A-Z0-9]*)\b[^>]*> /gi;
     var reTag = /<(?:.|\s)*?>/g;
	 //if(str.match(sTag))
	 	//return false;
	var reBadWords = /fuck|dick|sex|shit|boob|vagina|/gi;
     if(str.search(reBadWords)!=-1)
	 	return true;
	else
        return false;*/
	return false;
}
function tsSwitchTab(id,lid,count,cdiv){
	for(i=1;i<=count;i++)
	{ document.getElementById(id+i).style.display="none"; document.getElementById(lid+i).className=""; }
	document.getElementById(id+cdiv).style.display="block"; document.getElementById(lid+cdiv).className="activelink";
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
			curleft = obj.offsetLeft; curtop = obj.offsetTop;
			while (obj = obj.offsetParent) { curleft += obj.offsetLeft; curtop += obj.offsetTop;  }
	}
	return [curleft,curtop];
}
function showTip(refid,n,msg){
	var myPos = findPos(refid); var x = myPos[0]-(160);  var y = myPos[1]+36;
	document.getElementById("whodiv").style.left = x+"px"; document.getElementById("whodiv").style.top = y+"px";
	document.getElementById("whodiv").innerHTML = msg; 
	document.getElementById("whodiv").style.display = "block"; 
}
function hideTip(){	document.getElementById("whodiv").innerHTML = ''; document.getElementById("whodiv").style.display = "none"; }
function closeCoursePopUp(){
	document.getElementById("crspopupdiv").style.display = "none";	
}
function loadContainers(){
	Nifty("div#m1","big transparent bottom"); Nifty("div#m2","big transparent bottom"); Nifty("div#m3","big transparent bottom"); Nifty("div.mfdiv","normal transparent tl tr"); 
}
function loadTabSet(tid, uid,bid){ Nifty(tid,"normal transparent"); Nifty(uid, "normal transparent top"); Nifty(bid, "normal transparent br bl tr"); }
function loadIScroll(tid, uid,bid){ Nifty(tid,"normal transparent");  }
function loadListBox(tid, uid,bid){ Nifty(tid,"normal transparent"); Nifty(uid, "normal transparent top"); Nifty(bid, "normal transparent br bl tr"); }
function loadChromaBox(id){ Nifty(id,"normal transparent"); } function loadButtons(id){ Nifty(id,"small transparent"); }
function loadITabs(id){ Nifty(id,"normal transparent"); } function loadRates(id){ Nifty(id,"small transparent"); }
function loadSearchBox(){ Nifty('div.searchbox',"normal transparent"); Nifty('a.searchbtn',"small transparent"); Nifty('a.searchbtn1',"small transparent");	}
function loadFormDiv(id){ Nifty(id,"normal transparent"); }
function dateMe(y,m,d) { 
	var nd = new Date(y, (parseInt(m)-1), d); if (y == nd.getFullYear() && (parseInt(m)-1) == nd.getMonth() && d == nd.getDate()) return nd; else return false;
} 
function trim(str, chars) { return ltrim(rtrim(str, chars), chars); }
function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); }
function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); }
/******** this script is for cpanel drop down items ***********/
var timeout = 500; var closetimer = 0; var ddmenuitem = 0;
// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();
	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose;
/******** and that script ends here ***********/


/******************************* Nifty Script *********************************************/
var niftyOk=(document.getElementById && document.createElement && Array.prototype.push);
var niftyCss=false;

String.prototype.find=function(what){
return(this.indexOf(what)>=0 ? true : false);
}

var oldonload=window.onload;
if(typeof(NiftyLoad)!='function') NiftyLoad=function(){};
if(typeof(oldonload)=='function')
    window.onload=function(){oldonload();AddCss();NiftyLoad()};
else window.onload=function(){AddCss();NiftyLoad()};

function AddCss(){
niftyCss=true;
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","");
l.setAttribute("media","screen");
document.getElementsByTagName("head")[0].appendChild(l);
}

function Nifty(selector,options){
if(niftyOk==false) return;
if(niftyCss==false) AddCss();
var i,v=selector.split(","),h=0;
if(options==null) options="";
if(options.find("fixed-height"))
    h=getElementsBySelector(v[0])[0].offsetHeight;
for(i=0;i<v.length;i++)
    Rounded(v[i],options);
if(options.find("height")) SameHeight(selector,h);
}

function Rounded(selector,options){
var i,top="",bottom="",v=new Array();
if(options!=""){
    options=options.replace("left","tl bl");
    options=options.replace("right","tr br");
    options=options.replace("top","tr tl");
    options=options.replace("bottom","br bl");
    options=options.replace("transparent","alias");
    if(options.find("tl")){
        top="both";
        if(!options.find("tr")) top="left";
        }
    else if(options.find("tr")) top="right";
    if(options.find("bl")){
        bottom="both";
        if(!options.find("br")) bottom="left";
        }
    else if(options.find("br")) bottom="right";
    }
if(top=="" && bottom=="" && !options.find("none")){top="both";bottom="both";}
v=getElementsBySelector(selector);
for(i=0;i<v.length;i++){
    FixIE(v[i]);
    if(top!="") AddTop(v[i],top,options);
    if(bottom!="") AddBottom(v[i],bottom,options);
    }
}

function AddTop(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Top");
if(options.find("small")){
    d.style.marginBottom=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginBottom=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginBottom=(p-5)+"px";
for(i=1;i<=lim;i++)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingTop="0";
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Bottom");
if(options.find("small")){
    d.style.marginTop=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginTop=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginTop=(p-5)+"px";
for(i=lim;i>0;i--)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateStrip(index,side,color,border,btype){
var x=CreateEl("b");
x.className=btype+index;
x.style.backgroundColor=color;
x.style.borderColor=border;
if(side=="left"){
    x.style.borderRightWidth="0";
    x.style.marginRight="0";
    }
else if(side=="right"){
    x.style.borderLeftWidth="0";
    x.style.marginLeft="0";
    }
return(x);
}

function CreateEl(x){
return(document.createElement(x));
}

function FixIE(el){
if(el.currentStyle!=null && el.currentStyle.hasLayout!=null && el.currentStyle.hasLayout==false)
    el.style.display="inline-block";
}

function SameHeight(selector,maxh){
var i,v=selector.split(","),t,j,els=[],gap;
for(i=0;i<v.length;i++){
    t=getElementsBySelector(v[i]);
    els=els.concat(t);
    }
for(i=0;i<els.length;i++){
    if(els[i].offsetHeight>maxh) maxh=els[i].offsetHeight;
    els[i].style.height="auto";
    }
for(i=0;i<els.length;i++){
    gap=maxh-els[i].offsetHeight;
    if(gap>0){
        t=CreateEl("b");t.className="niftyfill";t.style.height=gap+"px";
        nc=els[i].lastChild;
        if(nc.className=="niftycorners")
            els[i].insertBefore(t,nc);
        else els[i].appendChild(t);
        }
    }
}

function getElementsBySelector(selector){
var i,j,selid="",selclass="",tag=selector,tag2="",v2,k,f,a,s=[],objlist=[],c;
if(selector.find("#")){ //id selector like "tag#id"
    if(selector.find(" ")){  //descendant selector like "tag#id tag"
        s=selector.split(" ");
        var fs=s[0].split("#");
        if(fs.length==1) return(objlist);
        f=document.getElementById(fs[1]);
        if(f){
            v=f.getElementsByTagName(s[1]);
            for(i=0;i<v.length;i++) objlist.push(v[i]);
            }
        return(objlist);
        }
    else{
        s=selector.split("#");
        tag=s[0];
        selid=s[1];
        if(selid!=""){
            f=document.getElementById(selid);
            if(f) objlist.push(f);
            return(objlist);
            }
        }
    }
if(selector.find(".")){      //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    if(selclass.find(" ")){   //descendant selector like tag1.classname tag2
        s=selclass.split(" ");
        selclass=s[0];
        tag2=s[1];
        }
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass==""){
    for(i=0;i<v.length;i++) objlist.push(v[i]);
    return(objlist);
    }
for(i=0;i<v.length;i++){
    c=v[i].className.split(" ");
    for(j=0;j<c.length;j++){
        if(c[j]==selclass){
            if(tag2=="") objlist.push(v[i]);
            else{
                v2=v[i].getElementsByTagName(tag2);
                for(k=0;k<v2.length;k++) objlist.push(v2[k]);
                }
            }
        }
    }
return(objlist);
}

function getParentBk(x){
var el=x.parentNode,c;
while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
    el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}

function getBk(x){
var c=getStyleProp(x,"backgroundColor");
if(c==null || c=="transparent" || c.find("rgba(0, 0, 0, 0)"))
    return("transparent");
if(c.find("rgb")) c=rgb2hex(c);
return(c);
}

function getPadding(x,side){
var p=getStyleProp(x,"padding"+side);
if(p==null || !p.find("px")) return(0);
return(parseInt(p));
}

function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}

function rgb2hex(value){
var hex="",v,h,i;
var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
var h=regexp.exec(value);
for(i=1;i<4;i++){
    v=parseInt(h[i]).toString(16);
    if(v.length==1) hex+="0"+v;
    else hex+=v;
    }
return("#"+hex);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    r[i]=r[i].toString(16);
    if(r[i].length==1) r[i]="0"+r[i];
    }
return("#"+r[0]+r[1]+r[2]);
}
/******************************* Nifty Script *********************************************/
