function closeDailog()
{
	$.modal.close();
	document.body.style.overflow="visible";
}

function openVideo(name,imgName)
{
	$("body").css("overflow","hidden");
	$("#playerDiv").modal({
		minHeight: 445,
		minWidth:655,
		containerCss:{backgroundColor:"black"},
		closeClass:"videoClose",
		opacity: 95,
		onClose:function(dialog){
					closeDailog();
				}
	});
	createPlayerDiv(name, imgName);
}

function createPlayerDiv(name, imgName)
{
	//name = "N24.flv";
	var s1 = new SWFObject(documentRoot+'gallery/videos/mediaplayer.swf','mediaplayer','650','440','7');	s1.addParam('allowfullscreen','true');
	s1.addParam("menu","false");
	s1.addVariable('width','650');
	s1.addVariable('height','440');	
	s1.addVariable('image',documentRoot+'gallery/videos/images/'+imgName);
	s1.addVariable('file',documentRoot+'/gallery/videos/'+name);
	s1.addVariable('image',documentRoot+'gallery/videos/images/'+imgName);
	s1.write('container');	
}

function loadingMessage(val)
{
	if(val)
	{
		var width = $(window).width();
		var height = $(window).height();
		$("#overlayDiv").css({width: width, height: height});
		$("#overlay-image").css({width: width, height: height});
		$("#overlayMain").show();
	}
	else
	{
		$("#overlayMain").hide();	
	}
	
}

function apiRequest(details, onSuccess, onError, valueString)
{
    $.ajax({
	url: details.url,dataType: "html",
	type: details.type,data: details.string,
	cache:details.cache,
	success: function(data)
	{
	   onSuccess(data, valueString);
	},
	error: function(data)
	{
	    if(onError == undefined)
		alert("Process not completed"); return;
	    onError(data);
	}
						
    });
	
}
// Edit user details
function userDetails(usrId, ext)
{
    document.body.style.overflow = "hidden";
    var urlString = "usrId="+usrId+"&getBack="+ext;
    apiRequest({url: "edit_user_details.php", type: "GET",
	string: urlString, cache: true},
	userDetailModal,
	function(data){alert("Cannot load user details");}, null);
}

function editLanguage(lngId)
{
    document.body.style.overflow = "hidden";
    var urlString = "lang_id="+lngId;
    apiRequest({url: "edit_language", type: "GET",
	string: urlString, cache: true},
	userDetailModal,
	function(data){alert("Cannot load user details");}, null);
}
function addLanguage()
{
    document.body.style.overflow = "hidden";
    var urlString = "action=add_new_language";
    apiRequest({url: "add_language", type: "GET",
	string: urlString, cache: true},
	userDetailModal,
	function(data){alert("Cannot load user details");}, null);
}
function userDetailModal(data)
{
    $.modal(data,{
	    containerCss:{border:"solid 2px #d8dad9"},
	    onClose: function(dialog)
	    {
			closeDialogRole();
			window.location.reload();
	    }
    });
}
//for user suggestions 
function userSuggestion(url)
{
    document.body.style.overflow = "hidden"; 
	url = url.replace("&","#");
    var urlString = "action=Suggestion&url="+url;
    apiRequest({url: DOCUMENT_ROOT+"users/user_suggestion.php", type: "POST",
	string: urlString, cache: true},
	userDetailModal,
	function(data){alert("Cannot load user page");}, null);
}
function closePopUp()
{
	document.body.style.overflow = "visible";
	$.modal.close();
}


// Validations............
function validate(theform)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if(theform.username.value.length=='')
	{
		alert("please enter ur username");
		theform.username.focus();
		return(false);
	}
	if(theform.username.value.length<6)
	{
		alert("please enter ur username minimum 6 characters");
		theform.username.focus();
		return(false);
	}
	if(theform.password.value.length=='')
	{
		alert("please enter ur password");
		theform.password.focus();
		return(false);
	}
	if(theform.password.value.length<7)
	{
		alert(" please enter ur password maximum 7 characters");
		theform.password.focus();
		return(false);
	}
	if(theform.confirmpassword.value.length==0)
	{
		alert("please enter ur confirmpassword");
		theform.confirmpassword.focus();
		return(false);
	}
	if(theform.password.value!=theform.confirmpassword.value)
	{
		alert(" Your Pasworrs didn't match,Try again");
		theform.confirmpassword.focus();
		return(false);
	}
	if(theform.firstname.value.length==0)
	{
		alert("please enter ur firstname");
		theform.firstname.focus();
		return(false);
	}
	if(reg.test(theform.email.value) == false)
	{
		alert('Invalid Email Address');
		theform.email.focus();
		return false;
	}
	if(theform.question.value==0)
	{
		alert("please select any question");
		theform.question.focus();
		return(false);
	}
	if(theform.answer.value.length=='')
	{
		alert("please write ur answer");
		theform.answer.focus();
		return(false);
	}
	if(theform.securitycode.value.length=='')
	{
		alert("please write ur Securitycode");
		theform.securitycode.focus();
		return(false);
	}
	return(true);
} 
function validatepassword(theform)
{
	if(theform.password.value.length==0)
	{
		alert("please enter your old password");
		theform.password.focus();
		return(false);
	}
	if(theform.newpassword.value.length==0)
	{
		alert("please enter your new password");
		theform.newpassword.focus();
				return(false);
	}
	if(theform.changepassword.value.length==0)
	{
		alert("please enter your Re-type password");
		theform.changepassword.focus();
				return(false);
	}
	if(theform.newpassword.value!=theform.changepassword.value)
	{
		alert("Your password's didn't match ,Try again");
		return(false);
	}
	return(true);
}
function updatedetails(theform)
{
	var reg1 = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(theform.fname.value.length==0)
	{
		alert("please enter ur firstname");
		theform.firstname.focus();
		return(false);
	}
	if(reg1.test(theform.email.value) == false)
	{
		alert('Invalid Email Address');
		theform.email.focus();
		return false;
	}
	if(theform.securitycode.value.length=='')
	{
		alert("please write ur Securitycode");
		theform.securitycode.focus();
		return(false);
	}
		return(true);
}
 
