ferror='loading';
mferror='modalerror';
function idtobj(id){return document.getElementById(id); }
function currentdate(){
	var t = new Date(); month = t.getMonth()+1; 	day = t.getDate();	year = t.getFullYear();
	(day<10)?day="0"+day:day; (month<10)?month="0"+month:month;
	var date = ""+year+"-"+month+"-"+day+""; 	return date;
}
function currenttime(){
	var t = new Date(); tm="am";
	h= t.getHours(); if(h>12) { tm="pm"; h=h-12; }if(h==0) h=12;
	m=t.getMinutes();	time=h+":"+m+" "+tm;
	return  time;
}
function rewriteurl(str){
 var stateObj = { foo: "bar" };
  alert(stateObj);
	window.history.pushState(stateObj, "page 2", "bar.html");}
function ajaxreturnobj(rs, divid){
	data=divid.split(","); width=data[3]; height=data[2]; obj=idtobj(data[0]+'data'); title=data[1];
	borderdiv=modalcontentdiv(obj, width, height, title, data[0]);
	borderdiv.innerHTML+='<div id="modalcontent" style=" -webkit-border-top-right-radius: 0px;  -moz-border-radius-topright: 0px; -webkit-border-top-left-radius: 0px;  -moz-border-radius-topleft: 0px;" class="modalcontent">'+rs+'</div>';
	obj.appendChild(borderdiv);
}
function modalpadzero(rs, divid) {
	if(rs!="no"){
		ajaxreturnobj(rs, divid);
		document.getElementById('modalcontent').style.padding = '0px';
	} else closeWindow('modal');

}
function todocall(rs, divid){ ajaxreturnobj(rs, divid);	currentsysdate();}
function modalcontentdiv(obj, width, height, title, divid){
	obj.innerHTML='';
	obj.style.width=width; obj.style.height=height;	
	borderdiv=document.createElement('div');
	borderdiv.className='modalborders';
	borderdiv.innerHTML='<div class="change_label" ><span style="float: right;"><a style="text-decoration: none;" href="javascript:void(0);" onclick="closeWindow(\''+divid+'\');" >X Close</a></span><label>'+title+'</label></div>'
						+'<div class="modalprocess" id="modalprocess" style="display: none;"></div>';
	return borderdiv;
}
function justaddhtml(rs, divid){  idtobj(divid).innerHTML=rs;}
function justinview(rs, divid){	window.location=rs;}
function viewrecent(id, param){	
	if((param == 'image') || (param=='comment'))	param = 'media';
	var post = "id="+id+"&param="+param;
	request('ajax/recentviewpost.jsp', post, 'no', justinview);
}
function viewdoc(id, param){	
	var post = "id="+id+"&param="+param; 
	if (param=='class') { request('classes.jsp?setcok', post, 'no', justinview);  return; }else {
		request('alldocuments.jsp?setcok', post, 'no', justinview); }
}
function getpostresult(rs, divid){
	process=idtobj(divid+'process');  content=idtobj(divid+'content');
	if(rs.substr(0, 7)=='success'){
		process.style.display='none';
		content.style.display='block';
		content.innerHTML=rs.substr(7);
	}else {
		process.className='modalprocesserror';		
		content.style.display='block';
		process.innerHTML='<div class="modalerrors">'+rs+'</div>';
	}
}
function rotations(start){
	var imgdiv = document.getElementById("footerads");
	if(start>=images.length) start=0;
	imgdiv.innerHTML='<img src="images/'+images[start]+'" />';	
	start=start+1;
	setTimeout("rotations("+start+")", 15000);
}
function displaywindow(showid, url, width, height, type, title, callback){
	idtobj(showid).style.display='block'; idtobj(showid).style.top="20%";
	idtobj('background').style.display='block';
	obj=idtobj(showid+"data");

	obj.style.width='450px'; 	obj.innerHTML=''; bordiv=document.createElement('div');	bordiv.className='modalborders';
	bordiv.innerHTML='<div class="modaloading">Loading...</div>';
	obj.appendChild(bordiv);
	if(type=="iframe"){
		idtobj(showid).style.top="10%";
		borderdiv=modalcontentdiv(obj, width, height, title, showid);
		width=parseInt(width)-15;
		borderdiv.innerHTML+='<div id="modalcontent" style="padding: 0px; -webkit-border-top-right-radius: 0px;  -moz-border-radius-topright: 0px; -webkit-border-top-left-radius: 0px;  -moz-border-radius-topleft: 0px;" class="modalcontent"><iframe src="'+url+'" style="border: 0px solid #FFF; width:'+width+'px; height:'+height+'; scrolling:no;"></iframe></div>';
		obj.appendChild(borderdiv);
	}else {
	
	divid=showid+","+title+","+height+","+width;
	request(url, '', divid, callback); }
}
function closeWindow(hideid) {	idtobj(hideid).style.display='none'; idtobj('background').style.display='none';}
 
