
$(document).ready(function(){

//changes product color
$("select[name='id[2]']").change(function(){

  $('.replaceThumb').attr('src', $("input[name='image_directory_big']").attr('value') + "_" + this.options[this.selectedIndex].text.toLowerCase()+ ".jpg");
  $('.replaceLink').attr('href', $("input[name='image_directory_big']").attr('value') + "_" + this.options[this.selectedIndex].text.toLowerCase()+ ".jpg");
  $('.oscwp_p_backpic img').attr('src', $("input[name='image_directory_back']").attr('value') + "_" + this.options[this.selectedIndex].text.toLowerCase()+ "_back.jpg");	  


});
	


//custom select box
	//define custom selectbox
	//if( $('.select_1').length > 0 ) $('.select_1').selectbox();
	
	//$('#top_slide').animate({top: '-129px'});
	//ipod player init
	if($('#placeholder1').length > 0){
		createPlayer()	
	}
	
	//video lists
	if($('.video_list').length > 0 ){
			$('.video_list dd a').hover(
				function(){
					$(this).next().fadeIn();
					$(this).parent().css('z-index','100');
				},
				function(){
				}
			);
			
			$('.video_list dd .video_pop').hover(
				function(){
				},
				function(){
					$(this).fadeOut();
					$(this).parent().css('z-index','2');
				}
			);
		
	}
	
	
	//up & down top slider
	if( $('.butn_topSlide').length > 0 ){
			$('.butn_topSlide').click(
				function(){
					$('.top_slideInner').slideToggle();
					/*if($(this).parent().parent().hasClass('open'))
						$(this).parent().parent().removeClass('open').animate({top: '-169px'});
					else
						$(this).parent().parent().addClass('open').animate({top: '0px'});*/
				}
			);
		
	}
	
	
	
	
	//up & down bottom slider
	if( $('.butn_btmSlide').length > 0 ){
			$('.butn_btmSlide').click(
				function(){
					if($(this).parent().hasClass('open')){
						$(this).parent().removeClass('open');
						$(this).parent().find('.hidden').slideUp();
					}
					else{
						$(this).parent().addClass('open');
						$(this).parent().find('.hidden').slideDown();
					}
				}
			);
		
	}
	
	//input question
	if( $('.qus_icon').length > 0 ){
			$('.qus_icon').hover(
				function(){	
					$('.qus_icon em').hide();
					$(this).find('.question_1').stop(true,true).fadeIn();
					placeCenter($(this).find('.question_1 i'));
				},
				function(){
					$(this).find('.question_1').fadeOut();	
				}
			);
			
			$('.qus_icon em').hover(
				function(){			
				},
				function(){
					$(this).fadeOut();	
				}
			);
			
			
			//put wrapper
			$('em.question_1').wrapInner(document.createElement("i"));
			
	}
	
	
	
	if( $('.friend_link').length > 0 ){
		$('.friend_link').click(
			function(){
				if($(this).parent().find('.friend_box').hasClass('open'))
					$(this).parent().find('.friend_box').removeClass('open').animate({left: '-255px'},600);	
				else
					$(this).parent().find('.friend_box').addClass('open').animate({left: '0px'},600);
			}
		);	
	}
	
	if( $('.issue_cont dd').length > 0 ){
		$('.issue_cont dd').hover(
			function(){
				var height=$(this).find('.trans_box').height();
				height=116-height;
				$(this).find('.trans_box').animate({top:height+'px'});	
			},
			function(){
				$(this).find('.trans_box').animate({top:'100px'});	
			}
		);
	}
	
	//all issues check
	if( $('.upToDate .chck_all').length > 0 ){
		$('.upToDate .chck_all').click(
			function(){	
				if($(this).attr('checked'))
					$('.upToDate .inpChk_1').attr('checked',true);
				else
					$('.upToDate .inpChk_1').attr('checked',false);
			}
		);
	}
	
	//show signin div
	if( $('.sign_In a').length > 0 ){
		$('.sign_In a').click(
			function(){	
				$(this).parent().parent().parent().hide();
				$('.retCont').fadeIn();
			}
		);
	
	}
	
	if( $('.signinshow').length > 0 ){
		$('.signinshow').click(
			function(){	
				$(this).parent().parent().hide();
				$(this).parent().parent().next().fadeIn();
			}
		);
	}
	
	if( $('.ret_show').length > 0 ){
		$('.ret_show').click(
			function(){	
				$(this).parent().parent().hide();
				$('.retCont').fadeIn();
			}
		);
	}
	
	

	
	
	
	
 });


