// JavaScript Document

var WarnColor = "#000000";
var WarnBgColor = "#FFDD88";

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_DisplayPackage(n) {
  var p = new Array ('none','none','none','none');
  p[n] = 'block';
  MM_changeProp('celoptionpopupA', '','style.display',p[0]);
  MM_changeProp('celoptionpopupB1','','style.display',p[1]);
  MM_changeProp('celoptionpopupB2','','style.display',p[2]);
  MM_changeProp('celoptionpopupC', '','style.display',p[3]);
}

function HideIt(code) {
  var account; var subject;
  if (code == "sb") {
    account = "sbammel";
    subject = "Asian%20Language%20DTP%20Inquiry"; }
  if (code == "sb-translation") {
    account = "sbammel";
    subject = "Translation%20Services%20Inquiry"; }
  if (code == "sb-privacy") {
    account = "sbammel";
    subject = "Privacy%20Inquiry"; }
  else if (code == "ca-inquiry") {
    account = "cards";
    subject = "Card%20Inquiry%20or%20Order"; }
  else if (code == "ca-artwork") {
    account = "cards";
    subject = "Card%20Artwork"; }
  var s = '<a onclick="return HideIt2(this,\''+account+'\',\''+subject+'\');" href="";>'+account+'@asianlanguagedtp.com</a>';
  document.write( s);
}

function HideIt2(el,acct,subj) {
    this.location.href = 'mailto:'+acct+'@asianlanguagedtp.com?subject='+subj;
	return false;
}

function HidePaypal(el) {
	var h = 'https://www.paypal.com/xclick/business=projects@asianlanguagedtp.com'
	    + '&amp;item_name=Asian-Language+Business+Card(s)'
		+ '&amp;return=http://www.asianlanguagedtp.com/index.php';
	el.href = h;
	return true;
}

// Used to Hide projects e-mail address in east-asian_business_training_materials.php
function HideProjects(form) {
  form.business.value = "projects@asianlanguagedtp.com";
  form.receiver_email.value = "projects@asianlanguagedtp.com";
  return true;
}

function isValidEmail(strEmail) {
  return (strEmail.search(/^[^@]+@[^@]+[.][a-z]{2,}$/i) != -1); 
}
	
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}


// *** Scripts for Feedback Form ***

var fbTesting = false;
var fbSavedColor = new Array();
var fbSavedBgColor = new Array();
var fbIsWarn;
var fbTheForm;
var fbIsHide;

function fbSubmitForm(form) {
  try {
    if (!fbValidate(form)) {
	  return false; }
    else {
      form.action = "feedback_confirmation.php";
      form.SendFeedback.value = "YeS";  // try to block bots
      return true; }
  } catch (e) {
      alert( "Code Error: "+e.message);
	  return false;
  }
}

function fbValidate(form) {
    if (fbIsHide) { fbIsHide=false; return false; }
	if (fbTesting) alert( "validateform()");
	try {
		fbTheForm = form; fbIsWarn = false;
		var ok_EmailAddress    = isValidEmail(form.EmailAddress.value);
		var ok_FeedbackMessage = (trim(form.FeedbackMessage.value) != "");
		fbShowWarn( true, "EmailAddress",  ok_EmailAddress);
		fbShowWarn( true, "FeedbackMessage",  ok_FeedbackMessage);
		var ok_fb_captcha_code = fbIsWarn || CheckCaptcha("fb_captcha");
		if (!ok_fb_captcha_code) ajaxCaptchaGetNew("fb_captcha");
		fbShowWarn( true, "fb_captcha_code",  ok_fb_captcha_code);
		var onoff = fbIsWarn ? "block" : "none";
		document.getElementById("FeedbackWarn").style.display = onoff;
	} catch (e) {
        if (fbTesting) alert( "Code Error");
		return false;
	}
	if (!fbIsWarn) {
	    fbTheForm.fbSubmit.disabled = "disabled";
		fbTheForm.fbCancel.disabled = "disabled";
		document.getElementById("FeedbackWarn").style.display = "none";
		document.getElementById("FeedbackWait").style.display = "block"; }
	if (fbTesting) alert( "return false");
	return !fbTesting && !fbIsWarn;
}

function fbShowWarn( isvisible, elname, ok) {
	if (ok && fbSavedColor[elname]==undefined) return;
	eval ("var el = fbTheForm."+elname);
	if (fbSavedColor[elname] == undefined) {
		fbSavedColor[elname] = el.style.color;
		fbSavedBgColor[elname] = el.style.backgroundColor; }
	if (ok) {
		el.style.color = fbSavedColor[elname];
		el.style.backgroundColor = fbSavedBgColor[elname]; }
	else {
		el.style.color = WarnColor;
		el.style.backgroundColor = WarnBgColor; }
	if (!ok && isvisible && !fbIsWarn) {
		try { eval ("fbTheForm."+elname+".focus()"); } catch(e) { }
		fbIsWarn = true; }
}

function fbHide() {
    fbIsHide = true;
    MM_changeProp('quiz','','style.display','none','DIV');
	MM_goToURL('parent','#bottomA');
    fbShowWarn( true, "EmailAddress",  true);
	fbShowWarn( true, "FeedbackMessage",  true);
	fbShowWarn( true, "fb_captcha_code",  true);
	document.getElementById("fb_captcha_code").value = "";
	document.getElementById("FeedbackWarn").style.display = "none";
	document.getElementById("FeedbackWait").style.display = "none";
    fbIsWarn = false;
	return document.MM_returnValue
}

//Simple Validation
//function fbValidateform) {
//  if (!isValidEmail(form.EmailAddress.value)) {
//	alert ("Invalid E-Mail address, please correct.");
//	return false; }
//  if (trim(form.FeedbackMessage.value) == "") {
//	alert ("Please enter a feedback message.");
//	return false; }
//  if (!CheckCaptcha("fb_captcha")) {
//    alert ("Please re-enter security code.");
//	return false; }
//  return true;
//}


//function dumpProps(obj, parent) {
//   // Go through all the properties of the passed-in object 
//   for (var i in obj) {
//      // if a parent (2nd parameter) was passed in, then use that to 
//      // build the message. Message includes i (the object's property name) 
//      // then the object's property value on a new line 
//      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
//      // Display the message. If the user clicks "OK", then continue. If they 
//      // click "CANCEL" then quit this level of recursion 
//      if (!confirm(msg)) { return; }
//      // If this property (i) is an object, then recursively process the object 
//      if (typeof obj[i] == "object") { 
//         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
//} } }