function displayloading(message){
	loaddiv=idtobj('loadmodal'); loaddiv.style.top="35%";
	loaddiv.style.display="block";
	obj=idtobj('loadmodaldata');
	idtobj('background').style.display='block';
	obj.style.width='450px'; 	obj.innerHTML=''; bordiv=document.createElement('div');	bordiv.className='loadmodalborders';
	bordiv.innerHTML='<div class="processmessage">'+message+'...</div>';
	obj.appendChild(bordiv);
	
}
function formposting(formname, url,  divid, callback){
	idtobj(mferror).style.display="none"; idtobj(divid+'process').style.display="none"; idtobj(divid+'process').className="modalprocess";
	var posturl	=validateform(formname);
	if(posturl!=false){
	process=idtobj(divid+'process'); process.style.display='block'; idtobj(divid+'content').style.display='none';
	process.innerHTML="Posting your data please wait for a while...";
	request(url, posturl.substr(1), divid, callback); } else { idtobj(mferror).style.display="block"; idtobj(mferror).innerHTML="Please fill in all the fields"; } 
}
function currentsysdate(){
	var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
	var today=new Date();
	var dayfield=document.getElementById("curday");
	var monthfield=document.getElementById("curmonth");
	var yearfield=document.getElementById("curyear");
	for (var i=1; i<=31; i++)
	dayfield.options[i]=new Option(i, i);
	dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true); //select today's day
	for (var m=0; m<12; m++)
	monthfield.options[m]=new Option(monthtext[m], m+1);
	monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], today.getMonth()+1, true, true); //select today's month
	var thisyear=today.getFullYear();
	for (var y=0; y<1; y++){
	yearfield.options[y]=new Option(thisyear, thisyear);
	thisyear+=1;
	}
	yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) ;//select today's year
}

function hidemodalload(){
	idtobj('loadmodal').style.display="none"; idtobj('background').style.display="none"; 
}
function postforms(formname, url, message, callback) { 
	var load=idtobj('loading');
	load.style.display="block";
	data=formname.split(','); 
	var posturl = validateform(data[0]); 
	if(posturl!=false){
		request(url, posturl.substr(1), formname, callback);
	} else { 
		load.innerHTML='<span>Please check error(s) and try again.</span>';}
}
function appendreply(rs, divid){
	data=divid.split(',');
	if(rs=='fail'){	idtobj(ferror).innerHTML='Sorry unable to post your reply. Try again later'; idtobj(ferror).style.display='block';}
	else {	resetform(data[0]); 
		if(idtobj(trimSpace(data[1]))!=null){
		li=document.createElement('li'); li.innerHTML=rs;
		idtobj(trimSpace(data[1])).appendChild(li);
		} else {
			idtobj('nocontent').className=''; idtobj('nocontent').innerHTML='';
			ul=document.createElement('ul'); ul.setAttribute('id', trimSpace(data[1]));
			ul.className+=' '+data[2];
			ul.innerHTML='<li>'+rs+'</li>';
			idtobj('nocontent').appendChild(ul);
		}
	}
	hidemodalload();
}
function uploadfile(formname, divid){ alert(ferror);
	idtobj(ferror).style.display="none"; 
	var posturl	=validateform(formname); 
	if(posturl!=false){
	process=idtobj(divid+'process'); process.style.display='block'; idtobj(divid+'content').style.display='none';
	process.innerHTML="Uploading file please wait for a while...";
	return true;}
	else { idtobj(ferror).style.display="block"; idtobj(ferror).innerHTML="Please fill in all the fields"; return false; }
}
function profileupdate(formname, btn) {
	idtobj(btn).value="Updating..."; idtobj(btn).setAttribute('type', 'button');
}
function addblock(parent, sample, pattren, count){
	parent=idtobj(parent); sample=idtobj(sample); count=idtobj(count);
	countvale=parseInt(count.value)+1;
	newobj=document.createElement('span');
	content = sample.innerHTML;
	newobj.innerHTML=content.replace(/-0/g, '-'+countvale+'');
	parent.appendChild(newobj);
	count.value=countvale;
}
function delblock(Node){
	var parent=Node.parentNode;
	parent.parentNode.removeChild(parent);

}
function deletedblock(rs, Node){
	if(rs="ok")	delblock(Node);	
}
function delrecblock(Node, id, type){
	Node.innerHTML="deleting...";	request("processproform.jsp?deltype="+type+"", "id="+id+"", Node, deletedblock);
}
function srchsuggest(obj, type){
	hidediv('suggestionboxes');
	if(trimSpace(obj.value)!=""){
		width = parseInt(obj.offsetWidth)-2;
		top=parseInt(obj.offsetTop)+(parseInt(obj.offsetHeight)); 
		left=parseInt(obj.offsetLeft);
		width=width+"px";
		suggest=document.createElement("div");
		suggest.setAttribute("id", type);
		suggest.setAttribute("class", "suggestionboxes");
		suggest.style.top=top+"px";
		suggest.style.left=left+"px";
		suggest.style.width=width;
		suggest.style.display="none";
		obj.parentNode.appendChild(suggest);
		request('ajax/suggestionsearch.jsp', 'type='+type+'&search='+trim(obj.value)+'', type+','+obj.getAttribute("name"), showsugg);
	} 
}
function showsugg(rs, id){
	list=eval (""+ rs +"");
	div=id.split(",");
	idtobj(div[0]).style.display="block";
	data='<ul>';
	for(i=0; i<list.length; i++){
		
	data += "<li onclick=\"selectsugg(this, '"+div[1]+"');\">"+list[i]+"</li>";
	}
	idtobj(div[0]).innerHTML=data+"</ul>";

}
function hidediv(classname){
	var x=document.getElementsByClassName(classname);
	for(i=0; i<x.length; i++){
		 x[i].parentNode.removeChild(x[i]);
	}
}
function selectsugg(obj, name){
	var x= document.getElementsByName(name);
	if(x.length==1){
	x[0].value=obj.innerHTML;
	}
	hidediv('suggestionboxes');
} 
function connectrequest(type, id) {
	if(type=='del') url='ajax/connectrequest.jsp?type=delete'; else url='ajax/connectrequest.jsp?type='+type;
	var post = "id=" + id; 
	request(url, post, id, connectstatuschange);
	idtobj(id).innerHTML = 'Requesting...';
}
function connectstatuschange(rs, divid) {
	var showcase = idtobj(divid); 
	if (rs == 'connect')	showcase.innerHTML = "Pending";
	else if (rs == 'delete')	showcase.parentNode.removeChild(showcase);
	else if (rs == 'accept')	showcase.parentNode.removeChild(showcase);
	else if (rs == 'deleted') { parent=showcase.parentNode; parent=parent.parentNode.parentNode; parent.parentNode.removeChild(parent); }
}