var curBnr=0;
function runBnr(){
	var allBnr=jQuery('.rotate_banner a');
	jQuery(allBnr[curBnr]).fadeOut(2000);
	curBnr=curBnr+1;
	if(curBnr==allBnr.length)
	curBnr=0;
	jQuery(allBnr[curBnr]).fadeIn(2000);
}

//LOAD IFRAME	
function loadIframe(){
	$('#phone-frame iframe').attr('src', $('.share_icon_phone').attr('href'));
	
	overlay('phone-frame');
	
}


//forget Password

function retPassword(id){
	
	
	if(id==1){
		var data = 'retPass=1&email=' + $('#ret_email').val();
		
		$.ajax({
			url: TemplatePath+'/ajax.php',	
			type: "POST",		
			data: data,		
			cache: false,
			success: function (html) {	
				if(html==-2){
					$('.retCont	.errMsg1').html('please enter a valid email address');
				}
				else if(html==-1){
					$('.retCont	.errMsg1').html('You are not registered yet');
				}
				else if(html==0){
					$('.retCont	.errMsg1').html('Could not send mail. Please try again.');
				}
				else if(html==1){
					$('.retCont	.errMsg1').html('Your new password is sent to your email address');	
				}	
				$('.retCont	.errMsg1').fadeIn();
				
			}		
		});	
	}
	else if(id==2){
		var data = 'retPass=1&email=' + $('#for_email').val();

		$.ajax({
			url: TemplatePath+'/ajax.php',	
			type: "POST",		
			data: data,		
			cache: false,
			success: function (html) {				
				if(html==-2){
					$('.retMsg').html('please enter a valid email address').fadeIn();
				}
				else if(html==-1){
					$('.retMsg').html('You are not registered yet').fadeIn();
				}
				else if(html==0){
					$('.retMsg').html('Could not send mail. Please try again.').fadeIn();
				}
				else if(html==1){
					$('.retMsg').html('Your new password is sent to your email address').fadeIn();	
				}	
			}		
		});	
	}
}


function showPlayer(){
	$('#playerHolder').fadeIn();
	
}

function hidePlayer(){
	//alert(1);
	//player2.startTimer(null);
	$('#playerHolder').fadeOut();	
}

function playShareVideo(enId){
	setTimeout(function() {
		player.runFunction('http://video.wegiveadamn.org/videos/'+enId+'-152636.mp4');
		viewMedia(enId);
	},2000);


}


		
var player = null;
	
	function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
			}

	function createPlayer() {
            var flashvars = {
					file:"mainvideo.flv", 
					autostart:"false",
					fullscreen:"true",
					mute:"false",
					controlbar:"none",
					caption:"true",
					logo:"logo.png",
					icons:"false",
					provider:"video",
					stretching:"uniform",
					image:"image.jpg",
					skin:TemplatePath+"/Scripts/purpleskin.zip",
					quality:"true",
					plugins:TemplatePath+"/Scripts/ipod.swf"
					
            }
            var params = {
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
					wmode:"transparent"
            }
            var attributes = {
                    id:"player1",  
                    name:"player1",
					wmode:"transparent"
            }

            swfobject.embedSWF(TemplatePath+"/Scripts/player-licensed.swf", "placeholder1", "390", "250", "9.0.115", false, flashvars, params, attributes);
			
			
        }


