/**
* For Talent Fan mail 
*
* @since Fri Sep 12, 2008 5:04AM PH Time
* @author HPI Team
*/
function checksSelected(msg){
	var obj = document.getElementsByTagName('input'); 
	if(msg==undefined)
		msg = 'mail';
	else
		msg = msg;
		
	var total=0;
	for(var i=0; i < obj.length; i++){
	if(obj[i].type == 'checkbox' && obj[i].checked && obj[i].name!='check_all')
		total++;
	}
	if(total>0){
		return true;
	}else{
		alert('No ' + msg + ' selected.');
		return false; 
	}
}

function gotoFanMailTab(el, url) {
	// Reset the classes of the buttons.
	$('mail_index').className = 'notselectedTab';
	$('mail_sent').className = 'notselectedTab';
	$('mail_trash').className = 'notselectedTab';
	$('mail_compose').className = 'notselectedTab';
	$('mail_block').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('mail_index').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('mail_sent').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('mail_trash').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('mail_compose').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('mail_block').getElementsByTagName('a')[0].style.color = '#9B6B00';

	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater(	'content', 
						url, 
						{ 
							method:'post', 
							onComplete:
								function(){ 
									$('loading').style.display = 'none';
									setTimeout("tooltipX();",500);

								}, 
							onLoading:
								function(){ 
									$('loading').style.display = '';
								}, 
							asynchronous:true, 
							evalScripts:true
						}
					);
}
/**   fot talent Fan mail scripts ends here    **/

function gotoTab(el, url) {
	
	// Reset the classes of the buttons.
	$('msg_inbox').className = 'notselectedTab';
	$('msg_sent').className = 'notselectedTab';
	$('msg_trash').className = 'notselectedTab';
	$('msg_compose').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('msg_inbox').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('msg_sent').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('msg_trash').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('msg_compose').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater(	'content', 
						url, 
						{ 
							method:'post', 
							onComplete:
								function(){ 
									$('loading').style.display = 'none';
									setTimeout("tooltipX();",500);

								}, 
							onLoading:
								function(){ 
									$('loading').style.display = '';
								}, 
							asynchronous:true, 
							evalScripts:true
						}
					);
}

