/*
 * Initialization
 */
var onloadFuncs = new Array();

function execOnloadFuncs(){
}

jQ(document).ready(function() {
	//verifyVisit();
});

jQ(document).ready(function() {
	for(var i=0;i<onloadFuncs.length;i++)
		onloadFuncs[i]();
	
	jQ(".sitenav li a").hover(
		function() {
			jQ(this).parent().find("ul.subnav").slideDown('fast').show();
			jQ(this).parent().hover(
				function() {},
				function(){  
					jQ(this).parent().find("ul.subnav").slideUp('fast');
				}
			); 
		},
		function(){}
	);
});
/*
 * Common
 */
function deleteCookie( c_name ) {
	if ( getCookie( c_name ) ) {
		document.cookie = c_name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");

		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);

			if (c_end==-1)
				c_end=document.cookie.length;
					
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
		
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var pos = document.domain.indexOf('.');
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/;domain="+document.domain.substr(pos));
}

function trunStr(str, max_length)
{
	if (str.length > max_length) {
		var tmp_str = str.substring(0, max_length-3);
		var last_idx = tmp_str.lastIndexOf(' ');
 		
		if (last_idx > 0) {
			tmp_str = tmp_str.substring(0, last_idx) + '...';
		}
 		
		tmp_str += '...';
		return tmp_str;
	}
 	
	return str;
}

function showMessages(err, root_div)
{
	var elem = document.getElementById(root_div);
	
	if (!elem)
		return;
 	
	while (elem.firstChild)
		elem.removeChild(elem.firstChild);

	var ulElem = document.createElement('ul');
	var liElem = null;
	var tmpElem = document.createElement('h1');
	
	if (err.msgType == 'error')
		tmpElem.className = 'err';
	
	tmpElem.innerHTML = err.msg;
	elem.appendChild(tmpElem);

	for (var i in err.errors) {
		jQ('#' + i).addClass('errbdr');
 		
		if (err.errors[i] != '') {
			jQ('#' + i + '_msg').html(err.errors[i]);
/*
			liElem = document.createElement('li');
			liElem.id = i + '_lbl_msg';
			liElem.innerHTML = err.errors[i];
			ulElem.appendChild(liElem);
*/
		}
	}
	
	if (err.msg != '' || err.errors.length > 0) {
		if (err.msgType == 'error')
			ulElem.className = 'err';
		
		elem.appendChild(ulElem);
		elem.style.display = 'block';
	} else {
		elem.style.display = 'none';
	}
}

function closeMessages(root_div)
{
	var elem = document.getElementById(root_div);
	
	if (!elem)
		return;
 	
	while (elem.firstChild)
		elem.removeChild(elem.firstChild);

	elem.style.display = 'none';
}

function goHome()
{
	window.location.href = BU;
}

function minMaxDiv(div_id)
{
	if (jQ('#'+div_id+'_but').attr('title') == 'show more') {
		jQ('#'+div_id).toggle("slow");
		jQ('#'+div_id+'_but').attr('title', 'show less').html('<img src="arrow-up-orange-solid.png" alt="" /> <span>show less</span>');
		jQ('#'+div_id+'_but2').attr('title', 'show less').html('<img src="arrow-up-orange-solid.png" alt="" /> <span>show less</span>');
	} else {
		jQ('#'+div_id).toggle("slow");
		jQ('#'+div_id+'_but').attr('title', 'show more').html('<img src="arrow-down-orange-solid.png" alt="" /> <span>show more</span>');
		jQ('#'+div_id+'_but2').attr('title', 'show more').html('<img src="arrow-down-orange-solid.png" alt="" /> <span>show more</span>');
	}
}

function hasSignedIn()
{
	var clogged_in = getCookie('logged_in');
	return (clogged_in && clogged_in > 0) ? true : false;
}

function toBeFan(ct, ce, sn)
{
	if (!hasSignedIn()) {
		if (!postLoginCommands) {
			postLoginCommands = new Array();
			postLoginCommands.push("toBeFan(" + ct + "," + ce + ",'" + sn + "')");
		}
		
		showSignInForm();
		return;
	}
	
	jQ.post(BU + 'main/abefan', { ct:ct, ce:ce }, function(json) {
		alert('Thank you for becoming a fan of ' + sn);
		jQ('#befan-'+ct+'-'+ce).css('display', 'none');
		
		if (json.eCode == 0) {
			var str = '';
			
			if (json.total_fans > 1)
				str = json.total_fans + ' fans';
			else if (json.total_fans > 0)
				str = json.total_fans + ' fan';
			
			jQ('#tfans-'+ct+'-'+ce).html(str);
		}
	}, "json");
}

function toEmail(mid, eid)
{
	var elem = document.getElementById('pop_email_form');
	
	if (!elem) {
		elem = document.createElement('div');
		elem.id = 'pop_email_form';
		elem.className = 'pop_email_form';
		document.body.appendChild(elem);
	}
	
	elem.innerHTML = '<iframe class="pop_email_frame" src="' + BU + 'main/emailform/' + mid + '/' + eid + '"></iframe>' +
					 '<div class="pop_email_form_bot">' +
					 	'<div style="float:left">Copyright &copy;2010 Desi Hits! Inc. All rights reserved.</div>' +
					 	'<div style="float:right; margin-right:40px;"><a class="simplemodal-close" href="javascript:void(0)">Close</a></div>' +
					 '</div>';
	//FB.XFBML.Host.parseDomTree();
	
	jQ('#pop_email_form').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ['2%',]});
}

function toFavorite(bid, str)
{
	if (!hasSignedIn()) {
		if (!postLoginCommands) {
			postLoginCommands = new Array();
			postLoginCommands.push("toFavorite('" + bid + "')");
		}
		
		showSignInForm();
		return;
	}
	
	var bt = document.getElementById(bid);
	
	if (!bt) {
		return;
	}

	var flds = bid.split('-');
	
	jQ.post(BU + 'main/afavorite', { ct:flds[1], eid:flds[2] }, function(json) {
		if (json.eCode > 0) {
			showMessages(json.errors, 'signin_frm_msg');
			return;
		}

		if (json.total_fans > 0) {
			bt.innerHTML = '';
		} else {
			bt.innerHTML = '';
		}
		
		alert(str + ' has been added to your favorite list.');
	}, "json");
}

function toShare(select_id)
{
	var elem = document.getElementById(select_id);
	
	if (!elem) return;
	
	var str = elem.options[elem.selectedIndex].innerHTML;
	
	if (str == 'Facebook' || str == 'Digg' || str == 'Del.icio.us') {
		window.open(elem.options[elem.selectedIndex].value);
	} else if (str == 'Email Friends') {
		var fd = elem.options[elem.selectedIndex].value.split('::');
		toEmail(fd[0], fd[1]);
	}
}

