// JavaScript Document

//+++++++++  This function return the page height and width start here ++++++++++++++++++++//

function getPageSize(){

	

	var xScroll, yScroll;

	

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = document.body.scrollWidth;

		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

		xScroll = document.body.scrollWidth;

		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

		xScroll = document.body.offsetWidth;

		yScroll = document.body.offsetHeight;

	}

	

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer

		windowWidth = self.innerWidth;

		windowHeight = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

		windowWidth = document.documentElement.clientWidth;

		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers

		windowWidth = document.body.clientWidth;

		windowHeight = document.body.clientHeight;

	}	

	

	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}

	

	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	

		pageWidth = windowWidth;

	} else {

		pageWidth = xScroll;

	}

	

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}

//+++++++++  This function return the page height and width end here ++++++++++++++++++++//





/*===============================================================*/

//=== 		This code for float the div		======================



var ns = (navigator.appName.indexOf("Netscape") != -1);

var d = document;

function JSFX_FloatDiv(id, sx, sy)

{

	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];

	var px = document.layers ? "" : "px";

	window[id + "_obj"] = el;

	if(d.layers)el.style=el;

	el.cx = el.sx = sx;el.cy = el.sy = sy;

	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};



	el.floatIt=function()

	{

		var pX, pY;

		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 

		document.documentElement && document.documentElement.clientWidth ? 

		document.documentElement.clientWidth : document.body.clientWidth;

		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 

		document.documentElement.scrollTop : document.body.scrollTop;

		if(this.sy<0) 

		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 

		document.documentElement.clientHeight : document.body.clientHeight;

		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;

		this.sP(this.cx, this.cy);

		setTimeout(this.id + "_obj.floatIt()", 40);

	}

	return el;

}

/*===============================================================*/


function isEmail(str){

	var at="@";

	var dot=".";

	var lat=str.indexOf(at);

	var ldot=str.indexOf(dot);

	var lstr=str.length;



	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		return false;

	}

	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		return false;

	}

	if(str.indexOf(" ")!=-1){

		return false;

	}

	if(str.indexOf(at,(lat+1))!=-1){

		return false;

	}

	if(str.indexOf(dot,(lat+2))==-1){

		return false;

	}

	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		return false;

	}

	return true;

}




/*++++++++++++++   START 1 May 2009	++++++++++++++++++++*/



function setHidVal(iVal)

{

	$('hidIValFSh').value = iVal;	

}





function shareEventVideo(divId,relativeDivId)
 {
 	var iVal = $('hidIValFSh').value;
 	$('shDoneBtnId').disabled = false;
  	$('hiShLiVal').value = '';	
 	$('shareSubject').value = '';
 	$('friendEmail').value = '';	
 	$('shareMsg').value = '';
  	$('shMsgDiv').innerHTML = '';
 	var hidTxtFld = 'hidEvShViUrl'+iVal;
 	$('hiShLiVal').value = $(hidTxtFld).value;
  	var obj 		= document.getElementById(divId);
	var relObj		= document.getElementById(relativeDivId);
	var divPos 		= GetLeftTopPosition(relObj);
 	var posBody 	= divPos.split('::');
	var divLeft 	= parseInt(posBody[0]);
	var divTop 		= parseInt(posBody[1]);
	var openDivLeft = (divLeft);
	var openDivTop 	= (divTop-330);
	obj.style.top 	  = openDivTop+'px';
	obj.style.left 	  = openDivLeft+'px';
	//obj.style.display 	= 'block';
 	$j("#"+divId).fadeIn(2000);
 	var det = getPageSize();
	cntWidth = det[0];
	cntHeight= det[1];
	document.getElementById("maskDivMedia").style.height = cntHeight+"px";
	document.getElementById("maskDivMedia").style.width  = cntWidth+"px";	
	//document.getElementById("div_loading").style.display = 'block';	
	$j("#div_loading").fadeIn(2000);
	return false;

}


