if (!window.Utils) Utils ={};

Utils.Social = {
  cache_key: 'social_data',
	content_div: 'socialTab',
	TabHeaderPic: "socialTabHeaderPic",
  status: new Object(),
	social_data: {
	  sites : [ 'iwiw.hu','myvip.hu']
	},
	save: function() {

	},	
	onLoad: function(ok,data){
//		alert(JSON.stringify(Utils.Social.social_data));
//		alert(Utils.Social.social_data);
//		alert(JSON.stringify(social_data));
//		alert(social_data);
    if (data && data.value){
      data=data.value;
    }
		if (data){

			Utils.Social.status=JSON.parse(data);
		}
    Utils.Social.display_social_tab(1);
	},
		
	display_social_tab: function (id){
 		social_data.tabnr = id;
		someOutputDiv=document.getElementById(Utils.Social.content_div);
		emailTabHeader=document.getElementById(Utils.Social.TabHeaderPic);
		if (!someOutputDiv || !emailTabHeader) {
			return;
		}
		var result = SocialTemplateObj.process(social_data);
		if (emailTabHeader) emailTabHeader.src='http://img.hirkereso.hu/img/data/plain_doboz/23/social_header_tab'+id+'.gif';
		if (someOutputDiv) someOutputDiv.innerHTML = result;
		if (someOutputDiv) Utils.Social.fill_social_form(id);
	},

  reg: function (id){
    window.open(tww='http://www.hirkereso.hu/auth_redirect.fc?action=register&site=' + document.socialBox.site.options[document.socialBox.site.selectedIndex].text,'reg',"toolbar=yes,location=yes,resizable=yes,status=yes,scrollbars=yes,menubar=yes");
  },

  login: function (id){
    jo=1;
//    setCookie('test','test');
//   if(getCookie('test')!='test') {
//      window.alert("A böngésző nem fogadja az információt tároló cookie-t! Amíg nincs engedélyezve, addig ez a funkció nem használható");
//    }

    if(document.socialBox.login.value == ""){
      alert("Nem írtál be felhasználónevet!");
      jo=0;
			return;
    }
    if((document.socialBox.pwd.value == "") && jo){
      alert("Nem írtál be jelszót!");
      jo=0;
			return;
		}
//    if(jo){
//			if (document.socialBox.remember.checked){
//				value=document.socialBox.login.value+';'+document.socialBox.pwd.value+';'+document.socialBox.site.selectedIndex;
//			}else{
		//value=document.socialBox.login.value+';;'+document.socialBox.site.selectedIndex;
//			}
    var password='';

    if (document.socialBox.remember.checked){
      password = document.socialBox.pwd.value;
    }

		id=id-1;
		Utils.Social.status[id]={ 
			login: document.socialBox.login.value, 
			password: password,
			index: document.socialBox.site.selectedIndex
		};
		Store.save(Utils.Social.cache_key,JSON.stringify(Utils.Social.status));
		document.socialBox.submit();
  },

	fill_social_form: function(id){
		id = id-1;
		entry=Utils.Social.status[id];
		if (!entry){
			return;
		}
		
//		var checked='';
//		if (pass && pass.length>0){
//			checked='checked';
//		}
 // 	document.socialBox.login.value=login;
  	document.socialBox.login.value=entry.login;
//  document.socialBox.remember.checked=checked;
//		if (entry.password);
  //		document.socialBox.pwd.value=pass;
		if (entry.password){
			document.socialBox.remember.checked=1;
			document.socialBox.pwd.value=entry.password;
		}
//		}
 // 	document.socialBox.site.selectedIndex=index;
  	document.socialBox.site.selectedIndex=entry.index;
	}
};


var social_data = {
	  sites : [ 'iwiw.hu','myvip.hu']
};