function toRate(bid, r)
{ //alert('here');
	/* if (!hasSignedIn()) {
		if (!postLoginCommands) {
			postLoginCommands = new Array();
			postLoginCommands.push("toRate('" + bid + "'," + r + ")");
		}
		
		showSignInForm();
		return;
	}
	*/
	var bt = document.getElementById(bid);
	
	if (!bt) {
		return;
	}
	
	if (bt.alt != 'Rate') {
		return;
	}
	
	var flds = bt.id.split('-');
	
	jQ.post(BU + 'main/arate', { ct:flds[1], eid:flds[2], r:r }, function(json) {
		if (json.eCode > 0) {
			showMessages(json.errors, 'signin_frm_msg');
			return;
		}

		if (flds[1] == 2048) {
			jQ('#upratei-'+flds[1]+'-'+flds[2]).attr('src','ico-tup-bgrey-16.jpg');
			jQ('#downratei-'+flds[1]+'-'+flds[2]).attr('src','ico-tdown-bgrey-16.jpg');
		} else {
			jQ('#upratei-'+flds[1]+'-'+flds[2]).attr('src','ico-tup-bgrey-22.jpg');
			jQ('#downratei-'+flds[1]+'-'+flds[2]).attr('src','ico-tdown-bgrey-22.jpg');
		}
		
		jQ('#upratei-'+flds[1]+'-'+flds[2]).attr('alt','');
		jQ('#downratei-'+flds[1]+'-'+flds[2]).attr('alt','');
		jQ('#upratea-'+flds[1]+'-'+flds[2]).attr('title','');
		jQ('#downratea-'+flds[1]+'-'+flds[2]).attr('title','');		
		jQ('#ratescore-' + flds[1] + '-' + flds[2]).html(json.ave_score + '%');
		
		if (json.ave_score > 0) {
			jQ('#ratescorebx-'+flds[1]+'-'+flds[2]).removeClass('hide');
		} else {
			jQ('#ratescorebx-'+flds[1]+'-'+flds[2]).addClass('hide');
		}
		
		alert('Thank you for rating');
	}, "json");
}

/*  gbr start */
function esignup()
{
	jQ('#esign_email_lbl').removeClass("err");
	jQ('#esign_cemail_lbl').removeClass("err");
	jQ('#modal_msg').css('display', 'none');	
	var email = document.getElementById('esign_email').value;
	var cemail = document.getElementById('esign_cemail').value;
	var errors = new Object;
	var eCounter = 0;
	
	if (email == '') {
		errors['esign_email'] = 'Email is missing';
		eCounter + 1;
	} else if (email != cemail) {
		errors['esign_email'] = 'Email and confirm email do not match';
		errors['esign_cemail'] = '';
		eCounter += 1;
	} 
	/* gbr start email validation */
	else {
	  var regx = /^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i;
		if (!regx.test(email)) {
			errors['esign_email'] = 'Email address is invalid';
			errors['esign_cemail'] = '';
			eCounter += 1;
		}
	}
	
	/* gbr end email validation */
	
	if (eCounter > 0) {
		showErrors(errors, 'modal_msg');
		return;
	}

	var url = BU + 'user/aereg';
	jQ.post(url, { esign_email : email, esign_cemail : cemail }, function(json) {
		if (json.eCode > 0) {
			showErrors(json.errors, 'modal_msg');
		}
	
		setCookie('regconf', '1', 30);
		var elem = document.getElementById('modal_content');
		
		while (elem.firstChild)
			elem.removeChild(elem.firstChild);
/* GBR start - mod to not prompt for registration...just newsletter */			
//		if (json.result_code == 2) {
//			elem.appendChild(genAccountRegForm());
//			jQ('#regfrm_title').html('Thanks - Want to Join DesiHits.com?');
//			jQ('#regfrm_desc').html('<p>Thank you for signing up for our weekly email newsletter. Want more? Sign-up now for DesiHits.com for FREE music downloads, wallpapers and photos and to post comments</p>');
//		jQ('#regemail').val(email);
//	} else {
			elem.appendChild(genEmailRegComplete());
//		}
/* GBR end - mod to not prompt for registration...just newsletter */			
		
		if (jQ('#modal_dialog').css('display') == 'none')
			jQ('#modal_dialog').modal({onOpen: simpleModalOpen, onClose: simpleModalClose});
	}, "json");
}

function refuse_esignup()
{
	setCookie('regconf', '2', 30);
}
/*  gbr end */


function onSelectAll(elem)
{
	elem.select();
}
/*
 * End Common
 */

/*
 * Search
 */
function onSearchBox(sform)
{
	var elem = null;
	
	if (sform == 'global_search') {
		elem = document.getElementById('global_searchstr');
	}
	
	if (!elem) {
		return;
	}
	
	var str = elem.value;
	
	if (str == 'Search DesiHits') {
		elem.value = '';
	} else if (str != '') {
		elem.focus();
		elem.select();
	}
}

function search(sform) {
    var frm = document.getElementById(sform);

    if (!frm) {
    	return;
    }
    
    var str = frm.searchstr.value;
    
    if (str != '' && str != 'Search DesiHits') {
    	var re = /[.]+/g;
    	str = str.replace(re, '');
   		var re2 = /[^\w\d+-]+/g;
    	window.location = BU + "search/?searchstr=" + str.replace(re2, '+');
    }
}

function cancelEnter(e, sform) {
	if(window.event) {
		keynum = e.keyCode;
	} else if(e.which) {
		keynum = e.which;
	}

	if (keynum == 13) {
		search(sform);
		e.cancelBubble = true;
		e.returnValue = false;
		return false;
	}
}
/*
 * 
 */

/*
 * Comment
 */
function closeCommentForm()
{
	jQ('#comment_frm_bx').addClass('hide');
}

function showCommentForm()
{
	jQ('#comment_frm_bx').removeClass('hide');
}

function comment()
{
	jQ('#comment_frm_msg').html("");	
	var commentTxt = jQ('#comment_txt').attr('value');
	var commentNme = jQ('#comment_name').attr('value');
		//alert(commentNme);
	if (commentNme == '') {
		jQ('#comment_name_msg').html('Please, enter your name');
		return;
	}
	
	if (commentTxt == '') {
		jQ('#comment_frm_msg').html('Please, enter your comment');
		return;
	}
	
	var entryId = jQ('#comment_mid').attr('value');
	var contentId = jQ('#comment_mtype').attr('value');
	
	if (isNaN(entryId) || isNaN(contentId) || parseInt(entryId) < 1 || parseInt(contentId) < 1) {
		alert("Please, re-load the page and comment again.\n\nSorry for the inconvenience");
		return;
	}

	jQ.post(BU + 'main/acomment', { eid : entryId, cid : contentId, ctxt : commentTxt, nmtx : commentNme}, function(json) {
		if (json.eCode > 0) {
			//alert(json.eCode);
			if (json.eCode > 3) {
				alert("Please, re-load the page and comment again.\n\nSorry for the inconvenience");
			} else {
				if ((json.eCode & 1) == 1) {
					postLoginCommands.push("toComment()");
					toLogin();
				} else if ((json.eCode & 2) == 2) {
					jQ('#comment_frm_msg').html('Please enter your comment');
				}
			}

			return;
		}
		//alert(json.total);
		jQ('#comment_frm_bx').addClass('hide');
		jQ('#comment_txt').attr('value','');
		jQ('#comment_list').html(json.comment_str);		
		jQ('#tcomments-'+contentId+'-'+entryId).html('('+json.total+')');
	}, "json");
}
/*
 * End Comment 
 */

 /*
  * Sign in/Sign out
  */
var postLoginCommands = null;

function cancelSignup()
{
	if (postLoginCommands.length > 0)
		postLoginCommands.pop();
}

