//call HideShowContent('popular=inline','rating=none','rating=block','wishes=toggle-inline') where popular, rating and whishes are div id's
function WLCOMHideShowContent() {
   for (i = 0;i < arguments.length;i++)
   {
		var divid = arguments[i].split("=")[0];
		var sh_tmp = arguments[i].split("=")[1];
		var sh = sh_tmp.split("-")[0];
		var tog = sh_tmp.split("-")[1];
		
		if (sh == "toggle") {
		
		var cur = document.getElementById(divid).style.display;
		if (tog != cur) {sh=tog} else {sh="none"}
			document.getElementById(divid).style.display = sh;
		} 
		else 
		{
			document.getElementById(divid).style.display = sh;
		}
		// deactivate active buble drop if there's one.
		if (sh == "none") if (document.getElementById(divid).className=='active') document.getElementById(divid).className='';

   }
}

function WLCOMChangeClassName() {
   for (i = 0;i < arguments.length;i++)
   {
		var divid = arguments[i].split("=")[0];
		var cn_tmp = arguments[i].split("=")[1];
		var cn = cn_tmp.split("-")[0];
		var tog = cn_tmp.split("-")[1];
		if(tog){
			var cur = document.getElementById(divid).className;
			if (tog != cur) {cn=tog} else {cn="zzzz"}
		}
		document.getElementById(divid).className=cn;
   }
}



// call CopyFormField('first_name','screen_name') where firs_name is copied to screen_name which are id's
function WLCOMCopyFormField() {
	// if (document.getElementById(arguments[1]).value == ''){
	   document.getElementById(arguments[1]).value = document.getElementById(arguments[0]).value;
	//}
}


function WLCOManychecked(FormName, FieldName){
	var checkthere=false;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	var countCheckBoxes = objCheckBoxes.length;
	// if there's more than one, count is defined
	for(var i = 0; i < countCheckBoxes; i++){
		if(objCheckBoxes[i].checked) checkthere=true;
	}
	//if there's one checkbox, count isn't defined, so we can see if it's checked
	if (!countCheckBoxes){
		if (objCheckBoxes.checked) checkthere=true;
	}
	return checkthere;
}

function WLCOMSetAllCheckBoxes(FormName, AllCheckbox, FieldName){
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	//if(!objCheckBoxes)
		//return;
	var CheckValue = document.forms[FormName].elements[AllCheckbox].checked;
	var countCheckBoxes = objCheckBoxes.length;
	//if there's one checkbox, count isn't defined, so we can set the single checkbox
	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 WLCOMpopwin(){
	
		var winname = 'temp_popwin';
		var prms = "height=725,width=700,toolbar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,titlebar=yes";
		for (i = 0; i < arguments.length; i++) {
			if (i == 0 ) url = arguments[i];
			if (i == 1 ) winname = arguments[i];
			if (i == 2 ) prms = arguments[i];
		}

		var temp_popwin=window.open(url,winname, prms);
		temp_popwin.focus();
	}


	function WLCOMPG_addtowl(FormName){
		//do something to trigger light box
		//post the add to wishlist form to the light box
		document.forms[FormName].submit();
	}

	
function WLCOMchangedropselect(dropid, val){
	var dropobj = document.getElementById(dropid);
	for(i=0;i<dropobj.length;i++){
		if(dropobj.options[i].value==val){
			dropobj.selectedIndex=i
		}
	}
}


function WLCOMGrabUrl(fullUrl, divName)
{
	ColdFusion.navigate(fullUrl, divName)
	//DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'GrabUrl', fullUrl+'&hcaSuppressDebug=1', divName, resultGrabUrl);
	return true;
}
	
function WLCOMPostUrl(fullUrl, divName)
{
	//???? ColdFusion.navigate(fullUrl, divName)
	return true;
}

function WLCOMresultGrabUrl(RetVarFromGrabUrl)
{
	//alert(RetVarFromGrabUrl.newcontents);
	document.getElementById(RetVarFromGrabUrl.divname).innerHTML = RetVarFromGrabUrl.newcontents;
	try{
		if(RetVarFromGrabUrl.doafter)
		{
			eval(RetVarFromGrabUrl.doafter);
			
		}
	}
	catch(e)
		{}
	return true;
}

function WLCOMresizeWindow(windowName,width,height){
	//Get window object       
	var myWindow = ColdFusion.Window.getWindowObject(windowName);
	
	//use the setContentSize function WLCOMto resize the window.       
	myWindow.setContentSize(width, height);       
	myWindow.center();

	//var el = myWindow.getEl();
	//var s = myWindow.shadow.el;
	//s.fadeOut({duration: .5})
}

function WLCOMresizeImages(){
	// first arg img id, second is max width, third is max height
	for (i = 0;i < arguments.length-2;i++){
		var id=i;
		i=i+1;
		var w=i;
		i=i+1;
		var h=i;
		var img = document.getElementById(arguments[id]);
		var maxWidth = arguments[w];
		var maxHeight = arguments[h];
	
		var newWidth = img.width;
		var newHeight = img.height;
		
		if(img.width > img.height && img.width>maxWidth){
		  newWidth = maxWidth;
		  newHeight = parseInt(img.height + (maxWidth - img.width)/img.width*img.height); 
		}
		else if(img.width < img.height && img.height>maxHeight){
		  newHeight= maxHeight;
		  newWidth = parseInt(img.width + (maxHeight - img.height)/img.height*img.width); 
		}
		else if(img.width = img.height && img.height>maxHeight){
		  newWidth = maxWidth;
		  newHeight= maxHeight;
		  newHeight = parseInt(img.height + (maxWidth - img.width)/img.width*img.height); 
		}

		document.getElementById(arguments[id]).style.width = newWidth + "px";
		document.getElementById(arguments[id]).style.height = newHeight + "px"

	}
 }
 
 
function WLCOMAddAsFriend(id) {
	ColdFusion.navigate('/user/frm_become_friends.htm?request_friend_id_list=' + id, 'thecfwindow_body');
	resizeWindow('thecfwindow',800,200);
	ColdFusion.Window.show('thecfwindow');
}

function WLCOMSet_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function WLCOMGet_Cookie( check_name ) {
	// with this test document.cookie.indexOf( name + "=" );
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function WLCOMgetQueryVariable(variable) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
} 
