/*
  $Id: sfunctions.js,v 1.42 2010/08/19 10:26:40 cassius Exp $
*/
	function highlight_row(id, highlight) {
			var row= document.getElementById(id);
			if((typeof(row) == 'object') || (typeof(row) == 'function')) {
				if(highlight == true) {
					for(var i= 0; i < row.cells.length; i++) {
						row.cells[i].style.color= '#ffffff';
						row.cells[i].style.backgroundColor= '#770000';
					}
				}
				else {
					for(var i= 0; i < row.cells.length; i++) {
						row.cells[i].style.color= '';
						row.cells[i].style.backgroundColor= '';
					}
				}
			}
		}

	function validEmail(email, type)
	{
	  if (type == 'sms') {	
	  	email_regular_expression=new RegExp("^@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+\\.)+[a-zA-Z]{2,5}\$");
	  }  else {
	  	email_regular_expression=new RegExp("^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~ ])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~ ]+\\.)+[a-zA-Z]{2,5}\$");   // email_regular_expression= '^.+@.+\\..+$';  // simple one
	  }
	  return email_regular_expression.test(email);
	}
	
	function change_vis(elem_id, visible) {
		if(document.user_form.elements['user_type_f'].value > 1) {
			document.getElementById(elem_id).style.visibility= "visible";
		}
		else {
			document.getElementById(elem_id).style.visibility= "hidden";
		}
	}
	
	function expandSection(element, sectionName) {
		if(document.getElementById(sectionName)) {
			var expand= element.getAttribute('expand');
			//alert(expand);
			if(expand == '') {
				document.getElementById(sectionName).style.display= '';
				expand= 'expand';
			}
			else {
				document.getElementById(sectionName).style.display= 'none';
				expand= '';
			}
			
			element.setAttribute('expand', expand);
			return true;
		}
		return false;
	}
	
	
	function expandSection2(element, sectionName,script_url,scipt_flg) {
		
		//alert(sectionName+' '+script_url+'!');
		//alert('!!!!!!!!');
		if(document.getElementById(sectionName)) {
			if ($.cookie('opt_groups['+script_url+']['+sectionName+']')=='1' || (script_url=='ac_20' && scipt_flg!='')){
				element.setAttribute('expand', '');
			}
			var expand= element.getAttribute('expand');
			//alert(expand);
			expand= ((expand)? 'expand': '');
			
			if (scipt_flg==''){
				if(expand == '') {
					
					//document.getElementById(sectionName).style.display= '';
					$("#"+sectionName).hide();
					
					if ($("#group_header_type_"+sectionName).val() == undefined){
						// if default option group header
						//document.getElementById('gh_header_descr_'+sectionName).innerHTML = 'Click here to see your choices';
					}
					expand= 'expand';
					$.cookie('opt_groups['+script_url+']['+sectionName+']', 0);
				}
				else {
					//document.getElementById(sectionName).style.display= 'none';
					if ($("#group_header_type_"+sectionName).val() == undefined){	
						//document.getElementById('gh_header_descr_'+sectionName).innerHTML = 'Click here to close your choices';
					}
					$("#"+sectionName).show();
					expand= '';
					$.cookie('opt_groups['+script_url+']['+sectionName+']', 1);
				}
				element.setAttribute('expand', expand);
			}else{
				if(expand == '' || (script_url=='ac_20' && scipt_flg!='')) {
					//document.getElementById('gh_header_descr_'+sectionName).innerHTML = 'Click here to close your choices';
					$("#"+sectionName).show();
				}else{
					$("#"+sectionName).hide();
					//document.getElementById('gh_header_descr_'+sectionName).innerHTML = 'Click here to see your choices';
				}
			}
		}
		
		return false;
	}
	
	function submitmenu(context, method){
		if(context != '') {
			document.https_topmenu.actioncontext.value="page="+context;
			document.https_topmenu.submit();
		}
		return false;
	}
	
	function getHelpPopup(id) {
		window.open('?ap=help&at=show-'+id, '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	function getHelpPopup_q(id) {
		window.open('?ap=help&at=show-'+id+'&type=quest', '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	function getPublHelpPopup(id) {
		window.open('index.php?ap=help&at=show-'+id, '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	function getHelpPopup_agr(id) {
		window.open('?ap=help&at=show-'+id+'&type=agr', '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	
	function getHelpPopup_acc(id) {
		window.open('?ap=help&at=show-'+id+'&type=acc', '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	
	function getHelpPopup_whyrecommended_acc(id) {
		window.open('?ap=help&at=show-'+id+'&type=why_rec', '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}
	
	/*
	function prnt_getHelpPopup_agr(id) {
		var wnd = window.open('?ap=help&at=show-'+id+'&type=agr', '_blank', 'left=400, top=250, height=300, width=500, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
			wnd.onload = function(){
				wnd.print();
			}
	}
	*/
	
	function display_GroupOptions(gr_id){
		window.open('?ap=admin//DATABASE/optiongroups&act=show_options&gr_id='+gr_id, '_blank', 'left=400, top=250, height=400, width=500, menubar=no, toolbar=no, location=no, resizable=no, scrollbars=yes');
	}
	
	function display_Importfm(bl_id,current_area){
		window.open('?ap=admin//CMS/blockeditor&act=displ_import_fm&bl_id='+bl_id+'&cur_area='+current_area, '_blank', 'left=500, top=250, height=250, width=320, menubar=no, toolbar=no, location=no, resizable=no, scrollbars=no');	
	}
		
	/*	
	function display_CheckOrder(){
		window.open('?ap=cart&act=show_checkorder', '_blank','width=700, menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');
	}	
	*/
	//function display_covers(act){
	//	window.open('?ap=authorcenter8&todo=display_covers&act='+act, '_blank','menubar=no, toolbar=no, location=no, resizable=yes, scrollbars=yes');					
	//}
	function fupload_handler(val,form_object) {
		var upl_img = form_object.name+'_upl_img';
		var upl_err_box = form_object.name+'_err_box';
		document.getElementById(upl_img).style.display='none';
		
		// check server response
		if(val=='succ_upload'){
			$("#"+upl_err_box).css("color",'green');
			if (form_object.name=='uf1'){	// if it is an Author uploader photo
				$("#"+upl_err_box).text('File Uploaded Successfully!  Multiple authors?  You can upload up to 3 author photos.');
			}else{
				$("#"+upl_err_box).text('File uploaded successfully!');
			}
			$("#"+upl_err_box).fadeIn(800);
			if (document.getElementById('author_uploads_list')){
				get_upl_f_table();
			}
		}else{
			if (val.length>1000){	// if session expired
				document.location.href="./authors.php";
				return false;
			}else{ 
				$("#"+upl_err_box).css("color",'red');
				$("#"+upl_err_box).text(val);
				$("#"+upl_err_box).fadeIn(800);
			}
		}
	}
	
	function fileUploaded(element) {
			var form_object= element.form;
			var upl_img = form_object.name+'_upl_img';
			var upl_err_box = form_object.name+'_err_box';
			document.getElementById(upl_img).style.display='none';
			var val= element.data;
			// check server response
			if(val=='succ_upload'){
				$("#"+upl_err_box).css("color",'green');
				if (form_object.name=='uf1'){	// if it is an Author uploader photo
					$("#"+upl_err_box).text('File Uploaded Successfully!  Multiple authors?  You can upload up to 3 author photos.');
				}else{
					$("#"+upl_err_box).text('File uploaded successfully!');
				}
				$("#"+upl_err_box).fadeIn(800);
				if (document.getElementById('author_uploads_list')){
					get_upl_f_table();
				}
			}else{
				if (val.length>1000){	// if session expired
					document.location.href="./authors.php";
					return false;
				}else{ 
					$("#"+upl_err_box).css("color",'red');
					$("#"+upl_err_box).text(val);
					$("#"+upl_err_box).fadeIn(800);
				}
			}
		}

	function proofs_uploaded(b_id){


		i_version = $("#"+b_id+"_b_InteriorProofVersion").val();
		c_version = $("#"+b_id+"_b_CoverProofVersion").val();

		var req= new xRequest('GET');		
		$("#round_err_box").fadeOut(600);
		req.send('/managers.php?ap=projectManagement/tpsProject&at=validate_rounds-'+b_id+'&cv='+c_version+'&iv='+i_version, null);
		

		req.onReceive= function() {
			
			if (req.data!='ok'){
				$("#err_msg_conteiner").html(req.data);
				$("#round_err_box").fadeIn(800);
				return false;
			}else{
				if(document.getElementById(b_id+'_proofs_uploaded')) {
					document.getElementById(b_id+'_proofs_uploaded').value= 'yes';
				} 
				submit_form_users('do_edit');
			}
			
			
		}
		return false;
	}
	
	function getShockwaveFlashVersion() {
		if(typeof(ActiveXObject) == 'function') {
			var axoPath;
			var shockwaveFlash;
			var shockwaveFlashHighestVersion= 9;
			var shockwaveFlashVersion;
			for(var i= shockwaveFlashHighestVersion; i > 0; i--) {
				axoPath= 'ShockwaveFlash.ShockwaveFlash.'+ i;
				try {
					shockwaveFlash= new ActiveXObject(axoPath);
					shockwaveFlashVersion = shockwaveFlash.GetVariable("$version");
					if(shockwaveFlashVersion) {
						return shockwaveFlashVersion.replace(/win/ig, '').replace(/,/g, '.').replace(/\s/ig, '');
						//break;
					}
				}
				catch (e) {}
			}
		}
		else if(navigator.plugins) {
			var pluginsQuantity= navigator.plugins.length;
			for(var i= 0; i < pluginsQuantity; i++) {
				if(navigator.plugins[i].name.toLowerCase().indexOf('shockwave flash') != -1) {
					return navigator.plugins[i].description.replace(/shockwave flash/ig, '').replace(/r/ig, '.').replace(/\s/ig, '');
					//break;
				}
			}
		}
		return '';
	}
	
	function load_LandingRegForm(){
		var req= new xRequest('post');
		req.onReceive= function() {
			if (req.data == 'cookies_exist'){
				document.location.href="./authors.php";
			}else{
				$("#reg_container").html(req.data);
			}
			return false;
		}
		action = 'get_register_form';
		module_path = 'public//register';
		module_name = 'registration.php';
		
		// if form is data - send request 
		data =  'actioncontext[page]='+module_path+
		'&actioncontext[todo]='+action;
		req.send('./'+module_name, data);
	}
              		
    function landingPage_register(){
    	var req= new xRequest('post');
        req.onReceive= function() {
        	switch (req.data){
				case 'ok_author_published':{						// author registered succsessfully
								/*var pageTracker = _gat._getTracker("UA-1803760-1");
					             pageTracker._trackPageview();
								 pageTracker._trackPageview("/RP/registration.html");*/
								window.location.href="./authors.php?ap=registration";
								break;	
				}
				case 'author_registered':{
								document.lgn_fm.login_selection[0].checked=true;	
								login_radio_action();
								document.getElementById('err_box').style.display = 'none';
								document.getElementById('err_box').innerHTML = '<img src="./images/public/err_pointer.gif" width="15" height="16"> &nbsp; You have already registered with that email address.';
									
								break;
				}
				case 'authorcenter_redirect': {
								document.location.href="./authors.php";
								return false;
				}
				default : {											// error message
								document.getElementById('err_box').style.display = '';
								document.getElementById('err_box').innerHTML = '<img src="./images/public/err_pointer.gif" width="15" height="16"> &nbsp;';
								document.getElementById('err_box').innerHTML += req.data;
				}
			
			}
		}
              			
        // check Manus status selection
          			
		if ($("#uManuStatus").val() == ''){
			document.getElementById('err_box').style.display = '';
			document.getElementById('err_box').style.color = 'red';
			document.getElementById('err_box').innerHTML = '<img src="./images/public/err_pointer.gif" width="15" height="16"> &nbsp;';
			document.getElementById('err_box').innerHTML += 'Please Tell us about your book';
			return false;
		}
              			
              			
        document.getElementById('err_box').innerHTML = '';
        action = 'register';
		module_path = 'public//register';
		module_name = 'registration.php';
		
		// if form is data - send request 
		data =  'actioncontext[page]='+module_path+
			'&actioncontext[todo]='+action+
			'&au_firstName='+$("#au_firstName").val()+
			'&au_email='+$("#au_email").val()+
			'&au_email_='+$("#au_email_").val()+
			'&uManuStatus='+$("#uManuStatus").val()
			+'&package='+$("#package").val()
			+'&redirect=client'
			+'&landingPage=true'
			;
		req.send('./'+module_name, data);
   }
   
   function toBool(value) {
	   if(value == undefined) {
		   return true;
	   }
	   else {
		   var b= new Boolean(value);
		   return b.valueOf();
	   }
   }