function forgot(rMethod)
{
	return true;
	
	jQ('#regemail_lbl').removeClass('err');
	jQ('#recaptcha_response_field_lbl').removeClass('err');
	var eCount = 0;
	
	if (jQ('#regemail').val() == '') {
		eCount += 1;
		jQ('#regemail_lbl').addClass('err');
		jQ('#regemail_msg').html('Email is missing');
	}
	
	if (jQ('#recaptcha_response_field').val() == '') {
		eCount += 1;
		jQ('#recaptcha_response_field_lbl').addClass('err');
		jQ('#recaptcha_response_field_msg').html('Verification code is missing');
	}
	
	if (eCount > 0) {
		return false;
	} else {
		return true;
	}
}

function postFBSignin()
{
	var dsfb = getCookie('dsfb');

	if (!dsfb) {
		var fbapi = FB.Facebook.apiClient;
		var fbu = getCookie(FAID + '_user');
		 
		if (verifyNetworkId(fbu, 2)) {
			setCookie('dsfb', fbu, null);
		}
	}
}

function profileUniqueCheck(f)
{
	var str = '';
	var fldName = '';
		
	if (f == 'regemail') {
		str = jQ('#regemail').val();
		fldName = 'Email';
	} else if (f == 'regdname') {
		str = jQ('#regdname').val();
		fldName = 'Name'
	} else {
		return;
	}
	
	 jQ.post(BU + 'user/acunique', { fname:fldName, val:str }, function(json) {
		 if (json.eCode > 1) {
			 jQ('#' + f + '_lbl').addClass('err');
			 jQ('#' + f + '_msg').html(fldName + ' is already taken');
			 return;
		 }
	 }, "json");
}

function showSignInForm()
{
	var elem = document.getElementById('pop_signin_form');
	
	if (!elem) {
		elem = document.createElement('div');
		elem.id = 'pop_signin_form';
		elem.className = 'pop_signin_form hide';
		var elem2 = document.createElement('div');
		elem2.className = 'pop_signin_form2';
		elem.appendChild(elem2);
		var elem3 = document.createElement('div');
		elem3.className = 'pop_signin_form3';
		elem2.appendChild(elem3);
		elem3.innerHTML = '<div class="signin_frm_bx">' +
			'<h1>Sign in to Desi Hits!</h1>' +
		'<div class="msg_bx" id="signin_frm_msg">' +
		'</div>' +
		'<div class="signin_frm">' +
		'<form id="signin_form" method="post">' +
			'<div class="signin_frm_rw">' +
				'<div><span class="" id="uname_lbl"><label for="uname">Desi Hits! ID</label></span>: <span class="msg" id="uname_msg"></span></div>' +
				'<div class="">' +
					'<input class="dtd" id="uname" type="text" name="uname" size="37" maxlength="64" />' +
				'</div>' +
				'<div class="clr"></div>' +
			'</div>' +
			'<div class="signin_frm_rw">' +
				'<div><span class="" id="upass_lbl"><label for="upass">Password</label></span>: <span class="msg" id="upass_msg"></span></div>' +
				'<div class="">' +
					'<input class="dtd" id="upass" type="password" name="upass" size="37" maxlength="64" />' +
				'</div>' +
				'<div class="clr"></div>' +
			'</div>' +
			'<div class="signin_frm_rw">' +
				'<input type="checkbox" id="ureme" name="ureme" value="1" checked="checked" />&nbsp;&nbsp;Remember me on this computer' +
			'</div>' +
			'<div class="signin_frm_rw but" style="text-align:right">' +
				'<input class="simplemodal-close" type="button" name="cancel_signin_but" value="Cancel" />&nbsp;&nbsp;&nbsp;' +
  				'<input type="button" name="signin_but" value="Sign In" onclick="signin(\'ajax\')" />' +
			'</div>' +
			'<div class="signin_frm_rw" style="text-align:center">' +
				'<a href="' + BU + 'user/signup">Forgot your Desi Hits! password?</a>' +
			'</div>' +
		'</form>' +
		'</div>' +
			'<div class="signin_frm_btop">' +
				'<h2>You can also</h2>' +
				'<div class="fbbut">' +
					'<!-- <fb:login-button size="medium" length="long"></fb:login-button> -->' +
				'</div>' +
				'<p>To associate your existing Desi Hits! account with your facebook account, sign in with your Desi Hits! account first and then sign in with your facebook account.</p>' +
			'</div>' +
			'<div class="clear"><!--  --></div>' +
		'<div class="signin_frm_btop">' +
			'<h2>Don\'t have a Desi Hits! ID?</h2>' +
			'<a href="' + BU + 'user/signup">Sign up FREE Desi Hits! account</a>' +
		'</div>' +
	'</div>';
		document.body.appendChild(elem);
		FB.XFBML.Host.parseDomTree();
	}
	
	jQ('#pop_signin_form').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ['10%',]});
}

function signin(signinMethod)
{
	 closeMessages('signin_frm_msg');
	 jQ("#uname").removeClass('errbdr');
	 jQ("#upass").removeClass('errbdr');
	 var signinName = jQ("#uname").val();
	 var signinPass = jQ("#upass").val();
	 var errors = new Object;
	 var eCounter = 0;
 	
	 if (signinName == '') {
		 errors['uname'] = 'Desi Hits! ID is missing';
		 eCounter += 1;
	 }
 	
	 if (signinPass == '') {
		 errors['upass'] = 'Password is missing';
		 eCounter += 1;
	 }

	 if (eCounter > 0) {
		 var msgObj = new Object;
		 msgObj.errors = errors;
		 msgObj.msg = 'Please, verify your Desi Hits! ID and password';
		 msgObj.msgType = 'error';
		 showMessages(msgObj, 'signin_frm_msg');
		 return false;
	 } else {
		 var signinReme = 0;
		 
		 if (jQ("#ureme").attr('checked')) {
			 signinReme = 1;
		 }

		 jQ.post(BU + 'user/asignin', { uname:signinName, upass:signinPass, ureme:signinReme}, function(json) {
			 if (json.eCode > 0) {
				 showMessages(json.errors, 'signin_frm_msg');
				 return;
			 }
			 
			 if (signinMethod == 'ajax') {
				 var uselem = document.getElementById('user_stat');
				 
				 if (uselem) {
					 while (uselem.firstChild)
						 uselem.removeChild(uselem.firstChild);
					 
					 uselem.innerHTML = '<h1><span>' + json.profile.nick + '</span></h1>' +
						'<h2>Following <span>0</span>/<span>0</span> Followers</h2>' +
						'<h1><span><a href="javascript:void(0)" onclick="javascript:signout()">Sign Out</a></span></h1>';
				 }

				 jQ('#comment_frm_on_but').removeClass('hide');
				 jQ('#comment_signin_msg').addClass('hide');
				 closeModal();
				 
			    //for (var i = 0; i < postLoginCommands.length; i++) {
			    //	eval(postLoginCommands[i]);
			    //}
				 if (postLoginCommands.length > 0) {
					 var str = postLoginCommands.pop();
					 eval(str);
				 }
			 } else {
				 goHome();
			 }
		 }, "json");
/*
		 if (loginMethod == 'ajax') {
			 new Ajax.Request(BU+'/index.php/user/poplogin', {
 	                parameters: $('login_form').serialize(true),
 	                onSuccess: function(transport) {
				 	var json = transport.responseText.evalJSON();

				 		if (json.eCode == 0) {
				 			updateUserBoxes(json.profile);
				 			setLogin(json.profile);
				 			closeModal();
				 			return;
				 		}

				 		showErrors(json.errors, 'modal_msg');
			 	}
 	            });
 		} else {
 			return true;
 		}
 */
 	}
}