function checkSignForm(cls){
	var login = $('.'+cls+' input[name=log]');
	var pwd = $('.'+cls+' input[name=pwd]');
	
	if(login.val()==''){
		login.next().find('em i').html('Email address is required.').parent().fadeIn();
		placeCenter(login.next().find('em i'));
		return false;
	}
	else{
		login.next().find('em').fadeOut();	
	}
	
	if(pwd.val()==''){
		pwd.next().find('em i').html('Password is required.').parent().fadeIn();
		placeCenter(pwd.next().find('em i'));
		return false;
	}
	else{
		pwd.next().find('em').fadeOut();	
	}
	
	if(cls=='tell3'){
		var data = 'signIn=1&login=' + login.val()+'&pwd=' + pwd.val();
		$.ajax({
			url: TemplatePath+'/ajax.php',	
			type: "POST",		
			data: data,		
			cache: false,
			success: function (html) {				

				var pwd = $('.'+cls+' input[name=pwd]');
				if(html>0){
					
					pwd.next().find('em').fadeOut();
					if($('input[name=quick_login]').val()==0){
						$('input[name=quick_login]').val(0);
						// JEH - Note that the below isn't secure - but it works FOR NOW
						document.location.href=document.location.href + "&user_id=" + html;
					}
					else{
						$('input[name=quick_login]').val(0);
						var from=$('input[name=reg_for]').val();
						
						if(from=='tell')
							overlay('tellFriend');
						else if(from=='story')
							document.location.href=SiteUrl+'/user/post-a-story';
						else if(from=='video')
							saveVideoUserId();
					}
						
				}
				else if(html==0){
					pwd.next().find('em i').html('Wrong login information.').parent().fadeIn();
					placeCenter(pwd.next().find('em i'));
				}

			}		
		});			
	}
	else
		return true;
}

function placeCenter(ele){
	var H=ele.height();
	if(H < 65){
		var top=parseInt((65-H)/2);
		ele.css('top',top+'px');
	}	
}


function regFor(val){
	$('input[name=reg_for]').val(val);
	$('input[name=quick_login]').val(1);
	overlay('pledgeOverlayBig');		
}

var pledgeForm='';
function checkPledgeForm(cls,form){
	var first_name = $('.'+cls+' input[name=first_name]');
	var zip = $('.'+cls+' input[name=zip_code]');
	var email = $('.'+cls+' input[name=email_address]');	

	var newsletter_signup='';
	if($('.'+cls+' input[name=newsletter_signup]').attr('checked')) newsletter_signup='nws';

	pledgeForm=form;

	if(first_name.val()==''){
		first_name.next().find('em i').html('Name is required.').parent().fadeIn();
		placeCenter(first_name.next().find('em i'));
		return;
	}
	else{
		first_name.next().find('em').fadeOut();	
	}
	
	if(zip.val()==''){
		zip.next().find('em i').html('Zip Code is required.').parent().fadeIn();
		placeCenter(zip.next().find('em i'));
		return;
	}
	else{
		zip.next().find('em i').fadeOut();	
	}
	
	if(email.val()==''){
		email.next().find('em i').html('Email is required.').parent().fadeIn();
		placeCenter(email.next().find('em i'));
		return;
	}
	else{
		email.next().find('em').fadeOut();	
	}
	
	if (!email.val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){
		email.next().find('em i').html('Not a valid email address.').parent().fadeIn();
		placeCenter(email.next().find('em i'));
		return;
	}
	else{
		email.next().find('em').fadeOut();	
	}
	
	if(cls=='laybig'){
		var pass = $('.'+cls+' input[name=over_password]');
		var conf_pass = $('.'+cls+' input[name=over_conf_password]');
		
		if(pass.val()==''){
			pass.next().find('em i').html('Password is required.').parent().fadeIn();
			placeCenter(pass.next().find('em i'));
			return;
		}
		else{
			pass.next().find('em').fadeOut();	
		}
		
		if(pass.val()!= conf_pass.val()){
			conf_pass.next().find('em i').html('Password is not same.').parent().fadeIn();	
			placeCenter(conf_pass.next().find('em i'));
			return;
		}
		else{
			conf_pass.next().find('em').fadeOut();	
		}
		
		var way=2;
	}
	else{
		var way=1;	
	}
	

	if(way==2)
		var data = 'chk_email=1&email=' + email.val()+'&first_name=' + first_name.val()+'&pwd=' + conf_pass.val()+'&zip=' + zip.val()+'&way=' + way+'&newsletter_signup=' + newsletter_signup;
	else
		var data = 'chk_email=1&email=' + email.val()+'&first_name=' + first_name.val()+'&zip=' + zip.val()+'&way=' + way+'&newsletter_signup=' + newsletter_signup;
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				

				if (html==1) {					

					if(pledgeForm=='home')
						document.pledgeHome.submit();	
					else if(pledgeForm=='homeOverlay')
						document.pledgeOverlayHome.submit();
					else if(pledgeForm=='top')
						document.pledgeTop.submit();
					else if(pledgeForm=='overlay'){
						document.pledgeOverlay.submit();
					}
					else if(pledgeForm=='overlayBig'){
						$('input[name=quick_login]').val(0);
						var from=$('.'+cls+' input[name=reg_for]').val();
						if(from=='tell')
							overlay('tellFriend');
						else if(from=='story')
							document.location.href=SiteUrl+'/user/post-a-story';
						else if(from=='video')
							saveVideoUserId();
					}
					else if(pledgeForm=='right')
						document.pledgeRight.submit();

				} else {

					$('.'+cls+' input[name=email_address]').next().find('em i').html('This Email Address Already Exists.').parent().fadeIn();
					placeCenter($('.'+cls+' input[name=email_address]').next().find('em i'));
					return;
				}			
			}		
		});
}


