// *******************************************
// PRELOAD NAV ROLLOVERS
// *******************************************

function clickButton(buttonID, action, code, target) {
	setCookie('vokiButtonClicked', buttonID, '','/','voki.com');
	if (action == 'link') {
		if(target) {
			window.open(code, target);
		} else {
			window.location = code;
		}
	} else {
		eval(code);
	}
}
 
function changePass(){
	if (!checkLogin())
		return false;
		
	var email	= readChip(readCookie('vdata' + vokiEnv), 'em');
	topWin.openModalIframe(cachedDomain + 'changePass.php', 340, 250, 'Change Your Password');
}

function Register(){
	if (readCookie('vokiBlockedReg')) {
		topWin.openBlocked();
	}
	else{
		topWin.openModalIframe(topWin.cachedDomain + 'modal_register.php', topWin.modalSizes.get('regWindow').width, topWin.modalSizes.get('regWindow').height);
		topWin.Windows.getWindow('modal_window')//.setTitle('Create your Voki Account'+'<div class="subheader">Fill out the information below to create your account.</div>')
		;
	}
}

function RegisterClassroom(){
  var cookie 	= readCookie('vdata' + vokiEnv);  
  var	accChip	= parseInt(readChip(cookie, 'acc')) || 0;

  /* IF USER IS LOGGED IN */
  if (accChip > 0){
    topWin.openModalIframe('classroom/paypal/startPaypal.php', topWin.modalSizes.get('regWindowVC').width, topWin.modalSizes.get('regWindowVC').height);
    
    // topWin.Windows.getWindow('modal_window').setTitle('<div id="headerHolder"><div class="lg_vokiClassroom"></div><div class="headerTxtHolder">Choose your <span class="orange">Voki Classroom</span> Plan'+'<div class="subheaderSmaller">Select the plan that is right for you.<br />A 2-year plan will save you <span class="orange">25% </span>per month.<br />Multiple accounts will save you an additional <span class="orange">10-15%</span>.</div></div><div class="clearboth"></div></div>');
    }

  else {
		topWin.openModalIframe(topWin.cachedDomain + 'modal_register.php?upgrade=1', topWin.modalSizes.get('regWindow').width, topWin.modalSizes.get('regWindow').height);
		topWin.Windows.getWindow('modal_window')//.setTitle('Voki Classroom Registration'+'<div class="subheader">Fill out the form below to create your Voki account.</div>')
		;
		// $('showloginOrRegister').observe('click', function (e) {
		// 	showloginOrRegister('voki');
		// });	
	}
}

function startMultipaypalFunc(){	
	topWin.openModalIframe(topWin.cachedDomain + 'classroom/paypal/startMultiPaypal.php',670,637);
}

function callbackPaypal(){
	topWin.openModalIframe('classroom/paypal/startPaypal.php', topWin.modalSizes.get('regWindowVC').width, topWin.modalSizes.get('regWindowVC').height);
    // topWin.Windows.getWindow('modal_window').setTitle('<div id="headerHolder"><div class="lg_vokiClassroom"></div><div class="headerTxtHolder">Choose your <span class="orange">Voki Classroom</span> Plan'+'<div class="subheaderSmaller">Select the plan that is right for you.<br />A 2-year plan will save you <span class="orange">25% </span>per month.<br />Multiple accounts will save you an additional <span class="orange">10-15%</span>.</div></div><div class="clearboth"></div></div>');
  }

function openPartReg(){
	topWin.openModalIframe(topWin.cachedDomain   + 'modal_register.php', topWin.modalSizes.get('partReg').width, topWin.modalSizes.get('partReg').height, 'Become A Voki Partner');
}

function loginTag(){
	if (readCookie("vokiNoThanks")){
		thankSave();
	}else{
		topWin.openModalIframe(topWin.cachedDomain  + 'modal_login_tag.php', topWin.modalSizes.get('tagWindow').width, topWin.modalSizes.get('tagWindow').height, 'You just Created a Voki Character!');		
	}
}

function openLogin(dest, err){
	//debug(err);
	if (!err)
		err	= '';
	
	if (!dest)
		dest	= 'mywebsite.php';
		
	topWin.openModalIframe('login.php?destination=' + escape(dest) + '&err=' + escape(err), topWin.modalSizes.get('loginWin').width, topWin.modalSizes.get('loginWin').height);				
}

function thankSave(){
	//if (!oTitle)
		//oTitle	= '';
	//oTitle	= '<div align="center">' + oTitle + '</div>';
	topWin.openModalIframe(topWin.cachedDomain  + 'modal_saveVoki.php',topWin.modalSizes.get('thanksWin').width, topWin.modalSizes.get('thanksWin').height);
}

function forgotPass(){
	topWin.openModalIframe(topWin.cachedDomain  + 'modal_lost_password.php', topWin.modalSizes.get('forgotPass').width, topWin.modalSizes.get('forgotPass').height);
}

function resetPass(email, tmpP, dest){
	topWin.openModalIframe(topWin.cachedDomain  + 'resetpassform.php?email=' + email + '&tmpP=' + tmpP + '&dest=' + dest, topWin.modalSizes.get('changePass').width, topWin.modalSizes.get('changePass').height, 'Reset Your Password');
}

function openModalVoki(accountID, sceneID){
	////debug('openModalVoki');
	var width	= 300;
	var height	= 300;
	
	if(topWin.location.href.indexOf('browse') != -1 || topWin.location.pathname == "/") {
			width	= 400;
			height	= 420;
	}
	
	topWin.openModalIframe(topWin.cachedDomain + 'modal_vokiPlayer.php?accountID=' + accountID + "&sceneID=" + sceneID, width, height);
}