function signout()
{
	jQ.getJSON(BU+'user/asignout', function(json){
		deleteCookie('dsfb');
		//FB.Connect.logout(goHome);
		goHome();
	});
}

function signup(signupMethod)
{
	jQ('#regemail_lbl').removeClass('err');
	jQ('#regpass_lbl').removeClass('err');
	jQ('#regcpass_lbl').removeClass('err');
	jQ('#regdname_lbl').removeClass('err');
	jQ('#regfname_lbl').removeClass('err');
	jQ('#recaptcha_response_field_lbl').removeClass('err');
	var regemail = jQ('#regemail').val();
	var regpass = jQ('#regpass').val();
	var regcpass = jQ('#regcpass').val();
	var regdname = jQ('#regdname').val();
	var regfname = jQ('#regfname').val();
	var response_field = jQ('#recaptcha_response_field').val();
	var re1 = /^\w{3,100}$/;
	var re2 = /^[A-Za-z]{2,}$/;
	var eCount = 0;
	
	if (regemail == '' || regemail.length > 128) {
		eCount += 1;
		jQ('#regemail_lbl').addClass('err');
		jQ('#regemail_msg').html('Email is not valid');
	}
	
	if (regpass == '') {
		eCount += 1;
		jQ('#regpass_lbl').addClass('err');
		jQ('#regpass_msg').html('Password is missing');
	}
	
	if (regcpass == '') {
		eCount += 1;
		jQ('#regcpass_lbl').addClass('err');
		jQ('#regcpass_msg').html('Password is missing');
	}
	
	if (regpass != '' && regcpass != '') {
		if (regpass != regcpass) {
			eCount += 1;
			jQ('#regpass_lbl').addClass('err');
			jQ('#regcpass_lbl').addClass('err');
			jq('#regpass_msg').html('Passwords do not match');
		}
	}
	
	if (regdname == '' || regdname.length < 3 || regdname.length > 100 || !re1.test(regdname)) {
		eCount += 1;
		jQ('#regdname_lbl').addClass('err');
		jQ('#regdname_msg').html('Display name is not valid');
	}
	
	if (regfname == '' || regfname.length < 2 || regfname.length > 30 || !re2.test(regfname)) {
		eCount += 1;
		jQ('#regfname_lbl').addClass('err');
		jQ('#regfname_msg').html('First name is not valid');
	}
	
	if (response_field == '') {
		eCount += 1;
		jQ('#recaptcha_response_field_lbl').addClass('err');
		jQ('#recaptcha_response_field_msg').html('Verification code is not valid');
	}
	
	if (eCount > 0) {
		jQ('#signup_frm_msg').html('<span>Error!</span><br />Please, correct field(s) highlighted in red');
		return false;
	} else {
		return true;
	}
}

var verifyNetworkCounter = 0;

function verifyNetworkId(ext_id, nid)
{
	if (verifyNetworkCounter > 0)
		return;
		
	verifyNetworkCounter += 1;
	var url = BU + 'user/avsnid/' + ext_id + '/' + nid;

	jQ.getJSON(url, function(json) {
		alert('Returned from avsnid');
		
		if (json.eCode > 0) {
			return false;
		}
		
		updateUserBoxes(json.profile);
		setLogin(json.profile);
		
		if (json.profile.vCode == 3) {
			var elem = getModalDialog();
			elem = document.getElementById('modal_content');
		
			while (elem.firstChild)
				elem.removeChild(elem.firstChild);

			elem.appendChild(genConfirmNickForm(json.profile));
			
			if (jQ('#modal_dialog').css('display') == 'none')
				jQ('#modal_dialog').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ["10%",]});	
		} else {
			var re = /signup|signin_form$/;
			
			if (location.href.match(re))
				window.location.href(BU);
			else
				closeModal();
		}
	});
	
	return true;
}
/*
 * End Sign in/Sign out
 */
 
/*
 * Item browser
 */
var itemBrowsers=new Object();

function ItemBrowser(display_count, step_size, root_div_id)
{
	this.display_count = display_count;
	this.step_size = step_size;
	this.root_div_id = root_div_id;
	this.addItem = itemBrowserAddItem;
	this.getLength = itemBrowserGetLength;
	this.init = itemBrowserInit;
	this.setItemList = itemBrowserSetItemList;
	this.shiftBackward = itemBrowserShiftBackward;
	this.shiftForward = itemBrowserShiftForward;
	this.jumpTo = itemBrowserJumpTo;
	this.update = itemBrowserShowItems;
	this.updateButtons = itemBrowserUpdateButtons;
}

function itemBrowserAddItem(ds_item)
{
	if(!this.items){
		var items=new Array();
		this.items=items;
	}
	
	this.items.push(ds_item);
}

function itemBrowserGetLength()
{
	return this.items.length;
}

function itemBrowserInit()
{
	this.start_idx = 0;
	
	if (this.items && ((this.items.length - 1) < this.display_count))
		this.end_idx = this.items.length - 1;
	else
		this.end_idx = this.display_count - 1;
		
	this.update();
}

function itemBrowserSetItemList(itmList)
{
	if (itmList instanceof Array) {
		this.items = itmList;
		this.start_idx = 0;
		
		if ((this.items.length - 1) < this.display_count)
			this.end_idx = this.items.length - 1;
		else
			this.end_idx = this.display_count - 1;		
	}
}

function itemBrowserShiftBackward()
{
	var new_start_idx = this.start_idx - this.display_count;
	
	if (new_start_idx < 0)
		this.start_idx = 0;
	else
		this.start_idx = new_start_idx;
	
	this.end_idx = this.start_idx + this.display_count - 1;
	
	if (this.end_idx > (this.items.length-1))
		this.end_idx = this.items.length-1;
	
	this.update();
}

function itemBrowserShiftForward()
{
	var new_start_idx = this.start_idx + this.display_count;
	
	if (new_start_idx > (this.items.length-1))
		this.start_idx = Math.floor((this.items.length-1)/this.display_count) * this.display_count;
	else
		this.start_idx = new_start_idx;
		
	this.end_idx = this.start_idx + this.display_count -1 ;
	
	if (this.end_idx > (this.items.length-1))
		this.end_idx = this.items.length-1;

	this.update();
}

function itemBrowserJumpTo(n)
{
	var new_start_idx = n * this.display_count;
	
	if (new_start_idx > (this.items.length-1))
		this.start_idx = Math.floor((this.items.length-1)/this.display_count) * this.display_count;
	else
		this.start_idx = new_start_idx;
		
	this.end_idx = this.start_idx + this.display_count -1 ;
	
	if (this.end_idx > (this.items.length-1))
		this.end_idx = this.items.length-1;

	this.update();	
}