function sendShareEventVideo(divId)
{
	var errCnt  = 0;
	var linkUrl = $('hiShLiVal').value;
	var shSub 	= $('shareSubject').value;
	var yourname 	= $('yourname').value;
	var email	= $('friendEmail').value;
	var shMsg 	= $('shareMsg').value;
	shSub = rm_trim(shSub);
	
	if(yourname == '')
	{
		$('shMsgDiv').innerHTML = 'Enter your name.';
		errCnt++;
		return false;
	}
	if(shSub == '')
	{
		$('shMsgDiv').innerHTML = 'Enter subject.';
		errCnt++;
		return false;
	}
	email = rm_trim(email);
	if(email == '')
	{
		$('shMsgDiv').innerHTML = 'Enter friend\'s email.';
		errCnt++;
		return false;
	}
	if(!isEmail(email))
	{
		$('shMsgDiv').innerHTML = 'Enter valid friend\'s email.';
		errCnt++;
		return false;
	}
	shMsg = rm_trim(shMsg);
	if(shMsg == '')
	{
		$('shMsgDiv').innerHTML = 'Enter message.';
		errCnt++;
		return false;
	}

	if(errCnt == 0)
	{
		shSub = shSub.stripScripts();//for remove javascript tag
		email = email.stripScripts();
		shMsg = shMsg.stripScripts();
		var urlFile = 'share-events-video.php?url='+linkUrl+'&sub='+shSub+'&toEmail='+email+'&shMsg='+shMsg+'&yourname='+yourname;
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
			var response = transport.responseText || "no response text";
				if(response.indexOf('yes')!=-1)
				{
					$(divId).hide();
					$('shMsgDiv').innerHTML = '';
					$('hiShLiVal').value = '';
					$('hiShLiVal').value = '';
					$("div_loading").hide();
				}
				else
				{
					$('shMsgDiv').innerHTML = 'Please try again!';
				}

			},
			onCreate: function(transport){

				//mskDivObj.className = 'maskClass';
			},

			onException: function(){
			//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}
		});	

	}	

}

function limitComments(liId, fieldId, limitNum){
	
	var fieldObj = document.getElementById(fieldId);
	var comLen	 = fieldObj.value.length;
	
	if(comLen <= limitNum){
		document.getElementById(liId).innerHTML = limitNum - comLen;
	}else{
		fieldObj.value = fieldObj.value.substring(0, limitNum);
		document.getElementById(liId).innerHTML = 0;
		return false;
	}	
}

function GetLeftTopPosition(obj)
 {	
     var topValue= 0,leftValue= 0;
     while(obj){
 		leftValue+= obj.offsetLeft;
 		topValue+= obj.offsetTop;
 		obj= obj.offsetParent;
     }
 	finalvalue = leftValue+"::"+topValue;
     return finalvalue;
 }

function showTourVideoCommentPopup(divId,relativeDivId)
{
   	var vid 	= $('eventid').value;
	$('vid').value = vid;
	$('commentText').value = '';
 	var obj 		= document.getElementById(divId);
	var relObj		= document.getElementById(relativeDivId);
	var divPos 		= GetLeftTopPosition(relObj);
	var posBody 	= divPos.split('::');
	var divLeft 	= parseInt(posBody[0]);
	var divTop 		= parseInt(posBody[1]);
 	var openDivLeft = (divLeft);
	var openDivTop 	= (divTop-330);
    obj.style.top 	  = openDivTop+'px';
 	obj.style.left 	  = openDivLeft+'px';
   	$j("#"+divId).fadeIn(2000);
	var det = getPageSize();
	cntWidth = det[0];
	cntHeight= det[1];
 	document.getElementById("maskDivMedia").style.height = cntHeight+"px";
	document.getElementById("maskDivMedia").style.width  = cntWidth+"px";	
	//document.getElementById("div_loading").style.display = 'block';
	$j("#div_loading").fadeIn(2000);
	return false;

}

function showTourVideoCommentDelPopup(divId,tvid)
{
	var pageDet = getPageSize();	
	var vid 	= $('eventid').value;
 	$('VID').value = vid;
	$('TVID').value = tvid;

    var obj 		= document.getElementById(divId);
   	var relObj		= document.getElementById(tvid);
	var divPos 		= GetLeftTopPosition(relObj);
	var posBody 	= divPos.split('::');
	var divLeft 	= parseInt(posBody[0]);
	var divTop 		= parseInt(posBody[1]);
 	var openDivLeft = (divLeft);
	var openDivTop 	= (divTop);
    obj.style.top 	  = openDivTop+'px';
 	obj.style.left 	  = openDivLeft+'px';
  	$j("#"+divId).fadeIn(2000);
	var det = getPageSize();
	cntWidth = det[0];
	cntHeight= det[1];
 	document.getElementById("maskDivMedia").style.height = cntHeight+"px";
	document.getElementById("maskDivMedia").style.width  = cntWidth+"px";	
	//document.getElementById("div_loading").style.display = 'block';
	$j("#div_loading").fadeIn(2000);
	return false;

}

