var todbpath = 'http://spidergroup.co.in/';
var SITEPATH = "http://spidergroup.co.in/";
var signInreload;

var isdocReady = 0; //variable for too stop popup to be open until page is load
$(function(){isdocReady = 1;});

function submitPost(){
		var postTxt = $("#reply").val();
		var confirm_code = $("#confirm_code").val();
		var topic_id = $("#topic_id").val();

		if(postTxt == ""){
			alert("Enter post");
			$("#reply").focus();
			return false;
		}

		if(confirm_code == ""){
			alert("Enter code");
			return false;
		}

		$.post(todbpath+"reply2db.php", {'postTxt': postTxt,'confirm_code': confirm_code,'topic_id':topic_id}, function(data) {
				$("#showform").hide();

				$("#msg").html(data);
			});
	}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function setcookieinter( name, value, expires, path, domain, secure ){
	var expires_date = "int()''";
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

var var2 = $('#divsignin');
var divSI, divREG, divFP;
//divSI also defined in the footer
function checklogin(){
	if(isdocReady){
		if(!readCookie("ui")){
			_gaq.push(['_trackPageview', '/login.html']);
			$.blockUI(divSI, {width:'400px'});
		}
	}
}

function closesignin()
{
	
	$.unblockUI();
	//Changes on 15th July 2010 For Microsite Login START
	var microsite_value=$("#mtv_microsite").val();
	if(microsite_value == 1)
	{
		displayName();
	}
	//Changes on 15th July 2010 For Microsite Login END
	//window.location.reload();
}


var UNAME = '';
function LoginVerifynew(str){	
	
	var usernm = $("#f_id_new").val();
	var pswrd = $("#f_pwd_new").val();
	UNAME = usernm;

	if(usernm == ""){
		alert("Enter username.");
		return false;
	}

	if(pswrd == ""){
		alert("Enter Password");
		return false;
	}

	var url="http://www.in.com/loginverify.php";
	$.getJSON(url+"?f_id="+usernm+"&f_pwd="+pswrd+"&f_referrer=undefined&rememberme=&f_source=jquery&rcode=undefined&f_domain=cross&format=json&jsoncallback=?", 
	function(data){
		//alert(data["status"]);
		if(data["status"] == "success"){
				$.post(SITEPATH+"check_in_map.php", {"uId":data["userid"], "userName":UNAME}, function(data2) {
					if(signInreload=='' || signInreload==null){
						//window.location.reload();
						var data_arr = data2.split("|");
							if(document.getElementById('signin_info')){
								document.getElementById('signin_info').innerHTML = "Welcome <strong>"+data["username"]+"</strong>  | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>"; 
								if(data_arr[1] == "noFb"){
								document.getElementById('signin_info').innerHTML += " | <fb:login-button v=\"2\" size=\"small\" autologoutlink=\"false\" >Connect with Facebook</fb:login-button>";
							}
						}
						FB.XFBML.parse();
						closesignin();
					}else if(signInreload==1){
						closesignin();
					}
				});
		}else{
			if(data["errorcode"] == '4'){
				$("#signinErrormsg").html("Userid does not exist.");
			}else{
				$("#signinErrormsg").html("The username or password you entered is incorrect.");
			}
		}
	});
}


function checkMapping(){
	//alert("done");
	$.post(SITEPATH+"check_mapping.php", {}, function(data) {
			
			if(data == "oops"){
				$('#signin_info').html("Welcome <strong> <fb:name uid=\"loggedinuser\" useyou=\"false\" linked=\"false\"></fb:name></strong>  | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>");
				if(!readCookie("ui")){
				$('#siginFBmsg').html("You have logged in to Facebook as <strong><fb:name uid=\"loggedinuser\" useyou=\"false\" linked=\"false\"></fb:name></strong>");
				$('#registerFBmsg').html("You have logged in to Facebook as <strong><fb:name uid=\"loggedinuser\" useyou=\"false\" linked=\"false\"></fb:name></strong>");
				$('#forgetFBmsg').html("You have logged in to Facebook as <strong><fb:name uid=\"loggedinuser\" useyou=\"false\" linked=\"false\"></fb:name></strong>");
				}
				FB.XFBML.parse();
				
				//checklogin(); //YXP
				showRegMtv();
			}else{
				data_arr = data.split("|");
				if(data_arr.length >= 2)
				{
					if(data_arr[0] == '3'){
						document.getElementById('signin_info').innerHTML = "Welcome <strong>"+data_arr[1]+"</strong> | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>";
						if(data_arr[2] == "noFb"){
							document.getElementById('signin_info').innerHTML +=	" | <fb:login-button v=\"2\" size=\"small\" autologoutlink=\"false\" >Connect with Facebook</fb:login-button>";
						}
						FB.XFBML.parse();
					}else{
					$.getJSON("http://www.in.com/loginverify_auto.php?uid="+data_arr[1]+"&username="+data_arr[2]+"&f_source=jquery&f_domain=cross&format=json&jsoncallback=?", 
					function(data){
						if(data["dispname"] == "" || data["dispname"] == null){
							dName = readCookie("ui");
						}else{
							dName = data["dispname"];
						}
						//<fb:name uid=\"loggedinuser\" useyou=\"false\" linked=\"false\"></fb:name>
						document.getElementById('signin_info').innerHTML = "Welcome <strong> "+dName+"</strong>  | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>";
						closesignin();
						FB.XFBML.parse();
					});
					}
				}
				else
				{
					//checklogin();	//YXP
					showRegMtv();
				}
			}
	});
}


function htab(a, b, c, d)
{
for(var i=1; i<=b; i++)
{
	if(i == a){
		document.getElementById(c+i).className = "act";
		document.getElementById(d+i).style.display = "block"
	}
	else{
		document.getElementById(c+i).className = "nact";
		document.getElementById(d+i).style.display = "none"
	}
}
}
function Trim(str) {	
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function isValidEmail(str) 
{	
	if(str.length > 3)
	{
		emailRe = /^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|jobs|mobi|asia|tel|travel))$/
		if (!emailRe.test(str))	
		{
			return false;	
		}
		else
		{
			return true;				
		}
	}
	else
	{
		return false;	
	}
}
function isValidmobile(str) 
{
	mobileRe = /^([9]{1})([234789]{1})([0-9]{8})$/
	if (!mobileRe.test(str))	
		return false	
	else
		return true		
}
// To redirect user to personalise the Dedication. But first check if the user is logged in else redirect
function sendDedication(trackID,trackName){	//alert(readCookie("ui"));
	if(!readCookie("ui")){
		checklogin();
	}else{
		//location.href="dedicatesong_personalise.php?trackid="+trackID;
		location.href=SITEPATH+"music/dedicate_song/"+trackName+"-"+trackID+".html";
	}
}

