
function gi(val){return document.getElementById(val);}

// AJAX - MAKE WORK
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{xmlHttp=new XMLHttpRequest();} // Firefox, Opera 8.0+, Safari
	catch (e){
		try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");} //Internet Explorer
		catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} //Other from MS
	}
	return xmlHttp;
}

//SELECTBOX
function rs_Sel(id, type, count){
var drp = id+'_drp';
var lnk = id+'_lnk_0';
	if (type=='A'){
		if (document.getElementById(drp).style.display=='none'){
			change(id, 'rs_selup'); show(drp);
		}else{
			change(id, 'rs_sel'); hide(drp);
		}
	} else if (type=='B'){
		var lnk2 = id+'_lnk_'+count;
		change(id, 'rs_sel'); hide(drp); document.getElementById(lnk).innerHTML=document.getElementById(lnk2).innerHTML;
	}
}

//END GENERAL FUNCTIONS







//Update the tip box while ajax loads
function jaxStatus(type, txt){
	if (type=="loading"){
		change("tip1","user_warn")
		change("tip2","user_warn_load")
		document.getElementById("tip2").innerHTML="<p>Loading&hellip;</p>"
	} else if (type=="done"){
		change("tip1","user_tip")
		change("tip2","user_tip2")
		document.getElementById("tip2").innerHTML="<p>Done</p>"
	}else if (type=="warn"){
		change("tip1","user_warn")
		change("tip2","user_warn_ex")
		document.getElementById("tip2").innerHTML="<p>"+txt+"</p>"
	}else if (type=="ready"){
		change("tip1","user_tip")
		change("tip2","user_tip2")
		document.getElementById("tip2").innerHTML="<p>Ready</p>"
	}
}






//SITEBOX AJAX
function rs_SiteBox(fun, jax, div){
	if (div!='cluster_list') jaxStatus("loading");
	xmlHttp=GetXmlHttpObject()
	
	
	
	var url="/admin/sites/"+fun+".php"
	url=url+"?fun="+fun
	url=url+"&jax="+jax
	url=url+"&sid="+Math.random()
	
	
	var divbox
	if (div==null || div=="" || div=="undefined"){
		divbox="sites_rgt";
	}else if (div=="mod" || div=="mod_single"){
		divbox="sites_rgt"; url=url+"&mod="+div;
	}else{
		divbox=div;
	}
	
	function stateChanged(){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById(divbox).innerHTML=xmlHttp.responseText;
			jaxStatus("done"); 
		}
	}
	
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}





function sel_all_site_list(num, bol){
var x=0
var flip="A"
	while(x < num){
		if (bol==true){document.getElementById("data_list_chk"+x).checked=true; change('data_list_row'+x, 'data_list_rowC');}
		else {document.getElementById("data_list_chk"+x).checked=false; change('data_list_row'+x, 'data_list_row'+flip);}
		if (flip=="A"){flip="B";} else {flip="A";}
		x++
	}
}




function sel_one_site(id, flip){
	if (document.getElementById('data_list_chk'+id).checked==false){
			document.getElementById('data_list_chk'+id).checked=true;
			change('data_list_row'+id, 'data_list_rowC');
		}else{
			document.getElementById('data_list_chk'+id).checked=false;
			document.getElementById('data_list_chk_all').checked=false;
			if (flip=='B') change('data_list_row'+id, 'data_list_rowB'); else change('data_list_row'+id, 'data_list_rowA');
	}
}
function sel_one_site_chkbox(id, flip){
	if (document.getElementById('data_list_chk'+id).checked==true){
			change('data_list_row'+id, 'data_list_rowC');
	}else{
			document.getElementById('data_list_chk_all').checked=false;
			if (flip=='B') change('data_list_row'+id, 'data_list_rowB'); else change('data_list_row'+id, 'data_list_rowA');
	}
}




function chkForm(){
	
	var blnRtn = false;
	var warnName ="Please name your site.";
	var warnEmail ="Sorry, your email is not vaild, please double check.";
	var warnCust1 ="Please enter the url of your group booking solution.";
	var warnCust2 ="Please enter the url of your banner ads or select another method.";
	var getEmail = document.getElementById("email").value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	function warnBox(txt){ document.getElementById("warnbox_add").innerHTML=txt;}
	
	if(document.getElementById("site_name").value==""){
		jaxStatus("warn", warnName);
		warnBox(warnName);
	}
	else if(!filter.test(getEmail)){
		jaxStatus("warn", warnEmail);
		warnBox(warnEmail);
	}
	else if (document.getElementById("five_rooms").value=="1" && 
	(document.getElementById("five_rooms_url").value=="" || document.getElementById("five_rooms_url").value=="http://")){
		jaxStatus("warn", warnCust1);
		warnBox(warnCust1);
	}
	else if (document.getElementById("banner_ad").value=="3" && 
	(document.getElementById("banner_url").value=="" || document.getElementById("banner_url").value=="http://")){
		jaxStatus("warn", warnCust2);
		warnBox(warnCust2);
	}
	
	else{blnRtn = true; warnBox(""); document.getElementById("add_submit").value="Updating...";}
	return blnRtn;
}