function gotoMemberTab(el, url) {
	
	// Reset the classes of the buttons.
	$('myDetail').className = 'notselectedTab';
	$('changePassword').className = 'notselectedTab';
	$('cancelPortfolio').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('myDetail').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('changePassword').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('cancelPortfolio').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoScoutingTab(el, url) {
	
	// Reset the classes of the buttons.
	$('info').className = 'notselectedTab';
	$('more').className = 'notselectedTab';
	$('join').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('info').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('more').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('join').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}
function gotoProPickTabs(el, url,t) {
	
	// Reset the classes of the buttons.
	$('pro_picks').className = 'notselectedTab';
	$('pro_picks_mail').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('pro_picks').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('pro_picks_mail').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	if(t == '1' && el == 'pro_picks_save_crit'){
	elm.getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoPhotoTab(el, url) {
	
	// Reset the classes of the buttons.
	$('primary').className = 'notselectedTab';
	if ($('video')) {
		$('video').className = 'notselectedTab';
	}
	if ($('upload')) {
		$('upload').className = 'notselectedTab';
	}
	
	// Reset the color of the buttons;
	$('primary').getElementsByTagName('a')[0].style.color = '#9B6B00';
	if ($('video')) {
		$('video').getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	if ($('upload')) {
		$('upload').getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoCommentTab(el, url) {
	
	// Reset the classes of the buttons.
	$('current').className = 'notselectedTab';
	$('pending').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('current').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('pending').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoExperienceTab(el, url) {
	
	// Reset the classes of the buttons.
	$('resume').className = 'notselectedTab';
	if ($('past')) {
		$('past').className = 'notselectedTab';
	}
	if ($('interest')) {
		$('interest').className = 'notselectedTab';
	}
	if ($('acting')) {
		$('acting').className = 'notselectedTab';
	}
	
	// Reset the color of the buttons;
	$('resume').getElementsByTagName('a')[0].style.color = '#9B6B00';
	if ($('past')) {
		$('past').getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	if ($('interest')) {
		$('interest').getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	if ($('acting')) {
		$('acting').getElementsByTagName('a')[0].style.color = '#9B6B00';
	}
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoTravelTab(el, url) {
	
	// Reset the classes of the buttons.
	$('dates').className = 'notselectedTab';
	$('availability').className = 'notselectedTab';
	$('languages').className = 'notselectedTab';
	
	// Reset the color of the buttons;
	$('dates').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('availability').getElementsByTagName('a')[0].style.color = '#9B6B00';
	$('languages').getElementsByTagName('a')[0].style.color = '#9B6B00';
	
	// Set the class of the button to active.
	var elm = document.getElementById(el);
	elm.className = 'selectedTab';
	elm.getElementsByTagName('a')[0].style.color = 'white';
	
	new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
	
}

function gotoFavorites(el, url) {
	
	//reset classes for buttons
		$('fav_notification').className = 'notselectedTab';
		$('fav_searches').className = 'notselectedTab';
		$('fav_members').className = 'notselectedTab'; 
		if($('top10'))	$('top10').className = 'notselectedTab'; 
	//reset colors for buttons
		$('fav_notification').getElementsByTagName('a')[0].style.color = '#9B6B00';
		$('fav_searches').getElementsByTagName('a')[0].style.color = '#9B6B00';
		$('fav_members').getElementsByTagName('a')[0].style.color = '#9B6B00';
		if($('top10')) $('top10').getElementsByTagName('a')[0].style.color = '#9B6B00';
	//set button that is active
		var elmnt = document.getElementById(el);
		elmnt.className = 'selectedTab';
		elmnt.getElementsByTagName('a')[0].style.color = 'white';
		new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, evalScripts:true});
}

function checkAll(parent, nodeC) {
	var nodes = document.getElementsByName(nodeC);
	pNode = document.getElementsByName(parent)[0];
	if (pNode.checked == true) {
		for (var i=0; i<nodes.length; i++) {
			nodes[i].checked = true;
		}
	} else {
		for (var i=0; i<nodes.length; i++) {
			nodes[i].checked = false;
		}
	}
}


function deleteMessage(el, url, frm) {
	if(confirm('Are you sure you want to delete this message(s)?')) {
		new Ajax.Updater('content', url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, parameters:Form.serialize(frm), evalScripts:true});
	}
	return false;
}

function deleteSingle(el, url) {
	if(confirm('Are you sure you want to delete this message(s)?')) {
		gotoTab(el, url);
	}
	return false;
}

function selectCheck(parent, nodeC, sel) {
	var pNode = document.getElementsByName(parent)[0];
	switch(sel.value) {
		case "selectAll":
			pNode.checked = true;
			break;
		case "selectNone":
			pNode.checked = false;
			break;
		default:
			pNode.checked = false;
			break;
	}
	checkAll(parent, nodeC);
}

function checkAllList(elm) {
	var frm = elm.form;
	var checkBoxes = frm.getElementsByTagName('input');
	
	if (elm.type == 'select-one') {
		if (elm.value == '1') {
			check_str = true;
		} else {
			check_str = false;
		}
	} else if (elm.type == 'checkbox') {
		if (elm.checked) {
			var check_str = true;
		} else {
			var check_str = false;
		}
	}
	
	for(var i=0;i<checkBoxes.length;i++) {
		if (checkBoxes[i].type == 'checkbox') {
			checkBoxes[i].checked = check_str;
		}
	}
}

function ajaxForm(update, url, frm) {
		new Ajax.Updater(update, url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, parameters:Form.serialize(frm), evalScripts:true});
		return false;
}

function saveProfile(update, url, frm) {
	/*	
		frm.pinfo.value=tinyMCE.get('personal_introduction').getContent();
		frm.resinfo.value=tinyMCE.get('resume').getContent();
	*/
		new Ajax.Updater(update, url, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ $('loading').style.display = '';}, asynchronous:true, parameters:Form.serialize(frm), evalScripts:true});
		return false;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //return [ scrOfX, scrOfY ];
  return scrOfY;
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  
 var out = Array();
 out[0] = myWidth;
 out[1] = myHeight;
 return out;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function showLoading() {
  var screenY = getSize()[1];
  var offY = getScrollXY();
  var screenX = getSize()[0];
  var loadY = offY + ((screenY/2) - 20);
  $('loading').style.top = loadY + 'px';
  $('loading').style.width = screenX + 'px';
  $('loading').style.display = '';
}

function ajaxAnchor(update, url) {
	new Ajax.Updater(	update, 
						url, 
						{ 
							method:'post', 
							onComplete:
								function(){ 
									$('loading').style.display = 'none';

								}, 
							onLoading:
								function(){ 
									showLoading();
								}, 
							asynchronous:true, 
							evalScripts:true
						}
					);
}

//for the adding of favorite member 
function ajaxAddFav() {
	var txtval = document.getElementById('member_id');
	if (txtval.value != '') { 
		ajaxForm('content','favorites/functions.php?add_exist_fav=1&mem_id='+txtval.value,'this');	
	} 
}
function ajaxUpdatePhoto(user_id,prod_id,return_url,obj){
	if (obj.value != '') { 
	new Ajax.Updater('content', 'photos/updatePhoto.php?u_id='+user_id+'&p_id='+prod_id+'&sel='+obj.value+'&return='+return_url, { method:'post', onComplete:function(){ $('saveLoading').style.display = 'none';}, onLoading:function(){ $('saveLoading').style.display = '';}, asynchronous:true, evalScripts:true});
	} 
}
 function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
    }

function checkMessageForm(){
	if(trim(document.getElementById('to').value) == '' || trim(document.getElementById('subject').value) == '' || trim(document.getElementById('body').value) == ''){
		document.getElementById('messageError').style.display='';
		return false;
	}else{
		document.getElementsByClassName('buttons')[0].style.display = 'none';
		return true;
	}
}
function move_to_gallery(target_gallery_id,from_image_id,from_gallery_id){
	ajaxAnchor('gallery_'+target_gallery_id, 'photos/get_images.php?update=YES&image_id='+from_image_id+'&gallery_id='+target_gallery_id);
	ajaxAnchor('gallery_'+from_gallery_id, 'photos/get_images.php?gallery_id='+from_gallery_id);
}

function hasChecked(FormName, FieldName){
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes){
		return false;
	}else{
		var countCheckBoxes=objCheckBoxes.length;
		if(!countCheckBoxes){
			if(objCheckBoxes.checked==false){
				return false;
			}else{
				return true;
			}
		}else{
			var hasCheck=false;
			for(var i = 0; i < countCheckBoxes; i++)
				if(objCheckBoxes[i].checked ==true){
					hasCheck=true;
				}
			return hasCheck;
		}
	}
}
function SetAllCheckBoxes(FormName, FieldName, CheckValue){
	//CheckValue=document.forms[FormName].chkAll.checked;
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function setScoutingCompose(FormName, FieldName){
	if(hasChecked(FormName, FieldName)==true){
		document.getElementById('compose_message').className='launchpadButtons';
	}else{
		document.getElementById('compose_message').className='launchpadButtons1';
	}
}
 function comming_msg(html) {
    var effect = new PopupEffect(html, {className: "popup_effect2"})
        var win = new Window({className: "mac_os_x",  width:400, height:320, zIndex: 100, resizable: false,  url: "../comming_soon.html", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
        win.showCenter();         
  }
 function tooltipVideo(html) {
    var effect = new PopupEffect(html, {className: "popup_effect2"})
        var win = new Window({className: "mac_os_x",  width:400, height:290, zIndex: 100, resizable: false,  url: "photos/tooltipVideo.html", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
        win.showCenter();         
  }
function change_notification(obj){
	if(obj.value=='mail'){
		document.getElementById('contact_email_tr').style.display='none';	
		document.getElementById('contact_mail_tr').style.display='block';
		document.getElementById('notifyme').style.display='none';	
		document.getElementById('notifyme2').style.display='none';	

	}else{
		document.getElementById('contact_mail_tr').style.display='none';	
		document.getElementById('contact_email_tr').style.display='block';
		document.getElementById('notifyme').style.display='block';	
		document.getElementById('notifyme2').style.display='block';
	}
}
function check_contact_email(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if(unicode==64 && document.getElementById('notification_type').value=='mail'){
		return false;
	}else{
	}
}
function setPrice(both_payment, item_name, payment,new_membership_level,term,userID) {
	account_type = document.getElementById('account_type2').value;
	if (account_type == 3) {
		document.getElementById('a3').value = both_payment;
		document.getElementById('item_name').value = item_name;
	} else {
		document.getElementById('a3').value = payment;
	}
	document.getElementById('custom').value = 'membership|'+account_type+'|'+userID+'|'+new_membership_level+'|'+term;
}

function setEditGallery(gallery_name,gallery_id){
	document.getElementById('new_gallery_name').value= gallery_name;
	document.getElementById('gallery_id').value= gallery_id;
	document.getElementById('gallery_process').value= 'edit';
	document.getElementById('new_gallery').style.display='';
}
function checkEmailFormat(value,error_msg_id){
	error_element = document.getElementById(error_msg_id);
	if(error_element){
		if(value!=''){
			if(is_email_format(value)==true){
				error_element.style.display = 'none';
				return true;
			}else{
				error_element.style.display = '';
				return false;
			}
		}else{
			error_element.style.display = 'none';
			return true;
		}
	}else{
		return true;
	}
}
function is_email_format(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}
function checkMemberDetails(formobj,submit_url){
	if(checkEmailFormat(formobj.elements['email'].value,'email_error_div')==true && checkEmailFormat(formobj.elements['email2'].value,'email2_error_div')==true){
		ajaxForm('content',submit_url , formobj);
	}
	return false;
}

function ajaxsetAutoAddTop10(obj){
	if(obj.checked==true) url_val = 1;
	else url_val = 0;
	new Ajax.Updater('content', 'top-10/setAutoAdd.php?autoadd='+url_val, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ showLoading(); }, asynchronous:true, evalScripts:true});
	 
}
function ajaxFavremove(id,autoAdd){
	new Ajax.Updater('content', 'top-10/removeFromList.php?id='+id+'&autoadd='+autoAdd, { method:'post', onComplete:function(){ $('loading').style.display = 'none';}, onLoading:function(){ showLoading(); }, asynchronous:true, evalScripts:true});
}

function composemessage(frm)
{
var cnt=0;
	for(i=0;i<document.getElementById('chkcount').value;i++)
	{	
		if(document.getElementById('chkEmails_'+i).checked==true)
		{	
		 cnt = cnt + 1;
		}
	}
	if(cnt > 0)
	{		
		document.getElementById('contactlist').style.display="none";
		document.getElementById('composemsg').style.display="block";
		var scoutemails="";
		for(i=0;i<document.getElementById('chkcount').value;i++)
		{
			if(document.getElementById('chkEmails_'+i).checked==true){
				scoutemails =scoutemails+document.getElementById('chkEmails_'+i).value+",";	
			}
		}
		document.getElementById('scoutto').value=scoutemails;
	}else{
		alert("Please select the contacts you would like to email.");
		return false;
	}
}