//---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//		Serosoft Solutions Pvt. Ltd.
//		info@serosoft.in
//		Filename: 			standard.php
//		Author: 			Atul Kushwah  
//		Email: 				atul.kushwah@serosoft.in, atul.kushwah@gmail.com
//		Date:				17 June 2010
//		Script language: 	JS (Jquery)
//		Purpose: 			Web Guru Login and Ajax Relay
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------

$(document).ready(function(){ init(); bridge(); });
var ploader = '<img src="images/ajax-loader.gif" alt="..." />';
var init = function(){
	this.biending 		= function(){ alert('1'); }
	this.autoload 		= function(){ alert('2'); }
	this.bridge 		= function(){		
	$('#collegeList').html(ploader);
	$.get('process.php',{'httpRequest':'college'},function(rsps){ propagate(rsps); }); }
	this.propagate 		= function(rsData){ $('#collegeList').css({'display':'none'}).html(rsData).show('slow'); };
	this.ValidEnq	 	= $("#EnqMail").validate({  rules: { Name: "required", Email: {   required: true, email: true   } } });
	$('#LogMeIn').click(function(){logging()});
	$('#Proceed').click(function(){if($("#EnqMail").valid())$("#EForm").fadeTo("fast",0.2, function(){ enqSend(); });});
	$("#PreVidForm").validate({  rules: { Name: "required", Email: {   required: true, email: true   }, Institution:"required",	City:"required"} });
	$('#ProceedToVideo').click(function(){if($("#PreVidForm").valid())vidSend();});
}

var getCourse = function(college_s){
	$('#coursesList').html(ploader);	
	$.get('process.php',{'httpRequest':'courses','college':college_s},function(rsps){ propagate(rsps); });
	this.propagate = function(rsData){ $('#coursesList').css({'display':'none'}).html(rsData).show('slow'); };
}
var logging = function(){
	this.colls = $("#college").val();
	this.cours = $("#department").val();
	
	if(colls == "Please Select" || colls ==""){
		alert("Please select college."); 		$("#college").focus(); return false;
	}else
	if(cours == "Please Select" || cours ==""){
		alert("Please select course."); 		$("#department").focus(); return false;
	}else
	if($("#name").val()==""){
		alert("Please enter the user name."); 	$("#name").focus(); return false;
	}else
	if($("#pwd").val()==""){
		alert("Please enter the password."); 	$("#pwd").focus(); 	return false;
	}
	this.action = "process.php?httpRequest=login";
	$("#WebguruRemote").attr({'action':action}).submit();
}
var enqSend = function(){
	this.offsets 	=	$("#EnqMail").offset();
	this.top_p		=	offsets.top + 150;
	this.top_p_a	=	offsets.top + 180;	
	$('#WaitMsg').css({'top':top_p}).show('fast');
	$('#Proceed').hide("fast");
	$.post('feedback.php',$("#EnqMail").serialize(),function(d){mess();rs(d)});
	this.mess 		= 	function(){ $('#WaitMsg').hide('fast',function(){ $('#msgr').show('fast').animate({'top':top_p_a},'fast').animate({'top':top_p}); });}
	this.rs 		= 	function(d){this.t			=	setTimeout('resolve()',2000);};	
}
var resolve = function(){
	this.top_p		=	$('#msgr').offset().top + 30;
	$('#msgr').show('fast').animate({'top':top_p_a},'slow').animate({'top':-10},function(){
	$('#Proceed').show("fast");$("#EForm").fadeTo("fast",.8);cf('EnqMail');});	
}
var cf = function(form){$(':input','#'+form).not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');unsave=false;unsaved_tab=0;};


//--------------- Video Form & Ajax ------------------------------------------------------------------------------

var vidSend = function(){
	this.video		='<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/OKsOgiu4ElA&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/OKsOgiu4ElA&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	
	this.offsets 	=	$("#PreVidForm").offset();
	this.top_p		=	offsets.top + 150;
	this.top_p_a	=	offsets.top + 180;
	$('#dataContent').slideUp("fast");
	$('#bbclose').slideUp("fast");	
	$('#PgBar').show('fast');	
	$.post('video_entries.php',$("#PreVidForm").serialize(),function(d){mess(d);/*rs(d)*/ });
	this.mess 		= 	function(d){
		switch(d){
			case ('c'):
				$('#PgBar').hide('fast', function(){
					$('#dataContent').slideDown("slow", function(){
						$('#bbclose').show("fast", function(){
							$('#CAPTCHA').css({'borderColor': "red"});
						});
					});
				});
				//alert('invalid captcha');
			break;
			case ('1'):
				$('#dataContent').html('');
				$('#PgBar').hide('fast', function(){
					$('#dataContent').slideDown("slow", function(){	
						$('#dataContent').html(video); 
						$('#bbclose').show("fast");
					});
				});	
				//alert('ok');
			break;
			default:
				$('#PgBar').hide('fast', function(){
					$('#dataContent').slideDown("slow", function(){
						$('#bbclose').show("fast");
					});
				});
			break;
		}		
	}
	//this.rs 		= 	function(d){this.t			=	setTimeout('resolve()',2000);};	
}

//___________ Functions __________________________________________________________________________________________

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