function viewComments(vokiID, vokiName){
	////debug('viewComments');
	topWin.openModalIframe(topWin.dynamicDomain + 'getComments.php?vokiID=' + vokiID + '&vokiName=' + vokiName, 500, 400);
}

function createVoki(gMode, extra){
	if (!extra)
		extra = '';
	
	topWin.openModalIframe(topWin.cachedDomain + 'createScene.php?gMode=' + gMode + extra, topWin.modalSizes.get('createVoki').width, topWin.modalSizes.get('createVoki').height,'You have selected to create a new Voki');
}

function openGetCode(parameters){
	topWin.openModalIframe(topWin.dynamicDomain + "modal_getCode.php" + parameters,  topWin.modalSizes.get('embedCode').width, topWin.modalSizes.get('embedCode').height, 'Embed this Voki on your webpage');
}

// ALTERNATE SCRIPT
function openPublish(sceneID,checksum){
	if (location.toString().match("-vd") != null)
		
	{
	  var apiBase		= 'http://www-vd.voki.com/gigyawin.php?sceneID=';
	}
		else if(location.toString().match("-vs") != null)
	{
	  var apiBase		= 'http://www-vs.voki.com/gigyawin.php?sceneID=';
	}
		else
	{
	  var apiBase		= 'http://l-www.voki.com/gigyawin.php?sceneID=';
	}
	topWin.openModalIframe(apiBase + sceneID +"&checksum="+checksum, 400, 520, 'Publish this Voki directly to your site');

}
// END ALTERNATE SCRIPT
function openBlocked(){
	topWin.openModalIframe(topWin.cachedDomain + 'blocked.php', topWin.modalSizes.get('blocked').width, topWin.modalSizes.get('blocked').height, '&nbsp;');	
}

function openSceneSettings(sceneId){
	openModalIframe(topWin.cachedDomain + 'modal_settings_options.php?sceneID=' + sceneId, topWin.modalSizes.get('sceneSet').width, topWin.modalSizes.get('sceneSet').height,'Scene Settings');
}

function Login(url){	
	if (!url){
		url		= grabQueryValue('destination');
		if (url.toString() == 'false')
			 url	= 'mywebsite.php';
	}
	openModalIframe('login.php?destination=' + escape(url), topWin.modalSizes.get('loginWin').width, topWin.modalSizes.get('loginWin').height, 'Please login to access your account');	
}

function closeNoThanks(){
	//find out if the users created a voki then display the approiate page
	setCookie(topWin.cachedDomain + "vokiNoThanks",true,"","/",cookieDomain,"");
		
	if (readCookie('unregisteredCreation')) {	
		thankSave();
	}
}

function partnerTNC(){
	debug('partnerTNC');
	
	topWin.openModalIframe(topWin.cachedDomain  + 'modal_partnerTNC.php', topWin.modalSizes.get('partTNC').width, topWin.modalSizes.get('partTNC').height, '<div class="comNPub">For <strong>Communities</strong> and <strong>Publishers</strong> Only</div>Please Agree to the Partner Terms and Conditions');
}

function partThank(){
	debug('partThank');
	topWin.openModalIframe(topWin.cachedDomain  + 'modal_partnerThank.php', topWin.modalSizes.get('partThanks').width, topWin.modalSizes.get('partThanks').height, '<div class="comNPub">For <strong>Communities</strong> and <strong>Publishers</strong> Only</div>Thank you for signing up as a Voki Partner');
	modalWin	= topWin.Windows.getWindow('modal_window');	
	modalWin.setCloseCallback(function (){topWin.location = topWin.cachedDomain});
}

// ***************************
//  SEND-TO-FRIEND FUNCTIONS
// ***************************

function vokiReply(email){
	debug('vokiReply');
	createVoki(4, '&email=' + email);
	setCookie('reply',email);
	topWin.Windows.getWindow('modal_window').setTitle('Reply to your friend');
	//openModalIframe(topWin.cachedDomain + 'modal_emailSession.php?reply=yes&email=' + email, 380, 425, 'Reply to your friend');
}

function vokiForward(vokiID){
	debug('vokiForward');
	SendToFriend(vokiID);
	topWin.Windows.getWindow('modal_window').setTitle('Forward Your Voki');
	//openModalIframe(topWin.cachedDomain + 'modal_emailSession.php?reply=forward&sceneID=' + vokiID, 380, 425, 'Foward Your Voki');
}

function newMessage(){
	createVoki(4);	
	topWin.Windows.getWindow('modal_window').setTitle('New Voki Message');		
	//openModalIframe(topWin.cachedDomain + 'modal_emailSession.php', 400, 300, );
}

function SendToFriend(vokiID){
	debug('STAF Scene: ' + vokiID);
	openModalIframe(topWin.cachedDomain + 'sendToFriend.php?sceneID=' + vokiID, topWin.modalSizes.get('STAF').width, topWin.modalSizes.get('STAF').height, 'Send To A Friend');
}

function sendVokiToPhone(accId, scId, chsm, pid){
	sendToMobileComment = window.open( "http://" + VHOST_HTTP_SERVER + "/vhss_editors/sendVokiToPhone.php?acc="+accId+'&sc='+scId+'&chsm='+chsm+'&pid='+pid,"sendToMobileComment","width=730,height=625,toolbar=no,resizable=yes,scrollbars=yes");
	sendToMobileComment.focus();
}



//function openPublish(sceneID,checksum){	
//	topWin.openModalIframe("http://l-www.voki.com/gigyawin.php?sceneID="  + sceneID +"&checksum="+checksum, 400, 520, 'Publish this Voki directly to your site');
//}