function memSignChk(upd){
	var first_name = $('input[name=reg_first_name]');
	var zip = $('input[name=reg_zip_code]');
	var email = $('input[name=reg_email]');		
	var pass = $('input[name=reg_password]');
	var conf_pass = $('input[name=reg_conf_password]');	
	var update = $('input[name=profileupd]');
	
	var newsletter_signup='';
	if($('input[name=newsletter_signup]').attr('checked')) newsletter_signup='nws';
	
	var chk=false;
	
	if(first_name.val()=='')
		first_name.removeClass('inpTxt_5');
	else
		first_name.addClass('inpTxt_5');
		
	if(zip.val()=='')
		zip.removeClass('inpTxt_5');
	else
		zip.addClass('inpTxt_5');
		
	if(email.val()=='')
		email.removeClass('inpTxt_5');
	else
		email.addClass('inpTxt_5');
		
	if(pass.val() != '' || conf_pass.val() != '' ){
		if(pass.val()=='')
			pass.removeClass('inpTxt_5');
		else
			pass.addClass('inpTxt_5');
			
		if(conf_pass.val()=='')
			conf_pass.removeClass('inpTxt_5');
		else
			conf_pass.addClass('inpTxt_5');
	}
	
	if(first_name.val()=='' || zip.val()=='' || email.val()==''){
		$('.errMsg1').html('Please complete the red bordered fields.').fadeIn();
		chk=true;
	}
	else{
		$('.errMsg1').fadeOut();	
	}
	
	if(update!='y'){
		if( pass.val() != '' || conf_pass.val() != ''){
			if(pass.val()=='' || conf_pass.val()==''){
				$('.errMsg2').html('Please complete the red bordered fields.').fadeIn();
				chk=true;
			}
			else{
				$('.errMsg2').fadeOut();	
			}
		}
	}
	
	if(chk)
		return;
	
	
	
	if (!email.val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){
		$('.errMsg1').html('Not a valid email address.').fadeIn();
		email.removeClass('inpTxt_5');
		return;
	}
	else{
		$('.errMsg1').fadeOut();
		email.addClass('inpTxt_5');
	}
	
	
	if(update!='y'){
		if(pass.val() != conf_pass.val()){
			$('.errMsg2').html('Please retype the same password').fadeIn();
			pass.removeClass('inpTxt_5');
			conf_pass.removeClass('inpTxt_5');
			return;
		}
		else{
			pass.addClass('inpTxt_5');
			conf_pass.addClass('inpTxt_5');	
		}
	}
	

	
	var data = 'chk_email=1&upd='+upd+'&email=' + email.val() +'&newsletter_signup='+newsletter_signup;
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				if (html==1) {					
					document.memberSign.submit();		

				} else {
					$('.errMsg1').html('This Email Address Already Exists For Another User.').fadeIn();
					$('input[name=email_address]').removeClass('inpTxt_5');
					return;
				}			
			}		
		});
	
	
}