function itemBrowserShowItems()
{
	var str = '';
	var el = '';
	var aEl = '';
	var imgEl = '';
	var sp1El = '';
	var sp2El = '';
	var divEl = '';
	
	if (this.root_div_id) {
		var mtEl = document.getElementById(this.root_div_id + '_pan');
		
		if (!mtEl)
			return;
		
		while (mtEl.firstChild)
			mtEl.removeChild(mtEl.firstChild);

		for (var i=this.start_idx; i<=this.end_idx; i++) {
			if (!this.items[i].hasDomEl()) {
				el = document.createElement('li');
				
				if (i == this.start_idx)
					el.className = 'fitm mod_grad_bg';
				else
					el.className = 'mod_grad_bg';
				
				divEl = document.createElement('div');
				el.appendChild(divEl);
				aEl = document.createElement('a');
				aEl.href = this.items[i].url;
				divEl.appendChild(aEl);
				sp1El = document.createElement('span');
				
				if (this.items[i].thumb_url == 'last item') {
					divEl.className = 'outer litem';
					sp1El.innerHTML = this.items[i].title;
					aEl.appendChild(sp1El);
				} else {
					divEl.className = 'outer';
					imgEl = document.createElement('img');
					imgEl.src = this.items[i].thumb_url;
					aEl.appendChild(imgEl);
					sp1El.className = 'sp1';
					sp1El.innerHTML = this.items[i].title;
					aEl.appendChild(sp1El);
				}
				
				this.items[i].setDomEl(el);
			}
			
			mtEl.appendChild(this.items[i].getDomEl());
		}
		
		this.updateButtons();
	}
}

function itemBrowserUpdateButtons()
{
	mtEl = document.getElementById(this.root_div_id + '_back_but');
	
	if (mtEl) {
		if (this.start_idx < this.display_count)
			mtEl.src="but-arrow-left-white.jpg";
		else
			mtEl.src="but-arrow-left-red.jpg";
	}
	
	mtEl = document.getElementById(this.root_div_id + '_next_but');
	
	if (mtEl) {
		if (this.end_idx >= this.items.length-1)
			mtEl.src="but-arrow-right-white.jpg";
		else
			mtEl.src="but-arrow-right-red.jpg";
	}
	
	var page_num = Math.floor(this.start_idx / this.display_count) + 1;
	var pages = Math.floor(this.items.length/this.display_count) + 1;
	
	if (pages > 3)
		pages = 3;
	
	for (var i=1; i<=pages; i++) {
		mtEl = document.getElementById(this.root_div_id + '_dot' + i);
		
		if (mtEl) {
			if (page_num == i)
				mtEl.src="but-dot-red.jpg";
			else
				mtEl.src="but-dot-white.jpg";
		}
	}
}

function DHItem(url, title, thumb_url, thumb_title, time_length, title_show_length)
{
	this.url = url;
	this.title = title;
	this.thumb_url = thumb_url;
	this.thumb_title = thumb_title;
	this.time_length = time_length;
	this.title_show_length = (title_show_length > 0) ? title_show_length : 20;
	this.dom_elem = null;
	this.hasDomEl = dhItemHasDomEl;
	this.getDomEl = dhItemGetDomEl;
	this.setDomEl = dhItemSetDomEl;
}

function dhItemHasDomEl()
{
	if (this.dom_elem == null)
		return false;
	else
		return true;
}

function dhItemGetDomEl()
{
	return this.dom_elem;
}

function dhItemSetDomEl(dom_elem)
{
	this.dom_elem = dom_elem;
}

function shiftBackward(root_id)
{
	itemBrowsers[root_id].shiftBackward();
}

function shiftForward(root_id)
{
	itemBrowsers[root_id].shiftForward();
}

function clickToPage(root_id, n)
{
	itemBrowsers[root_id].jumpTo(n);
}

function showBrowsePan(pan_prefix, root_id_str)
{
	jQ('#' + root_id_str + '_buts').children('a').removeClass('slct');
	jQ('#' + pan_prefix + '_' + root_id_str + '_but').addClass('slct');
	jQ('#' + root_id_str + '_pans').children('ul').addClass('hide');
	jQ('#' + pan_prefix + '_' + root_id_str + '_pan').removeClass('hide');
	jQ('#' + root_id_str + '_dots').children('ul').addClass('hide');
	jQ('#' + pan_prefix + '_' + root_id_str + '_but_pan').removeClass('hide');
}

function toggleBrowsePan(showPan, hidePan, showBut, hideBut)
{
	jQ('#' + hidePan + '_pan').addClass('hide');
	jQ('#' + showPan + '_pan').removeClass('hide');
	jQ('#' + hidePan + '_but_pan').addClass('hide');
	jQ('#' + showPan + '_but_pan').removeClass('hide');
}
/*
 * End Item browser
 */

/*
 * Simple Modal Dialog
 */
/*
 * Simple Modal Dialog
 * Require jquery 1.3.2 and  jquery.simplemodal 1.2.3
 */

/* gbr start */
function getModalDialog()
{
	var elem = document.getElementById('modal_dialog');
	
	if (!elem) {
		elem = document.createElement('div');
		elem.className = 'modal_dialog';
		elem.id = 'modal_dialog';
		elem.innerHTML = '<div class="modal_content" id="modal_content"></div>';
		document.body.appendChild(elem);
	}
	
	elem = document.getElementById('modal_content');
		
	while (elem.firstChild)
		elem.removeChild(elem.firstChild);
	
	return elem;
}

/* gbr end */

function ModalDialog()
{
	this.close = simpleModalClose;
	this.open = simpleModalOpen;
	this.show = simpleModalShow;
}

function simpleModalClose(dialog) {
	if (dialog && dialog.data) {
		dialog.data.fadeOut('fast', function () {
			dialog.container.hide('fast', function () {
				dialog.overlay.slideUp('fast', function () {
					jQ.modal.close();
				});
			});
		});
	}
}

function simpleModalOpen(dialog) {
	if (dialog && dialog.data) {
		dialog.overlay.fadeIn('fast', function () {
			dialog.container.fadeIn('fast', function () {
				dialog.data.slideDown('fast');
			});
		});
	}
}

function simpleModalShow(dialog) {
	if (dialog && dialog.data) {
		dialog.data.find('input.animate').one('click', function () {
			dialog.data.slideUp('fast', function () {
				dialog.data.slideDown('fast');
			});
		});
	}
}

function closeModal()
{
	if (jQ.modal)
		simpleModalClose(jQ.modal.impl.dialog);
}
/*
 * End Simple Modal Dialog
 */


var verifyVisitCounter = 0;

function verifyVisit()
{

	if (verifyVisitCounter > 0) return;
	
	verifyVisitCounter += 1;

	if (!hasSignedIn()) {
		var confirm_reg = getCookie('regconf');
		var today = new Date();
		var last_first_visit = getCookie('lfvisit');

		if (confirm_reg == '0') {
			var day_in_milli = 60000; // 2592000000 = 30 days // 86400 * 1000  (3600 = 1 hour  * 24hrs = 1day  * 1000 = milliseconds in a day)
			var since_last_first = today.getTime() - last_first_visit;
			//alert(since_last_first);
			if (since_last_first > day_in_milli) {
				pageTracker._trackEvent('newsletter', 'signup', 'hitlist');
				var elem = getModalDialog();
				document.getElementById('modal_content').appendChild(genEmailRegForm());
				if (jQ('#modal_dialog').css('display') == 'none')
					jQ('#modal_dialog').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ["10%",]});
			}
		} else if (confirm_reg == 1 || confirm_reg == 2) {
		} else {
			if (last_first_visit == '')
				setCookie('lfvisit', today.getTime(), 30);

			setCookie('regconf', '0', 30);
		}
	}
}

