function formsubmit(formn,form,button){

var chk1=performCheck(formn, rules, 'classic');

	if(chk1==true){
		form.submit();
		button.disabled='disabled';
	}
	
}

function switchstyles(style,val){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
//	   alert(a.getAttribute("title"));
	   if(a.getAttribute("title") == 'green'){
		   if(val=='disabled'){
	   a.disabled = true;
		   }

		   if(val=='active'){
	   a.disabled = false;
		   }
	   }

   }

}

function disableEnterKey(e,count,caltype){
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13){
		 switch(caltype){
			 case "subtract":
			 checksubtract(count);
			 break;
			 case "multiply":
			 checkmultiply();
			 break;
			 default:
			 checkadd(count);
			 break;
			 }
	 }else{
     return true;
	 }
}

function res(t){
v="0123456789";
var w = "";
for (i=0; i < t.value.length; i++) {
x = t.value.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
t.value = w;
}

function checkadd(count){
	formn="document.addform"+count;
	form=eval(formn);
	id1="right";
	id2="wrong";
op1=parseInt(form.operand1.value);
op2=parseInt(form.operand2.value);
ans=form.answer.value;
if(ans==op1+op2){
	document.getElementById(id1).style.display='block';
	document.getElementById(id2).style.display='none';
}else{
	document.getElementById(id1).style.display='none';
	document.getElementById(id2).style.display='block';	
}
}

function checksubtract(count){
	formn="document.subtractform"+count;
	form=eval(formn);
	right="right";
	wrong="wrong";
op1=parseInt(form.operand1.value);
op2=parseInt(form.operand2.value);
ans=form.answer.value;
if(ans==op1-op2){
	document.getElementById(right).style.display='block';
	document.getElementById(wrong).style.display='none';
}else{
	document.getElementById(right).style.display='none';
	document.getElementById(wrong).style.display='block';	
}
}

function checkmultiply(){
	formn="document.form";
	form=eval(formn);
	right="right";
	wrong="wrong";
op1=parseInt(form.operand1.value);
op2=parseInt(form.operand2.value);
ans=form.answer.value;
if(ans==op1*op2){
	document.getElementById(right).style.display='block';
	document.getElementById(wrong).style.display='none';
}else{
	document.getElementById(right).style.display='none';
	document.getElementById(wrong).style.display='block';	
}
}

function showpopup(url){
hf=screen.height/4;
hf2=screen.width/8;
window.open(url,null,"top="+hf+",left="+hf2+",height=100,width=600,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

function generate_random(action,form,ran_dig){
document.getElementById('right').style.display='none';
document.getElementById('wrong').style.display='none';
document.forms[0].answer.value='';
form=eval('document.'+form);
sortfield=''; //changes the number of digits of the operands
switch(ran_dig){
case '2':
rantype=2;
val1=2;
val2='';
break;
case '3':
rantype=3;
val1=3;
val2='';
break;
case '4':
rantype=1;
val1=3;
val2='';
break;
case '5':
rantype=2;
val1=3;
val2='';
break;
case '6':
rantype=1;
val1=5;
rantype2=2;
val2=2;
break;
case '7':
rantype=1;
val1=2;
rantype2=1;
val2=2;
break;
case '8':
rantype=1;
val1=3;
rantype2=1;
val2=3;
break;
case '9':
rantype=1;
val1=3;
rantype2=1;
val2=3;
sortfield=true;
break;
case '10':
rantype=4;
val1=3;
rantype2=4;
val2=3;
break;
case '11':
rantype=1;
val1=3;
break;
case '12':
gen_ran12(form);
break;
case '13':
gen_squaring(form,11,20);
break;
case '14':
gen_squaring(form,51,100);
break;
case '15':
gen_squaring(form,101,900);
break;
case '16':
gen_squaring(form,900,1100);
break;
case '17':
gen_squaring2(form,25,8995);
break;
case '18':
gen_squaring3(form,11);
break;
case '19':
gen_squaring3(form,9);
break;
case '20':
gen_squaring(form,101,199);
break;
default:
rantype=1;
val1=1;
val2='';
break;
}

	switch (action){
	case 'addition':
	ran1=calcRand();
	ran1=ran1.toString();
	ran1=ran1.substr(0,2);
	form.operand1.value=ran1;
	ran2=calcRand();
	ran2=ran2.toString();
	ran2=ran2.substr(0,3);
	form.operand2.value=ran2;
	break;
	
	case 'subtract':
	ran1=calcRand();
	ran1=ran1.toString();
	ran1=ran1.substr(0,2);
	form.operand2.value=ran1;
	ran2=calcRand();
	ran2=ran2.toString();
	ran2=ran2.substr(0,3);
	form.operand1.value=ran2;
	break;

	case 'multiply':
//	alert(val1);
	if(rantype==1){
	ran1=calcRand();		
	}else if(rantype==2){
	ran1=gen_ran(11,20);
	}else if(rantype==3){
	ran1=gen_ran(20,29);
	}else if(rantype==4){
	ran1=gen_ran(90,120);
	}
	if(sortfield==true){
		val1=gen_ran(2,4);
	}
	ran1=ran1.toString();
	ran1=ran1.substr(0,val1);
	form.operand1.value=ran1;
	
	if(val2!=''){
	if(rantype2==1){
	ran2=calcRand();		
	}else if(rantype2==2){
	ran2=gen_ran(13,20);
	}else if(rantype2==3){
	ran2=gen_ran(20,29);
	}else if(rantype2==4){
	ran2=gen_ran(90,120);
	}
	if(sortfield==true){
		val2=gen_ran(2,4);
	}
	ran2=ran2.toString();
	ran2=ran2.substr(0,val2);
	form.operand2.value=ran2;
	}
	break;
	}	
}

function calcRand() {
date=new Date().getTime();
retVal = Math.floor(Math.random() * 1001);
retVal += Math.floor(Math.random() * date);
return retVal;
}

function gen_ran(st,en) {
retVal = Math.floor(Math.random() * en);
if(retVal<st){
	gen_ran(st,en);
}
if(retVal>en){
	gen_ran(st,en);
}
return retVal;
}

function gen_ran12(form) {
	date=new Date().getTime();
retval = Math.floor(Math.random() * date);
str=retval.toString();
digits=gen_ran(2,4);
str=str.substr(0,digits);
last=str.substr(-1,1);
if(last!=5){
	gen_ran12(form);
	return;
}
if(str>15){
	str2=str-10;
}
form.operand1.value=str;
form.operand2.value=str2;
}

function gen_squaring(form,st,en) {
num1=gen_ran(st,en);
//alert(num1);
form.operand1.value=num1;
form.operand2.value=num1;
}

function gen_squaring2(form,st,en) {
num1=gen_ran(st,en);
//alert(num1);
str=num1.toString();
last=str.substr(-1,1);
if(last!=5){
	gen_squaring2(form,st,en);
	return;
}
form.operand1.value=num1;
form.operand2.value=num1;
}

function gen_squaring3(form,type) {
if(type==11){
str='11111111111111111111111111111111111111111111111111111111111111111';
}else if(type==9){
str='999999999999999999999999999999999999999999999999999999999999999999';
}
//alert(num1);
digits=gen_ran(1,15);
num1=str.substr(0,digits);
form.operand1.value=num1;
form.operand2.value=num1;
}

function load_classes(){
	var var1=document.getElementById('classes').value;
	var url='';
	switch(var1){
	case "III":
	url="http://www.tcyonline.com/beta/categories.php?cid=100237";
	break;
	case "IV":
	url="http://www.tcyonline.com/beta/categories.php?cid=100235";
	break;
	case "V":
	url="http://www.tcyonline.com/beta/categories.php?cid=100234";
	break;
	case "VI":
	url="http://www.tcyonline.com/beta/categories.php?cid=100233";
	break;
	case "VII":
	url="http://www.tcyonline.com/beta/categories.php?cid=100232";
	break;
	case "VIII":
	url="http://www.tcyonline.com/beta/categories.php?cid=100231";
	break;
	}
	window.open(url);
	//window.location.href=url;
}

/*function load_childs(id,counter){
var anc=document.getElementById('visit_cat');
anc.style.display=(id)?'block':'none';
if(id){
var params = "&catid="+id+"&counter="+counter+"&func=show_child&rand="+calcRand();
params2=counter;
ajax_request("ajax_request.php",params,"category_response",params2);
}

}*/

function load_childs(id, counter){
if(id){
img='img_'+counter;
document.getElementById(img).style.visibility='visible';	
var params = "&catid="+id+"&counter="+counter+"&func=show_child&rand="+calcRand();
ahahscript.ahah("ajax_request.php", 'writer_root'+counter, '', 'post', params,img);
}else{
document.getElementById('img_'+counter).style.visibility='hidden';
document.getElementById('writer_root'+counter).innerHTML='';
}
var anc=document.getElementById('visit_cat_'+counter);
anc.style.display=(id)?'block':'none';
var links=document.getElementById('category_link_'+counter);
var selbox=document.getElementById('cat_select_'+counter);
var sel_val=selbox.options[selbox.selectedIndex].text;
links.href='http://www.tcyonline.com/india/categories.php?cid='+id;
links.innerHTML="View All Resources in "+sel_val;
}
function load_childs_dis(id, counter)
{
	
	if(id)
	{
		img='img_load';
		if(counter<2)
		{
			document.getElementById(img).style.visibility='visible';	
			var params = "&catid="+id+"&counter="+counter+"&func=show_child_dis&rand="+calcRand();		
			ahahscript.ahah("ajax_request_re.php", 'divcounter','', 'post', params,img);
		}
		else
		{			
			window.open("show_test.php?cid="+id,"_blank");
		}
	}
	else
	{
		document.getElementById('img_load').style.visibility='hidden';
		//document.getElementById('writer_root'+counter).innerHTML='';
		
	}	
}

function redirect_board(id){
location.href='rescources_cateogry.htm?cid='+id;
}

function load_cat(cat){
window.location.href="definition.php?cat="+cat;
}

function show_defination(){
var word=document.getElementById('tb').value;
window.location.href="definition.php?word="+word;
}

function loadvideo(id)
{
//window.location.href='http://www.tcyonline.com/india/videoscategory/categoryID/'+id ;

var opurl= 'http://www.tcyonline.com/india/videoscategory/categoryID/'+id ;
window.open(opurl,'_blank');

}