function contactChk(){
	var first_name = $('input[name=reg_first_name]');
	var zip = $('input[name=zip]');
	var email = $('input[name=reg_email]');	
	var post_content = $('textarea[name=post_content]');	
	
	var chk=false;		
	
	if(first_name.val()=='' || zip.val()=='' || email.val()=='' || post_content.val()==''){
		$('.errMsg1').html('Please complete the red bordered fields.').fadeIn();
		chk=true;
	}
	else{
		$('.errMsg1').fadeOut();	
	}
	
	if(chk)
		return;
	
	
	
	if (!email.val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){
		$('.errMsg1').html('Not a valid email address.').fadeIn();
		email.removeClass('inpTxt_4');
		return;
	}
	else if(chk==false){
		$('.errMsg1').fadeOut();
		email.addClass('inpTxt_4');
		document.contactuser.submit();
	}
	
	
/*	var data = 'chk_contact=1&reg_email=' + email.val()+'&reg_first_name=' + first_name.val()+'&last_name=' + last_name.val()+'&address=' + address.val()+'&city=' + city.val()+'&state=' + state.val()+'&zip=' + zip.val()+'&post_content=' + post_content.val()+'&subject=' + subject.val();
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				if (html==1) {					
					$('.errMsg1').html('Thanks for contacting us. Email confirmation sent to admin.').fadeIn();

				} else {
					$('.errMsg1').html('Email cannot send at this moment. Please try again later.').fadeIn();
					$('input[name=email_address]').removeClass('inpTxt_5');
					return;
				}			
			}		
		});
*/	
	
}
function memUpdChk(upd){
	var first_name = $('input[name=reg_first_name]');
	var zip = $('input[name=reg_zip_code]');
	var email = $('input[name=reg_email]');		
	var pass = $('input[name=reg_password]');
	var conf_pass = $('input[name=reg_conf_password]');	
	
	var chk=false;
	
	if(first_name.val()=='')
		first_name.removeClass('inpTxt_5');
	else
		first_name.addClass('inpTxt_5');
		
	if(zip.val()=='')
		zip.removeClass('inpTxt_5');
	else
		zip.addClass('inpTxt_5');
		
	if(email.val()=='')
		email.removeClass('inpTxt_5');
	else
		email.addClass('inpTxt_5');
		
	if(pass.val()!='' || conf_pass.val()!=''){
		if(pass.val()=='')
			pass.removeClass('inpTxt_5');
		else
			pass.addClass('inpTxt_5');
			
		if(conf_pass.val()=='')
			conf_pass.removeClass('inpTxt_5');
		else
			conf_pass.addClass('inpTxt_5');
	}
	
	if(first_name.val()=='' || zip.val()=='' || email.val()==''){
		$('.errMsg1').html('Please complete the red bordered fields.').fadeIn();
		chk=true;
	}
	else{
		$('.errMsg1').fadeOut();	
	}
	
	if(pass.val()!='' || conf_pass.val()!=''){
		if(pass.val()=='' || conf_pass.val()==''){
			$('.errMsg2').html('Please complete the red bordered fields.').fadeIn();
			chk=true;
		}
		else{
			$('.errMsg2').fadeOut();	
		}
	}
	
	if(chk)
		return;
	
	
	
	if (!email.val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){
		$('.errMsg1').html('Not a valid email address.').fadeIn();
		email.removeClass('inpTxt_5');
		return;
	}
	else{
		$('.errMsg1').fadeOut();
		email.addClass('inpTxt_5');
	}
	
	if(pass.val()!='' || conf_pass.val()!=''){
		if(pass.val() != conf_pass.val()){
			$('.errMsg2').html('Please retype the same password').fadeIn();
			pass.removeClass('inpTxt_5');
			conf_pass.removeClass('inpTxt_5');
			return;
		}
		else{
			pass.addClass('inpTxt_5');
			conf_pass.addClass('inpTxt_5');	
		}
	}
	

	
	var data = 'chk_email=1&upd='+upd+'&email=' + email.val();
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				if (html==1) {					
					document.memberSign.submit();		

				} else {
					$('.errMsg1').html('This Email Address Already Exists For Another User.').fadeIn();
					$('input[name=email_address]').removeClass('inpTxt_5');
					return;
				}			
			}		
		});
	
	
}

//set share link