function NewsletterSignup()
{
	pageTracker._trackEvent('newsletter', 'signup-button', 'hitlist');
	var elem = getModalDialog();
	document.getElementById('modal_content').appendChild(genEmailRegForm());
	if (jQ('#modal_dialog').css('display') == 'none')
			jQ('#modal_dialog').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ["10%",]});
}

function NewsletterVerify()
{
	pageTracker._trackEvent('newsletter', 'verify', 'hitlist');
	var elem = getModalDialog();
	document.getElementById('modal_content').appendChild(genVerifyComplete());
	if (jQ('#modal_dialog').css('display') == 'none')
			jQ('#modal_dialog').modal({onOpen: simpleModalOpen, onClose: simpleModalClose, position: ["10%",]});
}

/*
 * Pagination
 */
function ds_load_pagin(root_div, content, category, sorted_by, sort_order, search_str, limit, offset)
{
	var root_elem = document.getElementById(root_div);
	
	if (!root_elem || content == '')
		return;
	
	var re = /\s+/g;
	var url = BU + 'main/apagin/';
	var params = new Array();
	params.push('ct=' + content);
	
	if (category > 0)
		params.push('cr=' + category);
	
	if (sorted_by > 0)
		params.push('sc=' + sorted_by);
	
	if (sort_order > 0)
		params.push('so=' + sort_order);
	
	if (search_str != '')
		params.push('ss=' + search_str);
	
	if (limit > 0)
		params.push('lt=' + limit);
	
	if (offset > 0)
		params.push('ot=' + offset);
	
	if (params.length == 0)
		return;
	
	url += params.join('&');
	url = url.replace(re, '+');
	//alert("Query string: " + url);
	
	jQ.getJSON(url, function(json){
		alert(json.result);
	});
}

function apagin(root_div, url, n)
{
	jQ.getJSON(url+n, function(json){
		if (json.eCode > 0) {
			return;
		}

		if (json.html != '') {
			jQ('#'+root_div).html(json.html);
		}
	});
}
/*
 * End Pagination
 */

/*
 * Sort form
 */
function update_sort_frm(frm_name)
{
	var elem = document.getElementById(frm_name + '_fields');
	
	if (!elem) return;
	
	window.location = jQ('#' + frm_name + '_frm_uri').val() + '/?sc=' + elem.options[elem.selectedIndex].value;
}
/*
 * End sort form
 */

/*
 * Slide box
 */
function Slider(delay, root_id)
{
	this.delay = delay;
	this.root_id = root_id;
	this.root_elem = null;
	this.current_index = 0;
	this.next_index = 1;
	this.timer = 0;
	this.slides = new Array();
	this.dots = new Array();
	this.init = slideInit;
	this.forward = slideForward;
	this.backward = slideBackward;
	this.slide = slideNext;
	this.start = slideStart;
	this.slideto = slideTo;
	this.stop = slideStop;
	this.pause = slidePause;
}

function slideInit()
{
	var slides = jQ('#' + this.root_id + ' .slide');
	var dots = jQ('#' + this.root_id + ' .slide_dot');

	for (var i=0; i<slides.length; i++) {
		this.slides.push(jQ(slides[i]).css('z-index', String(slides.length-i)).css('position', 'absolute').hide());
		this.dots.push(jQ(dots[i]));
	}
}

function slideForward()
{
	var next_index = (this.current_index + this.slides.length + 1) % this.slides.length;
	this.slideto(this.next_index);
}

function slideBackward()
{
	var next_index = (this.current_index + this.slides.length - 1) % this.slides.length;
	this.slideto(next_index);
}

function slideNext()
{
	this.slides[this.current_index].fadeOut('slow');
	this.dots[this.current_index].attr('src',  'but-dot-white.png');
	this.slides[this.next_index].find('.slide_drop').hide();
	this.slides[this.next_index].find('.slide_info').hide();
	var nidx = this.next_index;
	this.dots[nidx].attr('src',  'but-dot-orange.png');
	this.current_index = this.next_index;
	this.next_index = (this.current_index + 1) % this.slides.length;
	this.slides[nidx].fadeIn('slow', function(){
		jQ(this).find('.slide_drop').slideDown('slow');
		jQ(this).find('.slide_info').hide().slideDown('show');
	});
}

function slideTo(n)
{
	if (n < 0 || n >= this.slides.length) {
		return false;
	}
	
    if (n != this.indexCurrent){
        this.pause(5000);
        this.next_index = n;
        this.slide();
    }
    
    return false;
}

function slideStart(n)
{
    //in ms
    this.timer = setInterval('slidebox.slide()',this.delay);
    
    //lets you start at some other slide
    if (typeof n == "number"){
        this.slideto(n);
    }
    
    return true;	
}

function slideStop()
{
    if ((typeof this.timer) == "number") {
    	clearInterval(this.timer);
    }
    
    return true;
}

function slidePause(msecs)
{
    this.stop();
    this.timer = setTimeout('slidebox.start()', msecs);
}

var slidebox = null;

function init_slider()
{
	slidebox = new Slider(4000, 'slide_bx');
	slidebox.init();
	slidebox.start(0);
}
/*
 * End slide box
 */
 
 /* gbr start */
 function genEmailRegComplete()
{
	var elem = document.createElement('div');
	elem.className = 'modal_one';
	elem.innerHTML = '<div class="modal_txt">Thank you for signing up for our weekly email newsletter.</div>' +
					 '<div class="modal_but">' +
					 '<div class="flor"><input type="button" name="close" value="OK" class="simplemodal-close" onclick="closeModal()" /></div>' +
					 '<div class="clear"><!-- --></div></div>' +
					 '<div class="clear"><!-- --></div>';
	return elem;
}

 function genVerifyComplete()
{
	var elem = document.createElement('div');
	elem.className = 'modal_one';
	elem.innerHTML = '<div class="modal_txt">Thank you for verifying your email address and signing up for our weekly email newsletter.</div>' +
					 '<div class="modal_but">' +
					 '<div class="flor"><input type="button" name="close" value="OK" class="simplemodal-close" onclick="closeModal()" /></div>' +
					 '<div class="clear"><!-- --></div></div>' +
					 '<div class="clear"><!-- --></div>';
	return elem;
}