function chkForm_su(){
	
	var blnRtn = false;
	var warnName ="Please name your site.";
	var warnEmail ="Sorry, your email is not vaild, please double check.";
	var warnCust1 ="Please enter the url of your group booking solution.";
	var warnCust2 ="Please enter the url of your banner ads or select another method.";
	var warnCust3 ="Please enter your Hitslink tracking codes.";
	var warnCust3a ="Please enter your Google Analytics tracking codes.";
	var warnCust4 ="Please enter your Google Adwords tracking ids.";
	var warnCust5 ="Please enter your Yahoo! Publisher Network tracking ids.";
	var warnCust6 ="Please enter your Microsoft adCenter tracking ids.";
	var getEmail = document.getElementById("email").value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	function warnBox(txt){ document.getElementById("warnbox_add").innerHTML=txt;}
	
	if(document.getElementById("site_name").value==""){
		jaxStatus("warn", warnName);
		warnBox(warnName);
	}
	else if(!filter.test(getEmail)){
		jaxStatus("warn", warnEmail);
		warnBox(warnEmail);
	}
	else if (document.getElementById("five_rooms").value=="1" && 
	(document.getElementById("five_rooms_url").value=="" || document.getElementById("five_rooms_url").value=="http://")){
		jaxStatus("warn", warnCust1);
		warnBox(warnCust1);
	}
	else if (document.getElementById("banner_ad").value=="3" && 
	(document.getElementById("banner_url").value=="" || document.getElementById("banner_url").value=="http://")){
		jaxStatus("warn", warnCust2);
		warnBox(warnCust2);
	}
	
	else if (document.getElementById("track").value=="hits" && 
	(document.getElementById("hits_acct").value=="" || document.getElementById("hits_loc").value=="" || document.getElementById("hits_type").value=="")){
		jaxStatus("warn", warnCust3);
		warnBox(warnCust3);
	}
	
	else if (document.getElementById("track").value=="gog" && document.getElementById("gog_acct").value==""){
		jaxStatus("warn", warnCust3a);
		warnBox(warnCust3a);
	}
	
	else if (document.getElementById("adwords").value==1 && document.getElementById("adwords_acct").value==""){
		jaxStatus("warn", warnCust4);
		warnBox(warnCust4);
	}
	
	else if (document.getElementById("yahoo").value==1 && document.getElementById("yahoo_acct").value==""){
		jaxStatus("warn", warnCust5);
		warnBox(warnCust5);
	}
	
	else if (document.getElementById("msn").value==1 && (document.getElementById("msn_acct").value=="" || document.getElementById("msn_acct2").value=="")){
		jaxStatus("warn", warnCust6);
		warnBox(warnCust6);
	}

	
	
	
	
	else{blnRtn = true; warnBox(""); document.getElementById("add_submit").value="Updating...";}

	 
	return blnRtn;
}




function add_tip(type, num){
	if (document.getElementById("add_tip_"+type).style.display=="none"){show('add_tip_'+type)}else{hide('add_tip_'+type)}
}



function mod_selected(type, num, name){
var arrRefid="";
	if (type=="cluster" || type=="concat_cluster" || type=="modify"){
		var i=0
		while (i<num){
			if (document.getElementById("data_list_chk"+i).checked==true){
				arrRefid=arrRefid+"^"+document.getElementById("dl_refid"+i).value;
			}
			i++;
		}
	}
	
	if (type=="cluster"){
		if (name!="^"){
			if (arrRefid!=""){
				arrRefid=name+arrRefid
				rs_SiteBox('data_list', 'newClust_'+arrRefid)
			}else{jaxStatus("warn", "Please select a few sites to group together.");}
		}else{jaxStatus("warn", "Please name this group");}
	}
	
	if (type=="concat_cluster"){
		if (arrRefid!=""){
			arrRefid=name+"^"+arrRefid
			rs_SiteBox('data_list', 'concatClust_'+arrRefid)
		}else{jaxStatus("warn", "Please select a site to add to this group.");}
	}

	if (type=="modify"){
		if (arrRefid!=""){
			rs_SiteBox('add_site', arrRefid, 'mod')
		}else{jaxStatus("warn", "Please select a few sites to modify.");}
	}
	
	if (type=="modify_single"){
		if (num!=""){
			rs_SiteBox('add_site', num,  'mod_single')
		}else{jaxStatus("warn", "Please select a site to modify.");}
	}
	
}


function rs_colors(refid){
	
	document.getElementById("clr_box_lnk").innerHTML="Updating&hellip;";
	
	var pass_colors="colors^";
	pass_colors=pass_colors+document.getElementById("clr1").value+"^";
	pass_colors=pass_colors+document.getElementById("clr2").value+"^";
	pass_colors=pass_colors+document.getElementById("clr3").value+"^";
	pass_colors=pass_colors+document.getElementById("clr4").value+"^";
	pass_colors=pass_colors+document.getElementById("clr5").value+"^";
	pass_colors=pass_colors+document.getElementById("clr6").value+"^";
	pass_colors=pass_colors+document.getElementById("clr7").value+"^";
	pass_colors=pass_colors+document.getElementById("clr8").value+"^";
	pass_colors=pass_colors+document.getElementById("clr9").value+"^";
	pass_colors=pass_colors+document.getElementById("clr10").value+"^";
	pass_colors=pass_colors+refid;
	rs_SiteBox('colors', pass_colors, 'clr_box');
	
}