function register(){
	_gaq.push(['_trackPageview', '/registation.html']);
	$.blockUI(divREG, {width:'413px', top: '35%'});
	captchaRefresh("regGlu");
	/*if ( FB.XFBML.Host.parseDomTree ){
		 setTimeout( FB.XFBML.Host.parseDomTree, 0 );
	}*/
}

function closeregister()
{
	$.unblockUI();
}

function forgetpassword(){
	$.blockUI(divFP, {width:'413px'});	
}

function closeFP(){
	$.unblockUI();
}
function  clearALL(divid){
	selfClose(divid);
}

//function for like
function doLike(contentId,contentType,contentTypeid,tablename,idfield,contentTitle, pgUrl){
	if(!readCookie("ui")){
		$.blockUI(divSI, {width:'400px'});
	}else{
		var Dbfilepath='';
		/*if(contentTypeid==8){
			Dbfilepath=todbpath+'mtvLike2db_forIN.php';
		}else{*/
			Dbfilepath=todbpath+'mtvLike2db.php';	
		//}
		$.post(Dbfilepath, { contentId: contentId,contentType: contentType,contentTypeid: contentTypeid,tablename: tablename,idfield: idfield,contentTitle: contentTitle,pgUrl: pgUrl},
		function(data){
			//alert("data "+data);
			var dataMsg = '';
			var dataArr = data.split('~');
				
				dataMsg = displayMsg('like',dataArr[0]);
				//alert(" >> "+dataMsg);
				if(dataMsg != ''){
					if(dataArr[0] == '1'){
						$('#con_like_'+contentId).html(dataArr[1]);
					}
					$('#divtablike_msg_'+contentId).html(dataMsg);
					$('#divtablike_msg_'+contentId).show();
					var t=setTimeout("clearALL('divtablike_msg_"+contentId+"')",3000);
				} // End If
		});
	}
} // doLike End

