//var file=location.href.substring(location.href.lastIndexOf('/')+1);
//if(file!='index_lite.php' && top.location!=location){
var hn = window.location.hostname;
if(hn!='ezcg.com' && top.location!=location){
  top.location.href=document.location.href;
}

function mngComms(content,id,site){

	var state=document.getElementById(content+"_"+id).style.visibility;
	if (state=="hidden" || state==''){
		document.getElementById(content+"_"+id).style.visibility="visible";
		callback.argument.el_id=id;
		callback.argument.dowhat="pic_comments";
		var sUrl=site+"/gallery/get_comments.php?id="+id;
		YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
	}else{
		document.getElementById(content+"_"+id).style.visibility="hidden";
	}
}

function mngDisplay(id){

	var dis_state=document.getElementById(id).style.display;
	if (dis_state=="none" || dis_state==''){
		document.getElementById(id).style.display="block";
	}else if (dis_state=="block"){
		document.getElementById(id).style.display="none";
	}

}

function mngVisibility(id){
	var vis_state=document.getElementById(id).style.visibility;
	if (vis_state=="hidden" || vis_state==''){
		document.getElementById(id).style.visibility="visible";
	}else if (vis_state=="visible"){
		document.getElementById(id).style.visibility="hidden";
	}

}

function checkAll(form_name,dowhat){

	var elem = document.getElementById(form_name).elements;

	for (i = 0; i<elem.length; i++){
		if (elem[i].type=='checkbox'){
			if (dowhat=='check_all')elem[i].checked = true ;
			else elem[i].checked = false;
		}
	}

}

function showContent(movie, width, height, quality,bgcolor){

	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" WIDTH="' + width+'"');
	document.write(' HEIGHT="' + height + '" id="FlashContent">');
	document.write('<PARAM NAME="movie" VALUE="' + movie + '"><PARAM NAME="quality" VALUE="' + quality + '">');
	document.write('<PARAM NAME="AllowScriptAccess" VALUE="never"><EMBED src="' + movie + '"');
	document.write(' quality="' + quality + '" WIDTH="' + width + '" HEIGHT="' + height + '" NAME="FlashContent"');
	document.write(' AllowScriptAccess="never" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
  document.write('<param name="bgcolor" value="'+bgcolor+'">');
	document.write('</EMBED></OBJECT>');
}

function countChars(max,id,output){

	var val=document.getElementById(id).value.length;
	document.getElementById(output).value=max-val;

	if (max-val<0){
		document.getElementById(id).value=document.getElementById(id).value.substring(0,max);
		alert("Max character limit for text field reached.");
		document.getElementById(output).value=max-document.getElementById(id).value.length;
	}	

} 

var submit_count=0;

function submitOnce(){

	submit_count++;
	if (submit_count>1){
		submit_count=0;
		alert("Please wait for the form to finish processing before hitting submit again.");
		return false;
	}

}


function createRequestObject(){

  var ro;
  var browser = navigator.appName;

  if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    ro = new XMLHttpRequest();
  }

  return ro;

}

var http = createRequestObject();

function buildParams(id_str){

	var id_arr=new Array();
	id_arr=id_str.split(",");

	var param_str='';

	for(i=0;i<id_arr.length;i++){
		param_str+=id_arr[i]+"="+escape(document.getElementById(id_arr[i]).value)+"&";
	}

	return param_str;		

}

function sndReq(url,method,id_str) {

	if (method==null)method='get';
	if (method=='get' && id_str!=null){
		params=buildParams(id_str);
		url=url+"?"+params;
	}
  http.open(method, url);
  http.onreadystatechange = handleResponse;
	var params=null;

	if (method=='post'){
		params=buildParams(id_str);
  	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	http.setRequestHeader("Content-length", params.length);
  	http.setRequestHeader("Connection", "close");
	}

  http.send(params);

}

function handleResponse(){

  if(http.readyState == 4){

    var response = http.responseText;

    var arr = new Array();

    if(response.indexOf('|' != -1)) {
      arr = response.split('|');
			var result=arr[0];
			if (result=='error_alert'){
				alert(arr[1]);
				return;
			}else{
				if (result=="comments"){
					ajaxCommentsFeedback(arr[1]);
				}else if (result=="profile"){
					ajaxProfileFeedback(arr[1]);
				}else if (result=="poll"){
					ajaxPollFeedback(arr[1]);
				}else if (result=="rating"){
					ajaxRatingFeedback(arr[1]);
				}else if (result=="tag"){
					ajaxTag(arr[1]);
				}else if (result=="activity"){
					ajaxActivity(arr[1]);
				}else if (result=="get_pics"){
					ajaxBlogPics(arr[1]);
				}else if (result=="items_my"){
					ajaxItemsMy(arr[1]);
				}else if (result=='store'){
					ajaxStore(arr[1]);
				}else if (result=='memory'){
					ajaxMemory(arr[1]);
				}else if (result=='thanks'){
					ajaxThanks(arr[1]);
				}else if (result=='check_my'){
					ajaxCheckMy(arr[1]);
				}else if (result=='check_store'){
					ajaxCheckStore(arr[1]);
				}else if (result=='redirect'){
					window.location=arr[1];
				}
			}

		}

	}

}