function rs_color_update(color, id){
	
	document.getElementById(id).style.background="#"+color;
	
}


function clust_drop(){
	if (document.getElementById('clust_drop').style.display=='none') show('clust_drop'); else hide('clust_drop'); 
}

function deactivate(){
	document.getElementById('rs_chk_in_rstats_txt').value='mm/dd/yyyy';
	document.getElementById('rs_chk_in_rstats').value='';
}

function ph_def(type, number){
	document.getElementById(type).value=number;
}


function update_path(opt){
	if (opt!=""){
		var temp_mod2=gi("temp_mod2").value;
		if (temp_mod2=="") temp_mod2="template.html";
		gi("temp_box_path2").innerHTML=gi("temp_mod1").value+"/"+temp_mod2;
	}else{
		gi("temp_box_path2").innerHTML=gi("mod_single").value+"/template.html";
	}
}


function asf(type, opt){
	if (type=="color"){if (opt==1) showInline('clr_box'); else hide('clr_box');}
	if (type=="five"){if (opt==1) showInline('frl_box'); else hide('frl_box');}
	if (type=="banner"){
		if (opt==3){ hide('bu_box2'); show('bu_box'); }
		else if (opt==2) {hide('bu_box'); show('bu_box2');}
		else {hide('bu_box'); hide('bu_box2');}
	}
	if (type=="track"){
		if (opt=='hits'){			show('track_box');hide('track_box2');hide('track_box3');}
		else if (opt=='gog'){	hide('track_box');hide('track_box2');show('track_box3');}
		else if (opt==1){		hide('track_box'); show('track_box2');hide('track_box3');}
		else {							hide('track_box');hide('track_box2');hide('track_box3');}
		hide("add_tip_hits");
		hide("add_tip_gog");
	}
	if (type=="adwords"){	hide("add_tip_adwords"); if (opt==1) show('adwords_box'); else hide('adwords_box');}
	if (type=="yahoo"){		hide("add_tip_adwords"); if (opt==1) show('yahoo_box'); else hide('yahoo_box');}
	if (type=="msn"){			hide("add_tip_adwords"); if (opt==1) show('msn_box'); else hide('msn_box');}
	
	if (type=="home_mod"){hide("add_tip_home"); if (opt==1) show('hm_box'); else hide('hm_box');}
	
	if (type=="temp_mod1"){
		hide("add_tip_temp");
		if (opt!="") show('temp_box'); else hide('temp_box');
		update_path(opt);
	}
	
}


function clr_up(){
	if (document.getElementById("clr_box_lnk").innerHTML=="Done") document.getElementById("clr_box_lnk").innerHTML="Update colors";
}


function tog_users(div, id, flip){
	
	if (document.getElementById(div).style.display=='none'){
		show(div);
		change('data_list_row'+id, 'data_list_rowC');
	}else{
		hide(div);
		if (flip=='B') change('data_list_row'+id, 'data_list_rowB'); else change('data_list_row'+id, 'data_list_rowA');
	}
	
}



function mod_class(cls,styl,value) {
	
	var rls;
	
	if (document.all){
		rls = 'rules';
	}else if (document.getElementById) {
		rls = 'cssRules';
	}
	
	var isad = false;
	for (var X = 0; X < document.styleSheets.length; X++){
		for (var Y = 0; Y < document.styleSheets[X][rls].length; Y++) {
			if (document.styleSheets[X][rls][Y].selectorText == cls) {
				if(document.styleSheets[X][rls][Y].style[styl]){
					document.styleSheets[X][rls][Y].style[styl] = value;
					isad=true;
					break;
				}
			}
		}
		
		if(!isad){
			if(document.styleSheets[X].insertRule){
				document.styleSheets[X].insertRule(cls+' { '+styl+': '+value+'; }',document.styleSheets[X][rls].length);
			} else if (document.styleSheets[X].addRule) {
				document.styleSheets[X].addRule(cls,styl+': '+value+';');
			}
		}
	}
	
}

function tog_chart(day){
	if (day=="sc_td"){
		mod_class('.sc_td','z-index','30');
		mod_class('.sc_yd','z-index','20');
		mod_class('.sc_lw','z-index','10');
	}else if (day=="sc_yd"){
		mod_class('.sc_td','z-index','20');
		mod_class('.sc_yd','z-index','30');
		mod_class('.sc_lw','z-index','10');
	}else if (day=="sc_lw"){
		mod_class('.sc_td','z-index','10');
		mod_class('.sc_yd','z-index','20');
		mod_class('.sc_lw','z-index','30');
	}
	
}
