function genEmailRegForm()
{
	var elem = document.createElement('div');
	elem.className = 'modal_one';
	elem.innerHTML = '<div class="modal_head">Sign up for the Desi Hits! Newsletter</div>' +
					 '<div class="modal_body">' +
					 '<div><p>Receive weekly emails of the HOTTEST news, videos and gossip from Bollywood to Bhangra to Urban Desi</p></div>' +
					 '<div class="modal_msg" id="modal_msg"><!-- --></div>' +
					 '<div><form id="esign_frm" name="esign_frm">' +
					 '<div class="modal_frm_row"><div class="modal_lbl" id="esign_email_lbl">Email Address:</div><div class="modal_dt"><input class="modal_min" id="esign_email" type="text" name="esign_email" value="" /></div></div>' +
					 '<div class="modal_frm_row"><div class="modal_lbl" id="esign_cemail_lbl">Confirm Email Address:</div><div class="modal_dt"><input class="modal_min" id="esign_cemail" type="text" name="esign_cemail" value="" /></div></div>' +
					 '<div class="modal_but">' +
					 '<div class="flo"><div style="float:left" class="btn" onmouseover="this.className=\'btn_over\'" onmouseout="this.className=\'btn\'" onclick="esignup()">SUBMIT</div><div class="flo" style="display:inline;margin:5px 0 0 20px;padding:0"><a class="simplemodal-close" href="javascript:void(0)" onclick="refuse_esignup()">No Thanks</a></div><div class="clear"><!-- --></div></div>' +
					 '<div class="clear"><!-- --></div></div>' +
					 '</form></div></div>' +
					 '<div class="clear"><!-- --></div>';
	return elem;
}

function showErrors(errors, root_div)
{
	var elem = document.getElementById(root_div);
	
	while (elem.firstChild)
		elem.removeChild(elem.firstChild);

	var ulElem = document.createElement('ul');
	var liElem = null;
	var len = 0;
	elem.innerHTML = '<p>Error! Please, correct the following error(s)</p>';
		
	for (var i in errors) {
		len += 1;
		jQ('#' + i + '_lbl').addClass("err");
		
		if (errors[i] != '') {
			liElem = document.createElement('li');
			liElem.id = i + '_lbl_msg';
			liElem.innerHTML = errors[i];
			ulElem.appendChild(liElem);
		}
	}

	if (len > 0) {
		elem.appendChild(ulElem);
		elem.style.display = 'block';
	} else {
		elem.style.display = 'none';
	}
}

function genAccountRegForm()
{
	var elem = document.createElement('div');
	elem.className = 'modal_one';
	elem.innerHTML = '<div class="modal_head" id="regfrm_title">Sign up FREE Desi Hits! account</div>' +
					 '<div class="modal_body">' +
						'<div><p id="regfrm_desc"></p></div>' +
						'<div class="modal_msg" id="modal_msg">Error Message</div>' +
					    '<div><form id="regfrm">' +
    				 	'<div class="modal_frm_row"><div class="modal_lbl" id="regemail_lbl">Email (Desi Hits! ID):</div>' +
    					'<div class="modal_dt">' +
      						'<input class="modal_min" id="regemail" type="text" name="regemail" />' +
    					'</div></div>' +
    					'<div class="clear"><!-- --></div>' +
    					'<div class="modal_frm_row"><div class="modal_lbl" id="regpass_lbl">Password:</div>' +
    					'<div class="modal_dt">' +
      						'<input class="modal_min" id="regpass" type="password" name="regpass"  />' +
    					'</div></div>' +
    					'<div class="clear"><!-- --></div>' +
    					'<div class="modal_frm_row"><div class="modal_lbl" id="regcpass_lbl">Confirm Password:</div>' +
    					'<div class="modal_dt">' +
      						'<input class="modal_min" id="regcpass" type="password" name="regcpass"  />' +
    					'</div></div>' +
    					'<div class="clear"><!-- --></div>' +
    					'<div class="modal_frm_row"><div class="modal_lbl" id="regdname_lbl">Display Name:</div>' +
    					'<div class="modal_dt">' +
      						'<input class="modal_min" id="regdname" type="text" name="regdname"  />' +
    					'</div></div>' +
    					'<div class="clear"><!-- --></div>' +
    					'<div class="modal_frm_row"><div class="modal_lbl" id="regfname_lbl">First Name:</div>' +
    					'<div class="modal_dt" >' +
      						'<input class="modal_min" id="regfname" type="text" name="regfname" />' +
    					'</div></div>' +
   						'<div class="clear"><!-- --></div>' +
    					'<div class="modal_but2 modal_mbut">' +
    						'<input type="button" name="submit" value="Join Now" onclick="signup(\'ajax\')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
    						'<input class="simplemodal-close" type="button" name="cancel" value="Cancel" onclick="toCancelSignup(\'ajax\')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
    					'</div>' +
  					'</form>' +
      				'<div style="font-size:8pt;margin:0 0 20px 0;text-align:center">' +
      					'By clicking Join Now, you are indicating that you have read and agree to the <a href="javascript:void window.open(\'http://www.desihits.com/terms\', \'popupterms\', \'toolbar=0, location=0, directories=0,status=1, menubar=0, scrollbars=1, resizable=1\', width=\'1024\', height=\'768\')">Terms of Use</a> and <a href="javascript:void window.open(\'http://www.desihits.com/privacy\', \'popupterms\', \'toolbar=0, location=0, directories=0,status=1, menubar=0, scrollbars=1, resizable=1\', width=\'1024\', height=\'768\')">Privacy Policy</a>' +
      				'</div>' +
  					'<hr style="width:70%; text-align:center; margin-bottom:20px;" />' +
/*					'<div style="text-align:center">' +
    					'<div style="margin:5px 0">Already have Desi Hits! account, <a href="javascript:void(0)" onclick="toLogin(\'\')">sign in</a></div>' +
    					'<div style="margin:10px 0">You can also&nbsp;&nbsp;<fb:login-button size="medium" length="long"></fb:login-button></div>' +
  					'</div></div></div>' +
*/
  					'</div></div>' +					
					 '<div class="clear"><!-- --></div>';
	return elem;
}

function genConfirmNickForm(obj)
{
	var elem = document.createElement('div');
	elem.className = 'modal_one';
	elem.innerHTML = '<div class="modal_head">Welcome, ' + obj.nick + '!</div>' +
					 '<div class="modal_body">' +
					 '<div class="modal_txt">You new Desi Hits! nick name is <span style="font-weight:bold">' + obj.nick + '</span></div>' +
					 '<div class="modal_txt">To change your Desi Hits! nick name, enter your new name below and click Update</div>' +
					 '<div class="modal_msg" id="modal_nick_confirm_msg">Error Message</div>' +
					 '<form id="confirm_nick_frm">' +
					 '<div class="modal_txt">Enter your new nick name here: <input type="text" id="new_nick" name="new_nick" value="' + obj.nick + '" size="20" maxlength="128" /></div>' +
					 '<div class="flor">' +
					 '<input type="button" id="update_nick_but" name="update_nick_but" value="Update" onclick="updateNick()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
					 '<input type="button" id="update_nick_close_but" name="update_nick_close_but" value="OK" class="simplemodal-close" onclick="acceptNick()" />' +
					 '</div>' +
					 '<input type="hidden" name="uid" value="' + obj.id + '" />' +
					 '</form>' +
					 '</div>' +
					 '<div class="clear"><!-- --></div>';
	return elem;
}

function toCancelSignup(signupMethod)
{
	if (signupMethod == 'ajax') {
		closeModal();
	} else {
		window.location = BU;
	}
}