function setLink(pg_link,post_id){
	$('input[name=pg_link]').val(pg_link);
	if(post_id != '')
		$('input[name=post_id]').val(post_id);

	if(SHARE_TYPE=='video'){
		$('input[name=post_id]').val(VIDEO_ID);	
	}
		
	$('input[name=friend_name]').val('');
	$('input[name=tell_email]').val('');	
	$('textarea[name=tell_message]').val('');	
		
	var data = 'showfr=1&user_id='+$('input[name=user_id]').val();
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				//alert(html);
				if (html) {		

					$('.friend_box').html(html);		
				}			
			}
	});
}

var SHARE_TYPE='';
var VIDEO_ID='';


function setVideoShare(){
	SHARE_TYPE='video';
}

//send mail for tell a friend
function TellFriend(pg_link){

	var friend_name = $('input[name=friend_name]');
	var email = $('input[name=tell_email]');
	var message = $('textarea[name=tell_message]');	
	var user_id = $('input[name=user_id]');
	var post_id = $('input[name=post_id]');
	var pg_link = $('input[name=pg_link]');
	

	if(friend_name.val()=='' || email.val()=='' || message.val()==''){
		$('.errMsg1').html('Please complete all the fields').fadeIn();
		return;
	}
	else
		$('.errMsg1').html('').fadeOut();
		
	if (!email.val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){
		$('.errMsg1').html('Not a Valid Email Address').fadeIn();
		return;
	}
	else
		$('.errMsg1').html('').fadeOut();

	//var pg_link=document.location.href;
	//var pg_link=SHARE_LINK;
	var data = 'tellfr=1&friend_name='+friend_name.val()+'&email=' + email.val()+'&message=' + message.val()+'&user_id=' + user_id.val()+'&post_id=' + post_id.val()+'&pg_link=' + pg_link.val()+'&share_type=' + SHARE_TYPE;
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {
				
				var data = 'showfr=1&user_id='+user_id.val();
					//start the ajax
						$.ajax({
							//this is the php file that processes the data and send mail
							url: TemplatePath+'/ajax.php',	
							
							//POST method is used
							type: "POST",
							//pass the data			
							data: data,		
							//Do not cache the page
							cache: false,
							//success
							success: function (html) {				
								if (html) {		
				
									$('.friend_box').html(html);		
								}			
							}
					});

				if (html!=0) {					
					$('.errMsg1').html('Page is successfully sent to your friend.').css('font-weight','bold').fadeIn();					
				} else {
					$('.errMsg1').html('Could not send email.').fadeIn();
					return;
				}			
			}		
		});	
}


//save video
function saveVideo(){
	var title = $('input[name=vid_title]');
	var cat_id = $('select[name=cat_id]');
	var message = $('textarea[name=vid_text]');	
	

	if(title.val()=='' || cat_id.val()=='' || message.val()==''){
		$('#saveVideo .errMsg1').html('Please complete all the fields').fadeIn();
		return;
	}
	else
		$('#saveVideo .errMsg1').html('').fadeOut();
		
	var data = 'saveVideo=1&vid_title='+title.val()+'&cat_id=' + cat_id.val()+'&vid_text=' + message.val();
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				if (html==1) {					
					overlayClose('saveVideo');		
				} else {
					regFor('video');
				}			
			}		
		});	
	
}

//save video user id after login
function saveVideoUserId(){
	var data = 'saveVideoUser=1';
	
	//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: TemplatePath+'/ajax.php',	
			
			//POST method is used
			type: "POST",
			//pass the data			
			data: data,		
			//Do not cache the page
			cache: false,
			//success
			success: function (html) {				
				if (html==1) {					
					overlayClose('');		
				} 			
			}		
		});		
}


//show editor
function clickEditor(){
	$("#mashUpWrap").html('');
	
	$("#mashUpWrap").append('<iframe frameborder="0" hspace="0" src="'+TemplatePath+'/editor.php" width="920" height="550"></iframe>');
	overlay('mashup');		  
}


function setTell(name,email){
	$('input[name=friend_name]').val(name);
	$('input[name=tell_email]').val(email);	
}


function overlay(id){
		$('#TB_window').children('div').hide();
		
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			//if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			//}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
	  tb_position_new(id);
	
	
	$('#'+id).fadeIn();
	$('#TB_overlay').show();
	$('#TB_window').fadeIn();
	
	
	//$("#new").append($('#signOverlay').children());
}