// contains all error & success msg for do like
function displayMsg(cType,msgId){
	var msg = '';
	if(cType == 'like'){
		//alert("msId "+msgId)
		switch(msgId){
			case '1' :
				msg='<div style="background:#eee; position:absolute; padding:5px; border: 1px #999 solid;   z-index:1; font:10px arial; color:#333;"><nobr>Thank you for your vote!</nobr><div>';
				//alert(" >> d1 >>"+msgId);
				break;
			case '2':
				msg='<div style="background:#eee; position:absolute; padding:5px; border: 1px #999 solid;   z-index:1; font:10px arial; color:#333;"><nobr>Already voted!</nobr><div>';
				//alert(" >> d2 >>"+msgId);
				break;
			case '3':
				msg='<div style="background:#eee; position:absolute; padding:5px; border:1px #999 solid; z-index:1; font:10px arial; color:#333;"><nobr><a href="#"  onclick=checklogin(); class="bl_11">Login </a> now to vote!</nobr><div>';
				//alert(" >> d3 >>"+msgId);
				break;
			default :
				msg = '<div style="background:#eee; position:absolute; padding:5px; border:1px #999 solid; z-index:1; font:10px arial; color:#333;"><nobr><a href="#"  onclick=checklogin(); class="bl_11">Login </a> now to vote!</nobr><div>';
				//alert(" >> d >>"+msgId);
	
		} // end switch	
	
	} // If End 
	return msg;
} // end displaymsg

function selfClose(divid){
	document.getElementById(divid).style.display='none';
}

//for Share div on consumption pages
function doShare(){
	 var e = document.getElementById('showshare2');
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
}

function forgotpwd()
{
	var url="http://www.in.com/forgotpwdmtv.php";
	var forgot_email = $("#forgot_email").val();
	var forgot_altemail = $("#forgot_altemail").val();
	$.getJSON(url+"?forgot_email="+forgot_email+"&forgot_altemail="+forgot_altemail+"&format=json&jsoncallback=?", 
	function(data){
		//console.debug(data);
		//alert(data["status"]);
		if(data["status"] == "success"){
				closesignin();			
				alert('Forgot password link has been sent');				
		}else{
				$("#fpwdErrMsg").html("Failed to send the link. Please try again.");
		}
	});
}

function clearInput(val){
	if(val == "First Name"){
		$("#fname").val('');
	}else
	if(val == "Last Name"){
		$("#lname").val('');
	}
}
function checkUsername(username){
	//alert(username);
	if($.trim(username) != ""){
		/*check for username available or not*/
		$("#usernameMsg").html("<img src='/images/L.gif'/>");
		$.post(SITEPATH+"checkusername.php", {'username': username, 'flag':'checkUsername'}, function(data) {
						//alert(data);
						if(data == "No"){
							$("#usernameMsg").html("<img src='/images/delete_icon.gif' alt='please wait'/>");
							$("#regErrormsg").html("Selected User name Not Available.");
						}else if(data == "Yes"){
							$("#usernameMsg").html("<img src='/images/DoneIcon.gif' alt='please wait'/>");
							$("#regErrormsg").html("");
						}
				});
	}else{
		/*username suggestion*/
		$("#usernameMsg").html("");
	}
		var fname = $.trim($("#fname").val());
		var lname = $.trim($("#lname").val());
		if(fname != "" && lname != "" && fname != "First Name" && lname != "Last Name"){
			$.post(SITEPATH+"checkusername.php", {'fname': fname, 'lname':lname, 'flag':'usernameSuggestion'}, function(data) {
					$("#usernameSuggestion").html(data);
					
			});
		}else{
			$("#regErrormsg").html("Enter your name so we can suggest a new available Username");
		}
}