function checkfield(){

	var collegeName = trim(document.studentintro.collegeName.value);
	var degree = trim(document.studentintro.degree.value);
	var stream = trim(document.studentintro.stream.value);
	var currentSemester = trim(document.studentintro.currentSemester.value);
	var email = document.studentintro.email.value; 
	var mobile = trim(document.studentintro.mobile.value);
	var landPh = trim(document.studentintro.landPh.value);
	var tpoName = trim(document.studentintro.tpoName.value);
	var tpoMob = trim(document.studentintro.tpoMob.value);

	
var count=0;
if(email!=""){
	checkfields();
	     document.getElementById("Msg5").innerHTML="";
	     var result=(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/).test(email); 
	     if (!result){
				document.getElementById("Msg5").innerHTML="InValid EmailId";
				count=1;
		 }
        if(count==1){
        	return false;
        }
}else{
	
    checkfields();

	if(email==""){
		 count=1;
		 document.getElementById("Msg5").innerHTML="Please enter emailId ";
	 }
	 if(count==1){
     	return false;
     }
	
}


function checkfields(){
	
	
	if(collegeName=="" ||collegeName.length == 0){
		 document.getElementById("Msg1").innerHTML="Please fill up college name";
		 count=1;
		
    }else{
		document.getElementById("Msg1").innerHTML="";
    }

	if(degree=="" ||degree.length == 0){
	      document.getElementById("Msg2").innerHTML="Please fill up degree ";
	      count=1;
	}else{
		document.getElementById("Msg2").innerHTML="";
	 }
    
	if(stream=="" ||stream.length == 0){
		count=1;
	     document.getElementById("Msg3").innerHTML="Please fill up stream ";
	}else{
		document.getElementById("Msg3").innerHTML="";
	 }
		
	if(currentSemester=="" ||currentSemester.length == 0){
		count=1;
	    document.getElementById("Msg4").innerHTML="Please fill up current semester ";
	}else{
		document.getElementById("Msg4").innerHTML="";
	}

	 if(mobile=="" ||mobile.length == 0){
		 count=1;
		 document.getElementById("Msg6").innerHTML="Please enter mobile no ";
		  
	}else{
		 document.getElementById("Msg6").innerHTML="";
	}
		
	if(landPh=="" ||landPh.length == 0){
		count=1;
	    document.getElementById("Msg7").innerHTML="Please enter landphone no ";
			
	}else{
		  document.getElementById("Msg7").innerHTML="";
	}
	
	if(tpoName=="" ||tpoName.length == 0){
		count=1;
	    document.getElementById("Msg8").innerHTML="Please fill up  TPO name ";
			
	}else{
		document.getElementById("Msg8").innerHTML="";
	}
			
	if(tpoMob=="" ||tpoMob.length == 0){
		count=1;
		document.getElementById("Msg9").innerHTML="Please enter TPO mobile no ";
			
	}else{
		document.getElementById("Msg9").innerHTML=""; 
	}

	
	
}


}