function postTourVideoComments(divId){
  	var errCnt  = 0;
	var commentText	= $('commentText').value;
	var vid 	= $('vid').value;
	
	cText = rm_trim(commentText);
  	if(cText == '')
	{
 		$('comErrId').innerHTML = '*Comment text is required.';
		errCnt++;
		return false;
	}

	if(errCnt == 0)
	{
 		cText = cText.stripScripts();//for remove javascript tag
		var urlFile = 'tour_video_comments.php?show=Yes&commText='+commentText+'&vid='+vid;
		 //alert(urlFile);
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! send mail :: " + response);
				if(response){				
					//$('comErrId').innerHTML = "Comment posted.";
					$('commentDivId').innerHTML = response;
					$('commentText').value = '';
					closeToursPopups(divId);
					//$(divId).hide();
					$("div_loading").hide();
					parent.doIframe();
				}else{
					$('shMsgDiv').innerHTML = 'Please try again!';
				}
			},

			onCreate: function(transport){
				//mskDivObj.className = 'maskClass';
			},
			onException: function(){
				//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}

		});	

	}	

}

function showTourVideoComments(vid,tvurl){

		$('eventid').value = vid;
				
		var urlFile = 'tour_video_comments.php?show=Yes&vid='+vid;
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! send mail :: " + response);
				if(response){				
					
					$('commentDivId').innerHTML = response;
					
					}
			},

			onCreate: function(transport){
				//mskDivObj.className = 'maskClass';
			},
			onException: function(){
				//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}

		});	
		getTourVideoDetails(vid);
		parent.doIframe();
		
	
}

function getTourVideoDetails(vid){
		
		var urlFile = 'tour_video_details.php?info=tvinfo&vid='+vid;
		
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! send mail :: " + response);
				if(response){				
					
					$('tvt').innerHTML = response;
					
					}
			},

			onCreate: function(transport){
				//mskDivObj.className = 'maskClass';
			},
			onException: function(){
				//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}

		});	
		parent.doIframe();
	
}

function delTourVideoComment(divId){

		var vid 	= $('VID').value;
		var tvid 	= $('TVID').value;
	
		var urlFile = 'tour_video_comments.php?show=Yes&del=Delete&vid='+vid+'&tvid='+tvid;
	//	alert(urlFile);
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! send mail :: " + response);
				if(response){				
					
					$('commentDivId').innerHTML = response;
					closeToursPopups(divId);
					parent.doIframe();
										
					}
			},

			onCreate: function(transport){
				//mskDivObj.className = 'maskClass';
			},
			onException: function(){
				//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}

		});	
	
}

function showTourVideoCommentsPaging(curval,vid){
	
	
		var urlFile = "tour_video_comments.php?show=Yes&vid="+vid+"&curpage="+curval;
		//alert(urlFile);
		new Ajax.Request(urlFile, {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! send mail :: " + response);
				if(response){				
					
					$('commentDivId').innerHTML = response;
					parent.doIframe();
				}
			},

			onCreate: function(transport){
				//mskDivObj.className = 'maskClass';
			},
			onException: function(){
				//alert('onException.. for evets sharing...');
			},
			onFailure: function(){
				//alert('onFailure.. for evets sharing...');
			}

		});	
	
}
function campuspopup(showDiv,relativeDivId){
	var obj 		= document.getElementById(showDiv);
   	var relObj		= document.getElementById(relativeDivId);
	var divPos 		= GetLeftTopPosition(relObj);
	var posBody 	= divPos.split('::');
	var divLeft 	= parseInt(posBody[0]);
	var divTop 		= parseInt(posBody[1]);
 	var openDivLeft = (divLeft);
	var openDivTop 	= (divTop+40);
    obj.style.top 	  = openDivTop+'px';
 	obj.style.left 	  = openDivLeft+'px';
  	$j("#"+showDiv).fadeIn(2000);
	var det = getPageSize();
	cntWidth = det[0];
	cntHeight= det[1];
 	document.getElementById("maskDivMedia").style.height = cntHeight+"px";
	document.getElementById("maskDivMedia").style.width  = cntWidth+"px";	
	//document.getElementById("div_loading").style.display = 'block';
	$j("#div_loading").fadeIn(2000);
	return false;
}
 function closecampus(id){
	document.getElementById("visit_campmsg").style.display='block';
	document.getElementById("send_campsmsg").style.display='none';
	document.getElementById("visit_name").value="";
	document.getElementById("visit_email").value="";
	document.getElementById("visit_UCS").value="";
	document.getElementById("visit_contact").value="";
	document.getElementById("visit_rqmsg").value="";
 	//document.getElementById(id).style.display = 'none';	
	//document.getElementById("div_loading").style.display = 'none';	 
	$j("#"+id).fadeOut(2000);
	$j("#div_loading").fadeOut(2000);
	 }
function closeToursPopups(divId){
	$j("#"+divId).fadeOut(2000);
	$j("#div_loading").fadeOut(2000);
	//document.getElementById(divId).style.display = 'none';
	document.getElementById("div_loading").style.display = 'none';
}