function selectusername(value){
	if(value!=""){
	$("#usernameMsg").html("");
	$("#username").val(value);
	}
}

function isValidEmail(str) 
{	
	if(str.length > 3)
	{
		emailRe = /^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|jobs|mobi|asia|tel|travel))$/
		if (!emailRe.test(str))	
		{
			return false;	
		}
		else
		{
			return true;				
		}
	}
	else
	{
		return false;	
	}
}

function validateSignup(){
	var fname = $.trim($("#fname").val());
	var lname = $.trim($("#lname").val());
	//var bday = $.trim($("#bday").val());
	//var bmonth = $.trim($("#bmonth").val());
	//var byear = $.trim($("#byear").val());
	var uesrname = $.trim($("#username").val());
	var password = $.trim($("#password").val());
	var confirmPas = $.trim($("#confirmPassword").val());
	var alernateEmail = $.trim($("#alernateEmail").val());
	var confirmCode = $.trim($("#confirm_code").val());
	var terms = $("#regTerms").is(":checked");
	$("#regErrormsg").html("");
	if(fname == ""){
		//alert("Please Enter First Name.");
		$("#regErrormsg").html("Please Enter First Name.");
		$("#fname").focus();
		return false;
	}
	if(lname == ""){
		//alert("Please Enter Last Name.");
		$("#regErrormsg").html("Please Enter Last Name.");
		$("#lname").focus();
		return false;
	}
	
	/*if(bday == "" || bmonth == "" || byear == ""){
		alert("Please Select Your Birth Date.");
		return false;
	}*/
	
	if(uesrname == ""){
		//alert("Please Enter Username.");
		$("#regErrormsg").html("Please Enter Username.");
		$("#uesrname").focus();
		return false;
	}
	
	if (isalphanumeric(uesrname) == false) {
		$("#regErrormsg").html("Username contains invalid characters.");
		$("#uesrname").focus();
		return false;
	}
	
	if(password == ""){
		//alert("Please Enter Password.");
		$("#regErrormsg").html("Please Enter Password.");
		$("#password").focus();
		return false;
	}else if(password.length < 6){
		//alert("Password should be 6 characters or more.");
		$("#regErrormsg").html("Password should be 6 characters or more.");
		$("#password").focus();
		return false;
	}
	
	if(confirmPas == ""){
		//alert("Please Enter Confirm Password.");
		$("#regErrormsg").html("Please Enter Confirm Password.");
		$("#confirmPassword").focus();
		return false;
	}
	
	if(password != confirmPas){
		//alert("Password and Confirm Password Does not match");
		$("#regErrormsg").html("Password and Confirm Password Does not match");
		$("#confirmPassword").focus();
		return false;
	}
	
	if(alernateEmail == ""){
		//alert("Please Enter Alternate Email.");
		$("#regErrormsg").html("Please Enter Alternate Email.");
		$("#alernateEmail").focus();
		return false;
	}else{
		if(isValidEmail(alernateEmail) == false){
			//alert("Invalid Email Address");
			$("#regErrormsg").html("Invalid Email Address.");
			$("#alernateEmail").focus();
			return false;
		}
	}
	if(confirmCode == ""){
		//alert("Please Enter the text you see in the image.");
		$("#regErrormsg").html("Please Enter the text you see in the image.");
		$("#confirm_code").focus();
		return false;
	}
	
	if(terms == false){
		//alert("Please Click on accept the term of use.");
		$("#regErrormsg").html("Please Click on accept the term of use.");
		return false;
	}
	
	var formData = $("#regForm").serialize();
	
	$.ajax({
			   type: "POST",
			   url: todbpath+"register2db.php",
			   data: formData,
			   success: registerChk
			});
return true;
}