function overlayClose(id){
	if(id==''){
		$('#TB_window').children('div').hide();
	}
	else{
		$('#'+id).fadeOut();
	}
	if(id=='pledgeOverlayHome'){
		$('#TB_window').children('div').hide();
	}
	$('#TB_overlay').hide();
	$('#TB_window').fadeOut();	
	//tb_remove();
	
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	
	SHARE_TYPE='';
	VIDEO_ID='';
	
}


function tb_position_new(idOverlay) {
	if(idOverlay=='pledgeOverlayHome'){
		var TB_WIDTH = (778*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
		var TB_HEIGHT = (308*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
	}
	else{
		var TB_WIDTH = (481*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
		var TB_HEIGHT = (522*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
	}

	$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		//$("#TB_window").css({marginTop: 0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop);
		//$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function clearSes(){
	clearMIX(1);	
}

function clearMIX(id){
		var parms = 'clear='+id;
		
		$.ajax({  
			  url: TemplatePath+"/ajax.php",   
			   type: "POST",          
				data: parms,        
				cache: false,  
				success: function (html) {                
				
			  }         
		});
}


function viewMedia(enId){
	var parms = 'vid_view=1&vid_id='+enId;
	VIDEO_ID=enId;
	
	$.ajax({  
		  url: TemplatePath+"/ajax.php",   
		   type: "POST",          
			data: parms,        
			cache: false,  
			success: function (html) {                
			
		  }         
	});	
}


function LoadMedia(enId) {
	//alert (entryId);
	//console.log(entryId);
	$('.twitter-box, .facebook-box').hide();
	//update view
	var parms = 'vid_view=1&vid_id='+enId;
	VIDEO_ID=enId;
	$.ajax({  
		  url: TemplatePath+"/ajax.php",   
		   type: "POST",          
			data: parms,        
			cache: false,  
			success: function (html) {
			
				html = html.split(',#,');
				var mytitle = html[1]
				var myyoutube = html[0]
				
				if(myyoutube == 0){
					$('.twitter-box" > a').attr('href', '#')
					$('.facebook-box > a').attr('href', '#')
				}else{
					$('.twitter-box" > a').attr('href', 'http://twitter.com/share?text='+mytitle.replace('#','')+'&url=' +myyoutube)
					$('.facebook-box > a').attr('href', 'http://www.facebook.com/sharer.php?u='+myyoutube+'&t='+mytitle.replace('#',''))
					$('.twitter-box, .facebook-box').show();
				}
				
				$('.phone-box > a').attr('href', 'http://www.thwapr.com/partner.aspx?apikey=gads2p&title='+mytitle.replace('#','')+'&thumb=http://content.bitsontherun.com/thumbs/'+enId+'-120.jpg&brandthumb=http://www.wegiveadamn.org/wp-content/themes/DAMN/images/img_5.gif&file=http://content.bitsontherun.com/videos/'+enId+'.mp4')
			}			
	});
	
	
	
	$('#kplayer').html('<embed src="http://video.wegiveadamn.org/players/'+enId+'-2GzdssPd.swf" width="320" height="275" allowfullscreen="true" allowscriptaccess="always" flashvars="plugins=sharing.link=http://www.wegiveadamn.org/videos/?vid_id='+enId+'&sharing.code=%3Cembed%20src%3D%22http%3A//video.wegiveadamn.org/players/'+enId+'-2GzdssPd.swf%22%20width%3D%22320%22%20height%3D%22275%22%20allowfullscreen%3D%22true%22%20allowscriptaccess%3D%22always%22%3E"/>');

	if($('#videoPlayer').is(':hidden'))
		overlay('videoPlayer');
 }
 
function closeMedia(){
	overlayClose('videoPlayer');
	$('#kplayer').html('');
}
	
function checkForm(formName){
    
	var form = document.getElementsByName(formName);
	var pass = true;
    for(i=0; i<form[0].elements.length; i++){
		//alert("The field name is: " + form[0].elements[i].name + " and it's value is: " + form[0].elements[i].value + ".<br />");
		if(form[0].elements[i].value == 0){
			form[0].elements[i].style.background = "#bc8923";
			form[0].elements[i].style.border = " 2px solid #c01e24"; 
		    pass = false;
		}
	}
     
	  return pass;
}

