// JavaScript Document
// Date Created: 2008/05/02
// Date Updated: 2008/06/10

// Functions used in Product Detail Pages
function switch_video_content(id,idToShow,numOfLoop,videoUrl,xmlpath){
	 /*	Note: I am assuming that video is going to be a falsh file
	 */
	 switch_div_content(id,idToShow,numOfLoop);
	// if((idToShow == "main_prod_container2" || idToShow == "main_prod_container3") && videoUrl != ""){
	// Uncomment the IF statement above when we make video as default on some prod detail pages 
	 if((idToShow == "main_prod_container3") && videoUrl != ""){
		var so = new SWFObject(videoUrl, "hello", "573", "252", "9", "#ffffff");
		so.addParam("wmode", "transparent");
		so.addParam("allowscriptaccess", "samedomain");
		if(xmlpath != ""){
			so.addParam("FlashVars", "xmlFileName=" + xmlpath);
		}
		so.write(idToShow);
		restFlashPlayer(idToShow);
	}
	// Delete the ELSE IF statement below when we make video as default on some prod detail pages
	else if(idToShow == "main_prod_container2"){
		document.getElementById("main_prod_container2").innerHTML = '<a href="mailto:newvideo@scottevest.com?subject=Please email me when this product video is available - thanks!"><img src="/media_new/images/pd_video_email.jpg" width="573" height="252" border="0" alt="" /></a>';		
	}
}

function switch_color_content(id,idToShow,numOfLoop,xrayUrl) {
 	/*	this function calls the "switch_div_content" 
		before that, it makes sure the main DIV which contains head-shot is display
	*/
	switch_div_content('main_prod_container','main_prod_container','3');
	switch_div_content(id,idToShow,numOfLoop);
	
	restFlashPlayer(idToShow);
}

// the Function resets the Flash Video to prevent Playing in the background of IE browsers
function restFlashPlayer(currDIVID){
	if( currDIVID != "" ){
		if(currDIVID != "main_prod_container2"){ document.getElementById("main_prod_container2").innerHTML = ''; /*IE Fix for keep playing FLV*/}
	}
}
/*
 These variables will keep track of currently highlighted btn and other state
*/
var curr_img_pd_btn = "";
 
function do_btnover_btnout(id,img_url){
 	if(curr_img_pd_btn != id){
		do_mover_mout(id,img_url);
	}	
}
 
function switch_bullet_content(id,idToShow,numOfLoop,highlighted){		
	switch_div_content(id,idToShow,numOfLoop);
}
 
 
function switch_desc_content(id,idToShow,numOfLoop,highlighted){
	switch_div_content(id,idToShow,numOfLoop);
}
 
function SWFDelegate(url,width,height,caption) {
	popLargerImg(url);
} 
 
pd_btn_spy_hv= new Image(573,252);
pd_btn_spy_hv.src = "/media_new/images/pd_video_email.jpg";


/* Functions to use with Feedback Form */ 
function onblur_field(elm,val){
	if( (typeof elm) != 'undefined' ){
		if(elm.value == ""){
			elm.value = val;
		}else if(elm.value == val){
			elm.value = "";
		}
	}
}

function check_human(f,chkbox){
	if (document.forms.length > 0) {
	var frm = document.forms[f] ;
		for (i=0; i<frm.length; i++) {				
			if(frm.elements[i].type == "checkbox"){
				if(frm.elements[i].name==chkbox && frm.elements[i].checked==true){ 
				 	return true;
					break;
				} 
			}
		} // End for
	}
	return false;
}

function check_feedback(f){ 
	var return_val = true;
	if (document.forms.length > 0) {
		var frm = document.forms[f] ;
		var err = "\nPlease Correct the following field(s):\n\n";
		if(frm.user_email.value == '' || frm.user_email.value == 'Email:'){
			err += "* Email\n";
			return_val = false;
		}else if (Trim(frm.user_email.value).length < 1) {
			err += "* Email\n";
			return_val = false;
		}else if (echeck(frm.user_email.value)==false){
			err += "* Email\n";
			frm.user_email.select();
			frm.user_email.focus();
			return_val = false;
		}
		
		if(frm.user_comments.value == '' || frm.user_comments.value == 'Comments:'){
			err += "* Comments\n";
			return_val = false;
		}else if (Trim(frm.user_comments.value).length < 1) {
			err += "* Comments\n";
			return_val = false;
		}
		
		if( !check_human(f,'no-robot') ){
			err += "* Check this box to prove you are not a robot\n";
			return_val = false;
		}
		
	    if(!return_val){ 
			alert(err+"\nThanks!"); 
			return false;
		}else{
			//frm.feedback_submit.value = "Sending...";
			return submit_feedback_form(f);
		}		
	}
}


/////////////////
/// AJAX Stuff
var xmlHttp = false;
function  createRequest() {
	if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if(window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	  if (!xmlHttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
}
function submit_feedback_form(f) {
	createRequest();
	
	var str = ''; var straction = '';
	if (document.forms.length > 0) {
	var frm = document.forms[f] ;
		for (i=0; i<frm.length; i++) {
		  if ( (frm.elements[i].type != "image") &&
			   (frm.elements[i].type != "reset") &&
			   (frm.elements[i].type != "submit") && 
			   (!frm.elements[i].disabled) ) {
				
			if(frm.elements[i].type == "checkbox"){
				if(frm.elements[i].checked==true){ 
				 str += '&' + frm.elements[i].name + '=' + frm.elements[i].value;
				} 
			}else{	
				str += '&' + frm.elements[i].name + '=' + encodeURIComponent(frm.elements[i].value);
			}
		  }
		} // End for
	}	
		
	if(frm.action != null && frm.action != "")
		straction = frm.action;
	else
		straction = 'media/phpscripts/feedback_process.php ';
	
	var url = straction + "?" + str.substring(1) + "&ajax=true";
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange=function(){
				if(xmlHttp.readyState!=4)
					return;
				if(xmlHttp.status==200){
					rewriteDiv(xmlHttp.responseText, 'prod_desc_container5');
				}
			};
	xmlHttp.send(null);
	
	return false;
		
} //end function submit_feedback_form
function rewriteDiv(respondtext, divcontent) {
  if (respondtext != "") {
	  document.getElementById(divcontent).innerHTML ='<span><strong>&nbsp;&nbsp;&nbsp;' + respondtext + ' <strong></span>' ;
  }  
} //end function rewriteDiv 
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