function registerChk(data){
	data_arr = data.split("|");
	if(data_arr[0] == "1"){
		var url="http://www.in.com/loginverify.php";
		$.getJSON(url+"?f_id="+data_arr[2]+"&f_pwd="+data_arr[3]+"&f_referrer=undefined&rememberme=&f_source=jquery&rcode=undefined&f_domain=cross&format=json&jsoncallback=?", 
		function(data3){
			if(data3["status"] == "success"){
				
				$.post(SITEPATH+"check_in_map.php", {"uId":data3["userid"], "userName":data_arr[2], "Newuser":"yes"}, function(data2) {
					
						var data_arr = data2.split("|");
						
						document.getElementById('signin_info').innerHTML = "Welcome <strong>"+data3["username"]+"</strong>  | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>"; 
						if(data_arr[1] == "noFb"){
						document.getElementById('signin_info').innerHTML += " | <fb:login-button v=\"2\" size=\"small\" autologoutlink=\"false\" >Connect with Facebook</fb:login-button>";
						}
						FB.XFBML.parse();
						//$.unblockUI();
						closesignin();
				});
			}else{
				//$.unblockUI();	
				closesignin();
			}
		});
	}else{
		$("#regErrormsg").html(data);
	}
}

function captchaRefresh(id){
	var time = new Date().getTime();
	document.getElementById(id).src=SITEPATH+"captcha/captcha.php?ver="+time;
	return true;
}

function commentCountUpdate(contentId, tblName, idCloumn, contentType, contentTypeid, contentTitle, pgUrl){
	var formData = "id="+contentId+"&tblName="+tblName+"&idColumn="+idCloumn+"&contentType="+contentType+"&contentTypeid="+contentTypeid+"&contentTitle="+contentTitle+"&pgUrl="+pgUrl;

	$.ajax({
			   type: "POST",
			   url: todbpath+"comentCount2db.php",
			   data: formData,
			   success: function(data){
				  var data_arr = data.split('|');
				  if(data_arr[0] == 1){
					  if(tblName == "vjtravelogue"){
					  	$('#con_comment_'+data_arr[1]).html(data_arr[2]);  
					  }else{
					  	$('#con_comment_'+data_arr[1]).html(data_arr[2]);  
					  }
				  }
			   }
			});
}