function signup(signupMethod)
{
	jQ('#regemail_lbl').removeClass("err");
	jQ('#regpass_lbl').removeClass("err");
	jQ('#regcpass_lbl').removeClass("err");
	jQ('#regdname_lbl').removeClass("err");
	jQ('#regfname_lbl').removeClass("err");
	jQ('#modal_msg').css('display', 'none');
	var elem = $('regfrm');
	var errors = new Object;
	var eCounter = 0;

	if (elem.regemail.value == '') {
		errors['regemail'] = 'Email (Desi Hits! ID) is missing';
		eCounter += 1;
	} else if (elem.regemail.value.length > 128) {
		errors['regemail'] = 'Email (Desi Hits! ID) is too long, maximum 128 characters';
		eCounter += 1;
	}
	
	if (elem.regpass.value == '') {
		errors['regpass'] = 'Password is missing';
		eCounter += 1;
	}

	if (elem.regcpass.value == '') {
		errors['regcpass'] = 'Confirm password is missing';
		eCounter += 1;
	}

	if (elem.regpass.value != '' && elem.regcpass != '') {
		if (elem.regpass.value != elem.regcpass.value) {
			errors['regpass'] = 'Password and confirm password do not match';
			errors['regcpass'] = '';
			eCounter += 1;
		}
	}
	
	var re1 = /^\w{3,100}$/;
	
	if (elem.regdname.value == '') {
		errors['regdname'] = 'Display name is missing';
		eCounter += 1;
	} else if (elem.regdname.value.length < 3) {
		errors['regdname'] = 'Display name is too short, should be only letters, numbers or underscores between 3 and 100 characters';
		eCounter += 1;
	} else if (elem.regdname.value.length > 100) {
		errors['regdname'] = 'Display name is too long, should be only letters, numbers or underscores between 3 and 100 characters';
		eCounter += 1;
	} else if (!re1.test(elem.regdname.value)) {
		errors['regdname'] = 'Display name is not valid, should be only letters, numbers or underscores between 3 and 100 characters';
		eCounter += 1;	
	}

	var re2 = /^[A-Za-z]{2,30}$/;
		
	if (elem.regfname.value == '') {
		errors['regfname'] = 'First name is missing';
		eCounter += 1;
	} else if (elem.regfname.value.length < 2) {
		errors['regfname'] = 'First name is too short, should be only letter and between 2 and 30 characters';
		eCounter += 1;
	} else if (elem.regfname.value.length > 30) {
		errors['regfname'] = 'First name is too long, should be only letter and between 2 and 30 characters';
		eCounter += 1;
	} else if (!re2.test(elem.regfname.value)) {
		errors['regfname'] = 'First name is not valid, should be only letters and between 2 and 30 characters';
		eCounter += 1;
	}

	if (eCounter > 0) {
		showErrors(errors, 'modal_msg');
		return false;
	} else {
		if (signupMethod == 'ajax') {
		    new Ajax.Request('/index.php/user/popsignup', {
	                parameters: $('regfrm').serialize(true),
	                onSuccess: function(transport) {
	                	var json = transport.responseText.evalJSON();
	                	
	                	if (json.eCode == 0) {
	                		json.profile.nick = elem.regdname.value;
	                		updateUserBoxes(json.profile);
	                		setLogin(json.profile);
	                		pageTracker._trackPageview("/user/user-signup-sucess");
	                		closeModal();
	                		return;
	                	}

						showErrors(json.errors, 'modal_msg');
	                }
	            });
		} else {
			return true;
		}
	}
}

function updateUserBoxes(obj)
{
	var str = '';
	var str2 = '<input type="checkbox" id="fb_cbox" name="fb_cbox" value="1" /> Publish this comment on Facebook';
	
	if (obj.id >0) {
		str = '[&nbsp;<a href="' + BU + 'user/profile/' + obj.id + '">' + obj.nick + '</a>&nbsp;]';
		
		if (getCookie(FAID + '_user')) {
			str += '&nbsp;&nbsp;<img src="http://static.ak.fbcdn.net/images/icons/favicon.gif" alt="" />';
		} else {
			str += '&nbsp;&nbsp;You can also&nbsp;&nbsp;<fb:login-button size="medium" length="long"></fb:login-button>';
			str2 = 'You can also&nbsp;&nbsp;<fb:login-button size="medium" length="long"></fb:login-button>';
		}
		
		str += '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0)" onclick="signout()">Sign out</a>';
		jQ('#login_msg').html(str);
		jQ('#comment_fb_cbox').html(str2);
		FB.XFBML.Host.parseDomTree();
	} 
}

function process_submit(){
	var alphaRegex = /^([a-zA-Z ]+)$/;
	var numRegex = /^([0-9]+)$/;
	var emailRegex = /^([a-zA-Z0-9_]+@[a-zA-Z0-9]+[\.][a-zA-Z]+)$/;
	var is_valid = true;
	var err_message = "";
	if(document.blackeyedpeas_form.name.value.length < 1){
		is_valid = false;
		err_message += "Please enter a name\n";
	}else{
		if(!alphaRegex.test(jQ('#name').val())){
			is_valid = false;
			err_message += "Please only fill in characters and space for name\n";
		}
	}
	if(document.blackeyedpeas_form.email.value.length < 1){
		is_valid = false;
		err_message += "Please enter a valid email address. For example name@email.com\n";
	}else{
		if(!emailRegex.test(jQ('#email').val())){
			is_valid = false;
			err_message += "Please enter a valid email address. For example name@email.com\n";
		}
	}
	if(document.blackeyedpeas_form.age.value.length < 1){
		is_valid = false;
		err_message += "You must be over the age of 18 to enter\n";
	}else{
		if(!numRegex.test(jQ('#age').val()) || jQ('#age').val() < 18){
			is_valid = false;
			err_message += "You must be over the age of 18 to enter\n";
		}
	}
	if(document.blackeyedpeas_form.city.value.length < 1){
		is_valid = false;
		err_message += "Please enter a city\n";
	}else{
		if(!alphaRegex.test(jQ('#city').val())){
			is_valid = false;
			err_message += "Please only fill in characters and space for city\n";
		}
	}
	if(document.blackeyedpeas_form.state.value.length < 1){
		is_valid = false;
		err_message += "Please enter a state\n";
	}else{
		if(!alphaRegex.test(jQ('#state').val())){
			is_valid = false;
			err_message += "Please enter your state or county\n";
		}
	}
	if(document.blackeyedpeas_form.country.value.length < 1){
		is_valid = false;
		err_message += "Please enter a country\n";
	}else{
		if(!alphaRegex.test(jQ('#country').val())){
			is_valid = false;
			err_message += "Please only fill in characters and space for country\n";
		}
	}
	if(document.blackeyedpeas_form.area_code.value.length < 1){
		is_valid = false;
		err_message += "Please enter a valid area code\n";
	}else{
		if(!numRegex.test(jQ('#area_code').val()) || document.blackeyedpeas_form.area_code.value.length < 2){
			is_valid = false;
			err_message += "Please enter a valid area code\n";
		}
	}
	if(document.blackeyedpeas_form.phone.value.length < 1){
		is_valid = false;
		err_message += "Please enter a valid phone number\n";
	}else{
		if(!numRegex.test(jQ('#phone').val()) || document.blackeyedpeas_form.phone.value.length < 5){
			is_valid = false;
			err_message += "Please enter a valid phone number\n";
		}
	}
	if(!is_valid) alert(err_message);
	else document.blackeyedpeas_form.submit();
}

 /* gbr end */