//function used to get json values of view, comment, like
function populateContentCounts(contype, contid)
{
	$.getJSON(SITEPATH+"inc/content_json.php?contid="+contid+"&sec="+contype+"&format=json&EXT=1", 
	function(data){
		//document.write(data);
		  // here you will get the php out put in json array   
		 if(data["STATUS"] == "SUCCESS"){
			 //then apply the success action
			// alert(data["STATUS"]);
			var jObj =eval(data);
			var viewcnttext = '';
			var comcnttext = '';
			var comcnttextlink = '';
			var downcnttext = '';


			conArr = jObj.CONT;
			var  rec, i;
				for(i in conArr) {  //alert(i);
					rec = conArr[i]; //alert(rec['vcount']);
					if(contype == 'downloads'){
						$("#ddownload_"+i).html(rec['dcount']);
					}
					if(contype == 'downloadslist'){
						$("#download_"+i).html(rec['dcount']);
					}

					if(rec['vcount'] == '1' || rec['vcount'] == '0' ){
						viewcnttext = rec['vcount']+' View';
					}else{
						viewcnttext = rec['vcount']+' Views';
					}

					if(rec['dcount'] == '1' || rec['dcount'] == '0' ){
						downcnttext = rec['dcount']+' Download';
					}else{
						downcnttext = rec['dcount']+' Downloads';
					}

					if(rec['ccount'] == '1' ){
						comcnttext = rec['ccount']+' Comment';
						comcnttextlink = rec['ccount']+' Comment';
					}else if(rec['ccount'] == '0' ){
						comcnttext = 'Leave a comment';

						if(contype == 'games'){
							comcnttextlink = '<a href="javascript:void(0);" class="gL_11" onclick="open_popup(\''+rec['guid']+'\')"><b>Leave a comment</b></a>';
						}else{
							comcnttextlink = '<a href="'+rec['guid']+'" class="gL_11"><b>Leave a comment</b></a>';
						}
					}else{
						comcnttext = rec['ccount']+' comments';
						comcnttextlink = rec['ccount']+' Comments';
					}


					if(contype == 'blogsview' || contype == 'gamesview' || contype == 'photosview' || contype == 'videosview' || contype == 'downloadsview' || contype == 'travelogview' || contype == 'albumsview'){
						$("#con_view_"+i).html(viewcnttext);
						$("#con_comment_"+i).html(comcnttext);
					}else if(contype == 'games'){
						$("#gview_"+i).html(viewcnttext);
						$("#gcomment_"+i).html(comcnttextlink);
					}else if(contype == 'travelog'){
						$("#tview_"+i).html(viewcnttext);
						$("#tcomment_"+i).html(comcnttextlink);
					}else if(contype == 'downloads'){
						$("#dview_"+i).html(viewcnttext);
						$("#dcomment_"+i).html(comcnttextlink);
						$("#ddownload_"+i).html(downcnttext);
					}else{
						$("#view_"+i).html(viewcnttext);
						$("#comment_"+i).html(comcnttextlink);
					}
				}
		 }else{
			//apply the failed action
		 }
	});
}

//function used to get json values of view, comment, like
function populateContentCounts_n(contype, contid)
{
	$.getJSON(SITEPATH+"inc/content_json.php?contid="+contid+"&sec="+contype+"&format=json&EXT=1", 
	function(data){
		//document.write(data);
		  // here you will get the php out put in json array   
		 if(data["STATUS"] == "SUCCESS"){
			 //then apply the success action
			// alert(data["STATUS"]);
			var jObj =eval(data);
			var viewcnttext = '';
			var comcnttext = '';
			var comcnttextlink = '';
			var downcnttext = '';
			conArr = jObj.CONT;
			var  rec, i;
				for(i in conArr) {  //alert(i);
					rec = conArr[i]; //alert(rec['vcount']);
					if(contype == 'downloads'){
						$("#ddownload_"+i).html(rec['dcount']);
					}
					if(contype == 'downloadslist'){
						$("#download_"+i).html(rec['dcount']);
					}

					if(rec['vcount'] == '1' || rec['vcount'] == '0' ){
						viewcnttext = rec['vcount']+' View';
					}else{
						viewcnttext = rec['vcount']+' Views';
					}

					if(rec['dcount'] == '1' || rec['dcount'] == '0' ){
						downcnttext = rec['dcount']+' Download';
					}else{
						downcnttext = rec['dcount']+' Downloads';
					}

					if(rec['ccount'] == '1' ){
						comcnttext = rec['ccount']+' Comment';
						comcnttextlink = rec['ccount']+' Comment';
					}else if(rec['ccount'] == '0' ){
						comcnttext = 'Leave a comment';

						if(contype == 'games'){
							comcnttextlink = '<a href="javascript:void(0);" class="gL_11" onclick="open_popup(\''+rec['guid']+'\')"><b>Leave a comment</b></a>';
						}else{
							comcnttextlink = '<a href="'+rec['guid']+'" class="gL_11"><b>Leave a comment</b></a>';
						}
					}else{
						comcnttext = rec['ccount']+' comments';
						comcnttextlink = rec['ccount']+' Comments';
					}

					

					if(contype == 'blogsview' || contype == 'gamesview' || contype == 'photosview' || contype == 'videosview' || contype == 'downloadsview' || contype == 'travelogview' || contype == 'albumsview'){
						$("#con_view_"+i).html(viewcnttext);
						$("#con_comment_"+i).html(comcnttext);
					}else if(contype == 'games'){
						$("#gview_"+i).html(viewcnttext);
						$("#gcomment_"+i).html(comcnttextlink);
					}else if(contype == 'travelog'){
						$("#tview_"+i).html(viewcnttext);
						$("#tcomment_"+i).html(comcnttextlink);
					}else if(contype == 'downloads'){
						$("#dview_"+i).html(viewcnttext);
						$("#dcomment_"+i).html(comcnttextlink);
						$("#ddownload_"+i).html(downcnttext);
					}else{
						$("#view_"+i).html(viewcnttext);
						$("#comment_"+i).html(comcnttextlink);
					}
				}
		 }else{
			//apply the failed action
		 }
	});
}


//for GAME player
function open_popup(gameUrl){

window.open(''+gameUrl+'','','location=no,scrollbars=yes,status=no,height=750,width=870');

}

function isalphanumeric(str)
{
	 var bReturn = true;
	 var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-";
	 var invalidfirst = "._-";
	 var invalidlast = "._-";
	 for (var i=0; i<str.length; i++) {
	 if ( i == 0 && (invalidfirst.indexOf(str.charAt(i)) > 0)){
	 bReturn = false;
	 break;
	 }
	 else if ( i == (str.length-1) && (invalidlast.indexOf(str.charAt(i)) > 0)) {
	 bReturn = false;
	 break;
	 }
	 else if (valid.indexOf(str.charAt(i)) < 0) {
	 bReturn = false;
	 break;
	 }
	 }
	 return(bReturn);
} 

function showRegMtv(){
$.get(SITEPATH+'registermtv.php', function(data) {
		$('#divRegMtv').html(data);
		divRegMtv = $('#divRegisterMTV');
	    $.blockUI(divRegMtv, {width:'400px', top:'40%'});
		captchaRefresh("regGlumtv");
		FB.XFBML.parse(document.getElementById('regMtvFBmsg'));
	});
}

function facebookLogout(){
	FB.logout(function(response) {
		 window.location.reload();
	});
}
function checkUsernameMtv(username){
	if($.trim(username) != ""){
		/*check for username available or not*/
		$("#usernameMsgMtv").html("<img src='/images/L.gif'/>");
		$.post(SITEPATH+"checkusername.php", {'username': username, 'flag':'checkUsername'}, function(data) {
						if(data == "No"){
							$("#usernameMsgMtv").html("<img src='/images/delete_icon.gif' alt='please wait'/>");
							$("#regmtvErrorMsg").html("Selected User name Not Available.");
							$("#validUser").val("0");
						}else if(data == "Yes"){
							$("#usernameMsgMtv").html("<img src='/images/DoneIcon.gif' alt='please wait'/>");
							$("#regmtvErrorMsg").html("");
							$("#validUser").val("1");
						}
				});
	}else{
		$("#usernameMsgMtv").html("");
	}
}

var userNamemtv;
var userIdmtv;
function registerVerifyMtv(){
	
	var validUser = $("#validUser").val();
	var usernameMtv = $("#usernameMtv").val();
	var  altEmailMtv = $("#altEmailMtv").val();
	var confirmCode = $.trim($("#confirm_codemtv").val());
	var terms = $("#regTermsmtv").is(":checked");
	var fbName = $("#fbName").is(":checked");

	if($.trim(usernameMtv) == ""){
		$("#regmtvErrorMsg").html("Please Enter Username.");
		return false;
	}
	
	if(validUser == 0){
		$("#regmtvErrorMsg").html("Selected User name Not Available.");
		return false;
	}
	
	if(altEmailMtv == ""){
		$("#regmtvErrorMsg").html("Please Enter Alternate Email Address.");
		return false;
	}
	
	if(isValidEmail(altEmailMtv) == false){
		$("#regmtvErrorMsg").html("Invalid Email Address.");
		return false;
	}
	
	if(fbName == false){
		fnamemtv = $("#fnamemtv").val();
		lnamemtv = $("#lnamemtv").val();
		if(fnamemtv == "" || fnamemtv == "First Name"){
			$("#regmtvErrorMsg").html("Please Enter First Name.");
			return false;	
		}
		
		if(lnamemtv == "" || lnamemtv == "First Name"){
			$("#regmtvErrorMsg").html("Please Enter Last Name.");
			return false;	
		}
	
	}
	if(confirmCode == ""){
		$("#regmtvErrorMsg").html("Please Enter the text you see in the image.");
		$("#confirm_codemtv").focus();
		return false;
	}
	
	if(terms == false){
		$("#regmtvErrorMsg").html("Please Click on accept the term of use.");
		return false;
	}
	
	dataString = $("#regMtvUser").serialize();
	$.post(todbpath+"registermtv2db.php", dataString, function(data) {
		//alert(data);
		$("#regmtvWait").html("<img src='/images/L.gif' alt='Please wait'/>");
		dataArr = data.split("|");
		userNamemtv = usernameMtv;
		userIdmtv = dataArr[4];
		if(dataArr[0] == "1"){
			$.getJSON("http://www.in.com/loginverify_auto.php?uid="+dataArr[3]+"&username="+dataArr[2]+"&f_source=jquery&f_domain=cross&format=json&jsoncallback=?", 
					function(data){
						//alert(data["status"]);
						if(data["status"] == "success"){
				
							$.post(SITEPATH+"check_in_map.php", {"uId":userIdmtv, "userName":userNamemtv, "Newuser":"yes"}, function(data2) {
									if(document.getElementById('signin_info')){
										if(data["dispname"] == "" || data["dispname"] == null){
											dName = readCookie("ui");
										}else{
											dName = data["dispname"];
										}
									document.getElementById('signin_info').innerHTML = "Welcome <strong>"+dName+"</strong>  | <a href=\""+SITEPATH+"logout.php\" class=\"w_11L\">Logout</a>"; 
									}
									$("#regmtvWait").html("");
									closesignin();
							});
						}else{
							$("#regmtvWait").html("");
							closesignin();
						}
					
					});
		}else{
			$("#regmtvErrorMsg").html(data);
			$("#regmtvWait").html("");
			return false;
		}
	});
}

function usernameSugMtv(){
	$.get(todbpath+"usersugmtv.php", function(data) {
					$("#usernameSuggestionmtv").html(data);
	});
}
function selectusernamemtv(value){
	if(value!=""){
	$("#usernameMsgMtv").html("");
	$("#usernameMtv").val(value);
	$("#validUser").val("1");
	}
}

function nameToggle(){
		var fbname = $("#fbName").is(":checked");
		
		if(fbname == false){
			$("#mtvnameTog").show();
		}else{
			$("#mtvnameTog").hide();
		}
}

function clearName(name){
	if(name == "First Name"){
		$('#fnamemtv').val('');
	}
	if(name == "Last Name"){
		$('#lnamemtv').val('');
	}
}

//SAME AS STOP_WORD FUNCTION to break string after requred characters
//var getstring = stopword('No Record found, Please enter valid text', 20);
function stopword(str, reqstringlength){
	var arrstr = str.split(' ');
	var newstr = '';
	var strlen = str.length;
	var newstrlen = 0;
	var thisstringlen =0;
	for(var i=0;i<arrstr.length;i++){
		thisstringlen = parseInt(arrstr[i].length);
		newstrlen = parseInt(newstrlen)+thisstringlen;
		if(newstrlen >= reqstringlength){
			newstr += '...';
			break;
		}else{
			newstr += ' '+arrstr[i];
		}
	}
	return newstr;
}

